:root {
  --bg: #0c1220;
  --bg-elevated: #141c2e;
  --bg-card: rgba(22, 32, 52, 0.72);
  --border: rgba(148, 163, 184, 0.12);
  --text: #e8edf7;
  --text-muted: #94a3b8;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.15);
  --accent-warm: #fbbf24;
  --danger: #fb7185;
  --radius: 16px;
  --radius-sm: 10px;
  --font-ui: "Outfit", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
}

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

html {
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(94, 234, 212, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(251, 191, 36, 0.06), transparent),
    radial-gradient(ellipse 50% 30% at 0% 80%, rgba(99, 102, 241, 0.08), transparent);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
}

/* —— Gate —— */
.gate {
  min-height: 80dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  padding: 36px 28px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.gate-mark {
  width: 48px;
  height: 48px;
  margin-bottom: 20px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  box-shadow: 0 8px 24px rgba(94, 234, 212, 0.25);
}

.gate-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gate-lead {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.gate-lead code {
  font-size: 0.82em;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 6px;
  border-radius: 4px;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gate-error {
  margin: 16px 0 0;
  color: var(--danger);
  font-size: 0.88rem;
}

/* —— Shell —— */
.shell.hidden {
  display: none;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 20px var(--accent);
}

.brand-kicker {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.brand-title {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.nav-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.nav-btn:hover {
  border-color: rgba(94, 234, 212, 0.35);
  background: var(--accent-dim);
}

.date-pill {
  flex: 1;
  min-width: 140px;
  position: relative;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.date-pill-title {
  display: block;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  pointer-events: none;
}

.date-picker {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.btn-today {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent);
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}

.btn-today:hover {
  background: rgba(94, 234, 212, 0.25);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 18px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}

.stat-card.featured {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, rgba(94, 234, 212, 0.1), rgba(99, 102, 241, 0.08));
  border-color: rgba(94, 234, 212, 0.2);
}

.stat-label {
  margin: 0 0 6px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.stat-value small {
  font-family: var(--font-ui);
  font-size: 0.55em;
  font-weight: 400;
  color: var(--text-muted);
}

.stat-sub {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stat-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.stat-list li + li {
  margin-top: 4px;
}

/* Panels */
.panel {
  margin-bottom: 24px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 500;
}

.badge-warn {
  background: rgba(251, 191, 36, 0.15);
  color: var(--accent-warm);
}

.panel-pending {
  border-color: rgba(251, 191, 36, 0.35);
  background: linear-gradient(160deg, rgba(251, 191, 36, 0.08), var(--bg-card));
}

.pending-date {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.pending-body {
  margin-bottom: 14px;
  font-size: 0.92rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.pending-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.insight-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.btn-secondary {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-secondary:hover {
  border-color: rgba(94, 234, 212, 0.35);
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: wait;
}

.insight-out {
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.92rem;
  line-height: 1.55;
  min-height: 3rem;
  max-height: min(70vh, 640px);
  overflow-y: auto;
}

.insight-out:not(.hidden):empty::before {
  content: "Загрузка…";
  color: var(--text-muted);
  font-style: italic;
}

.insight-out.loading {
  color: var(--text-muted);
  font-style: italic;
}

.insight-alert {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--accent-warm);
  font-size: 0.88rem;
  line-height: 1.5;
}

.insight-hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.insight-stat {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.insight-stat-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.insight-stat-value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
}

.insight-stat-value small {
  font-family: var(--font-ui);
  font-size: 0.55em;
  font-weight: 400;
  color: var(--text-muted);
}

.insight-card {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.insight-card h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.insight-card ul {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text-muted);
}

.insight-card li + li {
  margin-top: 4px;
}

.insight-muted {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.insight-prose {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.insight-line {
  margin: 0;
}

.insight-line :is(b, strong) {
  color: var(--accent);
  font-weight: 600;
}

.insight-line i {
  color: var(--text-muted);
  font-style: normal;
}

.entry-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.entry-list li {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.entry-list li:last-child {
  border-bottom: none;
}

.entry-kind {
  flex-shrink: 0;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-elevated);
  font-size: 0.72rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.entry-summary {
  flex: 1;
  color: var(--text);
}

.empty {
  margin: 0;
  color: var(--text-muted);
  font-style: italic;
}

/* Charts */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-controls select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
}

.chart-hint {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(251, 191, 36, 0.1);
  color: var(--accent-warm);
  font-size: 0.88rem;
}

.charts {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chart-block {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0a0e16;
}

.chart-block img {
  display: block;
  width: 100%;
  height: auto;
}

.chart-caption {
  margin: 0;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
}

/* Log weight */
.log-card {
  margin-bottom: 24px;
  padding: 20px;
  background: linear-gradient(160deg, var(--bg-card), rgba(99, 102, 241, 0.06));
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.log-card h2 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.weight-form {
  display: flex;
  gap: 10px;
}

.weight-form input {
  flex: 1;
  max-width: 120px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1.1rem;
}

.weight-msg {
  margin: 12px 0 0;
  font-size: 0.88rem;
  color: var(--accent);
}

.weight-msg.err {
  color: var(--danger);
}

/* Buttons */
.btn,
.btn-ghost {
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:active,
.btn-ghost:active {
  transform: scale(0.98);
}

.btn-primary {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #2dd4bf, #14b8a6);
  color: #042f2e;
  font-size: 0.95rem;
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-ghost {
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border);
}

input[type="password"],
.gate-form input[type="password"] {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding-top: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.meta-goal {
  color: var(--accent);
}

@media (min-width: 600px) {
  .stat-card.featured {
    grid-column: span 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
