/* Admin panel. Light mode only, same palette and fonts as the public site. */
:root {
  color-scheme: light only;
  --bg: #f8f6f6;
  --surface: #ffffff;
  --tint: #fbf2f1;
  --ink: #10303a;
  --ink-2: #3f5660;
  --muted: #6c7f86;
  --line: #ece4e3;
  --primary: #c8202a;
  --primary-600: #a3161e;
  --primary-50: #fdeceb;
  --accent: #ee3a34;
  --accent-50: #fff1ec;
  --danger: #b4372f;
  --danger-50: #fbeceb;
  --success: #1c8a5a;
  --success-50: #e5f4ec;
  --warn: #a86a12;
  --warn-50: #fdf3e2;
  --font-sans: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-serif: 'Lora', Georgia, serif;
  --font-logo: 'Didact Gothic', 'Manrope', sans-serif;
  --radius: 16px;
  --shadow: 0 2px 6px rgba(16, 48, 58, .05), 0 14px 32px -14px rgba(16, 48, 58, .16);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font-sans); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--font-serif); font-weight: 600; margin: 0; line-height: 1.2; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 999px; padding: 10px 18px; font-weight: 700; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, color .15s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 7px 13px; font-size: .86rem; }
.btn-xs { padding: 4px 10px; font-size: .78rem; border-radius: 8px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
input[type='text'], input[type='tel'], input[type='email'], input[type='date'], input[type='search'], select, textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); padding: 10px 12px; font-size: .95rem;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }
.label { display: block; font-weight: 700; font-size: .85rem; margin: 14px 0 6px; color: var(--ink-2); }
.alert { background: var(--danger-50); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: .9rem; margin: 14px 0 0; }

