:root {
  --bg: #f6f7f9; --card: #fff; --ink: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #1d4ed8; --accent-ink: #fff; --good: #15803d; --warn: #b45309; --bad: #b91c1c;
  --good-bg: #dcfce7; --warn-bg: #fef3c7; --bad-bg: #fee2e2;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #181b21; --ink: #e5e7eb; --muted: #9ca3af; --line: #2a2f38;
    --accent: #60a5fa; --accent-ink: #0b1220; --good: #4ade80; --warn: #fbbf24; --bad: #f87171;
    --good-bg: #12301d; --warn-bg: #3a2c0b; --bad-bg: #3b1515;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.35rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .7rem 16px; padding-top: max(.7rem, env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--ink); }
.ws, .switcher summary { color: var(--muted); font-size: .9rem; cursor: pointer; }
.switcher { position: relative; }
.switcher .menu { position: absolute; right: 0; top: 1.8rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .4rem; min-width: 12rem; }
.switcher .menu .current { font-weight: 700; }

.page { max-width: 760px; margin: 0 auto; padding: 1rem 16px 6.5rem; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { flex: 1; text-align: center; padding: .45rem 0 .5rem; color: var(--muted); font-size: .75rem; }
.tabs a .i { display: block; font-size: 1.25rem; line-height: 1.3; }
.tabs a.on { color: var(--accent); font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: .8rem; }
.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--good-bg); }
.flash.error { background: var(--bad-bg); }
.alert { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--warn-bg); }
.alert.bad { background: var(--bad-bg); }
.alert ul { margin: .3rem 0 0; padding-left: 1.1rem; }

.dayhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.dayhead h1 { margin: 0; text-align: center; }
.dayhead a { padding: .3rem .6rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; }
.stat b { display: block; font-size: 1.15rem; }
.stat span { color: var(--muted); font-size: .78rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.block { display: flex; gap: .75rem; background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--c, var(--accent));
  border-radius: 10px; padding: .65rem .8rem; margin-bottom: .5rem; align-items: center; }
.block .time { min-width: 3.4rem; font-variant-numeric: tabular-nums; font-size: .9rem; }
.block .time small { display: block; color: var(--muted); }
.block .body { flex: 1; min-width: 0; }
.block .title { font-weight: 600; overflow-wrap: anywhere; color: var(--ink); }
.block.event { background: color-mix(in srgb, var(--c) 9%, var(--card)); }
.tag { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: color-mix(in srgb, var(--c, var(--accent)) 18%, transparent);
  color: var(--ink); margin-right: .3rem; white-space: nowrap; }
.pill { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; white-space: nowrap; }
.pill.p1 { background: var(--bad-bg); color: var(--bad); }
.pill.p2 { background: var(--warn-bg); color: var(--warn); }
.pill.late { background: var(--bad-bg); color: var(--bad); }
.pill.done { background: var(--good-bg); color: var(--good); }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; gap: .7rem; align-items: center; background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--c, var(--line));
  border-radius: 10px; padding: .6rem .8rem; margin-bottom: .45rem; }
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.row .meta { font-size: .8rem; color: var(--muted); }
.row.done .title { text-decoration: line-through; color: var(--muted); }
.row.cancelled .title { text-decoration: line-through; color: var(--muted); }

.check { width: 2.1rem; height: 2.1rem; border-radius: 50%; border: 2px solid var(--line); background: transparent; color: var(--good); font-size: 1rem; cursor: pointer; flex: none; }
.check:hover { border-color: var(--good); }

form p { margin: 0 0 .85rem; }
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
input[type=color] { width: 3.5rem; height: 2.4rem; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; }
input[type=checkbox] { width: 1.15rem; height: 1.15rem; vertical-align: middle; }
.helptext { display: block; color: var(--muted); font-size: .78rem; margin-top: .2rem; }
.errorlist { color: var(--bad); margin: .2rem 0; padding-left: 1rem; font-size: .85rem; }
.checks > div { display: flex; flex-wrap: wrap; gap: .3rem 1rem; }
.checks > div label { font-weight: 400; display: inline-flex; gap: .3rem; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .7rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 .7rem; }

