/* ==========================================================================
   Salary Tracker -- mobile-first stylesheet.
   One file, no build step, no external fonts: the whole UI loads in one
   round trip and the CSP can stay at style-src 'self'.
   ========================================================================== */

:root {
  --teal-900: #10333f;
  --teal-700: #1f4e5f;
  --teal-500: #2f7389;
  --teal-100: #d9eaef;

  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #fafbfa;
  --border: #dfe2de;
  --text: #1b2022;
  --text-dim: #5d6b70;
  --text-faint: #87959a;

  --accent: var(--teal-700);
  --accent-text: #ffffff;

  --good: #1d7a4f;
  --good-bg: #e2f3e9;
  --warn: #9a6212;
  --warn-bg: #fdf0db;
  --bad: #a32c28;
  --bad-bg: #fbe6e5;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 51, 63, .06), 0 4px 14px rgba(16, 51, 63, .05);
  --tap: 44px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11171a;
    --surface: #1a2226;
    --surface-2: #202a2f;
    --border: #2d3a40;
    --text: #e8edef;
    --text-dim: #a4b3b9;
    --text-faint: #7d8d94;

    --accent: #4f97ad;
    --accent-text: #06161c;

    --good: #6fd39b;
    --good-bg: #16342a;
    --warn: #e8b464;
    --warn-bg: #3a2d16;
    --bad: #f28b85;
    --bad-bg: #3b1d1c;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .22);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

@media (min-width: 760px) {
  body { padding-bottom: 0; }
}

a { color: var(--accent); }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Layout -------------------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}
.wrap-narrow { max-width: 420px; padding-top: 8vh; }

.page-title { margin-bottom: .2em; }
.lede { color: var(--text-dim); margin: 0 0 1rem; font-size: .95rem; }

.page-head {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: flex-start; justify-content: space-between;
  margin-bottom: 16px;
}

.back-link {
  display: inline-block; font-size: .85rem; text-decoration: none;
  color: var(--text-dim); margin-bottom: 6px;
}
.back-link:hover { color: var(--accent); }

/* --- Top bar (desktop) --------------------------------------------------- */

.topbar {
  display: none;
  align-items: center; gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
@media (min-width: 760px) { .topbar { display: flex; } }

.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 650; text-decoration: none; color: var(--text);
}
.brand-mark {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: .95rem;
}

.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav a {
  padding: 7px 13px; border-radius: 999px;
  text-decoration: none; color: var(--text-dim); font-size: .92rem;
}
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav a.active { background: var(--teal-100); color: var(--teal-900); font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .topnav a.active { background: var(--surface-2); color: var(--accent); }
}

.signout { margin: 0; }

/* --- Bottom tab bar (mobile) --------------------------------------------- */

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 760px) { .tabbar { display: none; } }

.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tap); padding: 8px 4px;
  text-decoration: none; color: var(--text-faint); font-size: .7rem;
}
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tab-icon { font-size: 1.15rem; line-height: 1; }

.foot {
  padding: 16px; text-align: center;
  font-size: .75rem; color: var(--text-faint);
}
@media (max-width: 759px) { .foot { display: none; } }

/* --- Cards --------------------------------------------------------------- */

.card, .form-card, .auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.card-head h2 { margin: 0; }

.card-note { color: var(--text-dim); font-size: .88rem; margin: 8px 0; }
.card-note.muted { color: var(--text-faint); }

.card-actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px;
}

.card-next { border-left: 3px solid var(--accent); }
.card-total { text-align: center; }
.card-total .breakdown { text-align: left; }

.big-amount {
  font-size: 2.1rem; font-weight: 680; letter-spacing: -.02em;
  margin: 4px 0 12px; font-variant-numeric: tabular-nums;
}

.link-small { font-size: .85rem; }

/* --- Banners and flashes ------------------------------------------------- */

.flashes { margin-bottom: 14px; }

