:root {
  --bg: #f7f7f8; --surface: #fff; --text: #17181c; --muted: #6b6f7a; --line: #e4e5e9;
  --accent: #2f6fde; --accent-text: #fff; --stop: #d6453d; --warn-bg: #fff5d6; --warn-text: #6b4e00;
  --ok: #1f8a4c; --radius: 10px; --shadow: 0 1px 2px rgb(0 0 0 / .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16181d; --surface: #1f2228; --text: #ececef; --muted: #9a9ea8; --line: #30343c;
          --accent: #5b8ff0; --stop: #ef6a62; --warn-bg: #3a3014; --warn-text: #f3d98a; --ok: #4cc27f; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; padding-bottom: 48px; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
input, select { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; }
input:focus-visible, select:focus-visible, button:focus-visible, .blk:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { cursor: pointer; border: 0; border-radius: 8px; min-height: 40px; padding: 0 16px; }
.start { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.stop { background: var(--stop); color: #fff; font-weight: 600; }
.ghost, .btn { background: transparent; border: 1px solid var(--line); color: var(--text); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; min-height: 40px; padding: 0 12px; }
.ghost.small { min-height: 28px; padding: 0 8px; font-size: 13px; }
.danger { color: var(--stop); }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line);
       display: flex; align-items: center; gap: 8px; padding: 0 16px; padding-top: env(safe-area-inset-top); }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a { padding: 14px 12px; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a[aria-current] { color: var(--text); border-color: var(--accent); }
.sync button { min-height: 32px; font-size: 13px; color: var(--muted); }

/* start bar */
.startbar { max-width: 1100px; margin: 16px auto; padding: 8px; display: flex; gap: 8px; align-items: center;
            background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); width: calc(100% - 32px); }
.startbar input { flex: 2; border: 0; font-size: 17px; min-width: 0; }
.startbar select { flex: 1; min-width: 0; max-width: 280px; }
.startbar button { min-width: 88px; min-height: 44px; }
.startbar.is-running { border-color: var(--stop); }
.run-info { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 8px; }
.run-info .desc { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-info .proj { color: var(--muted); font-size: 13px; }
.clock { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; padding: 0 8px; }

.banner { max-width: 1100px; margin: 8px auto; padding: 10px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); width: calc(100% - 32px); }
.banner.ok { border-color: var(--ok); }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
main .banner { width: auto; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; }
.hint { color: var(--muted); font-size: 13px; }

/* recent chips */
.recent { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; min-height: 34px; padding: 0 14px; text-decoration: none; color: var(--text); font-size: 14px; }
.chip small { color: var(--muted); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* manual entry */
.manual { margin: 8px 0 16px; }
.manual summary { cursor: pointer; color: var(--accent); padding: 6px 0; }
.grid-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-items: end; padding-top: 8px; }
.grid-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid-form .wide { grid-column: span 2; }
.grid-form .check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.grid-form .check input { min-height: auto; }

/* day list */
.day h2 { display: flex; justify-content: space-between; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 4px 6px; }
.entries { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.entry { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr) 36px auto 52px auto auto; gap: 8px; align-items: center; padding: 6px 8px; border-top: 1px solid var(--line); transition: background .3s; }
.entry:first-child { border-top: 0; }
.entry input, .entry select { border-color: transparent; border-bottom-color: var(--line); background: transparent; min-height: 40px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.entry input:hover, .entry select:hover { border-color: var(--line); }
.entry.noproj .e-proj { color: var(--warn-text); background: var(--warn-bg); }
.entry.saved { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.entry.running { box-shadow: inset 3px 0 var(--stop); }
.e-time { display: flex; align-items: center; color: var(--muted); }
.e-time input { padding: 4px; width: 92px; }
.e-time .now { padding: 0 8px; color: var(--stop); font-weight: 600; }
.e-dur { text-align: right; font-weight: 600; }
.e-bill { min-height: 32px; width: 32px; padding: 0; border-radius: 50%; background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 700; }
.e-bill.on { color: var(--ok); border-color: var(--ok); }
.e-actions { display: flex; gap: 4px; }
.e-actions button { min-height: 32px; padding: 0 10px; border-color: transparent; color: var(--muted); }
.e-actions button:hover { border-color: var(--line); color: var(--text); }
.entry.confirm .e-del { color: var(--stop); border-color: var(--stop); }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

/* cards, tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); }
.card header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card h2 { margin: 0; font-size: 18px; }
.big { font-size: 18px; font-weight: 600; margin: 0; }
.card details { margin: 8px 0 12px; }
.card summary { cursor: pointer; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; }
.plain { list-style: none; padding: 0; margin: 8px 0; }
.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
form.inline { display: inline; margin-left: auto; }
.upto, .periods { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.upto label, .periods label { display: flex; gap: 6px; align-items: center; color: var(--muted); }

/* summary */
.kpis { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
.kpis div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 140px; }
.kpis span { display: block; color: var(--muted); font-size: 13px; }
.kpis strong { font-size: 24px; }
.summary { background: var(--surface); border-radius: var(--radius); }
.bar-col { width: 30%; }
.bar { display: block; height: 10px; width: var(--w); background: color-mix(in srgb, var(--accent) 25%, transparent); border-radius: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; width: var(--b); background: var(--accent); }

/* week calendar */
.weekbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.weekbar h2 { margin: 0 8px; font-size: 18px; }
.weekbar .hint { flex-basis: 100%; }
.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-head, .cal-body { display: grid; grid-template-columns: 52px repeat(7, minmax(0, 1fr)); }
.cal-head div { padding: 8px 6px; font-size: 13px; color: var(--muted); border-left: 1px solid var(--line); display: flex; justify-content: space-between; gap: 4px; }
.cal-head div:first-child { border: 0; }
.cal-head .today { color: var(--accent); font-weight: 600; }
.cal-body { height: 70vh; overflow-y: auto; position: relative; border-top: 1px solid var(--line); touch-action: pan-y; }
.hours div { height: 48px; font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.col { position: relative; height: calc(24 * 48px); border-left: 1px solid var(--line);
       background: repeating-linear-gradient(to bottom, transparent 0 47px, var(--line) 47px 48px); cursor: crosshair; user-select: none; }
.blk { position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 3px 6px; overflow: hidden; font-size: 12px; cursor: grab;
       background: hsl(var(--hue) 70% 92%); border-left: 3px solid hsl(var(--hue) 60% 45%); color: #1b1d22; display: flex; flex-direction: column; }
@media (prefers-color-scheme: dark) { .blk { background: hsl(var(--hue) 35% 25%); color: #eef; border-left-color: hsl(var(--hue) 60% 60%); } }
.blk strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.blk span { opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.blk em { font-style: normal; opacity: .75; }
.blk.noproj { --hue: 40; background: var(--warn-bg); }
.blk.nonbill { background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgb(0 0 0 / .05) 6px 12px); }
.blk.running { border-left-color: var(--stop); cursor: default; }
.blk .grip { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; }
.ghostblk { background: color-mix(in srgb, var(--accent) 25%, transparent); border-left-color: var(--accent); }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px)); padding: 16px; }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog h3 { grid-column: 1 / -1; margin: 0; }
dialog .grid-form { grid-template-columns: 1fr 1fr; }
.actions { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; max-width: calc(100vw - 32px); }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login .card { width: min(340px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 10px; }
.login h1 { margin: 0 0 8px; }
.err { color: var(--stop); margin: 0; }

/* phone */
@media (max-width: 720px) {
  .startbar { flex-wrap: wrap; }
  .startbar input { flex-basis: 100%; }
  .startbar select { max-width: none; }
  .entry { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "d dur act" "p bill act" "t t tag"; }
  .e-desc { grid-area: d; } .e-proj { grid-area: p; } .e-bill { grid-area: bill; } .e-time { grid-area: t; }
  .e-dur { grid-area: dur; } .e-actions { grid-area: act; flex-direction: column; } .entry .tag { grid-area: tag; }
  .grid-form { grid-template-columns: 1fr 1fr; }
  .entry input, .entry select, .e-bill, .e-actions button { min-height: 44px; }
  .e-bill { width: 44px; }
  .e-time input { width: auto; }
  .recent { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .chip { white-space: nowrap; }
  .cal-head, .cal-body { grid-template-columns: 40px repeat(7, minmax(44px, 1fr)); }
  .cal { overflow-x: auto; }
  .bar-col { display: none; }
}
