:root {
  --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f8fafc; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #2563eb; --accent-2: #1d4ed8; --accent-text: #ffffff; --accent-soft: #e0eaff;
  --side: #0f172a; --side-text: #cbd5e1; --side-active: #1e293b;
  --ok: #16a34a; --warn: #f59e0b; --bad: #dc2626; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1017; --surface: #121a24; --surface-2: #17212d; --text: #e5edf5; --muted: #8b9bb0; --line: #233041;
    --accent: #5b8def; --accent-2: #7aa3f5; --accent-text: #08101c; --accent-soft: #1b2a45;
    --side: #080c12; --side-text: #9fb0c4; --side-active: #16202d;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
body.viewer .adm { display: none !important; }
body.employee #sync-btn { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; margin: 0; }
.grow { flex: 1; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 16px; color: #fff; }
.brand b { display: block; font-size: 15px; line-height: 1.2; }
.brand small { color: var(--side-text); font-size: 11px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; }
.logo.big { width: 52px; height: 52px; font-size: 22px; border-radius: 14px; }
#nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
#nav .group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 14px 10px 6px; }
#nav a { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 9px; color: var(--side-text); text-decoration: none; font-weight: 500; }
#nav a:hover { background: var(--side-active); color: #fff; }
#nav a.active { background: var(--accent); color: #fff; }
.side-foot { margin-top: auto; padding: 14px 18px; font-size: 12px; border-top: 1px solid #1e293b; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 18px; margin: 0; white-space: nowrap; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.icon-btn.menu-btn { display: none; }
main { padding: 22px 24px 40px; max-width: 1500px; width: 100%; }
.scrim { display: none; }

/* ---------- sync pill ---------- */
.sync-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.sync-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync-pill.ok i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.sync-pill.bad i { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); }
.sync-pill.busy i { background: var(--warn); }
.sync-pill svg.machine { width: 16px; height: 16px; color: var(--muted); }
.sync-pill.ok svg.machine { color: var(--ok); }
.sync-pill.bad svg.machine { color: var(--bad); }
.sync-pill i { position: relative; }
.sync-pill.tick i::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--ok); animation: pulse 1.2s ease-out; }
@keyframes pulse { from { transform: scale(.6); opacity: 1; } to { transform: scale(2.2); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sync-pill.tick i::after { animation: none; } }

/* ---------- notes / alarms / files ---------- */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.note { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--c, var(--line)); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.note h4 { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.note p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); font-size: 13.5px; }
.note.done { opacity: .55; }
.note.done h4 { text-decoration: line-through; }
.note .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.note .actions { display: flex; gap: 6px; margin-top: auto; flex-wrap: wrap; }
.color-dots { display: flex; gap: 8px; }
.color-dots label { width: 26px; height: 26px; border-radius: 50%; background: var(--c); cursor: pointer; border: 2px solid transparent; }
.color-dots input { display: none; }
.color-dots input:checked + label { border-color: var(--text); }
.alarm-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.alarm-row:last-child { border-bottom: 0; }
.alarm-row b { font-size: 24px; font-variant-numeric: tabular-nums; min-width: 110px; }
.alarm-ring { position: fixed; inset: 0; z-index: 70; background: rgba(2,6,23,.75); display: flex; align-items: center; justify-content: center; padding: 16px; }
.alarm-ring .box { background: var(--surface); border-radius: 18px; padding: 28px; text-align: center; max-width: 360px; width: 100%; }
.alarm-ring .box b { display: block; font-size: 44px; margin: 6px 0; }
.ios-hint { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 45; background: var(--surface); border: 1px solid var(--accent);
  border-radius: 14px; padding: 14px 16px; box-shadow: 0 10px 40px rgba(0,0,0,.4); display: flex; gap: 12px; align-items: flex-start; }
.ios-hint p { margin: 0; font-size: 13.5px; }
.file-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
tr.total-row td { background: var(--surface-2); border-top: 2px solid var(--line); }

