/* ==========================================================================
   Жизнесвод — calm light interface

   Loaded LAST. One quiet visual language for every signed-in screen: white
   surfaces on a barely cool background, dark readable text, thin dividers,
   the existing petrol accent. It re-points the shared tokens (so older
   screens follow automatically) and replaces the heavy glass / gradient /
   shadow treatment with flat, low-contrast structure.

   Light is the default regardless of time of day (no prefers-color-scheme
   switching exists in this product; `color-scheme: light` stays).
   No inline styles anywhere: the CSP is `style-src 'self'`.
   ========================================================================== */

:root {
  color-scheme: light;

  --color-bg: #f7f9fb;
  --color-bg-subtle: #f1f4f7;
  --color-surface: #ffffff;
  --color-text: #17212b;
  --color-text-secondary: #55636f;
  --color-text-muted: #6a7782;
  --color-divider: #e6eaee;
  --color-border: #e6eaee;
  --color-border-strong: #d3d9df;

  /* flatten the glass language to opaque, quiet surfaces */
  --glass-bg: #ffffff;
  --glass-bg-strong: #ffffff;
  --glass-bg-soft: #f7f9fb;
  --glass-border: #e6eaee;
  --glass-edge: #e6eaee;
  --glass-highlight: 0 0 0 0 transparent;
  --glass-dock: #ffffff;
  --shadow-1: none;
  --shadow-2: 0 1px 2px rgba(23, 33, 43, 0.06);
  --shadow-3: 0 8px 28px rgba(23, 33, 43, 0.14);
  --shadow-dock: none;
  --shadow-accent: none;
  --shadow-accent-hover: none;
  --dock-add-bg: var(--color-accent);
  --dock-add-ring: 0 0 0 0 transparent;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;

  --container: 720px;
  --gutter: 1rem;
  --nav-height: 3.5rem;
  --dock-height: var(--nav-height);
  --dock-bottom: 0px;
  --dock-add-lift: 0px;
  --dock-add-size: 2.75rem;
  --dock-clearance: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + var(--space-6));
}

/* No atmosphere glows behind the app. */
body::before, body::after { display: none !important; background: none !important; }
html, body { background: var(--color-bg); }

/* ---- shell: top safe area, calm header --------------------------------- */
.shell {
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--space-2));
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
  padding-bottom: var(--dock-clearance);
}
.app-header { min-height: 2.75rem; margin-bottom: var(--space-1); }
.app-header .wordmark { font-size: var(--text-md); font-weight: 650; letter-spacing: -0.01em; color: var(--color-text); }

h1 { font-size: 1.5rem; font-weight: 650; margin: 0 0 var(--space-2); letter-spacing: -0.01em; }
h2 { font-size: 1.0625rem; font-weight: 650; margin: var(--space-6) 0 var(--space-2); letter-spacing: 0; }
.lede { font-size: var(--text-sm); margin: 0 0 var(--space-4); max-width: 40rem; }

.section-nav { margin: 0 0 var(--space-4); gap: var(--space-1); }
.section-nav .chip.on { background: var(--color-accent-tint); color: var(--color-accent-strong); }

/* ---- surfaces: flat, thin divider instead of boxes ---------------------- */
.card, .empty, form.entry, .inspect-block, .chapter, .toc {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: none;
  padding: var(--space-3) var(--space-4);
}
.empty { border-style: solid; background: transparent; text-align: left; }
.stack { gap: var(--space-2); }
.item-title { font-size: var(--text-base); font-weight: 600; margin: 0 0 2px; }
.meta { font-size: var(--text-sm); color: var(--color-text-secondary); }
.counts { display: none; }
.banner {
  background: var(--color-accent-tint);
  border: 0;
  border-radius: var(--radius-md);
  color: var(--color-accent-strong);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-3);
}