.flash, .banner {
  padding: 11px 14px; border-radius: var(--radius-sm);
  font-size: .9rem; margin-bottom: 10px;
  border: 1px solid transparent;
}
.flash-success { background: var(--good-bg); color: var(--good); border-color: currentColor; }
.flash-error   { background: var(--bad-bg);  color: var(--bad);  border-color: currentColor; }
.flash-warning { background: var(--warn-bg); color: var(--warn); border-color: currentColor; }
.banner-alert  { background: var(--bad-bg);  color: var(--bad);  border-color: currentColor; }
.banner-alert a { color: inherit; }

/* --- Chips and pills ----------------------------------------------------- */

.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-dim);
}
.chip-lg { font-size: .85rem; padding: 5px 14px; }
.chip-paid { background: var(--good-bg); color: var(--good); }
.chip-due  { background: var(--bad-bg);  color: var(--bad); }
.chip-wait { background: var(--warn-bg); color: var(--warn); }
.chip-ok   { background: var(--teal-100); color: var(--teal-900); }
@media (prefers-color-scheme: dark) {
  .chip-ok { background: var(--surface-2); color: var(--accent); }
}

.pill {
  display: inline-block; margin: 0 6px 6px 0; padding: 3px 10px;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  font-size: .78rem; color: var(--text-dim);
}
.worker-meta { margin: 6px 0 0; }

.count-badge { font-size: .8rem; color: var(--text-dim); }

/* --- Stats --------------------------------------------------------------- */

.stat-grid {
  display: grid; gap: 10px; margin-bottom: 16px;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 620px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; text-align: center;
}
.stat-value {
  display: block; font-size: 1.2rem; font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.stat-label { display: block; font-size: .72rem; color: var(--text-dim); margin-top: 2px; }

/* --- Definition lists ---------------------------------------------------- */

.breakdown, .kv { margin: 0; }
.breakdown > div, .kv > div {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
}
.breakdown > div:last-child, .kv > div:last-child { border-bottom: 0; }
.breakdown dt, .kv dt { color: var(--text-dim); font-size: .9rem; }
.breakdown dd, .kv dd {
  margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 550;
}
.dd-note { display: block; font-size: .72rem; color: var(--text-faint); font-weight: 400; }
.neg { color: var(--bad); }

/* --- Period list --------------------------------------------------------- */

.period-list { list-style: none; margin: 0; padding: 0; }
.period-list li { border-bottom: 1px solid var(--border); }
.period-list li:last-child { border-bottom: 0; }

.period-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 2px; min-height: var(--tap);
  text-decoration: none; color: inherit;
}
.period-row:hover { background: var(--surface-2); }
.period-date { display: block; font-weight: 600; }
.period-sub { display: block; font-size: .76rem; color: var(--text-dim); }
.period-right { text-align: right; white-space: nowrap; }
.period-amount {
  display: block; font-weight: 600; font-variant-numeric: tabular-nums;
}

/* --- Tables -------------------------------------------------------------- */

.table-scroll { margin-bottom: 16px; }

.sched {
  width: 100%; border-collapse: collapse;
  background: var(--surface); font-size: .88rem;
}
.sched caption { text-align: left; }
.sched th, .sched td {
  padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.sched thead th {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-dim); background: var(--surface-2); font-weight: 650;
}
.sched .num { text-align: right; font-variant-numeric: tabular-nums; }
.sched .strong { font-weight: 650; }
.sched tfoot td {
  font-weight: 650; background: var(--surface-2); border-top: 2px solid var(--border);
}
.sched .restdays { font-size: .78rem; color: var(--text-dim); max-width: 210px; }
.cell-sub { display: block; font-size: .72rem; color: var(--text-faint); }
.row-link { font-weight: 600; text-decoration: none; }
.row-overdue { background: var(--bad-bg); }

/* Desktop: a scrolling table. Mobile: each row becomes its own card. */
@media (min-width: 760px) {
  .table-scroll {
    overflow-x: auto; border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
  }
}