.btn, button.btn { display: inline-block; font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: .65rem 1.1rem;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; text-align: center; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.block { display: block; width: 100%; }
.btn.sm { padding: .35rem .7rem; font-size: .85rem; }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: .3rem .4rem; display: block; width: 100%; text-align: left; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .4rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .9rem; }
.toolbar select, .toolbar input { width: auto; flex: 1; min-width: 8rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg a { padding: .4rem .75rem; color: var(--muted); font-size: .9rem; }
.seg a.on { background: var(--accent); color: var(--accent-ink); }

.quick summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.quick form { margin-top: .8rem; }
.fab { position: fixed; right: 16px; bottom: calc(4.6rem + env(safe-area-inset-bottom)); width: 3.4rem; height: 3.4rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 1.8rem; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 4; }

table.bal { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.bal th, table.bal td { padding: .45rem .3rem; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
table.bal th:first-child, table.bal td:first-child { text-align: left; }
.scroll { overflow-x: auto; }
.bar { height: .55rem; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: .25rem; }
.bar i { display: block; height: 100%; background: var(--c, var(--accent)); }
.swatch { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; background: var(--c); vertical-align: -1px; margin-right: .35rem; }

.auth { max-width: 420px; margin: 2rem auto; }
.auth h1 { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem 1rem; }
.bad { color: var(--bad); }

/* AI and the day */
.ai-badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .05rem .45rem; border-radius: 999px;
  background: linear-gradient(90deg, #7c3aed, #2563eb); color: #fff; vertical-align: 1px; }
.btn.ai { background: linear-gradient(90deg, #7c3aed, #2563eb); color: #fff; }
.btn.ai[disabled] { opacity: .7; cursor: progress; }
.summary { background: color-mix(in srgb, #7c3aed 8%, var(--card)); border-radius: 10px; padding: .7rem .85rem; margin: .4rem 0 .9rem; }
.planmeta { margin: -.2rem 0 .5rem; text-align: center; }
.why { font-size: .8rem; color: var(--muted); font-style: italic; margin-top: .15rem; }
.why.bad { color: var(--bad); font-style: normal; }
.block.done { opacity: .6; }
.block.done .title { text-decoration: line-through; }
.block.clash { border-color: var(--bad); }
.advice { margin: 0 0 1rem; padding-left: 1.2rem; }
.advice li { margin-bottom: .35rem; }
.plan-form details { margin-bottom: .6rem; }
.plan-form summary { cursor: pointer; color: var(--accent); margin-bottom: .4rem; }

/* Dashboard */
.myday .head { display: flex; justify-content: space-between; align-items: flex-start; gap: .8rem; }
.myday h1, .myday .dayhead-title { margin: 0; font-size: 1.15rem; color: var(--ink); }
.myday h2 { margin: .9rem 0 .5rem; font-size: .95rem; color: var(--muted); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: .8rem; flex-wrap: wrap; }
.titlebar { display: flex; justify-content: space-between; align-items: flex-start; gap: .8rem; margin-bottom: .6rem; }
.titlebar h1 { margin: 0 0 .2rem; }
.titlebar .swatch { width: 1rem; height: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.cards .card { margin: 0; }
.acard { border-top: 5px solid var(--c); display: flex; flex-direction: column; gap: .55rem; }
.acard .name { font-weight: 700; font-size: 1.08rem; color: var(--ink); }
.acard .nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: .3rem; text-align: center; }
.acard .nums div { background: var(--bg); border-radius: 8px; padding: .35rem .2rem; }
.acard .nums b { display: block; font-size: 1rem; }
.acard .nums span { font-size: .68rem; color: var(--muted); }
.acard .nums .bad b { color: var(--bad); }
.acard .projects, .acard .next { list-style: none; margin: 0; padding: 0; }
.acard .projects li { margin-bottom: .45rem; }
.acard .prow { display: flex; justify-content: space-between; gap: .5rem; font-size: .9rem; }
.acard .prow a { color: var(--ink); font-weight: 600; }
.acard .projects .bar i { background: var(--c); }
.acard .next { border-top: 1px solid var(--line); padding-top: .45rem; }
.acard .next li { display: flex; justify-content: space-between; gap: .5rem; font-size: .9rem; padding: .15rem 0; }
.acard .next a { color: var(--ink); overflow-wrap: anywhere; }
.acard footer { margin-top: auto; }
.list.compact .row { padding: .45rem .7rem; }

/* Planned and actual */
.pva { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin-top: .3rem; flex-wrap: wrap; }
.pva b { color: var(--ink); font-weight: 600; }
.over { color: var(--warn); font-weight: 600; }
.under { color: var(--good); font-weight: 600; }
.pva-actions { display: flex; gap: .4rem; align-items: flex-start; flex-wrap: wrap; margin-top: .4rem; }
.pva-actions form { margin: 0; }
.logtime > summary { list-style: none; display: inline-block; }
.logtime > summary::-webkit-details-marker { display: none; }
.logtime[open] form { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin-top: .45rem; }
.logtime label { font-size: .8rem; font-weight: 600; margin: 0; }
.logtime input[type=number] { width: 6rem; display: block; margin-top: .2rem; }
label.inline { display: inline-flex; gap: .35rem; align-items: center; font-weight: 400; }
.btn.stop { background: var(--bad); color: #fff; }
.block.live { box-shadow: 0 0 0 2px color-mix(in srgb, var(--bad) 45%, transparent); }
.live-dot { color: var(--bad); }
.live-dot::before { content: "●"; margin-right: .25rem; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.timerbar { position: sticky; top: 3.1rem; z-index: 4; display: flex; align-items: center; gap: .6rem; padding: .45rem 16px;
  background: color-mix(in srgb, var(--c) 12%, var(--card)); border-bottom: 1px solid var(--line); font-size: .9rem; }
.timerbar .what { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.timerbar .elapsed { font-variant-numeric: tabular-nums; }
.timerbar form { margin: 0; }
table.bal tr.total td { font-weight: 700; border-bottom: 0; }

/* Weekly allocation */
table.alloc { width: 100%; border-collapse: collapse; margin-bottom: .8rem; }
table.alloc td { padding: .5rem 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.alloc label { margin: 0; font-size: .95rem; }
table.alloc .swatch { background: var(--c); }
table.alloc .hours { text-align: right; white-space: nowrap; width: 7.5rem; }
table.alloc .hours input { width: 4.8rem; text-align: right; }
table.alloc tr.total td { border-bottom: 0; }
.alloc-bar { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }
.alloc-bar.over b { color: var(--warn); }
@media (max-width: 480px) { .grid2, .grid3 { grid-template-columns: 1fr; } .cards { grid-template-columns: 1fr; } }

/* Home layout. Phones: one column (cards, then deadlines and My day, then quick add). */
.home { display: flex; flex-direction: column; }
.home-main, .home-side { display: contents; }
.home .quick { order: 2; }

/* Wide screens: use the width. The tabs move into the top bar; the home page puts the assignment cards on the left
   and My day in a column on the right that stays in view while the cards scroll. */
@media (min-width: 1100px) {
  .page { padding-bottom: 2rem; }
  .page.wide { max-width: 1840px; padding-left: 24px; padding-right: 24px; }
  .top { padding-left: 24px; padding-right: 24px; }
  .tabs { top: 0; bottom: auto; left: 50%; right: auto; transform: translateX(-50%); background: transparent;
    border-top: 0; padding-bottom: 0; z-index: 6; }
  .tabs a { flex: none; display: flex; align-items: center; gap: .4rem; padding: .85rem 1rem; font-size: .9rem; }
  .tabs a .i { display: inline; font-size: 1rem; line-height: 1; }
  .tabs a.on { box-shadow: inset 0 -2px 0 var(--accent); }
  .fab { bottom: 1.5rem; }
  .timerbar { top: 3.15rem; }

  .home { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 1.4rem; align-items: start; }
  .home-main, .home-side { display: block; }
  .home-side { position: sticky; top: 4.2rem; max-height: calc(100vh - 5rem); overflow-y: auto; overscroll-behavior: contain; }
  .home-side .myday { margin: 0; }
  .home .cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}
@media (min-width: 1600px) {
  .home { grid-template-columns: minmax(0, 1fr) 460px; }
}
