:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efefec;
  --border: #dcdbd6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --accent: #2a78d6;
  --accent-text: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #1a7f37;
  --warn: #9a6700;
  --bad: #c62828;
  --today: #e8f0fb;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #3a3936;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #4cc26b;
    --warn: #e0a526;
    --bad: #ef6b6b;
    --today: #1d2a3b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #242422;
  --border: #3a3936;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #4cc26b;
  --warn: #e0a526;
  --bad: #ef6b6b;
  --today: #1d2a3b;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; color: var(--text-2); }
.section-title { margin: 1.5rem 0 .6rem; font-size: 1.25rem; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.small { font-size: .85em; }

input, select, textarea, button {
  font: inherit;
  color: inherit;
}
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .6rem;
  min-width: 0;
}
::placeholder { color: var(--muted); opacity: .7; font-style: italic; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .8rem;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--text-2); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: .8rem; }
.login-logo { align-self: center; width: 96px; height: 96px; }
.login-card h1 { text-align: center; }
.topbar .logo { width: 32px; height: 32px; flex: none; }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: .5rem; align-items: center;
  padding: .6rem 16px; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar select { flex: 1; font-weight: 600; }
.sync { white-space: nowrap; font-size: .85rem; }
.sync::before { content: "●"; margin-right: .35rem; color: var(--good); }
.sync.pending::before { color: var(--warn); }
.sync.offline::before { color: var(--muted); }
.sync.error::before { color: var(--bad); }

