/* Design tokens */
:root {
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --ink:           #0f172a;
  --ink-2:         #334155;
  --muted:         #64748b;
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;
  --accent:        #2563eb;
  --accent-hover:  #1d4ed8;
  --success:       #16a34a;
  --success-bg:    #dcfce7;
  --danger:        #dc2626;
  --danger-bg:     #fee2e2;
  --warning:       #d97706;
  --warning-bg:    #fef3c7;
  --font:          "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:     "JetBrains Mono", "Fira Code", Consolas, monospace;
  --radius:        6px;
  --radius-md:     8px;
  --radius-lg:     12px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,.07);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-2);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 12px; color: var(--ink); font-weight: 600; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
p { margin: 0 0 12px; }

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 52px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.01em;
  text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--ink); }
nav { display: flex; gap: 2px; align-items: center; }
nav a {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: var(--radius);
  text-decoration: none;
  transition: color .12s, background .12s;
}
nav a:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.tabs a {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: var(--radius);
  text-decoration: none;
}
.tabs a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.tabs a.active { background: var(--accent); color: #fff; }

/* Page layout */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 24px; }

/* Hero / page-header */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin: 0 0 4px;
}
.meta { color: var(--muted); font-size: 12px; font-family: var(--font-mono); line-height: 1.9; overflow-wrap: anywhere; }

/* Status cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card.status-running { border-top: 3px solid var(--success); }
.card.status-stopped { border-top: 3px solid var(--border-strong); }
.card h2 { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0; }
.card-status-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.card pre {
  margin: 0;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 72px;
  overflow-y: auto;
}
.metric-list {
  display: grid;
  gap: 7px;
  margin-top: 2px;
}
.metric-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.metric-list div:last-child { border-bottom: none; }
.metric-list span {
  color: var(--muted);
  font-size: 12px;
}
.metric-list strong {
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
}

/* Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.panel > h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* State */
.state { font-size: 13px; font-weight: 600; }
.state.on  { color: var(--success); }
.state.off { color: var(--muted); }

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; flex-shrink: 0; }
.pill.ok    { background: var(--success-bg); color: #15803d; }
.pill.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.warn  { background: var(--warning-bg); color: var(--warning); }

/* Buttons */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: 500 13px/1 var(--font);
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}
button:hover { background: var(--accent-hover); }
button.compact { padding: 5px 11px; font-size: 12px; border-radius: var(--radius); }
button.danger  { background: var(--danger); }
button.danger:hover { background: #b91c1c; }
button.ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--border-strong);
}
button.ghost:hover { background: var(--surface-2); }
.link-button {
  background: none;
  border: none;
  color: var(--muted);
  font: 500 13px/1 var(--font);
  padding: 0;
  cursor: pointer;
}
.link-button:hover { color: var(--ink); }

/* Inputs */
input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
  width: 100%;
  font: 13px/1.5 var(--font);
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 10px;
  transition: border-color .12s, box-shadow .12s;
}
input:not([type="checkbox"]):not([type="radio"]):focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; }
label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-2);
  cursor: pointer;
}
.check input { width: auto; }
.hint { color: var(--muted); font-size: 11px; font-weight: 400; margin-top: 2px; display: block; }

/* Form layouts */
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.wide { grid-column: 1 / -1; }
.compact-footer { grid-column: 1 / -1; display: flex; justify-content: flex-end; padding-top: 4px; }
.stack { display: grid; gap: 14px; }

.checkbox-group {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

/* Form sections - visual grouping within a .grid-form or .panel */
.form-section { grid-column: 1 / -1; }
.form-section + .form-section { margin-top: 6px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-section .inner-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-section .inner-grid .wide { grid-column: 1 / -1; }

/* Filters / action bars */
.filters, .actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 10px 0;
}
.filters input  { max-width: 360px; width: auto; flex: 1 1 220px; }
.filters select { max-width: 180px; width: auto; }

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.table-scroll {
  height: min(480px, 55vh);
  min-height: 260px;
  overflow-x: auto;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.tracked-variants { background: var(--surface); }
.hv-products { background: var(--surface); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
}
th, td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--border-strong);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfc; }
td input[type="checkbox"] { width: auto; }

/* Logs panel */
.logs {
  display: grid;
  gap: 0;
  max-height: 380px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  background: #0f172a;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: #94a3b8;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}
.logs span { color: #4ade80; margin-right: 8px; }

/* Flash messages */
.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 18px;
  border-left: 3px solid;
}
.flash.success { background: var(--success-bg); color: #14532d; border-color: var(--success); }
.flash.error   { background: var(--danger-bg);  color: #7f1d1d; border-color: var(--danger); }

/* Two-col layout */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }

/* Login */
.login-wrap {
  min-height: calc(100vh - 52px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}
.login-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 40px;
  width: 100%;
  max-width: 400px;
}
.login-panel h1 { font-size: 20px; margin-bottom: 4px; }
.login-panel .login-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-panel button { width: 100%; justify-content: center; padding: 9px 14px; font-size: 13px; }

/* Misc */
pre { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font-family: var(--font-mono); font-size: 12px; }

/* Responsive */
@media (max-width: 860px) {
  .topbar  { padding: 0 16px; }
  .page    { padding: 20px 16px; }
  .cards   { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .grid-form, .form-section .inner-grid { grid-template-columns: 1fr; }
  .wide, .form-section .inner-grid .wide { grid-column: 1; }
  .hero    { flex-direction: column; align-items: flex-start; }
  .page-header { flex-direction: column; }
  .filters input, .filters select { max-width: 100%; }
}
@media (max-width: 520px) {
  nav a { padding: 5px 8px; }
  .login-panel { padding: 28px 20px; }
}
