/* ============================================================================
   Contatto Osteo — Admin Gestionale PWA
   Design: iOS-inspired, mobile-first, teal brand
   ============================================================================ */

:root {
  --bg:          #eef2f7;
  --surface:     #ffffff;
  --sep:         rgba(13, 23, 38, .14);
  --border:      rgba(13, 23, 38, .22);
  --text:        #0f172a;
  --text2:       #334155;
  --text3:       #64748b;
  --brand:       #0a66ff;
  --brand-dk:    #004ecc;
  --brand-lt:    #e8f0ff;
  /* Status */
  --s-pending:      #b45309;
  --s-pending-bg:   #fff7ed;
  --s-confirmed:    #166534;
  --s-confirmed-bg: #ecfdf3;
  --s-cancelled:    #b91c1c;
  --s-cancelled-bg: #fef2f2;
  --s-completed:    #4338ca;
  --s-completed-bg: #eef2ff;
  /* Layout */
  --header-h:    52px;
  --tab-h:       49px;
  --safe-b:      env(safe-area-inset-bottom, 0px);
  --r:           12px;
  --r-lg:        16px;
  --shadow:      0 1px 3px rgba(15, 23, 42, .08), 0 0 0 1px rgba(15, 23, 42, .08);
  --shadow-md:   0 4px 20px rgba(0,0,0,.12);
}

*,*::before,*::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  height: 100%; font-size: 16px; line-height: 1.58;
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}

/* ── Boot loader ─────────────────────────────────────────────────────────── */
.boot-loader {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100dvh; gap: 14px;
  color: var(--text2); font-weight: 600;
}

/* ── Shell ───────────────────────────────────────────────────────────────── */
.shell {
  display: flex; flex-direction: column; min-height: 100dvh;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--tab-h) + var(--safe-b));
}

/* ── Header (fixed top) ──────────────────────────────────────────────────── */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h); background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.15);
}
.header-logo { width: 28px; height: 28px; flex-shrink: 0; opacity: .9; }
.header-brand {
  font-size: 16px; font-weight: 700; color: #fff;
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-spin {
  width: 18px; height: 18px; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.header-mini-btn {
  border: 1px solid rgba(255,255,255,.28);
  background: rgba(255,255,255,.14);
  color: #fff;
  border-radius: 999px;
  height: 30px;
  padding: 0 11px;
  font-size: .74rem;
  font-weight: 700;
  cursor: pointer;
}

.header-mini-btn.ghost {
  background: transparent;
  border-color: rgba(255,255,255,.22);
}

/* ── Tab bar (fixed bottom, iOS style) ──────────────────────────────────── */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: calc(var(--tab-h) + var(--safe-b));
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--sep);
  display: flex; align-items: flex-start;
  padding-top: 5px; padding-bottom: var(--safe-b);
}
.tab-btn {
  flex: 1; min-height: 44px; padding: 2px 4px;
  border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: #475569; transition: color .15s;
  font-size: 10px; font-weight: 500; letter-spacing: .1px;
}
.tab-btn .tab-icon { font-size: 22px; line-height: 1.15; display: block; }
.tab-btn.active { color: var(--brand); }

/* ── Main content ────────────────────────────────────────────────────────── */
.main {
  flex: 1; padding: 18px 16px 4px;
  max-width: 760px; margin: 0 auto; width: 100%;
  display: flex; flex-direction: column; gap: 16px;
}

/* ── Error alert ─────────────────────────────────────────────────────────── */
.alert-error {
  background: var(--s-cancelled-bg); color: var(--s-cancelled);
  border: 1px solid rgba(185, 28, 28, .28);
  border-radius: var(--r); padding: 11px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: .88rem; font-weight: 600;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + var(--safe-b) + 14px);
  left: 50%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: 999px;
  font-weight: 700; font-size: .85rem; z-index: 500;
  box-shadow: var(--shadow-md); pointer-events: none;
  white-space: nowrap; max-width: 90vw;
}
.toast-ok    { background: var(--brand);       color: #fff; }
.toast-error { background: var(--s-cancelled); color: #fff; }

/* ── View header ─────────────────────────────────────────────────────────── */
.vhead {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 6px 2px 4px;
}
.vhead h1 { font-size: 26px; font-weight: 750; letter-spacing: -.01em; }
.muted { color: var(--text2); }
.sm    { font-size: .82rem; }
.mono  { font-family: monospace; font-size: .8rem; }
.empty { color: var(--text2); text-align: center; padding: 28px 16px; font-size: .9rem; }
.hint  { font-size: .73rem; color: var(--text3); margin-top: 3px; line-height: 1.4; }

/* ── Metric cards ────────────────────────────────────────────────────────── */
.metrics {
  display: grid; grid-template-columns: repeat(4,1fr); gap: 8px;
}
.metric {
  background: var(--surface); border-radius: var(--r);
  padding: 14px 12px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 3px;
}
.metric-lbl { font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--text2); }
.metric-val { font-size: 24px; font-weight: 800; line-height: 1.1; }
.metric-val.warn   { color: var(--s-pending); }
.metric-val.ok     { color: var(--s-confirmed); }
.metric-val.purple { color: var(--s-completed); }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--sep);
}

