/* ─── CSS Custom Properties ─────────────────────────────────────────────────── */
:root {
  --teal:         #4A9B8E;
  --teal-light:   #6AB5AA;
  --teal-dark:    #357A6F;
  --teal-bg:      #EBF5F3;

  --blue:         #3B82F6;
  --blue-bg:      #EFF6FF;
  --yellow:       #F59E0B;
  --yellow-bg:    #FFFBEB;
  --green:        #22C55E;
  --green-bg:     #F0FDF4;
  --red:          #EF4444;
  --red-bg:       #FEF2F2;
  --grey:         #6B7280;
  --grey-bg:      #F9FAFB;

  --bg-page:      #F0F4F3;
  --bg-card:      #FFFFFF;
  --bg-sidebar:   #FFFFFF;

  --text-main:    #1A2E2C;
  --text-muted:   #6B7280;
  --text-light:   #9CA3AF;

  --border:       #E5E7EB;
  --border-focus: #4A9B8E;

  --shadow-sm:    0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.14);

  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    16px;
  --radius-xl:    20px;

  --nav-height:   64px;
  --header-height: 56px;
  --transition:   0.2s ease;
}

/* ─── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  overscroll-behavior: none;
}
a { color: var(--teal); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ─── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Layout ────────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
#app-header {
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  position: sticky; top: 0; z-index: 50;
  flex-shrink: 0;
}
.header-title { display: flex; align-items: center; gap: 0.625rem; }
.header-title .logo { font-size: 1.4rem; }
.header-title h1 { font-size: 1.1rem; font-weight: 700; color: var(--teal); }
.header-date { font-size: 0.78rem; color: var(--text-muted); text-align: right; }

/* Main content area */
#app-main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Views */
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 1rem;
  padding-bottom: calc(var(--nav-height) + 1rem);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.view.active {
  opacity: 1;
  pointer-events: auto;
}

/* Bottom navigation */
#app-nav {
  height: var(--nav-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.5rem 0;
  transition: color var(--transition);
  cursor: pointer;
}
.nav-item .nav-icon { font-size: 1.4rem; line-height: 1; }
.nav-item.active { color: var(--teal); }
.nav-item.active .nav-icon { transform: scale(1.1); }

/* ─── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1rem; }

/* ─── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.375rem; text-transform: uppercase; letter-spacing: 0.04em; }
.form-input, .form-select, .form-textarea {
  display: block;
  width: 100%;
  padding: 0.75rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1rem;
  color: var(--text-main);
  background: var(--bg-card);
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(74,155,142,0.15);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.875rem center; padding-right: 2.5rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.toggle-group { display: flex; align-items: center; gap: 0.75rem; }
.toggle { position:relative; width:48px; height:26px; }
.toggle input { opacity:0; width:0; height:0; }
.toggle-slider {
  position:absolute; inset:0;
  background: var(--border);
  border-radius: 13px;
  transition: background var(--transition);
  cursor: pointer;
}
.toggle-slider::after {
  content:'';
  position:absolute;
  width:20px; height:20px;
  background: white;
  border-radius: 50%;
  top:3px; left:3px;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-slider { background: var(--teal); }
.toggle input:checked + .toggle-slider::after { transform: translateX(22px); }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem; font-weight: 600;
  border: none; cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary   { background: var(--teal);  color: white; }
.btn-primary:hover:not(:disabled) { background: var(--teal-dark); }
.btn-secondary { background: var(--bg-page); color: var(--text-main); border: 1.5px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); }
.btn-danger    { background: var(--red-bg); color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red); color: white; }
.btn-success   { background: var(--green-bg); color: var(--green); }
.btn-success:hover:not(:disabled) { background: var(--green); color: white; }
.btn-sm { padding: 0.45rem 0.875rem; font-size: 0.8rem; }
.btn-icon { padding: 0.5rem; border-radius: var(--radius-sm); }
.btn-full { width: 100%; }

/* ─── Status Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  font-size: 0.75rem; font-weight: 600;
  white-space: nowrap;
}
.badge-IN_ATTESA        { background: var(--blue-bg);   color: var(--blue);   }
.badge-SMS_INVIATO      { background: var(--yellow-bg); color: var(--yellow); }
.badge-CONFERMATO       { background: var(--green-bg);  color: var(--green);  }
.badge-CANCELLATO       { background: var(--red-bg);    color: var(--red);    }
.badge-CONFERMATO_MANUALE { background: var(--grey-bg); color: var(--grey);   }

/* ─── Appointment Card ───────────────────────────────────────────────────────── */
.appt-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
  border-left: 4px solid transparent;
}
.appt-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.appt-card.status-IN_ATTESA        { border-left-color: var(--blue);   }
.appt-card.status-SMS_INVIATO      { border-left-color: var(--yellow); }
.appt-card.status-CONFERMATO       { border-left-color: var(--green);  }
.appt-card.status-CANCELLATO       { border-left-color: var(--red);    opacity: 0.7; }
.appt-card.status-CONFERMATO_MANUALE { border-left-color: var(--grey); }

