:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --surface: #171a21;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --pos: #35c281;
  --neg: #ff5c5c;
  --warn: #e0b400;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* дефолтний колір посилань (синій/фіолетовий visited) не узгоджений з темною темою --
   фіксуємо під --text/--accent скрізь, окрім .topnav, у якого свій стиль нижче */
a { color: var(--text); text-decoration: none; }
a:visited { color: var(--text); }
a:hover { color: var(--accent); text-decoration: underline; }

.topnav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topnav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.topnav a.brand { color: var(--text); font-weight: 700; margin-right: 1rem; }
.topnav a:hover { color: var(--accent); }

main { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

h1, h2, h3 { font-weight: 600; }
h2 { margin-top: 2.5rem; }

.hint { color: var(--muted); font-size: 0.9rem; }

.stat-row { display: flex; gap: 1rem; flex-wrap: wrap; margin: 1rem 0; }
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  min-width: 150px;
}
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }

.table-wrap { overflow-x: auto; margin-top: 0.75rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.45rem 0.55rem; border-bottom: 1px solid var(--border); font-size: 0.85rem; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
.nowrap { white-space: nowrap; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }

.price-safe { color: var(--pos); }
.price-warn { color: var(--warn); }
.price-danger { color: var(--neg); font-weight: 700; }

.dir { padding: 0.1rem 0.5rem; border-radius: 6px; font-size: 0.8rem; text-transform: uppercase; }
.dir.long { background: rgba(53, 194, 129, 0.15); color: var(--pos); }
.dir.short { background: rgba(255, 92, 92, 0.15); color: var(--neg); }

.badge { padding: 0.1rem 0.5rem; border-radius: 6px; font-size: 0.75rem; }
.badge.active { background: rgba(53, 194, 129, 0.15); color: var(--pos); }
.badge.retired { background: rgba(154, 163, 178, 0.2); color: var(--muted); }
.badge.testing { background: rgba(79, 140, 255, 0.15); color: var(--accent); }
.badge.inverted { background: rgba(240, 160, 60, 0.18); color: #e0a040; }

.rule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.rule-card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.rule-card-head h3 { margin: 0; display: flex; gap: 0.5rem; align-items: center; }
.rule-stats { display: flex; gap: 1.25rem; color: var(--muted); font-size: 0.9rem; flex-wrap: wrap; }

.rule-chart { margin-top: 0.75rem; }
.equity-chart { width: 100%; height: auto; display: block; }
.equity-grid { stroke: var(--border); stroke-width: 1; }
.equity-axis-label { font-size: 10px; fill: var(--muted); }
.equity-seg { stroke-width: 2; stroke-linecap: round; }
.equity-seg.pos { stroke: var(--pos); }
.equity-seg.neg { stroke: var(--neg); }
.equity-dot.pos { fill: var(--pos); }
.equity-dot.neg { fill: var(--neg); }
.equity-label { font-size: 11px; }
.equity-label.pos { fill: var(--pos); }
.equity-label.neg { fill: var(--neg); }

.chart-legend { display: flex; gap: 1.25rem; align-items: center; color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0 1rem; }
.chart-legend .swatch { display: inline-flex; align-items: center; gap: 0.4rem; }
.chart-legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chart-legend .dot.pos { background: var(--pos); }
.chart-legend .dot.neg { background: var(--neg); }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
}
button:hover { opacity: 0.9; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-head h1 { margin: 0; }

.btn-danger { background: var(--neg); }
.btn-muted { background: var(--border); color: var(--muted); }

.rule-card-actions { display: flex; gap: 0.5rem; }

.coin-add-form { display: flex; gap: 0.5rem; margin: 0.75rem 0; }
.coin-add-form input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  color: var(--text);
  font-size: 0.85rem;
}

.stars { color: var(--warn); letter-spacing: 1px; white-space: nowrap; }

/* --- auth: користувач у навігації --- */
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }
.nav-user form { margin: 0; }
.nav-email { color: var(--muted); font-size: 0.85rem; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: block; }
.nav-count {
  display: inline-block; min-width: 1.2rem; padding: 0 0.35rem; margin-left: 0.2rem;
  border-radius: 999px; background: var(--neg); color: #fff; font-size: 0.72rem;
  font-weight: 700; text-align: center; line-height: 1.2rem;
}
.btn-ok { background: var(--pos); color: #0b1a12; }
.row-actions { display: flex; gap: 0.4rem; }
.row-actions form { margin: 0; }

/* --- auth: сторінки входу / очікування --- */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 2.25rem 1.75rem 1.75rem;
}
.auth-brand { font-size: 1.5rem; font-weight: 700; }
.auth-title { font-size: 1.2rem; margin: 0.5rem 0 0.25rem; }
.auth-sub { color: var(--muted); font-size: 0.92rem; margin: 0.5rem 0 1.5rem; line-height: 1.45; }
.auth-icon { font-size: 2.2rem; margin-top: 1.25rem; }
.auth-foot { color: var(--muted); font-size: 0.8rem; margin: 1.25rem 0 0; }
.auth-alert {
  background: rgba(255, 92, 92, 0.12); border: 1px solid rgba(255, 92, 92, 0.35); color: #ffb3b3;
  border-radius: 8px; padding: 0.6rem 0.75rem; font-size: 0.85rem; margin-bottom: 1rem;
}
.auth-actions { display: flex; gap: 0.75rem; justify-content: center; align-items: center; }
.auth-actions form { margin: 0; }
.auth-link { color: var(--accent); font-size: 0.9rem; }
.auth-link:visited { color: var(--accent); }

/* Кнопка Google у темному варіанті (за гайдлайнами Google Sign-In) */
.gsi-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; height: 44px; padding: 0 16px;
  background: #131314; color: #e3e3e3; border: 1px solid #8e918f; border-radius: 22px;
  font-family: Roboto, -apple-system, "Segoe UI", sans-serif; font-size: 15px; font-weight: 500;
  text-decoration: none; transition: background 0.15s, border-color 0.15s;
}
.gsi-button:visited { color: #e3e3e3; }
.gsi-button:hover { background: #1f2023; border-color: #c4c7c5; color: #fff; text-decoration: none; }
.gsi-logo { width: 20px; height: 20px; flex: none; }
