/* Скрытое должно быть скрыто.

   У .setup стоит display:grid, у .sheet — display:flex. Правило класса
   сильнее браузерного [hidden]{display:none}, поэтому без этой строки
   экран подключения и форма траты висят поверх приложения всегда.
   Это не косметика: именно так выглядел первый запуск. */
[hidden] { display: none !important; }

:root {
  --base: #14100E;
  --surface: #1E1815;
  --line: #2C241F;
  --text: #EDE6DC;
  --dim: #9A8E82;
  --brass: #C8A15A;
  --sage: #7E9B76;

  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --voice: ui-serif, "New York", Charter, Georgia, serif;

  --pad: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--base);
  color: var(--text);
  font-family: var(--ui);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-top: var(--safe-top); }

h1, h2 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }

/* ---------- подключение ---------- */

.setup { min-height: 100dvh; display: grid; place-items: center; padding: var(--pad); }
.setup-inner { width: 100%; max-width: 380px; }
.setup-title { font-size: 30px; margin: 0 0 8px; letter-spacing: -0.02em; }
.setup-note { color: var(--dim); font-size: 15px; margin: 0 0 28px; }

.field { display: block; margin-bottom: 18px; }
.field span { display: block; font-size: 13px; color: var(--dim); margin-bottom: 7px; }
.field input {
  width: 100%; padding: 14px 16px; font-size: 17px; font-family: var(--ui);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 13px;
}
.field input:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

.setup-error { color: #D98A72; font-size: 15px; margin-top: 16px; }

.btn-primary {
  width: 100%; padding: 15px; margin-top: 10px;
  font-family: var(--ui); font-size: 17px; font-weight: 600;
  color: var(--base); background: var(--brass);
  border: 0; border-radius: 13px; cursor: pointer;
}
.btn-primary:active { transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.5; }

.btn-quiet {
  width: 100%; padding: 13px; margin-top: 10px;
  font-family: var(--ui); font-size: 16px;
  color: var(--brass); background: none; border: 0; cursor: pointer;
}

/* ---------- каркас ---------- */

.view { padding: 14px var(--pad) calc(96px + var(--safe-bottom)); max-width: 620px; margin: 0 auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 9px 0 calc(9px + var(--safe-bottom));
  background: rgba(20, 16, 14, 0.82);
  backdrop-filter: saturate(160%) blur(20px);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; padding: 7px 0; font-family: var(--ui); font-size: 13px;
  color: var(--dim); background: none; border: 0; cursor: pointer;
}
.tab.is-active { color: var(--brass); }

/* ---------- сегодня ---------- */

.today-head { padding: 18px 0 6px; }
.today-date { font-size: 15px; color: var(--dim); margin: 0; }
.today-period { font-size: 15px; color: var(--brass); margin: 3px 0 0; }

.brief {
  font-family: var(--voice);
  font-size: 20px;
  line-height: 1.58;
  letter-spacing: -0.003em;
  margin: 14px 0 30px;
  max-width: 34em;
}
.brief p { margin: 0 0 0.85em; }
.brief p:last-child { margin-bottom: 0; }
.brief-loading { color: var(--dim); }
.brief.is-ready { animation: settle 0.5s ease-out; }

@keyframes settle {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

/* метрики — тихая строка на линейках, не плитки */
.metric-list { list-style: none; margin: 0 0 30px; padding: 0; border-top: 1px solid var(--line); }
.metric-list li {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.metric-name { color: var(--dim); font-size: 15px; }
.metric-value { font-size: 19px; font-variant-numeric: tabular-nums; }
.metric-value.is-good { color: var(--sage); }

.block { margin-bottom: 30px; }
.block-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.block-head h2 { font-size: 17px; }
.block-value { font-size: 19px; font-variant-numeric: tabular-nums; }

.category-list, .goal-list { list-style: none; margin: 0; padding: 0; }
.category-list li, .goal-list li {
  display: flex; justify-content: space-between;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
  font-size: 16px; color: var(--dim);
}
.category-list li span:last-child { color: var(--text); font-variant-numeric: tabular-nums; }
.goal-list li { color: var(--text); }

.hint, .sync-note { color: var(--dim); font-size: 14px; }
.sync-note { margin-top: 26px; }

/* ---------- разговор ---------- */

#view-chat { display: flex; flex-direction: column; height: 100dvh; padding-bottom: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px 0 12px; -webkit-overflow-scrolling: touch; }

.msg { max-width: 82%; padding: 11px 15px; margin-bottom: 10px; font-size: 16px; line-height: 1.45; }
.msg-user {
  margin-left: auto; background: var(--surface);
  border-radius: 19px 19px 5px 19px;
}
.msg-bot {
  margin-right: auto; font-family: var(--voice); font-size: 17px;
  background: none; padding-left: 2px; max-width: 100%;
}
.msg-pending { opacity: 0.45; }

.chat-bar {
  display: flex; gap: 9px; align-items: center;
  padding: 10px 0 calc(70px + var(--safe-bottom));
  background: var(--base);
}
.chat-bar input {
  flex: 1; padding: 12px 16px; font-size: 17px; font-family: var(--ui);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 21px;
}
.chat-bar input:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.chat-bar button {
  width: 42px; height: 42px; flex: none; font-size: 20px;
  color: var(--base); background: var(--brass);
  border: 0; border-radius: 50%; cursor: pointer;
}
.chat-bar button:disabled { opacity: 0.4; }

/* ---------- история ---------- */

.history-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 0 16px; }
.history-head h2 { font-size: 22px; }
.date-input {
  padding: 9px 13px; font-family: var(--ui); font-size: 16px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 11px;
}
.day-summary { font-family: var(--voice); font-size: 19px; line-height: 1.55; margin: 0 0 22px; }
.day-section { margin-bottom: 22px; }
.day-section h3 { font-size: 14px; color: var(--dim); font-weight: 500; margin: 0 0 8px; }
.day-section ul { list-style: none; margin: 0; padding: 0; }
.day-section li { padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 16px; }

/* ---------- шторка траты ---------- */

.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.55); display: flex; align-items: flex-end; }
.sheet-panel {
  width: 100%; padding: 12px var(--pad) calc(24px + var(--safe-bottom));
  background: var(--surface); border-radius: 22px 22px 0 0;
  animation: rise 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }

.sheet-grip { width: 38px; height: 4px; margin: 0 auto 18px; background: var(--line); border-radius: 2px; }
.sheet-amount {
  width: 100%; padding: 6px 0 14px; font-family: var(--ui);
  font-size: 44px; font-weight: 600; text-align: center; letter-spacing: -0.02em;
  color: var(--text); background: none; border: 0; border-bottom: 1px solid var(--line);
}
.sheet-amount:focus-visible { outline: none; border-bottom-color: var(--brass); }

.sheet-cats { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.cat {
  padding: 9px 15px; font-family: var(--ui); font-size: 15px;
  color: var(--dim); background: var(--base);
  border: 1px solid var(--line); border-radius: 19px; cursor: pointer;
}
.cat.is-on { color: var(--base); background: var(--brass); border-color: var(--brass); }

.sheet-note {
  width: 100%; padding: 13px 15px; font-family: var(--ui); font-size: 16px;
  color: var(--text); background: var(--base);
  border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px;
}

/* ---------- уведомление ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); z-index: 60;
  transform: translateX(-50%);
  padding: 11px 19px; font-size: 15px;
  color: var(--base); background: var(--text);
  border-radius: 21px; box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
