:root {
  --bg: #f6f7f5; --surface: #fff; --text: #1d2428; --muted: #5b676d; --line: #d5dbd8;
  --accent: #0b6e6e; --accent-text: #fff;
  --over: #b3261e; --today: #8a5a00; --soon: #0b6e6e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191b; --surface: #1d2427; --text: #e8ecec; --muted: #9aa8ad; --line: #34403f;
    --accent: #4fc3c3; --accent-text: #08201f;
    --over: #ff8a80; --today: #f2b84b; --soon: #4fc3c3;
    color-scheme: dark;
  }
}

.header-logo {
    display: inline-block;
    height: 1.4em;
    width: auto;
    vertical-align: -0.12em;
}

* { box-sizing: border-box; }
body { margin: 0 auto; max-width: 52rem; padding: 0 1rem 3rem; background: var(--bg); color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0; overflow-wrap: anywhere; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 0; flex-wrap: wrap; }
.header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
button, input, select, textarea { font: inherit; color: inherit; }
button { min-height: 2.5rem; padding: .35rem .85rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--over); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, select, textarea { width: 100%; min-height: 2.5rem; padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .75rem; }
label input, label select, label textarea { margin-top: .2rem; color: var(--text); }
.banner { padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid var(--over); border-radius: 6px; background: var(--surface); }
.tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.tabs button { flex: 1; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; align-items: end; }
.filters label:first-child { grid-column: 1 / -1; }
.filters button { margin-bottom: .75rem; }
@media (min-width: 40rem) {
  .filters { grid-template-columns: 2fr 1fr 1fr auto; }
  .filters label:first-child { grid-column: auto; }
}
.group { margin-top: 1.5rem; }
.group > h2 { padding-bottom: .25rem; border-bottom: 2px solid var(--line); }
.group.overdue > h2 { color: var(--over); border-color: var(--over); }
.group.today > h2 { color: var(--today); border-color: var(--today); }
.group.tomorrow > h2, .group.week > h2 { color: var(--soon); }
.item { background: var(--surface); border: 1px solid var(--line); border-left-width: 5px; border-radius: 6px; padding: .75rem; margin-bottom: .6rem; }
.overdue .item { border-left-color: var(--over); }
.today .item { border-left-color: var(--today); }
.tomorrow .item, .week .item { border-left-color: var(--soon); }
.item.done h3 { text-decoration: line-through; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .88rem; color: var(--muted); margin-top: .25rem; }
.meta .flag { font-weight: 700; }
.flag.overdue { color: var(--over); } .flag.today { color: var(--today); }
.notes { margin: .5rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .92rem; }
.item .buttons { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; border: 1px dashed var(--line); border-radius: 6px; margin-top: 1.5rem; }
.data { display: flex; gap: .5rem; margin-top: 2.5rem; }
dialog { width: min(32rem, calc(100vw - 1.5rem)); max-height: 95vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); padding: 1rem; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.err { display: block; color: var(--over); font-size: .85rem; min-height: 0; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; }
.toast { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); display: flex; gap: .75rem; align-items: center;
  max-width: calc(100vw - 2rem); padding: .6rem .9rem; border-radius: 8px; background: var(--text); color: var(--bg); }
.toast button { min-height: 2rem; background: transparent; color: inherit; border-color: currentColor; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* Companion uses the same markup and CSS in the floating and in-page fallback views. */
.companion-fallback { position: fixed; top: .65rem; right: .65rem; z-index: 50; max-width: min(340px, calc(100vw - 1.3rem)); }
.companion-pip-body { margin: 0; padding: .4rem; max-width: none; min-width: 0; }
.dewey-companion { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 4px 18px #0003; padding: .3rem; max-width: 330px; }
.companion-head { display: flex; align-items: center; gap: .5rem; }
.companion-clock { display: grid; width: 3.25rem; height: 3.25rem; min-height: 0; border-radius: 50%; padding: .3rem; position: relative; display: grid; place-items: center; }
.companion-clock img { width: 100%; height: 100%; object-fit: contain; }
.companion-dot { position: absolute; top: -.25rem; right: -.25rem; border-radius: 999px; background: #c62828; color: white; min-width: 1.15rem; height: 1.15rem; padding: 0 .2rem; font-size: .72rem; font-weight: 700; line-height: 1.15rem; }
.companion-title { flex: 1; }
.companion-action { font-size: .82rem; min-height: 2rem; padding: .25rem .45rem; }
.companion-items { display: grid; gap: .2rem; max-height: 270px; overflow: auto; }
.companion-row { padding: .35rem .45rem; border-top: 1px solid var(--line); display: grid; gap: .1rem; }
.companion-name { font-size: .86rem; overflow-wrap: anywhere; }
.companion-detail { font-size: .75rem; color: var(--muted); }
.companion-empty { margin: .5rem; font-size: .85rem; }
.dewey-companion { display: grid; gap: .35rem; min-width: min(290px, calc(100vw - 2rem)); }

/* Companion reminder header in floating and in-page modes. */
.companion-head { border-radius: 9px; padding: .1rem .2rem; }
.companion-head.has-reminders { background: color-mix(in srgb, #c62828 13%, var(--surface)); outline: 2px solid #c62828; outline-offset: -2px; }
.companion-head.has-reminders .companion-title { color: var(--over); }
.companion-clock { flex: 0 0 auto; }
.companion-title { font-size: .85rem; white-space: nowrap; }
