:root {
  --ink: #1c2a29;
  --muted: #667270;
  --canvas: #f6f1e8;
  --surface: #fffdf9;
  --surface-raised: #ffffff;
  --line: #e6dfd3;
  --ocean: #194d4c;
  --ocean-strong: #113a39;
  --sand: #ede4d5;
  --amber: #b67b2c;
  --on-dark: #fdf9f2;
  --shadow: 0 16px 44px rgba(28, 42, 41, 0.12);
  --radius-card: 20px;
  --radius-control: 14px;
  font-family: Manrope, Arial, sans-serif;
  color: var(--ink);
  background: #d9ddd9;
}

:root[data-theme="night"] {
  --ink: #f5f0e7;
  --muted: #b8c0bc;
  --canvas: #10201f;
  --surface: #172a29;
  --surface-raised: #1d3230;
  --line: #314443;
  --ocean: #a8d0c8;
  --ocean-strong: #c4e1da;
  --sand: #2a3d3a;
  --amber: #e5b961;
  --on-dark: #fdf9f2;
  --shadow: 0 16px 44px rgba(0, 0, 0, 0.28);
  background: #081110;
}

* { box-sizing: border-box; }
body { min-width: 320px; margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  position: relative;
  width: min(100%, 480px);
  min-height: var(--app-height, var(--tg-viewport-stable-height, 100dvh));
  margin: 0 auto;
  overflow: hidden;
  background: var(--canvas);
  box-shadow: 0 0 60px rgba(21, 38, 37, 0.22);
}