.login-card {
  max-width: 460px;
  margin: 10px auto 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 13px; border-bottom: 1px solid var(--sep);
}
.card-head h2 { font-size: 16px; font-weight: 700; }
.ctitle {
  font-size: 11px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .7px; color: var(--text2);
  padding: 14px 16px 6px;
}

/* ── Appointment rows ────────────────────────────────────────────────────── */
.alist { display: flex; flex-direction: column; }
.appt-row {
  display: flex; align-items: stretch; min-height: 70px;
  border-bottom: 1px solid var(--sep); transition: background .1s;
}
.appt-row:last-child { border-bottom: none; }
.appt-row:active { background: var(--bg); }

.appt-marker { width: 4px; flex-shrink: 0; }
.appt-row.status-pending   .appt-marker { background: var(--s-pending); }
.appt-row.status-confirmed .appt-marker { background: var(--s-confirmed); }
.appt-row.status-cancelled .appt-marker { background: var(--s-cancelled); opacity: .35; }
.appt-row.status-completed .appt-marker { background: var(--s-completed); }

.appt-body { flex: 1; padding: 11px 14px 10px; min-width: 0; }
.appt-body { padding: 14px 16px 12px; }
.appt-top  { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.appt-name { font-size: 16px; font-weight: 650; }
.appt-meta { font-size: 14px; color: var(--text2); }
.appt-key {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 700;
  color: var(--text3);
  margin-right: 4px;
}
.appt-sub  { font-size: 13px; color: var(--text2); margin-top: 1px; }
.appt-note { font-size: 12px; color: var(--text3); font-style: italic; margin-top: 3px; }
.appt-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.appt-mini-table {
  margin-top: 8px;
  border: 1px solid var(--sep);
  border-radius: 10px;
  overflow: hidden;
  background: #f8fafc;
}
.appt-mini-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--sep);
  align-items: baseline;
}
.appt-mini-row:last-child { border-bottom: none; }
.appt-mini-row strong {
  color: var(--text);
  font-weight: 650;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ── Action buttons ──────────────────────────────────────────────────────── */
.btn-action {
  height: 28px; padding: 0 11px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 3px;
  transition: opacity .15s, transform .1s;
}
.btn-action:active { transform: scale(.94); opacity: .8; }
.btn-confirm  { background: var(--s-confirmed-bg); color: var(--s-confirmed); border-color: rgba(22, 101, 52, .28); }
.btn-complete { background: var(--s-completed-bg); color: var(--s-completed); border-color: rgba(67, 56, 202, .28); }
.btn-cancel   { background: var(--s-cancelled-bg); color: var(--s-cancelled); border-color: rgba(185, 28, 28, .28); }
.btn-edit     { background: #f8fafc; color: var(--text); border-color: var(--border); }

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px; border-radius: 999px; border: 1px solid transparent;
  font-size: 11px; font-weight: 700; white-space: nowrap; flex-shrink: 0;
}
.badge-pending   { background: var(--s-pending-bg);   color: var(--s-pending); border-color: rgba(180, 83, 9, .28); }
.badge-confirmed { background: var(--s-confirmed-bg); color: var(--s-confirmed); border-color: rgba(22, 101, 52, .24); }
.badge-cancelled { background: var(--s-cancelled-bg); color: var(--s-cancelled); border-color: rgba(185, 28, 28, .24); }
.badge-completed { background: var(--s-completed-bg); color: var(--s-completed); border-color: rgba(67, 56, 202, .24); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 38px; padding: 0 16px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; font: 650 .9rem/1 inherit;
  white-space: nowrap; transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost   { background: #f8fafc; color: var(--text); border-color: var(--border); }
.btn-warn    { background: var(--s-cancelled-bg); color: var(--s-cancelled); }
.btn.sm      { height: 32px; padding: 0 12px; font-size: .82rem; }
.btn-icon-x  { border: none; background: none; cursor: pointer; color: var(--text2); font-size: 20px; padding: 4px; line-height: 1; }

/* ── Calendar toolbar ────────────────────────────────────────────────────── */
.cal-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 18px; border-bottom: 1px solid var(--sep);
}
.cal-date-inp { flex: 1; max-width: 160px; }
.cal-cnt { padding: 7px 16px 0; font-size: 13px; color: var(--text2); }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--sep);
}

