:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #142028;
  --ink-2: #4b5b67;
  --ink-3: #7b8994;
  --line: #dde3e8;
  --brand: #0e6b6f;
  --brand-ink: #ffffff;
  --brand-soft: #dff1f0;
  --warn: #b42318;
  --warn-soft: #fde8e6;
  --ok: #1a7f37;
  --today: #fff4c2;
  --shadow: 0 1px 2px rgba(16, 32, 40, .06), 0 4px 16px rgba(16, 32, 40, .06);
  --r: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1518; --surface: #172025; --surface-2: #1e2a30; --ink: #e8eef1; --ink-2: #a9b7bf; --ink-3: #7d8c95;
    --line: #2a3840; --brand: #3fb6b0; --brand-ink: #062b2c; --brand-soft: #173a3b; --warn: #ff8a80; --warn-soft: #3a1d1b; --today: #3b3415;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1518; --surface: #172025; --surface-2: #1e2a30; --ink: #e8eef1; --ink-2: #a9b7bf; --ink-3: #7d8c95;
  --line: #2a3840; --brand: #3fb6b0; --brand-ink: #062b2c; --brand-soft: #173a3b; --warn: #ff8a80; --warn-soft: #3a1d1b; --today: #3b3415;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px;
}
.top .brand { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.top .brand b { font-size: 17px; letter-spacing: .2px; }
.top .brand span { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.monthpick { display: flex; align-items: center; gap: 2px; background: rgba(255,255,255,.14); border-radius: 999px; padding: 2px; }
.monthpick button { background: none; border: 0; color: inherit; width: 34px; height: 34px; border-radius: 50%; font-size: 18px; }
.monthpick button:disabled { opacity: .35; }
.monthpick select { background: none; border: 0; color: inherit; font-weight: 600; padding: 4px 2px; appearance: none; -webkit-appearance: none; text-align: center; }
.monthpick select option { color: #142028; }

/* ---------- Tabs ---------- */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { background: none; border: 0; padding: 8px 4px 9px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink-3); font-size: 12px; font-weight: 600; }
.tabs button svg { width: 22px; height: 22px; }
.tabs button[aria-selected="true"] { color: var(--brand); }
main { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
@media (min-width: 860px) {
  .tabs { position: static; display: flex; justify-content: center; gap: 4px; border: 0; background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 16px; }
  .tabs button { flex-direction: row; gap: 8px; font-size: 14px; padding: 12px 16px; border-bottom: 3px solid transparent; }
  .tabs button[aria-selected="true"] { border-bottom-color: var(--brand); }
  .tabs button svg { width: 18px; height: 18px; }
  main { padding-bottom: 40px; }
}

/* ---------- Cards ---------- */
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-2); margin-bottom: 10px; font-weight: 700; }
.grid2 { display: grid; gap: 14px; }
@media (min-width: 860px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2 > .card { margin-bottom: 0; } }

.chip {
  display: inline-flex; align-items: center; justify-content: center; min-width: 30px; padding: 2px 7px; border-radius: 7px;
  background: var(--bg); color: var(--fg); font-weight: 700; font-size: 12.5px; line-height: 1.5; white-space: nowrap;
  --bg: #e9ecf1; --fg: #2b3442; background: var(--bg);
}
.chip.lg { font-size: 15px; padding: 4px 10px; min-width: 44px; border-radius: 9px; }
.chip.xl { font-size: 22px; padding: 8px 14px; min-width: 64px; border-radius: 12px; }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; font-weight: 600; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Hari ini ---------- */
.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.daynav .d { flex: 1; text-align: center; }
.daynav .d b { display: block; font-size: 19px; }
.daynav .d span { font-size: 13px; color: var(--ink-2); }
.iconbtn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: inline-grid; place-items: center; font-size: 20px; color: var(--ink); }
.banner { background: var(--brand-soft); color: var(--ink); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.banner.hol { background: #fff0c7; color: #4a3800; }
:root[data-theme="dark"] .banner.hol { background: #3b3112; color: #ffe39a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner.hol { background: #3b3112; color: #ffe39a; } }

.shiftgroup { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.shiftgroup:first-of-type { border-top: 0; padding-top: 0; }
.shiftgroup .who { flex: 1; min-width: 0; }
.shiftgroup .who .t { font-size: 13px; color: var(--ink-2); }
.shiftgroup .who .names { font-weight: 600; font-size: 16px; }
.offline { display: flex; flex-wrap: wrap; gap: 8px; }
.offline > span { display: inline-flex; gap: 6px; align-items: center; background: var(--surface-2); padding: 4px 8px 4px 10px; border-radius: 999px; font-size: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: center; }
.kv .k { color: var(--ink-2); font-size: 13px; font-weight: 600; }
.empty { text-align: center; padding: 30px 10px; color: var(--ink-2); }

/* ---------- Saya ---------- */
.pickname { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.pickname button { padding: 16px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 15px; }
.pickname button small { display: block; font-weight: 500; color: var(--ink-3); font-size: 12px; }
.mehead { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; font-size: 17px; flex: none; }
.mehead h2 { font-size: 20px; }
.todaybox { display: flex; gap: 14px; align-items: center; }
.todaybox .lbl { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.todaybox .v { font-size: 18px; font-weight: 700; }
.todaybox .t { font-size: 14px; color: var(--ink-2); }
.nextdays { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; margin-top: 12px; }
.nextdays div { text-align: center; background: var(--surface-2); border-radius: 10px; padding: 6px 4px 8px; font-size: 12px; color: var(--ink-2); }
.nextdays div b { display: block; color: var(--ink); font-size: 13px; margin-bottom: 3px; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .h { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--ink-3); padding-bottom: 2px; }
.cal .c { aspect-ratio: 1 / 1.08; border-radius: 9px; background: var(--surface-2); display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 4px 2px 5px; border: 2px solid transparent; position: relative; min-width: 0; }
.cal .c.code { background: var(--bg); color: var(--fg); }
.cal .c .n { font-size: 11.5px; font-weight: 600; opacity: .8; }
.cal .c .k { font-size: 14px; font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.cal .c.today { border-color: var(--ink); }
.cal .c.sel { outline: 3px solid var(--brand); outline-offset: 1px; }
.cal .c .dot { position: absolute; top: 4px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.cal button.c { cursor: pointer; font: inherit; }
.cal .blank { background: transparent; }
@media (min-width: 600px) { .cal { gap: 6px; } .cal .c { aspect-ratio: 1.3 / 1; } .cal .c .k { font-size: 16px; } }
.summary { display: flex; flex-wrap: wrap; gap: 8px; }
.summary > span { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; background: var(--surface-2); border-radius: 999px; padding: 3px 10px 3px 4px; }

/* ---------- Jadual penuh ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-weight: 600; color: var(--ink-2); font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tablewrap { overflow: auto; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); max-height: calc(100vh - 210px); -webkit-overflow-scrolling: touch; }
table.roster { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
table.roster th, table.roster td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 4px; text-align: center; vertical-align: middle; }
table.roster thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; font-weight: 700; padding: 6px 4px; min-width: 50px; }
table.roster thead th .wd { display: block; font-size: 11px; color: var(--ink-3); font-weight: 600; }
table.roster thead th.we .wd { color: var(--warn); }
table.roster th.name { position: sticky; left: 0; background: var(--surface); z-index: 1; text-align: left; padding: 6px 10px; font-weight: 700; white-space: nowrap; min-width: 92px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
table.roster thead th.name { z-index: 3; }
table.roster tr.sec td { background: var(--surface-2); border-right: 0; }
table.roster tr.sec th { background: var(--surface-2); overflow: visible; z-index: 1; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-2); padding: 4px 10px; position: sticky; left: 0; }
table.roster td.txt { font-size: 11.5px; color: var(--ink-2); max-width: 110px; min-width: 50px; line-height: 1.25; white-space: normal; word-break: break-word; }
table.roster .today { background: var(--today); }
table.roster thead th.today { background: var(--today); }
table.roster td.weekgap, table.roster th.weekgap { background: var(--surface-2); width: 4px; min-width: 4px; padding: 0; }
table.roster.week { width: 100%; }
table.roster.week td, table.roster.week th:not(.name) { width: calc((100% - 92px) / 7); }
.legendline { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.legendline span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Kod ---------- */
.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.codes div { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.codes div b { display: block; font-size: 14px; }
.codes div small { color: var(--ink-3); font-size: 12px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.simple th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-2); }
.foot { text-align: center; color: var(--ink-3); font-size: 12.5px; padding: 10px 0 20px; }

/* ---------- Dialog ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 20, 25, .45); }
dialog .dh { padding: 16px 18px 6px; display: flex; align-items: center; gap: 10px; }
dialog .dh h2 { font-size: 18px; flex: 1; }
dialog .db { padding: 8px 18px 14px; overflow: auto; max-height: calc(100vh - 190px); }
dialog .df { padding: 12px 18px 16px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--line); flex-wrap: wrap; }
label.f { display: block; margin: 10px 0; font-weight: 600; font-size: 14px; }
label.f input, label.f select, label.f textarea { display: block; width: 100%; margin-top: 5px; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); font-weight: 400; }
label.c { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; font-size: 14px; }
label.c input { margin-top: 3px; width: 18px; height: 18px; flex: none; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #142028; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 100; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; }

@media print {
  .top, .tabs, .noprint, .toast { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .tablewrap { max-height: none; overflow: visible; box-shadow: none; }
  .card { box-shadow: none; }
  .chip { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.roster { font-size: 10px; }
  @page { size: A4 landscape; margin: 8mm; }
}
@media (max-width: 600px) {
  table.roster.week { font-size: 12px; table-layout: fixed; }
  table.roster.week th.name { min-width: 0; width: 66px; max-width: 66px; padding: 4px 6px; font-size: 12px; }
  table.roster.week th.name .muted { display: none; }
  table.roster.week thead th { min-width: 0; padding: 4px 1px; }
  table.roster.week td { padding: 3px 1px; }
  table.roster.week td.txt { font-size: 10px; min-width: 0; }
  table.roster.week .chip { min-width: 0; padding: 1px 3px; font-size: 11px; border-radius: 5px; }
  table.roster.week tr.sec th { font-size: 10px; padding: 3px 6px; }
}