.lang-switch { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.lang-switch button { border: 0; background: transparent; cursor: pointer; border-radius: 999px; padding: 5px 10px; font-size: .78rem; font-weight: 800; color: var(--muted); }
.lang-switch button[aria-pressed='true'] { background: var(--primary); color: #fff; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 20% 10%, var(--primary-50), transparent 45%), radial-gradient(circle at 90% 90%, var(--accent-50), transparent 40%), var(--bg); }
.login-lang { position: fixed; top: 16px; right: 16px; }
.login-card { width: min(420px, 100%); background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 40px 32px; text-align: center; border: 1px solid var(--line); }
.login-card img { margin: 0 auto 18px; }
.login-card h1 { font-size: 1.6rem; margin-bottom: 8px; }
.login-card .btn { margin-top: 12px; width: 100%; }
.btn-google { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 24px; padding: 13px 18px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; color: #1f1f1f; font-weight: 700; text-decoration: none; transition: border-color .15s, box-shadow .15s; }
.btn-google:hover { border-color: #c6d1cd; box-shadow: 0 4px 14px -6px rgba(16, 48, 58, .25); }
.back-link { display: inline-block; margin-top: 24px; color: var(--muted); font-size: .88rem; text-decoration: none; font-weight: 600; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 20px 14px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; text-decoration: none; color: var(--ink); }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-family: var(--font-logo); font-size: 1.2rem; font-weight: 400; color: #111; }
.brand small { font-size: .72rem; color: var(--muted); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--ink-2); text-decoration: none; font-weight: 700; }
.side-nav a img { opacity: .75; }
.side-nav a:hover { background: var(--tint); }
.side-nav a[aria-current='page'] { background: var(--primary-50); color: var(--primary-600); }
.side-nav a[aria-current='page'] img { opacity: 1; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 10px; }
.user { display: flex; align-items: center; gap: 10px; font-size: .85rem; min-width: 0; }
.user img, .avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; }
.avatar { background: var(--primary-50); color: var(--primary); display: grid; place-items: center; font-weight: 800; }
.user div { min-width: 0; }
.user strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 28px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.45rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.view { padding: 24px 28px 48px; outline: none; }

/* ---------- cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { font-size: 1.1rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.stat small { display: block; color: var(--muted); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.stat strong { display: block; font-family: var(--font-serif); font-size: 2.1rem; font-weight: 600; color: var(--primary); line-height: 1.2; margin-top: 4px; }
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.dash-grid .card + .card { margin-top: 0; }

.bars { display: grid; gap: 10px; }
.bar { display: grid; gap: 4px; font-size: .86rem; }
.bar-row { display: flex; justify-content: space-between; gap: 8px; }
.bar-row span { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; border-radius: 99px; background: var(--tint); overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 99px; }

/* ---------- appointment list ---------- */
.appt-list { list-style: none; margin: 0; padding: 0; }
.appt { display: grid; grid-template-columns: 76px 1fr auto; gap: 14px; align-items: center; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.appt:last-child { border-bottom: 0; }
.appt-time { font-weight: 800; font-size: 1.05rem; color: var(--primary); line-height: 1.1; }
.appt-time small { display: block; font-size: .72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.appt-who { min-width: 0; }
.appt-who a { font-weight: 800; color: var(--ink); text-decoration: none; }
.appt-who a:hover { color: var(--primary); text-decoration: underline; }
.appt-who p { margin: 2px 0 0; color: var(--muted); font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .74rem; font-weight: 800; border-radius: 99px; padding: 3px 10px; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-scheduled { background: var(--primary-50); color: var(--primary); }
.st-completed { background: var(--success-50); color: var(--success); }
.st-cancelled { background: #f0f2f2; color: var(--muted); }
.st-no_show { background: var(--warn-50); color: var(--warn); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--tint); color: var(--ink-2); }
.tag-new { background: #fff4e0; color: #8a5a10; }

/* ---------- filters + table ---------- */
.filters { display: grid; grid-template-columns: 2fr repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.search-input { padding-left: 40px !important; background: var(--surface) url('/img/icons/search.svg') no-repeat 13px center / 17px !important; }
.chips { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 14px; font-weight: 700; font-size: .85rem; cursor: pointer; color: var(--ink-2); }
.chip[aria-pressed='true'] { background: var(--ink); border-color: var(--ink); color: #fff; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 800; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fbfcfc; white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafcfb; }
td.nowrap { white-space: nowrap; }
td .sub { display: block; color: var(--muted); font-size: .8rem; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.count { color: var(--muted); font-size: .85rem; font-weight: 600; margin: -6px 0 12px; }

/* ---------- patient view ---------- */
.back { display: inline-flex; margin-bottom: 14px; font-weight: 700; text-decoration: none; color: var(--muted); }
.back:hover { color: var(--primary); }
.patient-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.patient-head .avatar { width: 56px; height: 56px; font-size: 1.3rem; }
.patient-head h2 { font-size: 1.6rem; }
.patient-head p { margin: 2px 0 0; color: var(--muted); }
.patient-head .spacer { flex: 1; }
.patient-grid { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-weight: 600; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.saved { color: var(--success); font-weight: 700; font-size: .85rem; }
.medical textarea { min-height: 64px; }

.note-form { background: var(--tint); border-radius: 14px; padding: 14px; margin-bottom: 18px; }
.note-form textarea { background: var(--surface); }
.note-form .row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.note-form select { width: auto; flex: 1; min-width: 180px; }
.note-form .hint { font-size: .78rem; color: var(--muted); margin: 8px 0 0; }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 15px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl { position: relative; padding: 0 0 18px 46px; }
.tl-icon { position: absolute; left: 0; top: 0; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--line); }
.tl-icon img { width: 16px; height: 16px; }
.tl-note .tl-icon { border-color: var(--accent); background: var(--accent-50); }
.tl-appt .tl-icon { border-color: var(--primary); background: var(--primary-50); }
.tl-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.tl-meta { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.tl-title { font-weight: 800; }
.tl-body { white-space: pre-wrap; word-break: break-word; margin: 4px 0 0; }
.tl-quote { margin: 8px 0 0; padding: 8px 10px; border-left: 3px solid var(--line); background: #fafcfb; border-radius: 0 8px 8px 0; font-size: .88rem; color: var(--ink-2); white-space: pre-wrap; }
.tl-linked { font-size: .78rem; color: var(--muted); margin-top: 6px; }
.tl-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- dialog ---------- */
.dialog { border: 0; border-radius: 22px; padding: 0; width: min(520px, calc(100% - 32px)); box-shadow: 0 40px 80px -20px rgba(16, 48, 58, .4); }
.dialog::backdrop { background: rgba(16, 48, 58, .35); backdrop-filter: blur(2px); }
.dialog form { padding: 26px; }
.dialog h2 { font-size: 1.3rem; margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.seg { display: flex; gap: 6px; margin-top: 10px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; border: 1.5px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; font-weight: 700; font-size: .88rem; }
.seg input:checked + span { border-color: var(--primary); background: var(--primary-50); color: var(--primary-600); }
.pick-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.pick-list:empty { display: none; }
.pick-list li { padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.pick-list li:hover { background: var(--tint); }
.pick-list li[aria-selected='true'] { background: var(--primary-50); font-weight: 700; }
.pick-list small { color: var(--muted); }
#ap-other { margin-top: 8px; }

.toast { position: fixed; bottom: 22px; left: 50%; translate: -50% 0; background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 700; font-size: .9rem; box-shadow: var(--shadow); z-index: 100; }
.loading { color: var(--muted); padding: 30px 0; text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dash-grid, .patient-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search-input { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; }
  .brand span { display: none; }
  .side-nav { flex-direction: row; gap: 2px; flex: 1; justify-content: center; }
  .side-nav a { padding: 8px 10px; }
  .side-nav a span { display: none; }
  .side-foot { margin: 0; border: 0; padding: 0; display: flex; }
  .side-foot .user { display: none; }
  .topbar { position: static; padding: 14px 16px; flex-wrap: wrap; }
  .topbar h1 { font-size: 1.2rem; }
  .view { padding: 16px 16px 40px; }
  .stats { gap: 10px; }
  .stat { padding: 14px; }
  .stat strong { font-size: 1.6rem; }
  .appt { grid-template-columns: 60px 1fr; }
  .appt-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .filters { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* helpers (no inline styles: the Content-Security-Policy blocks them) */
.filters-single { grid-template-columns: 1fr !important; }
.card-head-sub { margin: 22px 0 0; }
.label-first { margin-top: 0; }
.lead-text { margin-top: 0; }

/* demo mode */
.demo-banner { background: #fff4e0; color: #7a4d0b; border-bottom: 1px solid #f1d9a8; padding: 9px 28px; font-weight: 700; font-size: .88rem; text-align: center; }
.btn-demo { margin-top: 10px; width: 100%; }

/* analytics */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; font-weight: 700; color: var(--ink-2); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ''; width: 10px; height: 10px; border-radius: 3px; }
.lg-views::before { background: #f6c9c6; }
.lg-visitors::before { background: var(--primary); }
.lg-bookings::before { background: #1c8a5a; border-radius: 50%; }
.chart svg { display: block; width: 100%; height: 220px; }
.bar-views { fill: #f6c9c6; }
.bar-visitors { fill: var(--primary); }
.dot-bookings { fill: #1c8a5a; stroke: #fff; stroke-width: 1.5; }
.chart g:hover .bar-views { fill: #f0a9a4; }
.chart-ticks { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); font-weight: 700; margin-top: 6px; }
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.analytics-grid .card + .card { margin-top: 0; }
.privacy-note { margin-top: 18px; }
@media (max-width: 760px) { .analytics-grid { grid-template-columns: 1fr; } .demo-banner { padding: 8px 16px; } }

/* ---------- phone polish ---------- */
.dash-grid > *, .patient-grid > *, .analytics-grid > *, .main, .view { min-width: 0; }
@media (max-width: 1100px) {
  .dash-grid, .patient-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .card { padding: 16px; border-radius: 14px; }
  .appt { grid-template-columns: 62px minmax(0, 1fr); gap: 10px; }
  .appt-who p { white-space: normal; }
  /* tables become stacked cards */
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
  .table-wrap tr:hover { background: #fff; }
  .table-wrap td { border: 0; padding: 3px 0; }
  .table-wrap td.nowrap { white-space: normal; }
  .table-wrap td .sub { display: inline; margin-left: 6px; }
  .table-wrap td:empty { display: none; }
  .table-wrap td.empty { border: 0; }
  .table-wrap .appt-actions { justify-content: flex-start; margin-top: 8px; }
  .patient-head { gap: 12px; }
  .patient-head h2 { font-size: 1.3rem; }
  .patient-head .spacer { display: none; }
  .patient-head .btn { width: 100%; }
  .note-form .row { flex-direction: column; align-items: stretch; }
  .note-form select { width: 100%; min-width: 0; }
  .tl { padding-left: 40px; }
  .dialog form { padding: 20px; }
  .chips { overflow-x: auto; flex-wrap: nowrap; }
  .topbar-actions .btn { padding: 7px 11px; }
  .legend { width: 100%; }
  .chart svg { height: 170px; }
}
.bars, .bars > *, .bar-row, .bar-row span { min-width: 0; }
@media (max-width: 760px) {
  .filters { grid-template-columns: 1fr 1fr; gap: 8px; }
  .filters .search-input { grid-column: 1 / -1; }
  .filters select, .filters input[type='date'] { padding: 9px 10px; font-size: .88rem; min-width: 0; }
  .filters-single { grid-template-columns: 1fr !important; }
}
@media (max-width: 1100px) { .patient-grid > section { order: -1; } } /* history & notes first on small screens */
.nowrap { white-space: nowrap; }
