:root {
  --bg: #17171c;
  --glow: rgba(94, 72, 170, 0.22);
  --surface: #26262d;
  --surface-border: #33333b;
  --surface-active: #1b1b21;
  --text: #f4f4f6;
  --text-muted: #a3a3ad;
  --accent: #7b6cf6;
  --danger: #ef5b6e;
  --good: #5bd6a0;
  --radius: 999px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  background-image: radial-gradient(120% 70% at 100% 100%, var(--glow), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Переключатель-пилюля как на макете */
.segmented {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
}

.segmented::-webkit-scrollbar { display: none; }

.segmented button {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 10px 8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #cfcfd6;
  font: 500 14px/1 var(--font);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.segmented button.active {
  background: var(--surface-active);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.segmented svg {
  width: 15px;
  height: 15px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 12px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
}

.title {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
}

.panel { min-height: 320px; }

.chart-box {
  position: relative;
  height: 340px;
}

.table-box { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 10px 8px;
  text-align: right;
  border-bottom: 1px solid var(--surface-border);
  white-space: nowrap;
}

th:first-child, td:first-child { text-align: left; }

th {
  color: var(--text-muted);
  font-weight: 500;
}

td.break { color: var(--danger); font-weight: 700; }

tfoot td { font-weight: 700; border-bottom: 0; }

/* Вкладка «Статистика» */
.stats-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.habit-card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
}

.habit-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.habit-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.habit-name {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-rule {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 8px;
}

.metric-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.metric-value.bad { color: var(--danger); }

.metric-label {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.habit-foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--surface-border);
  font-size: 13px;
  color: var(--text-muted);
}

.wb-empty {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.wb-links {
  margin: 0;
  padding-left: 18px;
  line-height: 1.5;
}

.wb-links li + li { margin-top: 4px; }

.delta { font-weight: 700; }
.delta.down { color: var(--good); }
.delta.up { color: var(--danger); }


.empty, .error {
  margin: 48px 0;
  text-align: center;
  color: var(--text-muted);
}

.error { color: var(--danger); }

@media (max-width: 480px) {
  #views svg { display: none; }
}

@media (max-width: 380px) {
  .segmented button { font-size: 13px; padding: 9px 4px; gap: 4px; }
  .segmented svg { display: none; }
  .kpi-value { font-size: 20px; }
}

/* Навигация между статистикой и отчётами */
.top-nav {
  display: flex;
  gap: 16px;
  font-size: 15px;
}

.top-nav a {
  color: var(--text-muted);
  text-decoration: none;
}

.top-nav-current {
  color: var(--text);
  font-weight: 700;
}

/* Страница отчёта */
.report-list button { flex: 0 0 auto; padding: 10px 14px; }

#report {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.verdict-card {
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
}

.verdict-card.praise {
  border-color: rgba(91, 214, 160, 0.45);
  background: linear-gradient(160deg, rgba(91, 214, 160, 0.16), var(--surface) 60%);
}

.verdict-card.scold {
  border-color: rgba(239, 91, 110, 0.45);
  background: linear-gradient(160deg, rgba(239, 91, 110, 0.16), var(--surface) 60%);
}

.verdict-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.verdict-badge {
  padding: 4px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.praise .verdict-badge { background: rgba(91, 214, 160, 0.18); color: var(--good); }
.scold .verdict-badge { background: rgba(239, 91, 110, 0.18); color: var(--danger); }

.verdict-period {
  font-size: 13px;
  color: var(--text-muted);
}

.verdict-headline {
  margin: 14px 0 8px;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.3;
}

.verdict-summary {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  color: #d6d6dd;
}

.section-title {
  margin: 8px 0 0;
  font-size: 17px;
  font-weight: 700;
}

.report-comment {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
}

.report-facts {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.advice {
  margin: 0;
  padding: 16px 16px 16px 36px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
}

.advice li + li { margin-top: 8px; }

.report-foot {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