.appt-time { font-weight: 700; font-size: 1rem; color: var(--teal); min-width: 48px; }
.appt-info { flex: 1; min-width: 0; }
.appt-name { font-weight: 600; font-size: 0.95rem; truncate; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-type { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-status-icon { font-size: 1.1rem; }

/* ─── Calendar ───────────────────────────────────────────────────────────────── */
.cal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.cal-header h2 { font-size: 1.1rem; font-weight: 700; }
.cal-nav-btn {
  background: var(--bg-card); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.4rem 0.75rem;
  font-size: 1rem; cursor: pointer;
  transition: all var(--transition);
}
.cal-nav-btn:hover { border-color: var(--teal); color: var(--teal); }

.view-tabs {
  display: flex; background: var(--bg-page); border-radius: var(--radius-md);
  padding: 3px; margin-bottom: 1rem; gap: 2px;
}
.view-tab {
  flex: 1; padding: 0.5rem; border: none; background: transparent;
  border-radius: calc(var(--radius-md) - 3px);
  font-size: 0.82rem; font-weight: 600; color: var(--text-muted);
  cursor: pointer; transition: all var(--transition);
}
.view-tab.active { background: var(--bg-card); color: var(--teal); box-shadow: var(--shadow-sm); }

/* Monthly grid */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.month-dow {
  text-align: center; font-size: 0.7rem; font-weight: 700;
  color: var(--text-muted); padding: 0.5rem 0; text-transform: uppercase;
}
.month-day {
  background: var(--bg-card); border-radius: var(--radius-sm);
  min-height: 60px; padding: 4px 5px;
  cursor: pointer; transition: all var(--transition);
  position: relative;
}
.month-day:hover { background: var(--teal-bg); }
.month-day.other-month { opacity: 0.35; }
.month-day.today { box-shadow: inset 0 0 0 2px var(--teal); }
.month-day.selected { background: var(--teal-bg); }
.day-num {
  font-size: 0.8rem; font-weight: 600; margin-bottom: 3px;
  width: 22px; height: 22px; display: flex; align-items:center; justify-content:center;
  border-radius: 50%;
}
.today .day-num { background: var(--teal); color: white; }
.day-dots { display: flex; flex-wrap: wrap; gap: 2px; }
.day-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink:0; }
.dot-IN_ATTESA        { background: var(--blue);   }
.dot-SMS_INVIATO      { background: var(--yellow); }
.dot-CONFERMATO       { background: var(--green);  }
.dot-CANCELLATO       { background: var(--red);    }
.dot-CONFERMATO_MANUALE { background: var(--grey); }

/* Weekly grid */
.week-grid { display: grid; grid-template-columns: 48px repeat(7, 1fr); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--bg-card); }
.week-header { background: var(--bg-page); border-bottom: 1px solid var(--border); padding: 0.5rem 0.25rem; text-align: center; }
.week-header.time-col { }
.week-day-hdr { font-size: 0.75rem; font-weight: 700; }
.week-day-hdr .wday { color: var(--text-muted); }
.week-day-hdr .wdate { font-size: 1rem; color: var(--text-main); }
.week-day-hdr.today .wdate { color: var(--teal); font-weight: 900; }
.week-time-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 2px 4px; font-size: 0.68rem; color: var(--text-muted); height: 40px; display:flex; align-items:flex-start; }
.week-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); height: 40px; position: relative; }
.week-cell:last-child { border-right: none; }
.week-appt-block {
  position: absolute; left: 1px; right: 1px;
  border-radius: 4px; padding: 2px 4px;
  font-size: 0.68rem; font-weight: 600;
  overflow: hidden; cursor: pointer;
  z-index: 2;
}

