/* Daybook — base.css
   Reset, typography and the app shell: boot splash, sidebar (desktop), top bar + journal switcher +
   bottom nav (mobile), FAB, view container, route progress, error cards, quick-add / more sheets content.
   Uses tokens from tokens.css (spec section 6). Shell-only classes are prefixed (sb-, tb-, bn-, js-, qa-, more-). */

/* ---------------------------------------------------------------- Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-padding-top: calc(var(--topbar-h, 56px) + 64px);
  background: var(--bg, #f4f5f8);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
  font-size: var(--fs-md, 15px);
  line-height: 1.5;
  color: var(--text, #0f172a);
  background: var(--bg, #f4f5f8);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, ol, ul {
  margin: 0;
}

ol, ul {
  padding: 0;
  list-style: none;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: var(--text);
  text-wrap: balance;
}

h1 { font-size: var(--fs-2xl, 24px); letter-spacing: -0.022em; }
h2 { font-size: var(--fs-xl, 20px); }
h3 { font-size: var(--fs-lg, 17px); }
h4 { font-size: var(--fs-md, 15px); }

p { text-wrap: pretty; }

/* Reset rules are zero-specificity so any class (incl. the .icon rule below) overrides them. */
:where(img, svg, video, canvas, picture) {
  display: block;
  max-width: 100%;
}

svg { overflow: visible; }

/* Zero specificity on purpose: any component/module rule (e.g. `.x .icon { display:none }`) wins. */
:where(svg.icon, .icon) {
  display: inline-block;
  flex: none;
  vertical-align: middle;
}

img { height: auto; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
}

button:disabled { cursor: not-allowed; }

/* iOS zooms into inputs < 16px */
input, select, textarea { font-size: max(16px, 1em); }

a {
  color: var(--primary);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

table { border-collapse: collapse; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  color: var(--text-3);
  background: var(--surface);
  border: 1px solid var(--border-strong, var(--border));
  border-bottom-width: 2px;
  border-radius: 6px;
}

[hidden] { display: none !important; }

::selection {
  background: color-mix(in srgb, var(--primary) 22%, transparent);
}

:focus { outline: none; }

/* The outline follows each element's own border-radius (no radius override here: pills stay pills). */
:focus-visible {
  outline: 2px solid var(--focus, var(--primary));
  outline-offset: 2px;
}

/* Programmatic focus target after navigation — no ring on the heading itself. */
#view:focus,
#view h1[tabindex="-1"]:focus,
#view h1:focus {
  outline: none;
}

.num, .tabular {
  font-variant-numeric: tabular-nums;
}

/* Shell-local visually-hidden helper (components.css also ships .sr-only) */
.sh-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- Theme transition (only while switching) */
html.theme-changing,
html.theme-changing *,
html.theme-changing *::before,
html.theme-changing *::after {
  transition: background-color 220ms ease-out, border-color 220ms ease-out, color 220ms ease-out,
    fill 220ms ease-out, stroke 220ms ease-out, box-shadow 220ms ease-out !important;
}

/* ---------------------------------------------------------------- Brand mark */
.brand-mark {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 26%;
  /* matches assets/icons/icon.svg: indigo→violet with a soft top-left glow */
  background: radial-gradient(120% 90% at 18% 0%, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0) 60%),
    linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  box-shadow: 0 1px 2px rgba(49, 46, 129, 0.25), 0 4px 12px -4px rgba(91, 61, 235, 0.55),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  color: #fff;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

/* ---------------------------------------------------------------- Boot splash */
.boot {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg, #f4f5f8);
  transition: opacity 320ms ease-out, visibility 320ms ease-out;
}

.boot.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  transition: transform 320ms ease-out;
}

.boot.is-done .boot-inner {
  transform: scale(0.96);
}

.boot-mark {
  position: relative;
  overflow: hidden;
  width: 76px;
  height: 76px;
  border-radius: 23%;
  box-shadow: 0 2px 4px rgba(49, 46, 129, 0.2), 0 18px 40px -12px rgba(91, 61, 235, 0.6),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  animation: boot-breathe 2.6s ease-in-out infinite;
}

