/* Tâm Trí: style chung cho trang đặt lịch và trang quản lý */
[hidden] { display: none !important; }
body { margin: 0; }
img { max-width: 100%; }
:root {
  --bg: #f3f6f6;
  --surface: #ffffff;
  --ink: #18282c;
  --muted: #5b6d71;
  --line: #d8e1e2;
  --accent: #2b6970;
  --accent-ink: #ffffff;
  --accent-soft: #e2eeef;
  --held: #a8670f;
  --held-soft: #fbf0dc;
  --sold: #8a9799;
  --sold-soft: #eceff0;
  --danger: #b3261e;
  --danger-soft: #fbe7e5;
  --good: #2f7a46;
  --good-soft: #e3f2e7;
  --font-display: "Lora", Georgia, serif;
  --font-body: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111a1c; --surface: #182427; --ink: #e4ecec; --muted: #9fb0b2; --line: #2b3b3e;
    --accent: #6fb3ba; --accent-ink: #0d1a1c; --accent-soft: #1f3538;
    --held: #e3a649; --held-soft: #3a2c15; --sold: #6f7d80; --sold-soft: #222e31;
    --danger: #f08a80; --danger-soft: #3b1f1d; --good: #7cc895; --good-soft: #1b3324;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111a1c; --surface: #182427; --ink: #e4ecec; --muted: #9fb0b2; --line: #2b3b3e;
  --accent: #6fb3ba; --accent-ink: #0d1a1c; --accent-soft: #1f3538;
  --held: #e3a649; --held-soft: #3a2c15; --sold: #6f7d80; --sold-soft: #222e31;
  --danger: #f08a80; --danger-soft: #3b1f1d; --good: #7cc895; --good-soft: #1b3324;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
.wrap { max-width: 860px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
h1, h2, h3 { text-wrap: balance; margin: 0; }
h1 { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; }
h2 { font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-block: 10px; }
.demo-tag { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--held); }
.roles { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.roles button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-size: 0.9rem; color: var(--muted); }
.roles button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }

.sos { background: var(--danger-soft); color: var(--ink); }
.sos .wrap { padding-block: 8px; font-size: 0.88rem; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.sos strong { color: var(--danger); }

main { padding-block: 24px 64px; display: grid; gap: 20px; }
.panel { scroll-margin-top: 90px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: grid; gap: 14px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.between { justify-content: space-between; }

.doctor { display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: center; }
@media (max-width: 480px) { .doctor { grid-template-columns: 56px 1fr; align-items: start; } .avatar { width: 56px !important; height: 56px !important; } }
.avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; }
.placeholder { background: var(--held-soft); color: var(--held); padding: 0 4px; border-radius: 4px; }
.prices { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 0.82rem; border: 1px solid var(--line); background: var(--bg); }

.days { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.day { flex: 0 0 auto; min-width: 64px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; text-align: center; }
.day .dow { font-size: 0.78rem; color: var(--muted); display: block; }
.day .dnum { font-weight: 600; font-variant-numeric: tabular-nums; }
.day .cnt { font-size: 0.72rem; color: var(--accent); display: block; }
.day[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.slot { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface); text-align: left; display: grid; gap: 2px; }
.slot .t { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.slot .k { font-size: 0.82rem; color: var(--muted); }
.slot .p { font-size: 0.9rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--accent); }
.slot.free:hover { border-color: var(--accent); }
.slot.free[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.slot.held { background: var(--held-soft); border-color: transparent; cursor: not-allowed; }
.slot.held .p, .slot.held .t { color: var(--held); }
.slot.sold, .slot.late { background: var(--sold-soft); border-color: transparent; cursor: not-allowed; }
.slot.sold .t, .slot.sold .p, .slot.late .t, .slot.late .p { color: var(--sold); }
.slot.sold .t { text-decoration: line-through; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

form { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
label { display: grid; gap: 4px; font-size: 0.88rem; font-weight: 500; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=time], select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface); width: 100%; min-width: 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0; display: grid; gap: 10px; }
legend { font-weight: 600; font-size: 0.9rem; padding: 0 4px; }
.yn { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; font-size: 0.9rem; }
.yn span { flex: 1 1 220px; }
.yn .opts { display: flex; gap: 12px; }
.yn .opts label { display: flex; gap: 4px; align-items: center; font-weight: 400; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 4px; }

.btn { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: 9px 16px; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.quiet { border-color: var(--line); background: var(--surface); color: var(--ink); font-weight: 500; }
.btn.danger { border-color: var(--danger); background: transparent; color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.pay { display: grid; grid-template-columns: 180px 1fr; gap: 18px; align-items: start; }
@media (max-width: 520px) { .pay { grid-template-columns: 1fr; } }
img.qr { width: 180px; height: 180px; background: #fff; border-radius: 8px; border: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.countdown { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--held); }
.sim { border-top: 1px dashed var(--line); padding-top: 12px; display: grid; gap: 8px; }
.sim-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--held); font-weight: 600; }

.alert { border-radius: 10px; padding: 14px 16px; display: grid; gap: 6px; }
.alert.crisis { background: var(--danger-soft); }
.alert.crisis h3 { color: var(--danger); }
.alert.ok { background: var(--good-soft); }
.alert.ok h3 { color: var(--good); }
.hotline { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; user-select: all; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.76rem; font-weight: 600; white-space: nowrap; }
.pill.paid { background: var(--good-soft); color: var(--good); }
.pill.held { background: var(--held-soft); color: var(--held); }
.pill.gone { background: var(--sold-soft); color: var(--sold); }
.pill.need { background: var(--danger-soft); color: var(--danger); }
.pill.free { background: var(--accent-soft); color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.82rem; color: var(--muted); }
.stat.warn b { color: var(--danger); }

.tpl-row { display: grid; grid-template-columns: 1.1fr 0.9fr 1.4fr 0.8fr 1fr auto; gap: 8px; align-items: end; }
@media (max-width: 640px) { .tpl-row { grid-template-columns: 1fr 1fr 1fr; padding-bottom: 8px; border-bottom: 1px solid var(--line); } .tpl-row .rm { justify-self: start; align-self: center; } }
.tpl-head { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
@media (max-width: 640px) { .tpl-head { display: none; } }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 0.9rem; max-width: calc(100% - 32px); z-index: 20; }
footer { padding-block: 0 40px; font-size: 0.8rem; color: var(--muted); }
@media (prefers-reduced-motion: no-preference) { .slot, .day, .btn { transition: border-color .15s, background-color .15s; } }
.notice { border: 1px dashed var(--held); background: var(--held-soft); border-radius: 10px; padding: 12px 14px; font-size: 0.9rem; }
.login { max-width: 380px; margin: 40px auto; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: 0.85rem; }
.filters button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
input[type=date], input[type=password] { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface); width: 100%; min-width: 0; }
@media (max-width: 640px) {
  table.stack thead { display: none; }
  table.stack tr { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.stack td { border: 0; padding: 0; }
  table.stack td.num { text-align: left; }
}
.slots > p { grid-column: 1 / -1; }