.tabs {
  display: flex; overflow-x: auto; gap: .25rem;
  padding: .4rem 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs a {
  padding: .4rem .75rem; border-radius: 999px; text-decoration: none; color: var(--text-2); white-space: nowrap;
}
.tabs a.active { background: var(--accent); color: var(--accent-text); }
main { max-width: 960px; margin: 0 auto; padding: 1rem 16px 4rem; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* week */
.weeknav { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.weeknav .title { flex: 1; text-align: center; line-height: 1.25; min-width: 0; }
.weeknav .title strong, .weeknav .title #week-total { display: block; }
.weeknav #week-total:empty { display: none; }
.card.days { padding: .4rem; }
.day {
  display: grid;
  grid-template-columns: 5.5rem 1fr auto;
  grid-template-areas: "label times opts" "label msg msg" "label note note";
  gap: .3rem .6rem;
  align-items: center;
  padding: .45rem .4rem;
  border-bottom: 1px solid var(--border);
}
.day:last-child { border-bottom: 0; }
.day.today { background: var(--today); border-radius: 8px; }
.day.weekend .label { color: var(--muted); }
.day .label { grid-area: label; line-height: 1.2; white-space: nowrap; }
.day .times { grid-area: times; display: flex; gap: .3rem; }
.day .times input { flex: 1; width: 100%; font-variant-numeric: tabular-nums; }
.day .opts { grid-area: opts; display: flex; gap: .6rem; align-items: center; font-size: .9rem; }
.day .total { min-width: 6.5rem; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.day .msg { grid-area: msg; }
.day .msg:empty { display: none; }
.day .note { grid-area: note; }
.day .note input { width: 100%; }
.day.plan { grid-template-columns: 5.5rem 1fr auto; grid-template-areas: "label est btn" "label note note"; padding: .3rem .4rem; }
.day.plan .label { color: var(--text-2); }
.day .est { width: 4.5rem; padding: .3rem .45rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; color: var(--text-2); flex-direction: row; }
.chip input { width: auto; }
/* start / stop */
.clock {
  display: flex; align-items: center; justify-content: center; gap: .4rem; width: 100%; margin-bottom: .6rem;
  font-weight: 600; background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
.clock:disabled { background: var(--surface-2); border-color: var(--border); color: var(--muted); }
.clock.running { background: var(--bad); border-color: var(--bad); color: var(--bg); }
.note-btn { padding: .2rem .45rem; opacity: .55; }
.note-btn[aria-pressed="true"] { opacity: 1; border-color: var(--accent); }
@media (max-width: 520px) {
  body { font-size: 14px; }
  main { padding: .6rem 10px 3rem; }
  .card { padding: .75rem; margin-bottom: .6rem; }
  .grid { gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .stat { padding: .5rem .7rem; }
  .stat .v { font-size: 1.25rem; }
  input, select, textarea { padding: .4rem .5rem; }
  button { padding: .4rem .6rem; }

  .topbar { padding: .4rem 10px; padding-top: max(.4rem, env(safe-area-inset-top)); gap: .4rem; }
  .topbar .logo { width: 26px; height: 26px; }
  .topbar select { padding: .3rem .45rem; }
  .sync { font-size: 0; padding: .45rem .55rem; }
  .sync::before { font-size: .8rem; margin-right: 0; }
  .tabs { padding: .3rem 8px; gap: .1rem; }
  .tabs a { padding: .25rem .55rem; font-size: .9rem; flex: 1; text-align: center; }

  .weeknav { gap: .35rem; margin-bottom: .5rem; }
  .weeknav button { padding: .35rem .6rem; }
  .card.days { padding: .15rem .3rem; }

  .day {
    grid-template-columns: 2.4rem 1fr; grid-template-areas: "label times" "label opts" "label msg" "label note";
    gap: .2rem .4rem; padding: .35rem .15rem;
  }
  .day .label { white-space: normal; align-self: start; padding-top: .35rem; font-size: .85rem; }
  .day .label b { display: block; }
  .day .label .small { font-size: .75rem; }
  .day .times { gap: .25rem; }
  .day .times input { padding: .35rem .45rem; letter-spacing: -.01em; }
  .day .opts { gap: .4rem; font-size: .8rem; }
  .day .opts .chip input { margin: 0; }
  .day .total { text-align: right; min-width: 0; flex: 1; }
  .note-btn { padding: .05rem .35rem; font-size: .8rem; }
  .day .msg { line-height: 1.2; }

  .day.plan { grid-template-columns: 2.4rem 1fr auto; grid-template-areas: "label est btn" "label note note"; padding: .25rem .15rem; }
  .day.plan .label { align-self: center; padding-top: 0; }
  .day.plan .label b { display: inline; }
  .day.plan .label .small { display: block; }
  .day .est { width: 3.5rem; padding: .25rem .4rem; }
}

/* stats */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.stat .k { font-size: .8rem; color: var(--text-2); }
.stat .v { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .s { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stat .v small { font-size: .6em; font-weight: 500; color: var(--text-2); }
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; gap: 2px; }
.bar > span { display: block; height: 100%; border-radius: 999px; }
.bar .used { background: var(--series-1); }
.bar .plan { background: var(--series-2); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-2); font-size: .85rem; }
td.r, th.r { text-align: right; }
.table-wrap { overflow-x: auto; }

/* chart */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; }
.chart .actual { stroke: var(--series-1); stroke-width: 2; fill: none; stroke-linejoin: round; }
.chart .planned { stroke: var(--series-2); stroke-width: 2; fill: none; stroke-dasharray: 5 4; }
.chart .budget { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .today-line { stroke: var(--muted); stroke-width: 1; }
.chart .label-text { fill: var(--text-2); font-size: 11px; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dot-a { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .dot-p { fill: var(--series-2); stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--text-2); margin-bottom: .5rem; flex-wrap: wrap; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: .35rem; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .4rem .6rem; font-size: .8rem; box-shadow: 0 2px 8px rgb(0 0 0 / .15);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .5rem 1rem; border-radius: 999px; font-size: .9rem;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: .95; }
.weekdays { display: flex; gap: .3rem; flex-wrap: wrap; }
.weekdays label { flex-direction: row; align-items: center; gap: .2rem; }

/* month calendar */
.cal { padding: .5rem; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head span { text-align: center; font-size: .75rem; color: var(--text-2); padding: .2rem 0; }
.cal-cell {
  min-height: 4.2rem; padding: .3rem; border-radius: 8px; text-align: left;
  display: flex; flex-direction: column; gap: .1rem; font-size: .8rem; line-height: 1.2;
  background: var(--surface); border: 1px solid var(--border); font-variant-numeric: tabular-nums; overflow: hidden;
}
.cal-cell .n { color: var(--text-2); font-size: .75rem; }
.cal-cell .marks { margin-top: auto; font-size: .7rem; }
.cal-cell.weekend { background: var(--surface-2); }
.cal-cell.out { opacity: .35; }
.cal-cell.tracked { background: color-mix(in srgb, var(--series-1) 20%, var(--surface)); border-color: var(--series-1); }
.cal-cell.estimated { border: 2px dashed var(--series-2); }
.cal-cell.gap { border: 1px solid var(--warn); }
.cal-cell.unfinished { border: 2px solid var(--bad); }
.card.unfinished { border-color: var(--bad); }
.card.unfinished button { font-size: .9rem; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: 1px; }

.legend i.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: .35rem; border: 1px solid var(--border); border-top-width: 1px; }
.legend i.sw-tracked { background: color-mix(in srgb, var(--series-1) 20%, var(--surface)); border-color: var(--series-1); }
.legend i.sw-est { border: 2px dashed var(--series-2); }
.legend i.sw-gap { border-color: var(--warn); }
@media (max-width: 520px) {
  .cal-cell { min-height: 3.6rem; font-size: .7rem; padding: .2rem; }
}
