/* Layout: one column of lists on the phone with tabs at the bottom; on a wide screen a sidebar on the left. */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #e9edf4;
  --line: #d9dfe9;
  --fg: #172033;
  --muted: #5d6980;
  --accent: #2f5bd8;
  --accent-soft: #e3eafc;
  --on-accent: #ffffff;
  --good: #1f8a5b;
  --warn: #b7791f;
  --bad: #c2413a;
  --chip: #eef1f7;
  --shadow: 0 10px 30px rgba(23, 32, 51, 0.16);
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Bricolage Grotesque", "Inter", system-ui, sans-serif;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420; --surface: #171e2d; --surface-2: #1f2839; --line: #2a3448;
    --fg: #e8ecf4; --muted: #95a1b8; --accent: #7d9bff; --accent-soft: #23305a; --on-accent: #0f1420;
    --good: #4cc38a; --warn: #e0a84a; --bad: #f07a72; --chip: #222b3d;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1420; --surface: #171e2d; --surface-2: #1f2839; --line: #2a3448;
  --fg: #e8ecf4; --muted: #95a1b8; --accent: #7d9bff; --accent-soft: #23305a; --on-accent: #0f1420;
  --good: #4cc38a; --warn: #e0a84a; --bad: #f07a72; --chip: #222b3d;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: flex; min-height: 100%; }

/* Sidebar (wide screens) */
.side {
  display: none;
  width: 230px;
  flex: none;
  padding: 24px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-family: var(--font-display); font-weight: 700; font-size: 20px; padding: 0 12px 18px; letter-spacing: -0.01em; }
.sync-line { font-size: 12px; color: var(--muted); padding: 0 12px 16px; margin-top: -12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  border: 0; background: none; text-align: left; padding: 9px 12px; border-radius: 10px; color: var(--muted);
}
.nav button:hover { background: var(--surface-2); color: var(--fg); }
.nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { font-size: 12px; font-variant-numeric: tabular-nums; }

/* Main column */
.main {
  flex: 1;
  min-width: 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 16px calc(96px + env(safe-area-inset-bottom, 0px));
}
.wrap { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

.top { display: flex; align-items: center; gap: 12px; }
.top h1 { font-family: var(--font-display); font-size: 28px; line-height: 1.15; margin: 0; flex: 1; letter-spacing: -0.02em; text-wrap: balance; }
.back { border: 0; background: var(--surface-2); border-radius: 10px; padding: 6px 10px; color: var(--muted); }
.icon-btn { border: 0; background: none; color: var(--muted); padding: 6px; border-radius: 10px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }

.sub { color: var(--muted); margin: -8px 0 0; font-size: 14px; }

.banner {
  background: var(--accent-soft); color: var(--fg); border-radius: var(--radius);
  padding: 12px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 14px;
}
.banner p { margin: 0; flex: 1; min-width: 200px; }

/* Quick add */
.quick { display: flex; gap: 8px; }
.quick input {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 11px 14px;
}
.quick input::placeholder { color: var(--muted); }
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.btn.ghost { background: var(--surface-2); color: var(--fg); font-weight: 500; }
.btn.danger { background: none; color: var(--bad); padding-inline: 8px; }
.btn.danger.sure { background: var(--bad); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 13px; }

/* Summary card */
.summary {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: flex; gap: 24px; flex-wrap: wrap;
}
.summary div { display: flex; flex-direction: column; }
.summary .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.summary .value { font-family: var(--font-display); font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Lists */
.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 600;
  margin: 4px 4px -8px; display: flex; justify-content: space-between; align-items: center;
}
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .body { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 0; }
.row .title { overflow-wrap: anywhere; }
.row.done .title { text-decoration: line-through; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; font-size: 12.5px; color: var(--muted); align-items: center; }
.chip { background: var(--chip); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.chip.from { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.chip.late { color: var(--bad); }
.chip.soon { color: var(--warn); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.check {
  flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line);
  background: none; display: grid; place-items: center; padding: 0;
}
.check:hover { border-color: var(--accent); }
.row.done .check { background: var(--good); border-color: var(--good); }
.row.done .check::after { content: ""; width: 10px; height: 6px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }

.status-btn {
  flex: none; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px;
  padding: 4px 10px; font-size: 12.5px; white-space: nowrap;
}
.status-btn:hover { border-color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty strong { display: block; color: var(--fg); margin-bottom: 4px; }

.toggle-done { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 4px; text-align: left; }

/* Segmented control */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 8px; border-radius: 9px; color: var(--muted); font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* Project cards */
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.project {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 6px;
}
.project:hover { border-color: var(--accent); }
.project .name { font-weight: 600; font-size: 16px; }
.project .counts { font-size: 13px; color: var(--muted); }

/* Bottom tabs (phone) */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px max(4px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-left, 0px));
}
.tabs button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10.5px; color: var(--muted); padding: 4px 0; min-width: 0;
}
.tabs button svg { width: 22px; height: 22px; }
.tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }

.fab {
  position: fixed; z-index: 21;
  right: calc(18px + env(safe-area-inset-right, 0px));
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }

/* Sheet (add / edit) */
.overlay {
  position: fixed; inset: 0; z-index: 40; background: rgba(10, 14, 24, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92%;
  overflow: auto; border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 14px;
}
.sheet h2 { font-family: var(--font-display); margin: 0; font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label, .field .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; width: 100%;
}
.field textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.types { display: flex; flex-wrap: wrap; gap: 6px; }
.types button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: 14px;
}
.types button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.checkline { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.checkline input { width: 18px; height: 18px; accent-color: var(--accent); }
.actions { display: flex; gap: 8px; align-items: center; }
.actions .spacer { flex: 1; }
.more { border: 0; background: none; color: var(--accent); padding: 0; text-align: left; font-size: 14px; }

.account { display: flex; flex-direction: column; gap: 10px; background: var(--bg); border-radius: 12px; padding: 12px 14px; }
.account .label { font-size: 12px; color: var(--muted); }
.account-form { display: flex; flex-direction: column; gap: 10px; }
.settings textarea { width: 100%; min-height: 140px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(150px + env(safe-area-inset-bottom, 0px));
  background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow);
}

@media (min-width: 820px) {
  .side { display: block; }
  .tabs { display: none; }
  .main { padding-block: 28px 48px; }
  .fab { bottom: calc(28px + env(safe-area-inset-bottom, 0px)); right: calc(28px + env(safe-area-inset-right, 0px)); }
  .overlay { align-items: center; }
  .sheet { border-radius: 20px; max-height: 88%; }
  .toast { bottom: 40px; }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up 0.18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
}
