@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800;900&family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.font-heading {
  font-family: 'Manrope', sans-serif;
}

.font-mono2 {
  font-family: 'JetBrains Mono', monospace;
}

::selection {
  background: #0f172a;
  color: #fff;
}

.scroll-thin::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.scroll-thin::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 999px;
}

/* Form controls */
.agenda-input {
  width: 100%;
  max-width: 100%;
  display: block;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  font-size: 1rem;
  line-height: 1.25rem;
  color: #0f172a;
  background: #fff;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.agenda-input:focus {
  outline: none;
  border-color: #0f172a;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #0f172a;
}

.agenda-checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: #0f172a;
  cursor: pointer;
}

/* Event datetime form */
.event-datetime-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
}

.event-time-row {
  display: contents;
}

#calendar-view {
  contain: layout style;
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: transparent;
}

.dialog-overlay.hidden {
  display: none;
}

.dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  touch-action: manipulation;
}

.dialog-panel {
  position: relative;
  z-index: 1;
}

.dialog-sheet-handle {
  display: none;
}

html.dialog-open,
body.dialog-open {
  overflow: hidden !important;
  overscroll-behavior: none;
  height: 100%;
}

html.dialog-open #app,
html.dialog-open #calendar-view,
html.dialog-open main,
html.dialog-open .overflow-auto {
  overflow: hidden !important;
}

html.dialog-open .dialog-panel {
  touch-action: pan-y;
}

html.dialog-open .app-shell {
  overflow: hidden;
}

.dialog-panel.flex.flex-col .dialog-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 900px) {
  .dialog-panel.flex.flex-col {
    max-height: min(90vh, 40rem);
    overflow: hidden;
  }

  .dialog-panel.flex.flex-col .dialog-sheet-body,
  .dialog-panel.flex.flex-col > form.dialog-sheet-body {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  #categories-dialog-overlay .dialog-panel.flex.flex-col {
    max-height: min(90vh, 44rem);
  }

  #categories-dialog-overlay .categories-dialog-body {
    overflow-y: auto;
    min-height: 0;
  }
}

/* Aviso: pacientes por hora por preencher */
.calendar-day-warning {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  color: #d97706;
}

.calendar-day-warning svg {
  width: 0.75rem;
  height: 0.75rem;
}

.mini-day-incomplete {
  position: relative;
}

.mini-day-incomplete::after {
  content: "";
  position: absolute;
  bottom: 1px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 9999px;
  background: #f59e0b;
}

.week-day-warning {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
  color: #d97706;
  vertical-align: middle;
}

.week-day-warning svg {
  width: 0.7rem;
  height: 0.7rem;
}

.event-chip-incomplete {
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.55);
}

.calendar-day--incomplete {
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.35);
}


/* Sidebar toggle (header) */
.sidebar-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  background: #fff;
  color: #475569;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}

.sidebar-toggle-btn.is-hidden {
  display: none !important;
}

.sidebar-close-btn {
  display: none;
}

.sidebar-toggle-desktop {
  display: none;
}

.sidebar-toggle-mobile {
  display: flex;
}

.sidebar-toggle-desktop-header {
  display: none;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.45);
}

#app.sidebar-open .sidebar-backdrop:not(.hidden) {
  display: block;
}

.toast-container {
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  right: max(1rem, env(safe-area-inset-right, 0px));
  left: auto;
}

/* Mobile event chips — horas visíveis */
.event-chip-mobile .event-chip-time {
  color: inherit;
  opacity: 1;
  margin-bottom: 0.125rem;
  letter-spacing: -0.02em;
}

.event-chip-mobile .event-chip-title {
  line-height: 1.2;
}

.calendar-day-earn {
  letter-spacing: -0.03em;
}

@media (max-width: 899px) {
  .calendar-day-earn {
    display: none !important;
  }
}