.boot-mark svg {
  filter: drop-shadow(0 2px 2px rgba(30, 27, 75, 0.28));
}

.boot-mark::after {
  content: "";
  position: absolute;
  inset: -20%;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 255, 255, 0.42) 50%, transparent 62%);
  transform: translateX(-110%);
  animation: boot-shine 2.2s cubic-bezier(0.4, 0, 0.2, 1) 0.2s infinite;
}

.boot-name {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1;
  color: var(--text, #0f172a);
}

.boot-bar {
  position: relative;
  overflow: hidden;
  width: 96px;
  height: 3px;
  border-radius: 3px;
  background: var(--surface-3, rgba(15, 23, 42, 0.08));
}

.boot-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4f46e5, #7c3aed);
  animation: boot-slide 1.3s ease-in-out infinite;
}

.boot-msg {
  max-width: 320px;
  font-size: var(--fs-sm, 13px);
  color: var(--text-2, #475569);
}

.boot-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.boot-btn {
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--r, 12px);
  font-weight: 600;
  color: #fff;
  background: var(--primary, #4f46e5);
}

.boot.is-error .boot-mark { animation: none; }
.boot.is-error .boot-mark::after,
.boot.is-error .boot-bar { display: none; }

@keyframes boot-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

@keyframes boot-shine {
  0% { transform: translateX(-110%); }
  60%, 100% { transform: translateX(110%); }
}

@keyframes boot-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

/* ---------------------------------------------------------------- App frame */
.app {
  --shell-gutter: 16px;
  min-height: 100vh;
  min-height: 100dvh;
}

@media (min-width: 640px) {
  .app { --shell-gutter: 24px; }
}

.app-main {
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

.skip-link {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 8px;
  z-index: 4000;
  padding: 10px 16px;
  border-radius: var(--r);
  background: var(--primary);
  color: var(--primary-contrast, #fff);
  font-weight: 600;
  transform: translateY(-200%);
  transition: transform 150ms ease-out;
}

.skip-link:focus-visible { transform: none; }

/* View container */
#view {
  display: block;
  min-height: 60vh;
  padding-top: var(--s-4, 16px);
  padding-right: calc(var(--shell-gutter) + env(safe-area-inset-right, 0px));
  padding-bottom: calc(var(--bottomnav-h, 64px) + env(safe-area-inset-bottom, 0px) + 104px);
  padding-left: calc(var(--shell-gutter) + env(safe-area-inset-left, 0px));
}

.view-page {
  width: 100%;
  max-width: var(--content-max, 1120px);
  margin-inline: auto;
  animation: view-in 220ms ease-out both;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* Route progress (appears only when a render takes a moment) */
.route-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900;
  height: 2.5px;
  pointer-events: none;
  opacity: 0;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  box-shadow: 0 0 8px color-mix(in srgb, var(--primary) 60%, transparent);
}

.route-progress.is-active {
  opacity: 1;
  transform: scaleX(0.85);
  transition: transform 6s cubic-bezier(0.08, 0.7, 0.2, 1), opacity 150ms ease-out;
}

.route-progress.is-done {
  opacity: 0;
  transform: scaleX(1);
  transition: transform 180ms ease-out, opacity 260ms ease-out 140ms;
}

/* ---------------------------------------------------------------- Mobile top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-nav, 100);
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-h, 56px) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: calc(6px + env(safe-area-inset-right, 0px));
  padding-left: calc(var(--shell-gutter) + env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid transparent;
  transition: border-color 200ms ease-out, background-color 200ms ease-out;
}

html.is-scrolled .topbar {
  border-bottom-color: var(--border);
}

html.has-switch .topbar {
  border-bottom-color: transparent;
}

.tb-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  font-size: var(--fs-lg, 17px);
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--text);
  text-decoration: none;
}

.tb-title-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}

/* While the page's own <h1> is visible the bar title steps back (app.js toggles .title-in-view). */
html.title-in-view .tb-title:not(.is-brand) .tb-title-text {
  opacity: 0;
  transform: translateY(4px);
}

.tb-title .brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.tb-title.is-brand {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.tb-title-swap {
  animation: tb-fade 200ms ease-out both;
}

@keyframes tb-fade {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.tb-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.tb-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--text-2);
  transition: background-color 150ms ease-out, color 150ms ease-out, transform 150ms ease-out;
}

.tb-btn:hover { background: var(--hover, var(--surface-2)); color: var(--text); }
.tb-btn:active { transform: scale(0.94); background: var(--press, var(--surface-3)); }

/* ---------------------------------------------------------------- Journal switcher (mobile) */
.journal-switch {
  position: sticky;
  top: calc(var(--topbar-h, 56px) + env(safe-area-inset-top, 0px));
  z-index: calc(var(--z-nav, 100) - 1);
  padding: 2px calc(var(--shell-gutter) + env(safe-area-inset-right, 0px)) 10px
    calc(var(--shell-gutter) + env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid transparent;
  transition: border-color 200ms ease-out;
}

html.is-scrolled .journal-switch {
  border-bottom-color: var(--border);
}

.js-track {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  max-width: 560px;
  margin-inline: auto;
  padding: 3px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.js-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  height: 38px;
  border-radius: 10px;
  font-size: var(--fs-sm, 13px);
  font-weight: 560;
  color: var(--text-2);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 180ms ease-out, color 180ms ease-out, box-shadow 180ms ease-out;
}

/* enlarge the hit area to ≥ 44px without making the control chunky */
.js-item::before {
  content: "";
  position: absolute;
  inset: -4px -1px;
}

.js-item .icon {
  color: var(--text-3);
  transition: color 180ms ease-out;
}

.js-item:hover { color: var(--text); }

.js-item[aria-current="page"] {
  color: var(--text);
  font-weight: 650;
  background: color-mix(in srgb, var(--accent, var(--primary)) 14%, var(--surface));
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), inset 0 0 0 1px color-mix(in srgb, var(--accent, var(--primary)) 22%, transparent);
}

.js-item[aria-current="page"] .icon {
  color: var(--accent, var(--primary));
}

/* ---------------------------------------------------------------- Bottom nav (mobile) */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-nav, 100);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--bottomnav-h, 64px) + 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: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}