/* ---------- building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .section + .section { margin-top: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; font-size: 15px; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 2.2fr) minmax(280px, 1fr); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; position: relative; overflow: hidden; box-shadow: var(--shadow); }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c, var(--accent)); }
.kpi span { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi b { display: block; font-size: 28px; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 11.5px; }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type=color] { padding: 2px; width: 46px; height: 36px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.btn { font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: wait; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 9px; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { font: inherit; font-size: 13px; border: 0; background: none; color: var(--text); padding: 7px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); min-width: 0; }
.field input, .field select, .field textarea { font-weight: 400; color: var(--text); font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.hint { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.search { position: relative; }
.search input { padding-left: 34px; width: 260px; max-width: 100%; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 11px; }
.card > .table-wrap { margin: 0 -1px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
tr.click { cursor: pointer; }
tr.deleted td { opacity: .45; text-decoration: line-through; }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; }
.emp { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; flex: none; }
.emp b { display: block; font-weight: 600; line-height: 1.2; }
.emp small { color: var(--muted); font-size: 11.5px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.chip { --c: #94a3b8; display: inline-flex; align-items: center; justify-content: center; min-width: 30px; padding: 2px 8px; border-radius: 7px; font-size: 12px; font-weight: 700;
  background: color-mix(in srgb, var(--c) 20%, transparent); color: color-mix(in srgb, var(--c) 70%, var(--text)); border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 5px; }
.tag.bad { color: var(--bad); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 1px; }
.punch-list { display: flex; flex-wrap: wrap; gap: 4px; }
.punch-list span { font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.punch-list span.manual { border-color: var(--warn); }

/* ---------- register / roster grids ---------- */
table.grid-t th, table.grid-t td { padding: 5px 3px; text-align: center; font-size: 12px; border-right: 1px solid var(--line); }
table.grid-t th.sticky, table.grid-t td.sticky { position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; padding: 6px 10px; min-width: 170px; }
table.grid-t th.sticky { z-index: 3; background: var(--surface-2); }
table.grid-t th.fri { color: var(--bad); }
table.grid-t th.today { background: var(--accent-soft); color: var(--accent); }
table.grid-t td.cell { cursor: pointer; min-width: 34px; }
table.grid-t td.cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
table.grid-t .chip { min-width: 26px; padding: 1px 4px; font-size: 11px; }
table.grid-t td.tot { font-weight: 600; background: var(--surface-2); }
.roster select { width: 52px; padding: 3px 2px; font-size: 11.5px; border-radius: 6px; text-align: center; }
.roster select.custom { background: var(--accent-soft); border-color: var(--accent); font-weight: 700; }
.roster select.off { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.roster select.dirty { outline: 2px solid var(--warn); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--muted); align-items: center; }

/* ---------- employee cards ---------- */
.emp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.emp-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.emp-card.inactive { opacity: .6; }
.emp-card .avatar { width: 44px; height: 44px; font-size: 15px; }
.emp-card dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 12.5px; }
.emp-card dt { color: var(--muted); }
.emp-card dd { margin: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emp-card .actions { display: flex; gap: 8px; margin-top: auto; }
.emp-card .actions .btn { flex: 1; }
.profile-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.profile-head .avatar { width: 64px; height: 64px; font-size: 22px; }
.profile-head > div { flex: 1; min-width: 220px; }
.profile-head h2 { margin: 0; font-size: 22px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 13px; color: var(--muted); margin-top: 4px; }
.facts b { color: var(--text); font-weight: 600; }

/* ---------- shifts ---------- */
.shift-card { border-top: 4px solid var(--c); }
.shift-card .rule { font-size: 12.5px; margin-top: 12px; padding: 10px 12px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); }

/* ---------- feed ---------- */
.feed { display: flex; flex-direction: column; }
.feed div { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.feed div:last-child { border-bottom: 0; }
.feed time { margin-left: auto; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.shift-bars { display: flex; flex-direction: column; gap: 12px; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: var(--c); }

/* ---------- modal / login / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(2,6,23,.55); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal-box { background: var(--surface); border-radius: 16px; width: 100%; max-width: 640px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-box h2 { margin: 0 0 4px; font-size: 18px; }
.modal-box .kpi b { font-size: 19px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.modal-section h3 { margin: 0 0 10px; font-size: 14px; }
.login { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card .login-company { font-size: 16px; font-weight: 600; color: var(--accent); margin-top: -4px; }
.login-card .login-company:empty { display: none; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 60; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.toast.bad { background: var(--bad); }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .cols-main, .cols-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(2,6,23,.5); z-index: 25; }
  .icon-btn.menu-btn { display: grid; }
  .topbar { padding: 10px 16px; gap: 8px; }
  .clock { display: none; }
  main { padding: 16px 16px 32px; }
  .cols-2 { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi b { font-size: 24px; }
  #sync-btn { padding: 7px 10px; }
  .sync-pill span { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
  .search input { width: 100%; }
  .search { flex: 1; }
}
@media (max-width: 420px) {
  .topbar h1 { font-size: 16px; }
  .sync-pill span { display: none; }
}
