/* Минимальная стилизация — без зависимостей.
   Тёмная тема по prefers-color-scheme. */

:root {
  --bg: #ffffff;
  --bg-2: #fafafa;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e5e5e5;
  --brand: #2c5cff;
  --brand-fg: #ffffff;
  --code-bg: #f4f4f5;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --accent-bg: #eff6ff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-2: #14171d;
    --fg: #e6e8eb;
    --muted: #8a8f99;
    --border: #2a2e36;
    --brand: #4f7cff;
    --brand-fg: #ffffff;
    --code-bg: #1a1d24;
    --green: #10b981;
    --amber: #f59e0b;
    --red: #ef4444;
    --accent-bg: #1a2540;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Text",
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.1em 0.4em;
}

pre {
  padding: 0.75em 1em;
  overflow-x: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.brand {
  font-weight: 600;
  font-size: 1.05rem;
}

.nav a {
  margin-left: 1rem;
  color: var(--muted);
}

.nav a.logout {
  color: var(--muted);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

h1 { font-size: 1.4rem; margin: 0 0 1rem; }

.muted {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

.welcome,
.login {
  max-width: 640px;
}

.login pre {
  display: inline-block;
}

/* ─── KPI cards ─── */

.kpi-block {
  margin-bottom: 1.5rem;
}

.kpi-block h2 {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 0.5rem;
}

.kpi-block h2 .muted {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  font-size: 0.78rem;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.6rem;
}

.kpi {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: var(--bg);
}

.kpi label {
  font-size: 0.74rem;
  color: var(--muted);
  text-transform: none;
}

.kpi strong {
  font-size: 1.4rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.kpi.warn {
  border-color: var(--amber);
}
.kpi.warn strong {
  color: var(--amber);
}

.kpi.accent {
  background: var(--accent-bg);
  border-color: var(--brand);
}

.kpi .delta {
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 0.1rem;
}
.kpi .delta.up    { color: var(--green); }
.kpi .delta.down  { color: var(--red); }
.kpi .delta.neutral { color: var(--muted); }

/* ─── Charts grid ─── */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  background: var(--bg);
}

.chart-card h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.chart-card.chart-wide {
  grid-column: span 2;
}

.chart-wrap {
  height: 280px;
  position: relative;
}

.chart-wrap-sm {
  height: 220px;
}

@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .chart-card.chart-wide { grid-column: span 1; }
}

/* ─── Funnel ─── */

.funnel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.funnel-step {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
}

.funnel-bar {
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand) 100%);
  color: var(--brand-fg);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  min-width: 30%;
  position: relative;
  overflow: hidden;
}

.funnel-bar .funnel-label {
  font-weight: 500;
  font-size: 0.85rem;
}

.funnel-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.funnel-num strong {
  font-size: 1.1rem;
}

/* ─── Mini-table inside chart cards (for MRR breakdown) ─── */

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.mini-table th, .mini-table td {
  padding: 0.4rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.mini-table th {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mini-table tr.tfoot td {
  border-bottom: none;
  border-top: 2px solid var(--border);
  padding-top: 0.6rem;
}

.mini-table td:nth-child(2),
.mini-table td:nth-child(3),
.mini-table td:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ─── Tables ─── */

.tables-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.table-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  background: var(--bg);
}

.table-card.table-wide {
  grid-column: span 2;
}

.table-card h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg);
}

.data-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.data-table td:first-child { white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: var(--bg-2); }

@media (max-width: 900px) {
  .tables-grid { grid-template-columns: 1fr; }
  .table-card.table-wide { grid-column: span 1; }
}

/* ─── Heatmap ─── */

.heatmap {
  overflow-x: auto;
}

.hm-grid {
  display: grid;
  grid-template-columns: 32px repeat(24, 1fr);
  gap: 2px;
  min-width: 600px;
}

.hm-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: var(--muted);
  min-height: 14px;
}

.hm-cell.hm-corner { aspect-ratio: auto; }

.hm-cell.hm-hour {
  aspect-ratio: auto;
  height: 14px;
  font-size: 0.6rem;
}

.hm-cell.hm-day {
  aspect-ratio: auto;
  font-weight: 500;
  font-size: 0.7rem;
  color: var(--fg);
  justify-content: flex-end;
  padding-right: 4px;
}

.hm-cell.hm-data {
  cursor: default;
}
.hm-cell.hm-data:hover {
  outline: 1px solid var(--brand);
}

/* ─── Users page ─── */

.users-page h1 { margin-bottom: 1rem; }

.search-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.search-bar input[type="text"] {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  min-width: 280px;
}

.search-bar button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--brand);
  color: var(--brand-fg);
  font: inherit;
  cursor: pointer;
}

.sort-bar {
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.sort-link {
  color: var(--muted);
}

.sort-link.active {
  color: var(--brand);
  font-weight: 600;
}