/* ── Treatments ──────────────────────────────────────────────────────────── */
.inline-form {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end;
  padding: 14px 18px;
}
.tlist { display: flex; flex-direction: column; }
.t-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--sep); min-height: 54px;
}
.t-head {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px 120px 90px;
  gap: 10px;
  padding: 9px 18px;
  background: #f8fafc;
  border-top: 1px solid var(--sep);
  border-bottom: 1px solid var(--sep);
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text3);
  font-weight: 700;
}
.t-row:last-child { border-bottom: none; }
.t-row.t-inactive { opacity: .45; }
.t-fields { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; }
.t-name   { flex: 1; min-width: 120px; }
.t-dur    { width: 70px !important; }
.toggle-check { display: flex; align-items: center; gap: 5px; font-size: .85rem; color: var(--text2); white-space: nowrap; }
.t-mini {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .78rem;
  font-weight: 700;
  color: var(--text2);
}
.t-mini-grow { flex: 1; min-width: 210px; }
.t-mini input { width: 100%; }

/* ── Settings sections ───────────────────────────────────────────────────── */
.settings-section {
  display: flex; flex-direction: column; gap: 11px;
  padding: 14px 18px;
}
.settings-section + .settings-section { border-top: 1px solid var(--sep); }
.hours-grid { display: grid; gap: 9px; }
.hours-row  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 44px; }
.day-lbl    { min-width: 115px; display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: .88rem; }
.settings-btn-row { padding: 4px 16px 16px; }

/* ── Form controls ───────────────────────────────────────────────────────── */
input, select, textarea {
  border: 1px solid var(--border); border-radius: 9px;
  padding: 11px 13px; font: inherit; font-size: .95rem;
  background: #fff; width: 100%; color: var(--text); font-weight: 500;
}
input[type="checkbox"] { width: auto; accent-color: var(--brand); }
input[type="time"]     { width: 94px; }
input[type="date"]     { width: auto; }
input[type="number"]   { width: 80px; }
input[type="password"] { letter-spacing: .1em; }
textarea               { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(10, 102, 255, .30); outline-offset: 1px; border-color: var(--brand);
}
.fl {
  display: flex; flex-direction: column; gap: 5px;
  font-size: .85rem; font-weight: 650; color: var(--text2); flex: 1;
}
.fl input, .fl select, .fl textarea { width: 100%; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Dialog (bottom sheet on mobile) ─────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 200;
}
@media (min-width: 500px) {
  .overlay { align-items: center; padding: 24px; }
}
.dialog {
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  width: 100%; max-height: 94dvh; overflow-y: auto;
  box-shadow: 0 -4px 32px rgba(0,0,0,.15);
  padding-bottom: var(--safe-b);
}
@media (min-width: 500px) {
  .dialog { border-radius: var(--r-lg); max-width: 520px; }
}
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--sep);
}
.dialog-head h2 { font-size: 17px; font-weight: 700; }
.dialog-body { padding: 18px 22px; display: grid; gap: 14px; }
.dialog-foot { padding: 8px 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .metrics { grid-template-columns: repeat(2,1fr); }
  .field-row { grid-template-columns: 1fr; }
  .t-mini-grow { min-width: 100%; }
  .appt-mini-row { grid-template-columns: 95px 1fr; }
  .t-head { display: none; }
}
@media (min-width: 640px) {
  .main { padding: 22px 24px 6px; gap: 18px; }
}
