/* ---- design tokens -------------------------------------------------- */
:root {
  --bg:        #f6f5f1;
  --surface:   #fffefb;
  --surface-2: #efeee8;
  --ink:       #1d2422;
  --muted:     #6b736f;
  --border:    #e0ded6;
  --border-strong: #c9c7be;
  --accent:    #1f7a5c;
  --accent-ink:#13503c;
  --danger:    #b23c2e;
  --warn-bg:   #fdf3df;
  --warn-ink:  #7a5a16;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,30,25,.06), 0 8px 24px rgba(20,30,25,.05);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[data-theme="dark"] {
  --bg:#14181a; --surface:#1c2123; --surface-2:#232a2c; --ink:#e7eae6;
  --muted:#97a09b; --border:#2c3437; --border-strong:#3a4448;
  --accent:#43b08a; --accent-ink:#bfe7d7; --danger:#e08a7d;
  --warn-bg:#332b16; --warn-ink:#e6c878;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
}
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg:#14181a; --surface:#1c2123; --surface-2:#232a2c; --ink:#e7eae6;
    --muted:#97a09b; --border:#2c3437; --border-strong:#3a4448;
    --accent:#43b08a; --accent-ink:#bfe7d7; --danger:#e08a7d;
    --warn-bg:#332b16; --warn-ink:#e6c878;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