.screen { min-height: calc(var(--app-height, var(--tg-viewport-stable-height, 100dvh)) - 88px); padding-bottom: calc(104px + var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); background: var(--canvas); }
.screen[hidden], .sheet[hidden], .bottom-nav[hidden] { display: none; }
.hero { position: relative; height: clamp(304px, 39vh, 340px); overflow: hidden; color: var(--on-dark); }
.hero__image, .hero__scrim { position: absolute; inset: 0; width: 100%; height: 100%; }
.hero__image { object-fit: cover; object-position: 52% center; }
.hero__scrim { background: linear-gradient(180deg, rgba(8, 22, 21, 0.55) 0%, rgba(8, 22, 21, 0.09) 44%, rgba(8, 22, 21, 0.62) 100%); }
.hero__topline, .hero__copy { position: absolute; right: 24px; left: 24px; z-index: 1; }
.hero__topline { top: max(20px, calc(var(--tg-content-safe-area-inset-top, env(safe-area-inset-top, 0px)) + 12px)); display: flex; align-items: center; justify-content: space-between; }
.hero__copy { bottom: 24px; }
.wordmark { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.19em; }
.wordmark--dark { color: var(--ink); }
.eyebrow, .section-label { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.eyebrow { color: rgba(253, 249, 242, 0.84); }
.eyebrow--dark { color: var(--muted); }
.hero h1, .page-title { margin: 8px 0; font-family: Fraunces, Georgia, serif; font-size: clamp(34px, 9vw, 43px); font-weight: 500; line-height: 1.03; letter-spacing: -0.04em; }
.hero__copy > p:last-child { margin: 0; font-size: 14px; }
.icon-button { display: inline-grid; width: 36px; height: 36px; place-items: center; border: 1px solid rgba(255,255,255,0.28); border-radius: 50%; color: var(--on-dark); background: rgba(16, 30, 29, 0.2); font-size: 20px; }
.icon-button--quiet { border-color: var(--line); color: var(--ink); background: var(--surface-raised); }
.content { padding: 26px 24px; }
.content--today { margin-top: -3px; }
.focus-card, .calendar-card, .task-card { border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface-raised); box-shadow: var(--shadow); }
.focus-card { padding: 18px; }
.section-label { color: var(--muted); }
.focus-card__row { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; margin-top: 9px; }
.focus-card h2, .agenda h2, .task-card h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.02em; }
.focus-card p:not(.section-label), .timeline p, .agenda p, .task-card p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.priority { display: inline-grid; flex: 0 0 auto; width: 28px; height: 28px; place-items: center; border-radius: 50%; color: var(--on-dark); background: var(--amber); font-size: 11px; font-weight: 700; }
.priority--low { color: var(--ocean-strong); background: var(--sand); }
.timeline { margin-top: 31px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin: 0; font-size: 16px; letter-spacing: -0.03em; }
.text-button { padding: 0; border: 0; color: var(--ocean-strong); background: transparent; font-size: 12px; font-weight: 700; }
.timeline__list { position: relative; display: grid; gap: 22px; margin: 20px 0 0; padding: 0; list-style: none; }
.timeline__list::before { position: absolute; top: 13px; bottom: 13px; left: 65px; width: 1px; background: var(--line); content: ""; }
.timeline__list li { position: relative; display: grid; grid-template-columns: 48px 17px 1fr; gap: 8px; align-items: start; }
.timeline time, .agenda time { color: var(--muted); font-size: 11px; font-weight: 700; }
.timeline__point { z-index: 1; display: block; width: 10px; height: 10px; margin-top: 3px; border: 2px solid var(--surface); border-radius: 50%; background: var(--line); }
.timeline__point--active { width: 12px; height: 12px; margin-top: 2px; border-color: var(--surface); background: var(--ocean); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ocean) 14%, transparent); }
.timeline strong, .agenda strong { font-size: 13px; }
.simple-header { display: flex; align-items: center; justify-content: space-between; padding: max(20px, calc(var(--tg-content-safe-area-inset-top, env(safe-area-inset-top, 0px)) + 12px)) 24px 6px; }
.page-title { color: var(--ink); }
.calendar-card { padding: 14px; margin-top: 22px; box-shadow: none; }
.weekdays, .days { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.weekdays { margin-bottom: 12px; color: var(--muted); font-size: 10px; font-weight: 700; }
.days { gap: 8px 2px; align-items: center; font-size: 12px; }
.days > span, .day-selected { display: inline-grid; width: 33px; height: 33px; place-items: center; justify-self: center; border: 0; border-radius: 50%; color: var(--ink); background: transparent; }
.days .muted { color: var(--muted); opacity: 0.55; }
.day-selected { color: var(--on-dark); background: var(--ocean); font-weight: 700; }
.agenda { margin-top: 32px; }
.agenda__item { display: grid; grid-template-columns: 52px 1fr; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.filters { display: flex; gap: 8px; margin: 23px 0 20px; overflow-x: auto; }
.filter { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; white-space: nowrap; }
.filter.is-selected { border-color: var(--ocean); color: var(--on-dark); background: var(--ocean); }
.task-list { display: grid; gap: 10px; }
.task-card { display: grid; grid-template-columns: 20px 1fr 28px; gap: 12px; align-items: start; padding: 16px; box-shadow: none; }
.check { width: 20px; height: 20px; margin-top: 1px; padding: 0; border: 1.5px solid var(--muted); border-radius: 50%; background: transparent; }
.primary-button, .secondary-button { min-height: 46px; padding: 0 18px; border-radius: var(--radius-control); font-size: 13px; font-weight: 700; }
.primary-button { border: 1px solid var(--ocean); color: var(--on-dark); background: var(--ocean); }
.primary-button--full { width: 100%; margin-top: 24px; }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: var(--surface-raised); }
.bottom-nav { position: fixed; z-index: 5; right: max(12px, calc((100vw - 480px) / 2 + 12px)); bottom: max(12px, calc(var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + 12px)); left: max(12px, calc((100vw - 480px) / 2 + 12px)); display: grid; grid-template-columns: repeat(3, 1fr); min-height: 66px; padding: 7px; border: 1px solid var(--line); border-radius: 20px; background: color-mix(in srgb, var(--surface-raised) 91%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.nav-item { display: grid; gap: 3px; place-items: center; padding: 4px; border: 0; border-radius: 14px; color: var(--muted); background: transparent; font-size: 10px; font-weight: 700; }
.nav-item > span:first-child { font-size: 16px; line-height: 1; }
.nav-item.is-active { color: var(--ocean-strong); background: var(--sand); }
.sheet { position: fixed; z-index: 10; inset: 0; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(8, 19, 18, 0.5); }
.sheet__panel { position: absolute; right: 0; bottom: 0; left: 0; padding: 11px 24px calc(28px + var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); border-radius: 24px 24px 0 0; color: var(--ink); background: var(--surface-raised); box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.16); }
.sheet__handle { width: 36px; height: 4px; margin: 0 auto 18px; border-radius: 99px; background: var(--line); }
.sheet__heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.sheet__heading h2 { margin: 5px 0 0; font-family: Fraunces, Georgia, serif; font-size: 29px; font-weight: 500; letter-spacing: -0.04em; }
.input-label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 700; }
input { width: 100%; min-height: 50px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius-control); outline: none; color: var(--ink); background: var(--surface); }
input:focus { border-color: var(--ocean); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ocean) 17%, transparent); }
.sheet__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }

