:root {
  --bg: #F5F7FB; --card: #FFFFFF; --text: #1B2333; --muted: #667085; --line: #E4E8F0;
  --accent: #1E5EFF; --accent-soft: #E6EDFF; --ok: #1B8A4B; --ok-soft: #E3F4EA; --bad: #C62828; --bad-soft: #FDECEC;
  --warn: #B86A12; --warn-soft: #FFF2E0; --off: #6A3FB5; --off-soft: #F0E9FB; --side: #FFFFFF;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151C; --card: #1A202B; --text: #E7EAF0; --muted: #98A2B3; --line: #2A3242;
    --accent: #6F97FF; --accent-soft: #1E2A47; --ok: #4CC38A; --ok-soft: #173326; --bad: #FF7B7B; --bad-soft: #3A1C1C;
    --warn: #F0A646; --warn-soft: #3A2A14; --off: #B798F0; --off-soft: #2B2140; --side: #161B24;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--text);
}
body.center #app { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
#app { min-height: 100%; }
body:not(.center) #app { display: grid; grid-template-columns: 220px 1fr; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 8px; }
h1 .sub { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0 0 12px; font-size: 17px; }
h4 { margin: 14px 0 6px; font-size: 14px; }
code { background: var(--accent-soft); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: Consolas, monospace; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); } .off { color: var(--off); } .accent { color: var(--accent); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* sidebar */
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; padding: 0 8px 18px; }
.brand span { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.side nav a:hover { background: var(--bg); }
.side nav a.active { background: var(--accent-soft); color: var(--accent); }
.side .ic { width: 20px; text-align: center; }
.side .me { border-top: 1px solid var(--line); padding: 12px 8px 0; }
.side .me button { margin-top: 8px; width: 100%; }

main { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; } .row.end { justify-content: flex-end; margin-top: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; overflow-x: auto; }
.card.error { color: var(--bad); }
.card.auth { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.loading { padding: 32px; color: var(--muted); text-align: center; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; font-family: Consolas, monospace; font-size: 12px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form.narrow { max-width: 620px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.error-text { color: var(--bad); min-height: 1em; }

button {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; cursor: pointer; border: 1px solid transparent;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover:not(:disabled) { background: var(--bg); }
button.danger { background: var(--bad-soft); color: var(--bad); }
button.ok-btn { background: var(--ok); color: #fff; }
button.wide { width: 100%; padding: 11px; }
.seg button { min-width: 80px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }

/* tables */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tfoot td { font-weight: 700; border-bottom: none; }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover td { background: var(--bg); }
table.grid.compact td { padding: 4px 6px; }
table.kv { width: 100%; border-collapse: collapse; margin: 6px 0; }
table.kv td { padding: 5px 0; border-bottom: 1px dashed var(--line); }
table.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
table.kv tr.total td { font-weight: 700; border-bottom: 2px solid var(--line); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.off { background: var(--off-soft); color: var(--off); }
.pill.accent { background: var(--accent-soft); color: var(--accent); } .pill.muted { background: var(--bg); color: var(--muted); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; z-index: 10; }
.modal { background: var(--card); border-radius: 14px; padding: 22px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal label { margin-top: 8px; }
.session { border-top: 1px solid var(--line); padding: 10px 0; }
.punch { display: flex; gap: 12px; align-items: center; margin: 6px 0; }
.photo { width: 84px; height: 84px; border-radius: 10px; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); overflow: hidden; flex: none; }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.fix label { flex-direction: row; align-items: center; gap: 6px; margin: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); color: #fff; }

/* phone / small windows */
@media (max-width: 760px) {
  body:not(.center) #app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 16px; border-right: none; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; flex: 1 1 100%; }
  .side nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; }
  .side nav a { padding: 6px 8px; font-size: 13px; }
  .side .me { display: none; }
  main { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
}

/* printing */
@media print {
  .side, .page-head .row, .noprint, .toast { display: none !important; }
  body:not(.center) #app { display: block; }
  body { background: #fff; color: #000; }
  .card, .stat { border: 1px solid #ccc; }
  body.print-modal #app { display: none; }
  body.print-modal .modal-back { position: static; background: none; padding: 0; }
  body.print-modal .modal { box-shadow: none; max-width: none; }
}

/* day editor */
.punch-row { display: flex; gap: 10px; align-items: center; margin: 6px 0; }
.photo.sm { width: 56px; height: 56px; }
.row.edit { margin: 6px 0; }
.row.edit input[type=time] { padding: 5px 8px; }
.row.add { border-top: 1px dashed var(--line); padding-top: 8px; }
.bonus { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.work { display: flex; flex-direction: column; gap: 8px; }
.work-item { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.work-item > div:nth-child(2) { flex: 1; }
.work-item .photo { cursor: zoom-in; }
.note-ic { font-size: 28px; width: 84px; text-align: center; }
audio { max-width: 260px; }

/* number columns: right-align header and cells together */
table.grid th.num, table.grid td.num { text-align: right; }
table.grid th:first-child, table.grid td:first-child { text-align: left; }
.tpick { display: inline-flex; align-items: center; gap: 3px; }
.tpick select { padding: 5px 4px; }
.lbl { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; }

/* printable workplace QR */
.qr-print { text-align: center; }
.qr-print h2 { margin-bottom: 4px; }
.qr-print img { background: #fff; padding: 12px; border-radius: 12px; }
#att { margin: 8px 0; }

/* ---- attachments, staff photos, locations */
.btnlike { display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; font-size: 13px; font-weight: 600; white-space: nowrap; }
.btnlike:hover { background: var(--bg); }
.btnlike.small { padding: 4px 8px; font-size: 12px; }
.attach { gap: 6px; flex-wrap: wrap; align-items: center; }
.photo.xs { display: inline-flex; width: 34px; height: 34px; border-radius: 6px; vertical-align: middle; }
.bonus-form { border: 1px dashed var(--line); border-radius: 10px; padding: 8px; margin-top: 6px; }
.bonus-form .row.edit { margin: 4px 0; }
.avatar { display: inline-flex; width: 34px; height: 34px; border-radius: 50%; overflow: hidden; background: var(--bg); align-items: center; justify-content: center; font-size: 16px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.pw { cursor: pointer; border-bottom: 1px dashed var(--muted); }
.docs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 6px; }
.doc { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.doc .thumb { width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; background: var(--bg); display: flex; align-items: center; justify-content: center; overflow: hidden; font-size: 26px; border: 1px solid var(--line); }
.doc.face .thumb { aspect-ratio: 1; border-radius: 50%; max-width: 92px; }
.doc .thumb img { width: 100%; height: 100%; object-fit: cover; }
.row.tight { gap: 4px; }
.kvline { font-size: 14px; }
details.pwbox { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
details.pwbox summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.map-card iframe { width: 100%; height: 380px; border: 0; border-radius: 10px; }
.map-card { margin-bottom: 14px; }
@media (max-width: 640px) { .docs { grid-template-columns: repeat(2, 1fr); } }
.doc .row.tight { flex-wrap: nowrap; justify-content: center; }
.who { display: inline-flex; align-items: center; gap: 8px; }
.avatar.md { width: 40px; height: 40px; }
td.nowrap, .nowrap { white-space: nowrap; }
button.small { padding: 4px 10px; font-size: 12px; }
[hidden] { display: none !important; }