/* Tablets: keep the five tabs together instead of spreading across the full width */
@media (min-width: 640px) {
  .bottom-nav {
    padding-left: max(env(safe-area-inset-left, 0px), calc(50% - 320px));
    padding-right: max(env(safe-area-inset-right, 0px), calc(50% - 320px));
  }
}

/* Short landscape phones: let the switcher scroll away so content keeps room */
@media (max-height: 520px) and (max-width: 959.98px) {
  .journal-switch { position: static; }
}

.bn-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 44px;
  font-size: 11px;
  font-weight: 560;
  letter-spacing: 0.005em;
  color: var(--text-3);
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  transition: color 180ms ease-out;
}

.bn-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 30px;
  border-radius: var(--r-full, 999px);
  transition: background-color 200ms ease-out, color 200ms ease-out, transform 150ms ease-out;
}

.bn-item:active .bn-icon { transform: scale(0.92); }

.bn-label {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.bn-item[aria-current="page"],
.bn-item.is-active {
  color: var(--text);
  font-weight: 650;
}

.bn-item[aria-current="page"] .bn-icon,
.bn-item.is-active .bn-icon {
  color: var(--accent, var(--primary));
  background: color-mix(in srgb, var(--accent, var(--primary)) 15%, transparent);
}

.bn-item[aria-current="page"] .icon,
.bn-item.is-active .icon {
  stroke-width: 2.1;
}

/* ---------------------------------------------------------------- FAB */
.fab {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(var(--bottomnav-h, 64px) + 16px + env(safe-area-inset-bottom, 0px));
  z-index: calc(var(--z-nav, 100) + 5);
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  color: var(--primary-contrast, #fff);
  background: linear-gradient(145deg, var(--primary), color-mix(in srgb, var(--primary), #8b5cf6 38%));
  box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--primary) 70%, transparent),
    0 2px 6px rgba(15, 23, 42, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 180ms ease-out, box-shadow 180ms ease-out, opacity 180ms ease-out;
}

.fab:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 14px 30px -8px color-mix(in srgb, var(--primary) 75%, transparent),
    0 3px 8px rgba(15, 23, 42, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.fab:active { transform: scale(0.94); }

.fab .icon { stroke-width: 2.25; transition: transform 220ms ease-out; }
.fab:hover .icon { transform: rotate(90deg); }

.fab:focus-visible {
  outline-offset: 3px;
  border-radius: 50%;
}

/* Hide the FAB while typing on phones (it would sit over inputs / the keyboard) */
@media (max-width: 959.98px) {
  html.is-typing .fab {
    opacity: 0;
    transform: scale(0.6);
    pointer-events: none;
  }
}

/* ---------------------------------------------------------------- Sidebar (desktop) */
.sidebar {
  display: none;
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 10px;
  border-radius: var(--r);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
  text-decoration: none;
}

.sb-brand:hover .brand-mark { transform: rotate(-6deg) scale(1.04); }
.sb-brand .brand-mark { transition: transform 220ms ease-out; }

.sb-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 2px 8px;
}

.sb-new {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px 0 12px;
  border-radius: var(--r);
  font-size: 14.5px;
  font-weight: 600;
  color: var(--primary-contrast, #fff);
  background: linear-gradient(145deg, var(--primary), color-mix(in srgb, var(--primary), #8b5cf6 30%));
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12), 0 6px 16px -8px color-mix(in srgb, var(--primary) 80%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transition: transform 150ms ease-out, box-shadow 150ms ease-out, filter 150ms ease-out;
}

.sb-new:hover { filter: brightness(1.06); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12), 0 10px 22px -8px color-mix(in srgb, var(--primary) 85%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.16); }
.sb-new:active { transform: scale(0.98); }
.sb-new .icon { stroke-width: 2.25; }

.sb-new kbd,
.sb-search kbd {
  margin-left: auto;
}

.sb-new kbd {
  color: color-mix(in srgb, var(--primary-contrast, #fff) 85%, transparent);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
}

.sb-search {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 38px;
  padding: 0 9px 0 12px;
  border-radius: var(--r);
  font-size: 14px;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: border-color 150ms ease-out, background-color 150ms ease-out, color 150ms ease-out;
}

.sb-search:hover {
  color: var(--text-2);
  border-color: var(--border-strong, var(--border));
}

.sb-search.is-active {
  color: var(--text);
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  background: color-mix(in srgb, var(--primary) 6%, var(--surface));
}

.sb-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-top: 6px;
}

.sb-group-label {
  padding: 18px 12px 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
}

.sb-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px 0 12px;
  border-radius: 10px;
  font-size: 14.5px;
  font-weight: 520;
  color: var(--text-2);
  text-align: left;
  text-decoration: none;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}

.sb-item .icon {
  color: var(--accent, var(--text-3));
  opacity: 0.9;
  transition: transform 180ms ease-out, opacity 150ms ease-out;
}

.sb-item:hover {
  color: var(--text);
  background: var(--hover, var(--surface-2));
}

.sb-item:hover .icon { opacity: 1; }

.sb-item[aria-current="page"] {
  color: var(--text);
  font-weight: 640;
  background: color-mix(in srgb, var(--accent, var(--primary)) 12%, transparent);
}

.sb-item[aria-current="page"] .icon {
  opacity: 1;
  stroke-width: 2.1;
}

.sb-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent, var(--primary));
}

.sb-item-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sb-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full, 999px);
  font-size: 11.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--accent, var(--primary)) 85%, var(--text));
  background: color-mix(in srgb, var(--accent, var(--primary)) 14%, transparent);
}