/* ---- buttons / chips: flat -------------------------------------------- */
.cta, button.primary {
  background: var(--color-accent);
  border: 0;
  border-radius: var(--radius-md);
  box-shadow: none;
  min-height: 2.5rem;
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  transform: none;
}
.cta:hover, button.primary:hover:not(:disabled) { background: var(--color-accent-hover); box-shadow: none; transform: none; }
.chip {
  min-height: 2rem;
  padding: 0 var(--space-3);
  background: transparent;
  border: 1px solid var(--color-border-strong);
  font-size: var(--text-sm);
}
a.chip:hover, button.chip:hover:not([disabled]) { background: var(--color-bg-subtle); border-color: var(--color-border-strong); }
.chip.on { background: var(--color-accent-tint); color: var(--color-accent-strong); border-color: var(--color-accent-tint-border); }
button:not([class]) { box-shadow: none; }

/* ---- bottom navigation: compact bar, one "+" --------------------------- */
.dock {
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  min-height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding: 0 max(var(--space-2), env(safe-area-inset-left, 0px)) env(safe-area-inset-bottom, 0px);
  border: 0;
  border-top: 1px solid var(--color-divider);
  border-radius: 0;
  background: var(--color-surface);
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  column-gap: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr)) 4rem repeat(2, minmax(0, 1fr));
}
.dock-item {
  min-height: var(--nav-height);
  gap: 2px;
  border-radius: 0;
  font-size: 0.6875rem;
  font-weight: 500;
}
.dock-item.active, .dock-item.active:hover { background: transparent; color: var(--color-accent); }
.dock-icon { width: 1.375rem; height: 1.375rem; stroke-width: 1.6; }
.dock-add {
  width: var(--dock-add-size);
  height: var(--dock-add-size);
  border: 0;
  background: var(--color-accent);
  box-shadow: none;
  transform: none;
}
.dock-add:hover, .dock-add:active { transform: none; box-shadow: none; background: var(--color-accent-hover); }
.dock-add.active { box-shadow: none; }
.dock-icon-add { width: 1.375rem; height: 1.375rem; stroke-width: 2.2; }
body.sheet-open .dock { display: none; }

/* ---- entries: a simple list ------------------------------------------- */
.entry-list { display: block; border-top: 1px solid var(--color-divider); }
.entry-row {
  display: block;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-divider);
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.entry-row:hover .entry-title { color: var(--color-accent-strong); }
.entry-title {
  display: block;
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.entry-snippet {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.entry-meta {
  display: block;
  margin-top: 4px;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}
.mark {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  line-height: 1.5;
}
.mark.tag { background: var(--color-accent-tint); color: var(--color-accent-strong); }
.mark.warn { background: var(--color-danger-tint); color: var(--color-danger); }

.entries-search { margin-bottom: var(--space-3); }
.tag-form { gap: var(--space-2); }

/* dashboard / overview quotes: same calm rhythm */
.dash-head { align-items: center; }
.dash-quote { padding: var(--space-2) 0; border-bottom: 1px solid var(--color-divider); }
.dash-quote:last-child { border-bottom: 0; }
.dash-quote .quote { font-size: var(--text-base); }
.dash-month h3 { font-size: var(--text-sm); color: var(--color-text-secondary); font-weight: 600; }
.dash-periods { gap: var(--space-1); margin: var(--space-3) 0; }
.first-run { padding: var(--space-6) 0; max-width: 28rem; }

/* ---- toast ------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + var(--space-3));
  transform: translateX(-50%);
  z-index: 80;
  max-width: calc(100% - 2rem);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--color-text);
  color: #fff;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-3);
}
.toast a { color: #fff; margin-left: var(--space-3); text-decoration: underline; font-weight: 600; }

/* ---- quick-add bottom sheet ------------------------------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(23, 33, 43, 0.32);
}
.sheet {
  --kb: 0px;
  --vvh: 100dvh;
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--kb);
  z-index: 61;
  display: flex;
  flex-direction: column;
  max-height: calc(var(--vvh) - env(safe-area-inset-top, 0px) - var(--space-4));
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-3);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overscroll-behavior: contain;
}
.sheet-grip {
  flex: none;
  width: 2.5rem;
  height: 4px;
  margin: var(--space-2) auto 0;
  border-radius: var(--radius-pill);
  background: var(--color-border-strong);
}
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-3) var(--space-4) var(--space-2);
}
#qa-text {
  display: block;
  width: 100%;
  min-height: 3.25rem;
  max-height: 45vh;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  resize: none;
  overflow-y: auto;
  font: inherit;
  font-size: 1.0625rem; /* >= 16px: iOS does not zoom the page on focus */
  line-height: 1.45;
  color: var(--color-text);
}
#qa-text:focus { outline: none; box-shadow: none; border: 0; }
#qa-text::placeholder { color: var(--color-text-muted); }
.qa-note, .qa-status { margin: var(--space-2) 0 0; font-size: var(--text-sm); color: var(--color-text-secondary); }
.qa-status.error { color: var(--color-danger); }
.qa-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.qa-chips:empty { display: none; }
.qa-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: var(--text-sm);
}
.qa-chip button {
  min-height: 2rem;
  padding: 0 var(--space-3);
  border: 0;
  background: transparent;
  color: var(--color-text-secondary);
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qa-chip button + button { padding: 0 var(--space-3) 0 0; font-size: 1.1rem; line-height: 1; }
.qa-chip.on { background: var(--color-accent-tint); border-color: var(--color-accent-tint-border); }
.qa-chip.on button { color: var(--color-accent-strong); }
.qa-chip.warn { border-style: dashed; }
.qa-date { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--color-text-secondary); }
.qa-date input { min-height: 2.25rem; font: inherit; font-size: 1rem; }
.qa-chip-btn { border: 0; background: transparent; color: var(--color-accent); font: inherit; font-size: var(--text-sm); cursor: pointer; }

