:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1d2433; --muted: #637083; --line: #e2e6ec;
  --brand: #0f6b78; --brand-ink: #fff; --brand-soft: #e3f2f3;
  --blue: #2563eb; --green: #15803d; --red: #c62828; --amber: #b45309; --violet: #6d28d9; --teal: #0f766e; --gray: #6b7280;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 15px;
  color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 14px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: #0c3f47; color: #d8eef0; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .logo { padding: 18px 16px 10px; font-weight: 700; color: #fff; font-size: 16px; }
.sidebar .logo img { display: block; background: #fff; border-radius: 50%; margin-bottom: 8px; }
.sidebar .logo small { display: block; font-weight: 400; color: #9cc9ce; font-size: 12px; }
.sidebar nav a { display: flex; gap: 10px; align-items: center; padding: 10px 16px; color: #d8eef0; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.1); border-left-color: #5fd0db; color: #fff; }
.sidebar .ico { width: 18px; text-align: center; opacity: .85; }
.sidebar .me { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; color: #9cc9ce; }
.sidebar .me a { color: #fff; }
.main { flex: 1; min-width: 0; padding: 20px 24px 60px; }
.topbar { display: none; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.warn b { color: var(--red); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
tr.row-link:hover { background: #f8fafc; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid; }
.badge.blue { color: var(--blue); border-color: #bfdbfe; background: #eff6ff; }
.badge.green { color: var(--green); border-color: #bbf7d0; background: #f0fdf4; }
.badge.red { color: var(--red); border-color: #fecaca; background: #fef2f2; }
.badge.amber { color: var(--amber); border-color: #fde68a; background: #fffbeb; }
.badge.violet { color: var(--violet); border-color: #ddd6fe; background: #f5f3ff; }
.badge.teal { color: var(--teal); border-color: #99f6e4; background: #f0fdfa; }
.badge.gray { color: var(--gray); border-color: #e5e7eb; background: #f9fafb; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-size: 14px; cursor: pointer; text-decoration: none; min-height: 38px; }
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #0c5a65; }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px; font-weight: 600; }
input[type=text], input[type=tel], input[type=number], input[type=date], input[type=datetime-local], input[type=password],
input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd6df; border-radius: 8px; font: inherit; font-size: 15px; background: #fff; min-height: 38px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #99d5dc; border-color: var(--brand); }
.field { margin-bottom: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; color: var(--ink); font-size: 14px; }
.check input { width: 18px; height: 18px; }
.msgs { margin-bottom: 14px; }
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; border: 1px solid; }
.msg.success { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }
.msg.error { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }
.msg.warning, .msg.info { background: #fffbeb; border-color: #fde68a; color: #78350f; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 13px; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.kv { margin: 0; display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 600; }
.banner.sandbox { background: #f5f3ff; color: var(--violet); border: 1px dashed var(--violet); }
.banner.off { background: #f9fafb; color: var(--gray); border: 1px dashed #cbd5e1; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--line); margin-left: 4px; position: relative; }
.timeline li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); position: absolute; left: -5px; top: 14px; }
details.box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fbfcfd; margin-bottom: 10px; }
details.box > summary { cursor: pointer; font-weight: 600; }
.notice-legal { font-size: 12px; color: var(--muted); margin-top: 30px; }
.split { display: grid; grid-template-columns: minmax(0,2fr) minmax(0,1fr); gap: 16px; }

/* ---------- Sơ đồ răng ---------- */
.tooth-chart { user-select: none; }
.tc-orient { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.tc-arch { display: flex; justify-content: center; gap: 10px; margin: 4px 0; }
.tc-quad { display: flex; gap: 3px; }
.tc-sep { width: 2px; background: #94a3b8; }
.tc-mid { border-top: 2px solid #94a3b8; margin: 6px 0; }
.tooth { width: 38px; min-height: 46px; border: 1.5px solid #cbd5e1; border-radius: 8px 8px 12px 12px; background: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #334155; padding: 2px; position: relative; }
.tooth.primary { width: 32px; min-height: 38px; font-size: 12px; background: #fdfcf7; border-style: dashed; }
.tooth small { font-size: 9px; font-weight: 500; color: var(--muted); line-height: 1.1; text-align: center; max-width: 100%; overflow: hidden; }
.tooth.sel { background: var(--brand); border-color: var(--brand); color: #fff; }
.tooth.sel small { color: #e0f2f4; }
.tooth.missing { background: repeating-linear-gradient(45deg, #fff, #fff 4px, #f1f5f9 4px, #f1f5f9 8px); color: #94a3b8; }
.tooth.implant { border-color: var(--blue); box-shadow: inset 0 -4px 0 var(--blue); }
.tooth.treated { border-color: var(--green); box-shadow: inset 0 -4px 0 var(--green); }
.tooth.issue { border-color: var(--red); box-shadow: inset 0 -4px 0 var(--red); }
.tooth.planned::after { content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.tc-tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.tc-selected { font-weight: 600; }
.tc-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.tc-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1.5px solid; }

/* ---------- Lịch ---------- */
.cal { display: grid; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow-x: auto; }
.cal-head { position: sticky; top: 0; background: #f8fafc; font-weight: 700; font-size: 13px; padding: 8px; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); text-align: center; }
.cal-time { font-size: 12px; color: var(--muted); padding: 0 6px; border-top: 1px solid var(--line); text-align: right; }
.cal-col { position: relative; border-left: 1px solid var(--line); }
.cal-slot { border-top: 1px solid #f1f4f7; }
.appt { position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 3px 6px; font-size: 12px; overflow: hidden; color: #0b2530;
  background: #dbeafe; border-left: 4px solid var(--blue); line-height: 1.25; }
.appt.arrived { background: #fef3c7; border-left-color: var(--amber); }
.appt.completed { background: #dcfce7; border-left-color: var(--green); }
.appt.no_show { background: #fee2e2; border-left-color: var(--red); }
.appt a { color: inherit; }
.appt b { display: block; }

/* ---------- Hộp thư ---------- */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; padding: 8px; background: #f8fafc; border-radius: 8px; }
.bubble { max-width: 80%; padding: 8px 12px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.bubble.out { align-self: flex-end; background: #e0f2fe; border-color: #bae6fd; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }

@media (max-width: 1024px) {
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .layout { display: block; }
  .topbar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 30; background: #0c3f47; color: #fff; padding: 10px 16px; }
  .topbar button { background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 18px; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 35; }
  .main { padding: 14px 16px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kv { grid-template-columns: 1fr; }
  .kv { gap: 2px; }
  .kv dt { margin-top: 8px; }
  .tooth { width: 100%; min-width: 0; min-height: 44px; font-size: 12px; border-radius: 6px; }
  .tooth.primary { min-height: 34px; font-size: 11px; }
  .tooth small { display: none; }
  .tc-arch { gap: 4px; }
  .tc-quad { gap: 2px; flex: 1; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .tc-quad.primary-q { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  table.stack thead { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.stack td { display: flex; justify-content: space-between; gap: 10px; border: none; padding: 4px 2px; }
  table.stack td::before { content: attr(data-l); color: var(--muted); font-size: 12px; font-weight: 600; }
  table.stack td.num { text-align: right; }
  .btn { min-height: 42px; }
}

[hidden] { display: none !important; }
