:root {
  --bg: #f2f5f2;
  --card: #ffffff;
  --text: #1e2a24;
  --muted: #5f7167;
  --line: #dce4de;
  --accent: #2c6a4f;
  --accent-ink: #ffffff;
  --break: #3b6f8f;
  --warn: #a8791f;
  --danger: #b04a3a;
  --radius: 12px;
  --panel-h: 0px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a16;
    --card: #1b241f;
    --text: #e3ebe5;
    --muted: #93a59a;
    --line: #2c3a33;
    --accent: #5fae88;
    --accent-ink: #0f1f17;
    --break: #6fa3c4;
    --warn: #d6a54e;
    --danger: #d9776a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--panel-h) + 24px + env(safe-area-inset-bottom));
}
a { color: inherit; }
h1 { font-size: 1.5rem; margin: .2rem 0; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.inline { display: inline; margin: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; align-items: center; font-size: .95rem; }
.topbar nav a { text-decoration: none; }

main { max-width: 860px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head a.muted { text-decoration: none; font-size: .9rem; }
.head-actions { display: flex; gap: .5rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: .8rem; }

.flash { padding: .6rem .8rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.error { border-color: var(--danger); color: var(--danger); }
.flash.ok { border-color: var(--break); color: var(--break); }
.badge { font-size: .75rem; vertical-align: middle; border: 1px solid var(--muted); color: var(--muted); border-radius: 99px; padding: .05rem .5rem; }

/* forms */
input, button, .button {
  font: inherit; color: inherit; border-radius: 8px;
}
input {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); background: var(--bg);
  min-height: 44px;
}
input:disabled { opacity: .7; }
label { display: block; font-size: .9rem; color: var(--muted); }
label input { margin-top: .25rem; color: var(--text); }
label small { display: block; margin-top: .2rem; }
.stack > * + * { margin-top: .8rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; }
@media (max-width: 600px) { .grid4 { grid-template-columns: repeat(2, 1fr); } }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  min-height: 44px; padding: .45rem .9rem; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.ghost, .button.ghost { background: transparent; }
button.small, .button.small { min-height: 36px; padding: .25rem .7rem; font-size: .9rem; }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: inherit; font-size: inherit; }
button:disabled { opacity: .5; cursor: default; }
.htmx-request button, button.htmx-request { opacity: .6; }

/* projects */
.projects { list-style: none; margin: 0; padding: 0; }
.projects li + li { border-top: 1px solid var(--line); }
.project-link { display: flex; flex-direction: column; padding: .7rem .2rem; text-decoration: none; }
.project-name { font-weight: 600; }
.project-link .muted { font-size: .88rem; }
.toggle { margin: .8rem 0 0; font-size: .9rem; }

/* tasks */
.add-task { display: grid; grid-template-columns: 1fr 6.5rem 10rem auto; gap: .5rem; margin-bottom: 1rem; }
@media (max-width: 600px) {
  .add-task { grid-template-columns: 1fr 1fr; }
  .add-task input[name=title] { grid-column: 1 / -1; }
  .add-task button { grid-column: 1 / -1; }
}
.tasks { list-style: none; margin: 0; padding: 0; }
.task { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .65rem .2rem; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tasks > .task:first-child { border-top: 0; }
.task-main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 14rem; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task-meta { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .88rem; color: var(--muted); }
.task-actions { display: flex; gap: .4rem; }
.task.overdue .deadline { color: var(--danger); font-weight: 600; }
.task.running { background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 8px; padding-left: .5rem; padding-right: .5rem; }
.tasks.compact .task-main { flex-direction: row; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.done-tasks { margin-top: 1rem; }
.done-tasks summary { cursor: pointer; color: var(--muted); }
.done-tasks .task-title { text-decoration: line-through; color: var(--muted); }
.danger-zone { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }

/* timer panel */
.timer-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 3px solid var(--accent);
  box-shadow: 0 -6px 24px rgba(0,0,0,.12);
  padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
}
.timer-panel > * { max-width: 860px; margin-left: auto; margin-right: auto; }
.timer-panel.is-idle { display: none; }
.timer-panel.phase-break, .timer-panel.phase-break_paused, .timer-panel.phase-break_done { border-top-color: var(--break); }
.timer-panel.phase-focus_paused, .timer-panel.phase-break_paused { border-top-color: var(--warn); }
.tp-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.tp-info { min-width: 0; }
.tp-phase { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; gap: .6rem; align-items: center; }
.tp-cycle { text-transform: none; letter-spacing: 0; }
.tp-task { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-task a { text-decoration: none; }
.tp-clock { font-variant-numeric: tabular-nums; font-size: 2.2rem; font-weight: 700; line-height: 1; }
[data-paused="true"] .tp-clock { color: var(--warn); }
.tp-progress { height: 4px; background: var(--line); border-radius: 2px; margin: .55rem auto .2rem; overflow: hidden; }
.tp-progress > div { height: 100%; background: var(--accent); transition: width 1s linear; }
.phase-break .tp-progress > div, .phase-break_paused .tp-progress > div { background: var(--break); }
.tp-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.tp-actions > * { flex: 1 1 auto; }
.tp-prompt p { margin: .3rem 0; color: var(--muted); }
.tp-error { color: var(--danger); margin-top: .4rem; font-size: .9rem; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: min(360px, 100%); }
.login-card h1 { margin-bottom: 1rem; }
.login-card button { width: 100%; margin-top: 1rem; }

/* reports */
main.wide { max-width: 1100px; }
.report-filters { display: flex; flex-direction: column; gap: .8rem; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: fit-content; max-width: 100%; }
.seg > a, .seg > .seg-static { padding: .4rem .8rem; text-decoration: none; font-size: .92rem; border-left: 1px solid var(--line); }
.seg > :first-child { border-left: 0; }
.seg > a:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.seg > .active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg-static { color: var(--muted); }
.range-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.range-row .step { font-size: 1.2rem; min-width: 40px; }
.range-form { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.range-form label { flex: 0 1 11rem; }
.range-form label.check { flex: 0 0 auto; display: flex; gap: .4rem; align-items: center; min-height: 36px; color: var(--text); }
.range-form label.check input { width: auto; min-height: 0; margin: 0; }
.range-form input[type=date] { min-height: 36px; padding: .3rem .5rem; }

.chart-card h2 { color: var(--muted); font-weight: 600; font-size: .95rem; }
.bar-chart { width: 100%; height: auto; display: block; font: 11px system-ui, sans-serif; }
.bar-chart .grid { stroke: var(--line); stroke-width: 1; }
.bar-chart .grid.base { stroke: var(--muted); }
.bar-chart .tick, .bar-chart .xlabel { fill: var(--muted); }
.bar-chart .bar { fill: var(--accent); }
.bar-chart .hit { fill: transparent; }
.bar-chart .col:hover .hit { fill: color-mix(in srgb, var(--accent) 8%, transparent); }
.bar-chart .col:hover .xlabel { fill: var(--text); }

.table-wrap { overflow-x: auto; }
table.report { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.report th, table.report td { padding: .4rem .6rem; text-align: left; border-bottom: 1px solid var(--line); }
table.report .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.report thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
table.report .row-period th, table.report .row-period td { background: color-mix(in srgb, var(--accent) 7%, transparent); font-weight: 700; border-top: 2px solid var(--line); }
table.report .row-project th, table.report .row-project td { font-weight: 600; }
table.report .row-project th a { text-decoration: none; }
table.report .row-task td:first-child { padding-left: 1.6rem; overflow-wrap: anywhere; }
table.report .row-task td { color: var(--text); }
table.report .row-total th, table.report .row-total td { font-weight: 700; border-top: 2px solid var(--muted); border-bottom: 0; }
.range-row { flex-wrap: nowrap; }
.range-row .seg { flex: 0 1 auto; min-width: 0; }
.chart-scroll { overflow-x: auto; }
table.report th:first-child, table.report td:first-child { min-width: 12rem; }
@media (max-width: 600px) {
  .bar-chart { min-width: 560px; }
  .range-row .seg > a, .range-row .seg > .seg-static { padding: .4rem .55rem; }
  .topbar { padding: .5rem .75rem; }
  .topbar nav { gap: .7rem; font-size: .88rem; }
  .brand { white-space: nowrap; }
}
@media (max-width: 440px) { .brand-text { display: none; } }