.sb-footer {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: auto;
  padding-top: 12px;
}

.sb-footer-rule {
  height: 1px;
  margin: 0 8px 10px;
  background: var(--border);
}

.sb-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 2px;
  font-size: var(--fs-xs, 12px);
  color: var(--text-3);
}

.sb-note .icon { color: var(--success, #16a34a); }

.sb-offline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 12px 0;
  font-size: var(--fs-xs, 12px);
  color: var(--warning, #d97706);
}

/* ---------------------------------------------------------------- Desktop layout */
@media (min-width: 960px) {
  .app { --shell-gutter: 40px; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: var(--z-nav, 100);
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w, 248px);
    padding: 20px 14px 16px calc(14px + env(safe-area-inset-left, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface);
    border-right: 1px solid var(--border);
    scrollbar-width: thin;
  }

  .app-main {
    margin-left: var(--sidebar-w, 248px);
  }

  .topbar,
  .journal-switch,
  .bottom-nav {
    display: none !important;
  }

  #view {
    padding-top: var(--s-7, 32px);
    padding-bottom: 120px;
  }

  .fab {
    right: calc(32px + env(safe-area-inset-right, 0px));
    bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  }
}

/* Desktop with the content column reaching the FAB's corner (960–1599px): the sidebar's "New" button
   (same quick-add, plus the N shortcut) already covers it, so the floating button would only sit on
   top of right-column cards. Wider screens keep it in the empty margin. */
@media (min-width: 960px) and (max-width: 1599.98px) {
  .fab { display: none; }
}

@media (min-width: 1280px) {
  .app { --shell-gutter: 56px; }
}

/* ---------------------------------------------------------------- Full-screen routes (welcome) */
html.is-fullscreen .sidebar,
html.is-fullscreen .topbar,
html.is-fullscreen .journal-switch,
html.is-fullscreen .bottom-nav,
html.is-fullscreen .fab {
  display: none !important;
}

html.is-fullscreen .app-main {
  margin-left: 0;
}

html.is-fullscreen #view {
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

html.is-fullscreen .view-page {
  max-width: none;
}

/* Toasts (components.css reads --toast-bottom): clear the bottom nav AND the FAB on phones;
   sit near the bottom edge on full-screen routes where there is no nav. */
@media (max-width: 959.98px) {
  html:not(.is-fullscreen) {
    --toast-bottom: calc(var(--bottomnav-h, 64px) + env(safe-area-inset-bottom, 0px) + 84px);
  }
}

html.is-fullscreen {
  --toast-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
}

/* ---------------------------------------------------------------- Error card (view) */
.view-error {
  max-width: 540px;
  margin: clamp(8px, 6vh, 72px) auto 0;
  padding: 36px 28px 28px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl, 24px);
  box-shadow: var(--shadow-sm);
}