/* ===== MOBILE (max 899px) ===== */
@media (max-width: 899px) {
  #app {
    height: 100dvh;
    max-height: 100dvh;
  }

  main {
    min-height: 0;
    overflow: hidden;
  }

  .app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: #fff;
    flex-shrink: 0;
  }

  #calendar-view {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-toggle-desktop,
  .sidebar-toggle-desktop-header {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: min(18rem, 88vw);
    max-width: min(18rem, 88vw);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateX(-105%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: none;
  }

  #app.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
  }

  /* X encostado à direita do cabeçalho da sidebar */
  .sidebar-close-btn {
    display: none;
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    background: #fff;
    color: #475569;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  }

  #app.sidebar-open .sidebar-close-btn {
    display: flex;
  }

  #app.sidebar-open .sidebar-toggle-btn {
    display: none !important;
  }

  html.dialog-open .sidebar-toggle-btn {
    display: none !important;
  }

  .sidebar-brand {
    padding-left: 1.25rem;
    padding-right: 1rem;
  }

  .app-header {
    position: relative;
    z-index: 30;
  }

  /* Modal bottom sheet */
  .dialog-overlay:not(.hidden) {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0;
    align-items: stretch;
  }

  .dialog-panel {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    max-height: min(85dvh, 85vh) !important;
    border-radius: 1rem 1rem 0 0 !important;
    touch-action: pan-y;
    overscroll-behavior: contain;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    flex-shrink: 0;
  }

  .dialog-panel.flex.flex-col .dialog-sheet-body,
  .dialog-sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scroll-padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
  }

  .dialog-sheet-body::after {
    content: "";
    display: block;
    height: max(1.5rem, env(safe-area-inset-bottom, 0px));
  }

  .dialog-sheet-drag-zone {
    position: relative;
    flex-shrink: 0;
    min-height: 3.5rem;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .dialog-sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    min-height: 1.75rem;
    width: 100%;
    padding: 0.75rem 1rem 0.25rem;
    cursor: inherit;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .dialog-sheet-handle-bar {
    display: block;
    width: 2.75rem;
    height: 0.3125rem;
    border-radius: 999px;
    background: #94a3b8;
    opacity: 0.5;
    pointer-events: none;
  }

  .dialog-panel.is-sheet-dragging {
    will-change: transform;
  }

  .dialog-panel.is-sheet-dragging .dialog-sheet-drag-zone,
  .dialog-panel.is-sheet-dragging .dialog-sheet-handle {
    cursor: grabbing;
  }

  #calendar-view .week-scroll {
    -webkit-overflow-scrolling: touch;
  }

  #category-buttons {
    grid-template-columns: 1fr;
  }

  .toast-container {
    left: max(1rem, env(safe-area-inset-left, 0px));
    right: max(1rem, env(safe-area-inset-right, 0px));
  }

  .toast-container .toast-item {
    width: 100%;
  }

  /* Data + horas no modal — igualar larguras (iOS) */
  #event-datetime-form,
  .event-datetime-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
  }

  #event-datetime-form .event-date-input,
  #event-datetime-form input[type="date"],
  .event-datetime-form .event-date-input,
  .event-datetime-form input[type="date"] {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 48px;
    display: block;
    -webkit-appearance: none;
    appearance: none;
  }

  #event-datetime-form .event-time-row,
  .event-datetime-form .event-time-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
  }

  #event-datetime-form .event-time-input,
  #event-datetime-form input[type="time"],
  .event-datetime-form .event-time-input,
  .event-datetime-form input[type="time"] {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 48px;
    display: block;
    font-size: 1rem;
    -webkit-appearance: none;
    appearance: none;
  }
}

@media (min-width: 900px) {
  .sidebar-close-btn {
    display: none !important;
  }

  .sidebar-toggle-mobile {
    display: none !important;
  }

  .sidebar-toggle-desktop-header {
    display: none;
  }

  #app.sidebar-collapsed .sidebar-toggle-desktop-header {
    display: flex;
  }

  .sidebar-toggle-desktop {
    display: flex;
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
  }

  #app.sidebar-collapsed .sidebar-toggle-desktop {
    display: none !important;
  }

  .sidebar {
    width: 18rem;
    min-width: 18rem;
    flex-shrink: 0;
    transition: width 0.25s ease, min-width 0.25s ease, border-color 0.25s ease;
    overflow: hidden;
  }

  #app.sidebar-collapsed .sidebar {
    width: 0 !important;
    min-width: 0 !important;
    border-right-color: transparent;
    pointer-events: none;
  }

  #app.sidebar-collapsed .sidebar-body,
  #app.sidebar-collapsed .sidebar-footer {
    display: none;
  }

  .event-datetime-form .event-time-input {
    width: 7rem;
    max-width: 7rem;
  }
}

/* Toast */
.toast-item {
  pointer-events: auto;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  animation: toast-in 0.2s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (display-mode: standalone) {
  html, body {
    touch-action: manipulation;
    overscroll-behavior: none;
  }
}

.auth-shell {
  padding-top: max(2rem, env(safe-area-inset-top, 0px));
  padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px));
  padding-left: max(1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
}

/* Categorias — ícones visuais */
.category-icon-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.375rem;
  padding: 0.25rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  background: #f8fafc;
  overflow: visible;
  max-height: none;
  contain: layout style;
}

.category-icon-option {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  background: #fff;
  color: #475569;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  touch-action: manipulation;
}

.category-icon-option:hover {
  border-color: #94a3b8;
  background: #f1f5f9;
}

.category-icon-option.is-selected {
  border-color: #0f172a;
  background: #f1f5f9;
  color: #0f172a;
  box-shadow: inset 0 0 0 1px #0f172a;
}

.category-form--editing {
  margin: 0 -0.5rem;
  padding: 1rem 0.5rem 0.5rem !important;
  border: 2px solid #0f172a !important;
  border-radius: 0.75rem;
  background: #f8fafc;
}

.category-list-item--editing {
  scroll-margin-top: 0.5rem;
}

@media (max-width: 899px) {
  .category-icon-picker {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.5rem;
    padding: 0.5rem;
  }

  #categories-dialog-overlay .dialog-panel {
    display: flex !important;
    flex-direction: column !important;
    max-height: min(90dvh, 90vh) !important;
  }

  #categories-dialog-overlay .categories-dialog-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}

@media (min-width: 900px) {
  .category-icon-picker {
    max-height: 10.5rem;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}
