:root {
  --color-bg: #f7f9fa;
  --color-surface: #ffffff;
  --color-border: #e3e8eb;
  --color-text: #1a2530;
  --color-text-muted: #5b6b76;
  --color-primary: #1d4ed8;
  --color-primary-dark: #1638a3;
  --color-blue: #1d4ed8;
  --color-green: #0f8a5f;
  --color-green-bg: #e7f6ef;
  --color-orange: #c2540c;
  --color-orange-bg: #fdf1e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 40, 0.06), 0 1px 1px rgba(20, 30, 40, 0.04);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
}

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

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0 0 0.5em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding-top: env(safe-area-inset-top);
}
.navbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  flex-wrap: wrap;
  row-gap: 8px;
}
.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--color-primary); }
.nav-links { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.nav-links a {
  color: var(--color-text-muted);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
}
.nav-links a:hover { background: var(--color-bg); text-decoration: none; color: var(--color-text); }
.nav-links a.active { color: var(--color-primary); background: #eef2ff; }
.nav-links form { display: inline; }

@media (max-width: 640px) {
  .navbar-inner { padding: 12px 16px; }
  .nav-links { gap: 0; width: 100%; }
  .nav-links a { padding: 6px 8px; font-size: 0.85rem; }
  .nav-links .text-muted { display: none; }
}

main.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  width: 100%;
  flex: 1;
}

.auth-container {
  max-width: 400px;
  margin: 64px auto;
  padding: 0 24px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card + .card { margin-top: 20px; }

.stack { display: flex; flex-direction: column; gap: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
/* .card + .card's margin-top (below) is for cards stacked directly in page flow; grid cards
   are spaced by the grid's own `gap` instead, and the leftover margin was eating into their
   stretched height, making the first card in each row look taller than the rest. */
.grid-2 > .card + .card, .grid-3 > .card + .card { margin-top: 0; }

@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-sub {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.delta-positive { color: var(--color-green); }
.delta-negative { color: var(--color-orange); }
.delta-neutral { color: var(--color-text-muted); }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
}
.badge-active { background: var(--color-green-bg); color: var(--color-green); }
.badge-watching { background: var(--color-orange-bg); color: var(--color-orange); }
.badge-inactive { background: var(--color-border); color: var(--color-text-muted); }

form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
form .field { margin-bottom: 16px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}
input[type=checkbox] { width: auto; margin-right: 8px; }
.checkbox-field { display: flex; align-items: flex-start; gap: 8px; }
.checkbox-field label { margin: 0; font-weight: 500; color: var(--color-text); }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: center;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-danger { background: var(--color-surface); color: var(--color-orange); border-color: var(--color-orange-bg); }
.btn-danger:hover { background: var(--color-orange-bg); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; font-weight: 500; }
.flash-error { background: var(--color-orange-bg); color: var(--color-orange); }
.flash-success { background: var(--color-green-bg); color: var(--color-green); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); vertical-align: top; white-space: nowrap; }
th { color: var(--color-text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
td { font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; }
tr:last-child td { border-bottom: none; }

@media (max-width: 640px) {
  table { font-size: 0.82rem; }
  th, td { padding: 8px 8px; }
}

.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

.river-bars { display: flex; gap: 6px; margin-top: 12px; align-items: flex-end; }
.river-bar { flex: 1; }
.river-bar-track {
  background: var(--color-bg);
  border-radius: 6px;
  height: 42px; /* reserves space for the tallest win-streak state (×7 of the 6px baseline) */
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  margin-bottom: 4px;
}
.river-bar-fill {
  width: 100%;
  height: 6px;
  background: var(--color-primary);
  border-radius: 6px;
  transition: height 0.35s ease, background-color 0.35s ease;
  animation: river-grow 0.5s ease-out;
}
.river-bar-fill-watching {
  background: #c7ccd1;
  animation: none;
}
/* Only the start state is defined — the browser fills in the end state from the
   element's actual (inline-styled) height/color, so this replays on every page
   load without needing to know each bar's target values up front. */
@keyframes river-grow {
  from {
    height: 6px;
    background-color: var(--color-primary);
  }
}
.river-bar-label { font-size: 0.72rem; color: var(--color-text-muted); text-align: center; font-variant-numeric: tabular-nums; }

.stream-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.stream-total { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.page-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header p { color: var(--color-text-muted); margin: 4px 0 0; }

.auth-card h1 { text-align: center; }
.auth-footer { text-align: center; margin-top: 16px; font-size: 0.88rem; color: var(--color-text-muted); }

.chart-controls { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.chart-controls .field { margin-bottom: 0; }
.chart-controls input { width: auto; }

.tx-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: 2px 4px;
  line-height: 1;
  display: inline-block;
  transition: transform 0.15s ease;
}
.tx-toggle:hover { color: var(--color-text); }
.tx-toggle-open { transform: rotate(90deg); }
.tx-detail-row td { padding: 0 12px 14px; }
.tx-detail-table { background: var(--color-bg); border-radius: 8px; font-size: 0.85rem; }
.tx-detail-table th, .tx-detail-table td { padding: 8px 12px; border-bottom: 1px solid var(--color-border); }
.tx-detail-table tr:last-child td { border-bottom: none; }