@media (max-width: 389px) {
  .hero__topline, .hero__copy { right: 20px; left: 20px; }
  .content { padding-right: 20px; padding-left: 20px; }
  .simple-header { padding-right: 20px; padding-left: 20px; }
  .days > span, .day-selected { width: 30px; height: 30px; }
  .bottom-nav { right: 10px; left: 10px; }
}

@media (min-width: 481px) {
  .app-shell { border-right: 1px solid rgba(255,255,255,0.4); border-left: 1px solid rgba(255,255,255,0.4); }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }

/* ---- Connected-frontend states (Checkpoint 4) ---- */

.boot { display: grid; gap: 20px; align-content: center; justify-items: center; min-height: 100dvh; padding: 24px; text-align: center; }
.boot__status { color: var(--muted); font-size: 13px; }
.boot__error { color: var(--ink); font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.boot__retry { margin-top: 10px; }

.banner { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 18px; padding: 13px 15px; border-radius: var(--radius-control); font-size: 12.5px; line-height: 1.5; }
.banner--info { border: 1px solid var(--line); background: var(--sand); color: var(--ink); }
.banner--error { border: 1px solid color-mix(in srgb, #b3432f 45%, var(--line)); background: color-mix(in srgb, #b3432f 12%, var(--surface-raised)); color: var(--ink); }
.banner--pending { border: 1px solid var(--ocean); background: color-mix(in srgb, var(--ocean) 10%, var(--surface-raised)); color: var(--ink); }
.banner button { flex-shrink: 0; }

.unavailable-card { margin-top: 22px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface-raised); }
.unavailable-card p { margin: 0 0 6px; font-size: 13px; color: var(--ink); }
.muted-small { color: var(--muted) !important; font-size: 12px !important; }
.unavailable-card .secondary-button { margin-top: 14px; width: 100%; }

.empty-state { margin-top: 20px; color: var(--muted); font-size: 13px; font-style: italic; }

.field-error { margin: 8px 0 0; color: #b3432f; font-size: 12px; }
.proposal-summary { margin: 10px 0 4px; padding: 12px 14px; border-radius: var(--radius-control); background: var(--sand); font-size: 13px; line-height: 1.5; }
.sheet__actions--single { grid-template-columns: 1fr; }

.focus-card__actions { margin-top: 14px; }

button[aria-busy="true"] { opacity: 0.65; pointer-events: none; }

.skeleton-line { height: 12px; margin-bottom: 8px; border-radius: 6px; background: linear-gradient(90deg, var(--line) 25%, var(--surface-raised) 50%, var(--line) 75%); background-size: 200% 100%; animation: skeleton-shimmer 1.4s ease-in-out infinite; }
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton-line { animation: none; } }

/* ---- UX P2 fixes ---- */

/* Fix 1: Quick Capture trigger -- a calm, adequately-sized entry point.
   Stays a ghost/outline control (not filled) so it never outweighs the
   primary Focus "Готово" button when a focus session is active. */
.quick-capture-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ocean-strong);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}
.quick-capture-trigger__icon { font-size: 15px; line-height: 1; }

/* Fix 4: Calendar/Tasks nav honesty -- a restrained badge next to the page
   title, visible immediately on arrival, before the explanatory paragraph
   below. Bottom nav itself is left untouched (least invasive, no overflow
   risk at 360px). */
.page-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.page-title-row .page-title { margin: 8px 0; }
.surface-badge {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--sand);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Fix 3: Focus visual priority -- a calmer, distinct concentration mode.
   Toggled by app.js via .is-focus-active on .app-shell when current_focus
   exists; no new screen, no timers, no business logic. */
.app-shell.is-focus-active .hero { height: clamp(232px, 30vh, 264px); }
.app-shell.is-focus-active .focus-card {
  border-color: var(--ocean);
  box-shadow: 0 20px 48px rgba(28, 42, 41, 0.18);
}
.app-shell.is-focus-active .focus-card__actions #focus-done {
  box-shadow: 0 10px 26px color-mix(in srgb, var(--ocean) 45%, transparent);
}
.app-shell.is-focus-active .timeline { opacity: 0.62; }
.app-shell.is-focus-active .bottom-nav { opacity: 0.72; }
