:root {
  --bg: #fafafa;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --card: #ffffff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #16a34a;
  --error: #dc2626;
  --info: #0891b2;
  --warn: #ea580c;
  --own: #2563eb;
  --comp: #64748b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 80px; }

h1 { font-size: 28px; margin: 12px 0 20px; }
h2 { font-size: 18px; margin: 28px 0 12px; }

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

code { background: #eef2ff; padding: 1px 5px; border-radius: 3px; font-size: 12px; }

/* topbar */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-right: 24px;
  font-size: 16px;
}
.topbar nav a {
  margin-right: 18px;
  color: var(--fg);
  font-weight: 500;
}
.topbar nav a:hover { color: var(--accent); text-decoration: none; }

/* flashes */
.flashes { list-style: none; padding: 0; margin: 12px auto; max-width: 1100px; padding: 0 20px; }
.flash {
  padding: 8px 12px;
  margin: 6px 0;
  border-radius: 4px;
  border-left: 3px solid var(--muted);
  background: #fff;
}
.flash-success { border-left-color: var(--success); }
.flash-error   { border-left-color: var(--error); }
.flash-info    { border-left-color: var(--info); }

/* cards & forms */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  margin: 14px 0;
}
.cards-row { display: flex; gap: 12px; margin: 14px 0; }
.cards-row .card { flex: 1; text-align: center; }
.stat-num { font-size: 28px; font-weight: 700; }
.stat-lbl { color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 8px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.checkbox { flex-direction: row; align-items: center; gap: 6px; }
input[type=text], select, textarea {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--fg);
  min-width: 160px;
}
textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, monospace; font-size: 13px; }
button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}
button:hover { background: var(--accent-hover); }
button:disabled { background: #cbd5e1; cursor: not-allowed; }
button.link {
  background: none;
  color: var(--error);
  padding: 0;
  font-weight: normal;
  text-decoration: underline;
}
button.link:hover { background: none; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* tables */
table.data, table.matrix {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
table.data th, table.data td,
table.matrix th, table.matrix td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 13px;
}
table.data thead, table.matrix thead { background: #f1f5f9; }
table.data tbody tr:hover { background: #f8fafc; }
table.data tr.tracked { background: #eff6ff; }

.country-head { margin-top: 24px; }
.muted { color: var(--muted); }

/* badges */
.badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 3px;
  text-transform: uppercase;
  color: white;
}
.badge.own { background: var(--own); }
.badge.comp { background: var(--comp); }

/* matrix */
.matrix-wrap { overflow-x: auto; }
.matrix .pos { font-weight: 600; }
.matrix .diff { font-size: 11px; margin-left: 4px; font-weight: 600; }
.matrix .diff.up   { color: var(--success); }
.matrix .diff.down { color: var(--error); }
.matrix .diff.flat { color: var(--muted); }

/* progress */
.progress {
  width: 100%;
  height: 12px;
  background: #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
  margin: 8px 0;
}
.progress .bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s ease;
}

/* run statuses */
.status-running { color: var(--accent); font-weight: 600; }
.status-done    { color: var(--success); font-weight: 600; }
.status-failed  { color: var(--error); font-weight: 600; }

/* group switcher */
.group-switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: auto;
}
.group-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}
.group-dot.lg { width: 14px; height: 14px; }
.group-menu summary {
  cursor: pointer;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-weight: 500;
  list-style: none;
}
.group-menu summary::-webkit-details-marker { display: none; }
.group-menu summary::after { content: " ▾"; color: var(--muted); }
.group-menu[open] summary { border-color: var(--accent); }
.group-menu ul {
  position: absolute;
  top: 100%;
  left: 0;
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  min-width: 200px;
  z-index: 20;
}
.group-menu li a {
  display: block;
  padding: 6px 12px;
  color: var(--fg);
}
.group-menu li a:hover { background: #f1f5f9; text-decoration: none; }
.group-menu li.sep { border-top: 1px solid var(--border); margin: 4px 0; }

/* secondary button */
button.secondary {
  background: #fff;
  color: var(--fg);
  border: 1px solid var(--border);
}
button.secondary:hover { background: #f1f5f9; }

/* card titles & active-run pulse */
.card-title {
  margin: 0 0 8px;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot-pulse {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.5);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(37, 99, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}