@media (max-width: 759px) {
  .sched, .sched tbody, .sched tr, .sched td { display: block; width: 100%; }
  .sched thead, .sched tfoot { display: none; }

  .sched tr {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    margin-bottom: 10px; padding: 4px 12px;
  }
  .sched td {
    display: flex; justify-content: space-between; gap: 14px;
    padding: 7px 0; text-align: right; border-bottom: 1px solid var(--border);
  }
  .sched td:last-child { border-bottom: 0; }
  .sched td::before {
    content: attr(data-label);
    font-size: .76rem; color: var(--text-dim); text-align: left;
    flex: 0 0 auto; font-weight: 500;
  }
  .sched .restdays { max-width: none; }
  .cell-sub { display: inline; margin-left: 6px; }
}

.audit-table { font-size: .8rem; }
.audit-table code { font-family: var(--mono); font-size: .92em; }

.pager { display: flex; gap: 8px; justify-content: center; }

/* --- Filter bar ---------------------------------------------------------- */

.filterbar { display: flex; gap: 6px; margin-bottom: 14px; }
.filter {
  padding: 7px 15px; border-radius: 999px; font-size: .85rem;
  text-decoration: none; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border);
  min-height: 36px; display: inline-flex; align-items: center;
}
.filter.active {
  background: var(--accent); color: var(--accent-text); border-color: var(--accent);
  font-weight: 600;
}

/* --- Forms --------------------------------------------------------------- */

fieldset { border: 0; padding: 0; margin: 0 0 18px; }
legend {
  padding: 0; margin-bottom: 10px; font-weight: 650; font-size: .95rem;
  color: var(--text);
}

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block; font-size: .82rem; font-weight: 600;
  color: var(--text-dim); margin-bottom: 5px;
}
.req { color: var(--bad); }

.field-row { display: grid; gap: 0 14px; }
@media (min-width: 560px) { .field-row { grid-template-columns: 1fr 1fr; } }

input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="file"], select, textarea {
  width: 100%; padding: 11px 12px; min-height: var(--tap);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  appearance: none;
}
textarea { min-height: 72px; resize: vertical; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

input[type="file"] { padding: 9px; background: var(--surface); }

.field-hint { display: block; font-size: .76rem; color: var(--text-faint); margin-top: 4px; }
.field-error { display: block; font-size: .8rem; color: var(--bad); margin-top: 4px; font-weight: 500; }

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }

.inline-form {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  padding-top: 10px; border-top: 1px solid var(--border); margin-top: 12px;
}
.inline-form:first-of-type { border-top: 0; }
.field-inline { margin-bottom: 0; flex: 0 1 140px; }