/* ---- base ----------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: .25rem 0 0; }

/* ---- top bar -------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem clamp(1rem, 4vw, 2rem);
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  font-weight: 650; font-size: 1.15rem; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none;
}
.brand-dot { color: var(--accent); }
.brand-lg { font-size: 1.9rem; }
.nav { display: flex; gap: .25rem; margin-left: .5rem; }
.nav a {
  color: var(--muted); text-decoration: none; padding: .35rem .6rem;
  border-radius: 8px; font-size: .95rem;
}
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.is-active { color: var(--accent-ink); background: var(--surface-2); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .25rem; }
.inline { display: inline; margin: 0; }
.icon-btn, .link-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; padding: .35rem .55rem; border-radius: 8px;
}
.icon-btn:hover, .link-btn:hover { color: var(--ink); background: var(--surface-2); }

/* ---- layout --------------------------------------------------------- */
.page { max-width: 760px; margin: 0 auto; padding: clamp(1rem, 4vw, 2rem); }
.page-head {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center;
  justify-content: space-between; margin-bottom: 1rem;
}
.page-title { font-size: 1.4rem; margin: 0; letter-spacing: -.01em; }
.section-title { font-size: 1rem; margin: 1.75rem 0 .6rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

/* ---- stat cards ----------------------------------------------------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
}
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 2rem; line-height: 1.1; margin-top: .15rem; font-weight: 600; }
.stat-sub { color: var(--muted); font-size: .78rem; margin-top: .3rem; }
.year-line { margin: .9rem 0 0; font-size: .95rem; }

/* ---- logger --------------------------------------------------------- */
.logger {
  margin-top: 1.5rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem;
}
.entry-row { display: flex; gap: .6rem; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field-label { font-size: .8rem; color: var(--muted); }
.field-date { flex: 0 0 auto; }
.field-hours { flex: 1 1 auto; }
.field-note { margin-top: .7rem; }
.field input, .field select, .filters input, .filters select {
  font: inherit; padding: .6rem .7rem; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--surface); color: var(--ink); width: 100%;
}
.field-hours input { font-family: var(--mono); font-size: 1.05rem; }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---- buttons -------------------------------------------------------- */
.btn {
  font: inherit; cursor: pointer; padding: .6rem 1.1rem; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-block { width: 100%; }
.btn-sm { padding: .35rem .6rem; font-size: .85rem; }

/* ---- status & dupe -------------------------------------------------- */
.status { min-height: 1.4em; margin: .8rem 0 0; font-size: .9rem; }
.status.ok { color: var(--accent-ink); }
.status.err { color: var(--danger); }
.status.busy { color: var(--muted); }
.dupe {
  margin-top: .7rem; padding: .6rem .8rem; font-size: .88rem;
  background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px;
}
.dupe-title { font-weight: 600; margin-right: .35rem; }

/* ---- hot list ------------------------------------------------------- */
.hotlist { margin-top: 1.5rem; }
.hotlist-items { list-style: none; margin: 0; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); }
.hot-item {
  display: flex; align-items: center; gap: .6rem; padding: .6rem .9rem;
  border-bottom: 1px solid var(--border);
}
.hot-item:last-child { border-bottom: none; }
.hot-date { color: var(--muted); min-width: 6.5rem; font-size: .9rem; }
.hot-hours { font-size: 1.05rem; font-weight: 600; min-width: 4.5rem; }
.hot-note { color: var(--muted); font-size: .85rem; flex: 1 1 auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hot-actions { margin-left: auto; display: flex; gap: .35rem; }
.hot-edit { display: flex; gap: .4rem; align-items: center; flex: 1 1 auto; }
.hot-edit input { padding: .35rem .5rem; }
.hot-edit .field-date { width: 9rem; }
.hot-edit .field-hours { width: 5rem; }

/* ---- tables --------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data-table th, .data-table td { padding: .6rem .8rem; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table thead th { color: var(--muted); font-weight: 600; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .04em; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.num-col { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sortable { cursor: pointer; user-select: none; }
.sortable::after { content: " ↕"; opacity: .35; }
.sortable.asc::after { content: " ↑"; opacity: .8; }
.sortable.desc::after { content: " ↓"; opacity: .8; }
.row-current td { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.actions-col { width: 1%; }
.empty { padding: 1.5rem; color: var(--muted); text-align: center; }

/* inline edit inside data table: a single full-width row that wraps */
.data-table tr.editing td { white-space: normal; }
.edit-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.edit-field { display: flex; flex-direction: column; gap: .25rem; }
.edit-actions { display: flex; gap: .4rem; align-items: flex-end; margin-left: auto; }
.edit-input { font: inherit; padding: .4rem .55rem; border: 1px solid var(--border-strong);
  border-radius: 6px; background: var(--surface); color: var(--ink); }
.edit-input.hours { width: 6rem; font-family: var(--mono); text-align: right; }
.edit-input.date { width: 10rem; }
.edit-input.note { width: 14rem; max-width: 100%; }

/* ---- filters -------------------------------------------------------- */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters input { width: auto; min-width: 12rem; }

/* ---- reports -------------------------------------------------------- */
.report-grid { display: grid; gap: .75rem;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1rem; }
.report-card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; }
.report-card.current { border-color: var(--accent); }
.report-card .yr { font-weight: 600; }
.report-card .big { font-size: 1.6rem; font-weight: 600; margin: .3rem 0 .1rem; }
.report-card .delta { font-size: .82rem; }
.delta.up { color: var(--accent-ink); }
.delta.down { color: var(--danger); }
.chart-block { margin-top: .5rem; }
.chart { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; }
.chart svg { width: 100%; height: auto; display: block; }
.bar { fill: var(--accent); }
.bar.current { fill: var(--accent-ink); }
.bar-label, .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.bar-value { fill: var(--ink); font-size: 11px; font-family: var(--mono); }

.cutoff-form { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.cutoff-form .field { width: auto; }
.cutoff-form select { width: auto; }
.settings-block { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }

/* ---- login ---------------------------------------------------------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2rem; box-shadow: var(--shadow); text-align: center; }
.login-form { margin-top: 1.2rem; text-align: left; display: flex;
  flex-direction: column; gap: 1rem; }

/* ---- responsive ----------------------------------------------------- */
@media (max-width: 640px) {
  /* Stacked "card" tables: each row becomes a labelled block, no sideways scroll. */
  .table-wrap { overflow-x: visible; border: none; background: none; }
  .data-table thead { position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0); }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: .6rem; padding: .25rem .25rem; }
  .data-table tbody tr:hover { background: var(--surface); }
  .data-table td { border: none; white-space: normal;
    display: flex; justify-content: space-between; gap: 1rem; padding: .4rem .8rem; }
  .data-table td::before { content: attr(data-label); color: var(--muted);
    font-size: .8rem; font-weight: 600; }
  .data-table td.actions-col { justify-content: flex-end; }
  .data-table td.actions-col::before { content: none; }
  .num-col { text-align: right; }
  .row-current { outline: 2px solid var(--accent); outline-offset: -2px; }
  .data-table tr.editing td::before { content: none; }
  .edit-form { flex-direction: column; align-items: stretch; }
  .edit-actions { margin-left: 0; }
  .edit-input.date, .edit-input.hours, .edit-input.note { width: 100%; }
}

@media (max-width: 560px) {
  .entry-row { flex-wrap: wrap; }
  .field-date, .field-hours { flex: 1 1 100%; }
  #btn-add { width: 100%; }
  .nav a { padding: .35rem .45rem; }
  .stat-value { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar { transition: height .3s ease, y .3s ease; }
}