.view-error-icon {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin: 0 auto 18px;
  border-radius: 18px;
  color: var(--accent, var(--danger));
  background: color-mix(in srgb, var(--accent, var(--danger)) 12%, transparent);
}

.view-error h1 {
  font-size: var(--fs-xl, 20px);
  margin-bottom: 8px;
}

.view-error p {
  color: var(--text-2);
  max-width: 400px;
  margin-inline: auto;
}

.view-error-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.view-error-actions .btn { min-width: 132px; }

.view-error details {
  margin-top: 22px;
  text-align: left;
  font-size: var(--fs-xs, 12px);
  color: var(--text-3);
}

.view-error summary {
  cursor: pointer;
  width: max-content;
  margin-inline: auto;
  padding: 6px 10px;
  border-radius: var(--r-sm, 8px);
  list-style: none;
}

.view-error summary::-webkit-details-marker { display: none; }
.view-error summary:hover { color: var(--text-2); background: var(--surface-2); }

.view-error pre {
  margin: 10px 0 0;
  max-height: 220px;
  overflow: auto;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 8px);
}

/* ---------------------------------------------------------------- Quick add sheet */
.qa-date {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding: 5px 10px 5px 8px;
  border-radius: var(--r-full, 999px);
  font-size: var(--fs-sm, 13px);
  font-weight: 560;
  color: var(--text-2);
  background: var(--surface-2);
}

.qa-date .icon { color: var(--primary); }

