/* Layout: one narrow column, sticky top bar, tab bar pinned to the bottom (thumb reach).
   Identity: a checkerboard strip (for Checkerz) and a collar-blue accent; status colours carry meaning. */
:root {
  --ink: #1c2336;
  --ink-soft: #545d75;
  --paper: #f5f6fa;
  --card: #ffffff;
  --line: #dfe2ec;
  --accent: #2f56d9;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecfd;
  --late: #c8372f;
  --late-soft: #fde9e7;
  --today: #b86a00;
  --today-soft: #fff1d6;
  --soon: #2f56d9;
  --ok: #217a52;
  --ok-soft: #e1f4ea;
  --check-a: #1c2336;
  --check-b: #f5f6fa;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9ecf5;
    --ink-soft: #a3abc2;
    --paper: #11151f;
    --card: #1a2030;
    --line: #2b3348;
    --accent: #7e9bff;
    --accent-ink: #0d1430;
    --accent-soft: #232f55;
    --late: #ff7a70;
    --late-soft: #3a1f22;
    --today: #ffb547;
    --today-soft: #3a2c14;
    --soon: #7e9bff;
    --ok: #5fd39a;
    --ok-soft: #173326;
    --check-a: #e9ecf5;
    --check-b: #11151f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.05rem; font-weight: 700; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px));
  background: var(--paper);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 6px;
  background: repeating-conic-gradient(var(--check-a) 0 25%, var(--check-b) 0 50%) 0 0 / 12px 12px;
  opacity: .9;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--card); border: 2px solid var(--ink); }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; letter-spacing: -.01em; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer;
}

main {
  max-width: 640px; margin: 0 auto;
  padding: 18px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 20px;
  outline: none;
}
.loading, .empty { color: var(--ink-soft); text-align: center; padding: 32px 8px; }

/* ---------- tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-soft); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--accent); }

/* ---------- sections and lists */
.section { display: flex; flex-direction: column; gap: 10px; }
.section-label {
  font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft);
}
.list { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }

.rem {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px;
  padding: 14px 14px 14px 16px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--line);
  color: inherit; text-decoration: none;
}
.rem[data-state="late"] { border-left-color: var(--late); }
.rem[data-state="today"] { border-left-color: var(--today); }
.rem[data-state="soon"] { border-left-color: var(--soon); }
.rem[data-state="done"] { border-left-color: var(--ok); }
.rem-title { font-weight: 700; font-size: 1.02rem; }
.rem-meta { grid-column: 1; color: var(--ink-soft); font-size: .86rem; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.rem-side { grid-row: 1 / span 2; grid-column: 2; display: flex; align-items: center; gap: 8px; }

.when { font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums; }
[data-state="late"] .when { color: var(--late); }
[data-state="today"] .when { color: var(--today); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; background: var(--accent-soft); color: var(--accent);
}
.chip.warn { background: var(--today-soft); color: var(--today); }
.chip.bad { background: var(--late-soft); color: var(--late); }
.chip.good { background: var(--ok-soft); color: var(--ok); }

/* ---------- buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--ok); border-color: var(--ok); color: var(--card); }
.btn.danger { color: var(--late); border-color: var(--late-soft); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .88rem; }
.btn.big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row > .btn { flex: 1 1 140px; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
}
form.panel { gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field > legend { font-weight: 700; font-size: .9rem; }
.hint { color: var(--ink-soft); font-size: .84rem; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 110px; resize: vertical; }
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline > input[type="number"] { width: 90px; }
.inline > select { width: auto; flex: 1; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; background: var(--paper);
}
.choice input { width: auto; min-height: 0; margin-top: 4px; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.templates { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.templates .btn { flex: 0 0 auto; }

/* ---------- detail */
.hero-due { display: flex; flex-direction: column; gap: 4px; }
.hero-due .big-when { font-family: var(--font-display); font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hero-due[data-state="late"] .big-when { color: var(--late); }
.hero-due[data-state="today"] .big-when { color: var(--today); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--ink-soft); font-size: .9rem; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.history .date { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.banner {
  padding: 12px 14px; border-radius: 12px; background: var(--today-soft); color: var(--ink);
  display: flex; gap: 10px; align-items: flex-start; font-size: .95rem;
}
.banner strong { color: var(--today); }
.banner.info { background: var(--accent-soft); }
.banner.info strong { color: var(--accent); }

/* ---------- notes */
.note { padding: 14px 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 4px; }
.note-body { color: var(--ink-soft); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-full { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- profile */
.profile-head { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.profile-photo {
  width: 168px; height: 168px; border-radius: 50%; object-fit: cover; background: var(--card);
  border: 4px solid var(--ink); box-shadow: 0 0 0 6px var(--paper), 0 0 0 9px var(--ink);
}
.tel { font-size: 1.05rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom, 0px)); z-index: 10;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--paper); font-weight: 600; box-shadow: 0 6px 24px rgb(0 0 0 / .25);
}

@media (prefers-reduced-motion: no-preference) {
  .rem, .note, .btn { transition: transform .12s ease; }
  .rem:active, .note:active, .btn:active { transform: scale(.98); }
}