/* Daily list */
.day-list { display: flex; flex-direction: column; gap: 0.5rem; }
.day-empty { text-align: center; color: var(--text-muted); padding: 3rem 1rem; font-size: 0.95rem; }

/* ─── Modal / Drawer ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-sheet {
  background: var(--bg-card);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%; max-width: 640px; margin: 0 auto;
  max-height: 92vh; overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  padding-bottom: env(safe-area-inset-bottom, 1rem);
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-handle {
  width: 40px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 0.75rem auto 0;
}
.modal-header {
  padding: 0.75rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-close { background:none; border:none; font-size:1.5rem; color:var(--text-muted); line-height:1; cursor:pointer; }
.modal-body { padding: 1rem; }
.modal-actions { padding: 0 1rem 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

/* ─── Section headers ────────────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.875rem;
}
.section-header h2 { font-size: 1.05rem; font-weight: 700; }

/* ─── Patient list item ──────────────────────────────────────────────────────── */
.patient-item {
  background: var(--bg-card); border-radius: var(--radius-lg);
  padding: 0.875rem 1rem; display: flex; align-items: center; gap: 0.875rem;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: box-shadow var(--transition);
}
.patient-item:hover { box-shadow: var(--shadow-md); }
.patient-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--teal-bg); color: var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem; flex-shrink: 0;
}
.patient-name { font-weight: 600; font-size: 0.95rem; }
.patient-meta { font-size: 0.78rem; color: var(--text-muted); }

/* ─── Settings ───────────────────────────────────────────────────────────────── */
.settings-section { margin-bottom: 1.5rem; }
.settings-section h3 { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.75rem; }
.settings-item {
  background: var(--bg-card); border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.5rem; box-shadow: var(--shadow-sm);
}
.settings-item-label { font-size: 0.9rem; font-weight: 500; }
.settings-item-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }

/* ─── Misc ───────────────────────────────────────────────────────────────────── */
.divider-text { text-align:center; color: var(--text-muted); font-size:0.8rem; margin: 1rem 0; position:relative; }
.divider-text::before,.divider-text::after { content:''; position:absolute; top:50%; width:40%; height:1px; background:var(--border); }
.divider-text::before { left:0; } .divider-text::after { right:0; }
.empty-state { text-align:center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state .empty-icon { font-size:3rem; margin-bottom:0.75rem; }
.empty-state p { font-size:0.95rem; }
.toast {
  position:fixed; bottom: calc(var(--nav-height) + 1rem); left:50%; transform:translateX(-50%) translateY(100px);
  background: var(--text-main); color:white; padding:0.75rem 1.25rem;
  border-radius: var(--radius-md); font-size:0.9rem; z-index:200;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  max-width: 90vw; text-align:center;
  white-space: nowrap;
}
.toast.show { transform:translateX(-50%) translateY(0); }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red);   }

.search-box { position:relative; margin-bottom:1rem; }
.search-box input { padding-left:2.5rem; }
.search-box .search-icon { position:absolute; left:0.875rem; top:50%; transform:translateY(-50%); color:var(--text-muted); font-size:1rem; pointer-events:none; }

/* Detail rows */
.detail-row { display:flex; gap:0.75rem; padding:0.6rem 0; border-bottom:1px solid var(--border); }
.detail-row:last-child { border-bottom:none; }
.detail-label { color:var(--text-muted); font-size:0.82rem; min-width:110px; flex-shrink:0; font-weight:500; }
.detail-value { color:var(--text-main); font-size:0.9rem; word-break:break-word; }

/* Passkey card */
.passkey-card { background:var(--bg-page); border-radius:var(--radius-md); padding:0.75rem 1rem; display:flex; align-items:center; justify-content:space-between; margin-bottom:0.5rem; }

/* Spinner */
.spinner { display:inline-block; width:18px; height:18px; border:2.5px solid rgba(255,255,255,0.4); border-top-color:white; border-radius:50%; animation:spin 0.7s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

/* ─── Responsive desktop ─────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .view { padding: 1.5rem 2rem; padding-bottom: 2rem; }
  .modal-overlay { align-items: center; }
  .modal-sheet { border-radius: var(--radius-xl); max-height: 85vh; margin: auto; max-width: 560px; }
  #app-nav { max-width: 640px; margin: 0 auto; }
  #app { max-width: 768px; margin: 0 auto; box-shadow: var(--shadow-lg); }
  body { background: var(--bg-page); }
}