.qa-date.is-past {
  color: color-mix(in srgb, var(--warning, #d97706) 80%, var(--text));
  background: color-mix(in srgb, var(--warning, #d97706) 12%, transparent);
}

.qa-date.is-past .icon { color: var(--warning, #d97706); }

.qa-grid {
  display: grid;
  /* 4 across on every width: 7 actions sit as 4 + 3 (3 across left 'Trade' orphaned on its own row) */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 559.98px) {
  .qa-grid .qa-tile { min-height: 96px; padding: 14px 4px 12px; gap: 8px; }
}

@media (min-width: 560px) {
  .qa-grid { gap: 10px; }
}

.qa-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  min-height: 106px;
  padding: 16px 8px 14px;
  border-radius: var(--r-lg, 16px);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm, 13px);
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  transition: transform 160ms ease-out, border-color 160ms ease-out, box-shadow 160ms ease-out,
    background-color 160ms ease-out;
  animation: qa-in 260ms ease-out both;
  animation-delay: calc(var(--i, 0) * 22ms);
}

.qa-tile:hover {
  border-color: color-mix(in srgb, var(--accent, var(--primary)) 42%, var(--border));
  background: color-mix(in srgb, var(--accent, var(--primary)) 5%, var(--surface));
  box-shadow: 0 6px 18px -10px color-mix(in srgb, var(--accent, var(--primary)) 70%, transparent);
  transform: translateY(-2px);
}

.qa-tile:active { transform: scale(0.96); }

.qa-tile:focus-visible { border-radius: var(--r-lg, 16px); }

.qa-chip {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  color: var(--accent, var(--primary));
  background: color-mix(in srgb, var(--accent, var(--primary)) 14%, transparent);
  transition: transform 200ms ease-out;
}

.qa-tile:hover .qa-chip { transform: scale(1.06); }

.qa-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.qa-key {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  min-width: 18px;
  height: 18px;
  font-size: 10.5px;
}

@media (hover: hover) and (pointer: fine) {
  .qa-key { display: inline-grid; }
}

.qa-foot {
  display: none;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 18px;
  font-size: var(--fs-xs, 12px);
  color: var(--text-3);
}

@media (hover: hover) and (pointer: fine) {
  .qa-foot { display: flex; }
}

@keyframes qa-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- More sheet */
.more-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -6px;
}

.more-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 60px;
  padding: 8px 10px;
  border-radius: var(--r, 12px);
  color: var(--text);
  text-align: left;
  text-decoration: none;
  transition: background-color 150ms ease-out;
}

.more-item:hover {
  background: var(--hover, var(--surface-2));
}

.more-item:active {
  background: var(--press, var(--surface-2));
}

.more-item[aria-current="page"] {
  background: color-mix(in srgb, var(--accent, var(--primary)) 9%, transparent);
}

.more-chip {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: var(--accent, var(--primary));
  background: color-mix(in srgb, var(--accent, var(--primary)) 14%, transparent);
}

.more-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.more-label {
  font-size: var(--fs-md, 15px);
  font-weight: 600;
  line-height: 1.3;
}

.more-sub {
  font-size: var(--fs-sm, 13px);
  color: var(--text-3);
  line-height: 1.35;
}

.more-chev { color: var(--text-3); }

.more-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs, 12px);
  color: var(--text-3);
}

.more-note .icon { color: var(--success, #16a34a); }

/* ---------------------------------------------------------------- Shortcuts + install help */
.kb-list {
  display: flex;
  flex-direction: column;
}

.kb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}

.kb-row:last-child { border-bottom: 0; }

.kb-keys {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-3);
  font-size: var(--fs-xs, 12px);
}

.kb-keys kbd {
  min-width: 24px;
  height: 24px;
  font-size: 12px;
  color: var(--text-2);
}

.install-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
  counter-reset: step;
}

.install-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: var(--text-2);
}

.install-step::before {
  counter-increment: step;
  content: counter(step);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.install-step strong { color: var(--text); }

/* ---------------------------------------------------------------- Noscript */
.noscript {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: var(--bg, #f4f5f8);
  color: var(--text, #0f172a);
}

/* ---------------------------------------------------------------- Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }

  .boot-mark,
  .boot-mark::after,
  .boot-bar::before {
    animation: none !important;
  }
}