.sheet-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-divider);
}
.sheet-bar.is-hidden { display: none; }
.bar-spacer { flex: 1; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--color-bg-subtle); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn svg, .send-btn svg { width: 1.4rem; height: 1.4rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  margin-left: var(--space-1);
  border: 0;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-on-accent);
  cursor: pointer;
}
.send-btn:disabled { background: var(--color-border-strong); cursor: not-allowed; }
.attach { position: relative; }
.menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + var(--space-2));
  z-index: 2;
  min-width: 16.5rem;
  padding: var(--space-1);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-3);
}
.menu button {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu button:hover { background: var(--color-bg-subtle); }

/* voice panel */
.voice-panel { display: grid; gap: var(--space-4); justify-items: center; padding: var(--space-4) 0 var(--space-2); }
.voice-top { display: flex; align-items: center; gap: var(--space-3); font-size: var(--text-lg); }
.voice-time { color: var(--color-text-secondary); font-variant-numeric: tabular-nums; font-size: var(--text-base); }
.voice-dot {
  width: 0.875rem;
  height: 0.875rem;
  border-radius: 50%;
  background: var(--color-danger);
  animation: voice-pulse 1.2s ease-in-out infinite;
}
.voice-dot.paused { animation: none; background: var(--color-text-muted); }
.voice-level { width: min(18rem, 100%); height: 6px; border-radius: var(--radius-pill); background: var(--color-bg-subtle); overflow: hidden; }
.voice-level span { display: block; width: var(--lvl, 0%); height: 100%; background: var(--color-accent); transition: width 90ms linear; }
.voice-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: center; }
.btn-main, .btn-soft {
  min-height: 2.75rem;
  padding: 0 var(--space-5);
  border-radius: var(--radius-pill);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-main { border: 0; background: var(--color-accent); color: var(--color-on-accent); }
.btn-soft { border: 1px solid var(--color-border-strong); background: transparent; color: var(--color-text-secondary); }
@keyframes voice-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.82); } }
@media (prefers-reduced-motion: reduce) {
  .voice-dot { animation: none; }
  .voice-level span { transition: none; }
}

/* desktop: the same sheet as a compact centred dialog */
@media (min-width: 700px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 14vh;
    width: min(36rem, calc(100% - 2rem));
    max-height: 70vh;
    transform: translateX(-50%);
    border-radius: var(--radius-xl);
    padding-bottom: 0;
  }
  .sheet-grip { display: none; }
  .shell { padding-bottom: var(--dock-clearance); }
}

/* phones: nothing may force sideways scrolling */
html, body { max-width: 100%; overflow-x: hidden; }
img, svg, video, table { max-width: 100%; }