.code-input {
  font-family: var(--mono); font-size: 1.4rem; letter-spacing: .3em;
  text-align: center;
}

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 11px 18px;
  font: inherit; font-size: .92rem; font-weight: 600;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent); color: var(--accent-text); border-color: var(--accent);
}
.btn-primary:hover { background: var(--teal-500); border-color: var(--teal-500); }
@media (prefers-color-scheme: dark) {
  .btn-primary:hover { background: #63a9bf; border-color: #63a9bf; }
}

.btn-ghost { background: transparent; }
.btn-warn { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn-warn:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn-block { width: 100%; }

.btn-link {
  background: none; border: 0; padding: 6px 2px; font: inherit; font-size: .88rem;
  color: var(--accent); cursor: pointer; text-decoration: underline;
  min-height: 32px;
}
.btn-danger { color: var(--bad); }

/* --- Rest day grid ------------------------------------------------------- */

.daygrid {
  display: grid; gap: 8px; list-style: none; margin: 12px 0; padding: 0;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
}

.daycheck { display: block; cursor: pointer; }
.daycheck input {
  position: absolute; opacity: 0; width: 0; height: 0;
}

.daycheck-body {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 10px 6px; min-height: 76px; justify-content: center;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-dim);
  transition: background .12s, border-color .12s, color .12s;
}
.daycheck input:checked + .daycheck-body {
  border-color: var(--good); background: var(--good-bg); color: var(--good);
}
.daycheck input:focus-visible + .daycheck-body {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.daycheck input:disabled + .daycheck-body { opacity: .6; cursor: not-allowed; }

.dayname { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; }
.daynum { font-size: 1.35rem; font-weight: 680; line-height: 1.1; }
.daymon { font-size: .68rem; text-transform: uppercase; }

.live-preview {
  margin: 10px 0 0; padding: 10px 12px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  font-size: .86rem; color: var(--text-dim);
}
.live-preview:empty { display: none; }
.live-preview strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* --- Proof of payment ---------------------------------------------------- */

.proof-list { list-style: none; margin: 0 0 14px; padding: 0; }
.proof {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.proof:last-child { border-bottom: 0; }

.proof-thumb {
  flex: 0 0 68px; width: 68px; height: 68px;
  border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--border); background: var(--surface-2);
  display: grid; place-items: center;
  text-decoration: none; color: var(--text-dim);
  font-size: .7rem; font-weight: 700; letter-spacing: .05em;
}
.proof-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.proof-meta { flex: 1 1 auto; min-width: 0; }
.proof-name {
  display: block; font-weight: 550; font-size: .9rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.proof-sub { display: block; font-size: .74rem; color: var(--text-faint); }
.proof-actions {
  display: flex; gap: 14px; align-items: center; margin-top: 4px; font-size: .82rem;
}
.proof-actions form { margin: 0; }

.upload-form { border-top: 1px solid var(--border); padding-top: 14px; }

.paid-summary { font-size: .95rem; margin: 0 0 12px; }

/* --- Sessions ------------------------------------------------------------ */

.session-list { list-style: none; margin: 0 0 12px; padding: 0; }
.session-list li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.session-list li:last-child { border-bottom: 0; }
.session-main { display: block; font-weight: 550; font-size: .9rem; }
.session-sub {
  display: block; font-size: .74rem; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis;
}

/* --- Auth pages ---------------------------------------------------------- */

.auth-card { padding: 24px; }
.auth-title { font-size: 1.4rem; margin-bottom: .15em; }
.auth-sub { color: var(--text-dim); font-size: .9rem; margin: 0 0 20px; }
.auth-help { font-size: .82rem; color: var(--text-dim); margin: 16px 0 0; }
.auth-alt { margin-top: 4px; text-align: center; }

.error-card { text-align: center; }
.error-code {
  font-size: 2.6rem; font-weight: 700; color: var(--text-faint);
  margin: 0 0 .1em; font-variant-numeric: tabular-nums;
}

/* --- Two-factor setup ---------------------------------------------------- */

.steps { margin: 0 0 18px; padding-left: 20px; }
.steps li { margin-bottom: 14px; }

.qr-wrap {
  display: grid; place-items: center; padding: 14px; margin: 10px 0;
  background: #ffffff; border: 1px solid var(--border); border-radius: var(--radius);
}
.qr { display: block; width: 220px; height: 220px; }

.manual-key summary { cursor: pointer; font-size: .85rem; color: var(--accent); }
.secret-key {
  font-family: var(--mono); font-size: .95rem; word-break: break-all;
  background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius-sm);
  user-select: all; margin: 8px 0 4px;
}

.codes {
  list-style: none; margin: 0 0 8px; padding: 0;
  display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.codes li {
  font-family: var(--mono); font-size: 1rem; letter-spacing: .05em;
  padding: 10px 12px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); user-select: all;
}

/* --- Print --------------------------------------------------------------- */

@media print {
  .topbar, .tabbar, .foot, .card-actions, .filterbar, .form-actions,
  .upload-form, .inline-form { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .card, .sched tr { box-shadow: none; break-inside: avoid; }
  .table-scroll { overflow: visible; }
  @page { margin: 14mm; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; transition-duration: .01ms !important;
  }
}
