/* ---- 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;
  --control-h: 2.85rem;
  --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;
  display: inline-flex; align-items: center; justify-content: center;
}
.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; }
.stat-card.secondary { background: var(--surface-2); border-color: transparent; }
.stat-card.secondary .stat-label,
.stat-card.secondary .stat-value { color: var(--muted); }
.stat-card.secondary .stat-value { font-weight: 500; }
.stat-card.primary .stat-value { color: var(--accent-ink); }
#btn-add { flex: 0 0 auto; }
.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; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field-label { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: .4rem; }
.field-date { flex: 1 1 12rem; }
.field-hours { flex: 2 1 8rem; }
.field input, .field select, .filters input, .filters select {
  font-family: var(--sans);
  font-size: 16px;             /* 16px keeps iOS from auto-zooming on focus */
  height: var(--control-h);
  padding: 0 .7rem; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--surface); color: var(--ink);
  width: 100%; box-sizing: border-box;
}
.field-hours input { font-family: var(--mono); }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* day stepper around the date input */
.date-nav { display: flex; gap: .35rem; align-items: stretch; }
.date-nav input[type="date"] { flex: 1 1 auto; text-align: center; }
.step-btn {
  flex: 0 0 auto; width: var(--control-h); height: var(--control-h);
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--ink); cursor: pointer;
  font-size: 1.3rem; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.step-btn:hover { background: var(--surface-2); }
.weekday-badge { font-family: var(--mono); font-weight: 600; color: var(--accent-ink);
  background: var(--surface-2); border-radius: 6px; padding: .05rem .4rem; font-size: .78rem; }

/* ---- buttons -------------------------------------------------------- */
.btn {
  font: inherit; cursor: pointer; height: var(--control-h); padding: 0 1.1rem;
  border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box;
}
.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 { height: auto; padding: .4rem .7rem; font-size: .9rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.edit-delete { margin-right: auto; }

/* ---- 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 .edit-input.date { width: 8.5rem; flex: 0 0 auto; }
.hot-edit .edit-input.hours { width: 5rem; flex: 0 0 auto; }

/* ---- 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); }

/* breakdown: collapsible Year -> Month -> Week tree */
.tw-year, .tw-month { cursor: pointer; }
.period-cell { white-space: nowrap; }
.period-cell .tw-toggle, .period-cell .tw-leaf {
  display: inline-block; width: 1.1rem; text-align: center; color: var(--muted);
  font-size: .8rem; user-select: none;
}
td.period-cell.lvl-month { padding-left: 1.3rem; }
td.period-cell.lvl-week { padding-left: 2.6rem; }
.group-row td { font-weight: 600; background: var(--surface-2); }
.group-row.current td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.month-row td { font-weight: 500; }
.week-row td { color: var(--muted); font-weight: 400; }
.week-row .period-cell { font-size: .88rem; }
.week-row.fully-np td { color: color-mix(in srgb, #c8861a 60%, var(--muted)); font-style: italic; }

/* non-productive day tint (Entries rows + legend swatch) */
.data-table tr.np-row:not(.editing) td { background: color-mix(in srgb, #d99a2b 15%, var(--surface)); }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: .6rem;
  font-size: .85rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.legend-swatch { width: .9rem; height: .9rem; border-radius: 3px; display: inline-block;
  border: 1px solid var(--border-strong); }
.swatch-normal { background: var(--surface); }
.swatch-np { background: color-mix(in srgb, #d99a2b 15%, var(--surface)); border-color: transparent; }

/* column-header info tooltip */
.th-info { background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: .9em; padding: 0 0 0 .15rem; vertical-align: middle; line-height: 1; }
.th-pop { position: absolute; max-width: 240px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: .55rem .7rem;
  font-size: .8rem; font-weight: 400; line-height: 1.4; box-shadow: var(--shadow);
  z-index: 50; white-space: normal; text-transform: none; letter-spacing: normal; }

/* settings: non-productive add form + list */
.np-form { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin: .5rem 0 1rem; }
.np-form .field { flex: 1 1 9rem; min-width: 0; }
.np-form .np-label { flex: 2 1 12rem; }
.np-list { margin-top: 1rem; }
.np-tag { font-size: .78rem; padding: .1rem .45rem; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); }
.actions-col { width: 1%; }
.note-cell { width: 1%; }
.note-clip { display: block; max-width: 13rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 1.5rem; color: var(--muted); text-align: center; }

/* inline edit inside data table: a grid that fills the edit area and never overflows */
.data-table tr.editing td { white-space: normal;
  background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.edit-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .75rem; align-items: start; }
.edit-field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.edit-field.full { grid-column: 1 / -1; }
.edit-actions { grid-column: 1 / -1; display: flex; gap: .4rem; align-items: center; }
.edit-input { font: inherit; font-size: 16px; width: 100%; min-width: 0; box-sizing: border-box;
  height: 2.6rem; padding: 0 .6rem; border: 1px solid var(--border-strong);
  border-radius: 6px; background: var(--surface); color: var(--ink);
  -webkit-appearance: none; appearance: none; }
.edit-input.hours { font-family: var(--mono); text-align: right; }

/* ---- 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:not(.current) .big { color: var(--muted); font-weight: 500; }
.report-card.current .big { color: var(--accent-ink); }
.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 ----------------------------------------------------- */
/* On wider screens the Note column is visible: pin every other column so Note
   takes the leftover space and truncates, keeping the Edit button in view. */
@media (min-width: 641px) {
  #entries-table { table-layout: fixed; }
  #entries-table th:nth-child(1) { width: 7.5rem; }  /* Date */
  #entries-table th:nth-child(2) { width: 5rem; }    /* Weekday */
  #entries-table th:nth-child(3) { width: 6rem; }    /* Hours */
  #entries-table th:nth-child(4) { width: 7rem; }    /* School year */
  #entries-table th:nth-child(6) { width: 5rem; }    /* Edit (actions) */
  /* Note (5th column) absorbs the remaining width and truncates. */
}

@media (max-width: 640px) {
  /* Keep tables as real tables, just tighter, and hide non-essential columns. */
  .col-hide-mobile { display: none !important; }
  .data-table { font-size: .9rem; }
  .data-table th, .data-table td { padding: .5rem .5rem; }
  .data-table th:first-child, .data-table td:first-child { padding-left: .6rem; }
  .filters { width: 100%; }
  .filters select { 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; }
  .topbar { padding: .55rem .8rem; gap: .5rem; }
  .topbar, .nav { flex-wrap: nowrap; }
  .brand { font-size: 1.05rem; }
}
@media (max-width: 380px) {
  /* Only the very smallest phones stack the edit fields one per line. */
  .edit-form { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar { transition: height .3s ease, y .3s ease; }
}
