:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --card: #1e293b;
  --card2: #263449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #6366f1;
  --primary-d: #4f46e5;
  /* Màu ca */
  --c-active: #f43f5e;
  --c-oncall: #f59e0b;
  --c-day: #eab308;
  --c-mini: #eab308;
  --c-office: #64748b;
  --c-off: #475569;
  --c-rest: #64748b;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: #fca5a5; font-size: 14px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--primary); color: #fff; text-transform: uppercase; letter-spacing: .03em; }

/* ===== ICON SYSTEM ===== */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; pointer-events: none; }

/* Buttons */
.btn { font-size: 15px; padding: 11px 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; transition: .15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-d); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-block { width: 100%; display: flex; margin-top: 8px; }
.btn.mini .icon { width: 16px; height: 16px; }
.icon-btn { background: none; border: none; color: var(--text); cursor: pointer; line-height: 1; padding: 4px 8px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn .icon { width: 22px; height: 22px; }

input, select { font-size: 16px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); width: 100%; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
label input { margin-top: 5px; }

/* ===== LOGIN ===== */
.login-screen { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 30px 24px; width: 100%; max-width: 380px; }
.login-card h1 { margin: 6px 0 2px; text-align: center; font-size: 24px; }
.login-card > p { text-align: center; margin-top: 0; margin-bottom: 22px; }
.login-logo { width: 64px; height: 64px; margin: 0 auto 6px; border-radius: 18px; background: linear-gradient(155deg, var(--primary), var(--primary-d)); display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 24px rgba(99,102,241,.35); }
.login-logo .icon { width: 30px; height: 30px; stroke: #fff; stroke-width: 1.6; }
.login-card label { margin-bottom: 16px; }

/* ===== TOPBAR ===== */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); background: var(--bg); border-bottom: 1px solid var(--border); gap: 10px; }
.topbar-title { font-weight: 700; display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.topbar-title .icon { color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-name { font-size: 14px; font-weight: 600; max-width: 110px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.menu { position: absolute; right: 12px; top: 52px; background: var(--card2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; min-width: 190px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.menu-user { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.menu-user .badge { align-self: flex-start; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: 12px 14px; font-size: 15px; cursor: pointer; }
.menu-item:active { background: var(--bg2); }

main { padding: 16px; padding-bottom: calc(80px + var(--safe-b)); max-width: 720px; margin: 0 auto; }

/* ===== TAB HIỆN TẠI ===== */
.now-card { background: linear-gradient(160deg, var(--card), var(--card2)); border: 1px solid var(--border); border-radius: 20px; padding: 24px; text-align: center; }
.now-time { font-size: 44px; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.now-date { display: block; font-size: 14px; color: var(--muted); font-weight: 500; margin-top: 6px; }
.now-badge { display: inline-block; margin: 18px 0; padding: 8px 18px; border-radius: 999px; font-weight: 700; font-size: 15px; color: #fff; background: var(--c-rest); }
.now-person { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 8px 0 4px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; flex-shrink: 0; }
.avatar .icon { width: 28px; height: 28px; stroke-width: 1.6; }
.now-name { font-size: 20px; font-weight: 700; text-align: left; }
.now-next { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted); }
.now-next b { color: var(--text); }

.next-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-top: 14px; text-align: center; }
.next-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; }
.next-badge { margin: 0 0 10px; padding: 5px 14px; font-size: 13px; }
.next-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.next-date { font-size: 13px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.next-time { font-size: 14px; }

/* State colours */
.s-ACTIVE { background: var(--c-active) !important; }
.s-ONCALL { background: var(--c-oncall) !important; }
.s-DAY { background: var(--c-day) !important; color: #1a1300 !important; }
.s-MINI { background: var(--c-mini) !important; color: #1a1300 !important; }
.s-OFFICE { background: var(--c-office) !important; }
.s-REST { background: var(--c-rest) !important; }

/* ===== TAB LỊCH ===== */
.sched-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.sched-head .btn { padding: 8px 12px; font-size: 14px; }
.week-block { margin-bottom: 18px; }
.week-title { font-weight: 700; margin: 0 0 8px; font-size: 15px; color: var(--muted); }
.week-title b { color: var(--text); }
table.sched { width: 100%; border-collapse: collapse; font-size: 16px; }
table.sched th, table.sched td { padding: 10px 8px; text-align: center; border-bottom: 1px solid var(--border); }
table.sched thead th { color: var(--muted); font-weight: 600; font-size: 15px; position: sticky; }
table.sched td.day-col { text-align: left; white-space: nowrap; color: var(--muted); font-weight: 600; }
tr.today { background: rgba(99,102,241,.12); }
tr.today .day-col { color: var(--primary); }
tr.sunday td { opacity: .55; }
.chip { display: inline-block; min-width: 36px; padding: 4px 8px; border-radius: 8px; font-weight: 700; font-size: 13px; color: #fff; white-space: nowrap; }
.chip-N { background: var(--c-active); }
.chip-DAY { background: var(--c-day); color: #1a1300; }
.chip-MINI { background: var(--c-mini); color: #1a1300; }
.chip-OFFICE { background: var(--c-office); }
.chip-OFF { background: transparent; color: var(--muted); font-weight: 500; }

.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* ===== TAB CẤU HÌNH ===== */
.config-block { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.config-block h2 { margin: 0 0 4px; font-size: 17px; }
.dev-list, .user-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.dev-row { display: flex; align-items: center; gap: 8px; }
.dev-row .pos { color: var(--muted); font-size: 12px; width: 20px; text-align: center; }
#cfg-msg .icon, #pw-msg .icon { width: 16px; height: 16px; vertical-align: -3px; margin-right: 2px; }
.dev-row input { flex: 1; }
.dev-row .mini { padding: 8px 10px; font-size: 14px; }
.times-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 10px; }
.time-card { background: var(--bg2); border-radius: 10px; padding: 10px 12px; }
.time-card h3 { margin: 0 0 8px; font-size: 14px; }
.time-inputs { display: flex; gap: 8px; flex-wrap: wrap; }
.time-inputs label { flex: 1 1 120px; min-width: 120px; margin: 0; }
.time-inputs input { padding: 10px 8px; }
.user-row { display: flex; align-items: center; gap: 8px; background: var(--bg2); padding: 10px 12px; border-radius: 10px; }
.user-row .u-main { flex: 1; }
.user-row .u-name { font-weight: 600; }
.user-row .u-sub { font-size: 12px; color: var(--muted); }
.adduser summary { list-style: none; display: inline-block; }
.adduser summary::-webkit-details-marker { display: none; }
.adduser-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.adduser-form button { grid-column: 1 / -1; }

/* ===== BOTTOM NAV ===== */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--bg2); border-top: 1px solid var(--border); padding-bottom: var(--safe-b); z-index: 20; }
.nav-btn { flex: 1; background: none; border: none; color: var(--muted); font-size: 11px; padding: 10px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.nav-btn .icon { width: 22px; height: 22px; opacity: .75; }
.nav-btn.active { color: var(--primary); }
.nav-btn.active .icon { opacity: 1; }

/* ===== MODAL ===== */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal-card { background: var(--card); border-radius: 16px; padding: 22px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

@media (min-width: 560px) {
  .times-grid { grid-template-columns: 1fr 1fr; }
  .now-time { font-size: 52px; }
}
