/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f1a;
  --bg-card:   #16213e;
  --bg-input:  #1a1a2e;
  --bg-hover:  #1e2a4a;
  --border:    #2a2a4a;
  --text:      #e0e0e0;
  --text-muted:#8888aa;
  --accent:    #39ff14;
  --accent-dim:#1a7a0a;
  --yellow:    #ffd60a;
  --red:       #ff4d6d;
  --radius:    8px;
  --transition: 0.2s ease;
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===== Utility ===== */
.hidden    { display: none !important; }
.accent    { color: var(--accent); }
.muted     { color: var(--text-muted); font-size: 0.9rem; }

/* ===== Spinner ===== */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #0a0a0a;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: #2de010; border-color: #2de010; }

.btn-danger {
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover { background: rgba(255,77,109,0.15); }

.btn-ghost  { border-color: transparent; }
.btn-full   { width: 100%; justify-content: center; }
.btn-sm     { padding: 4px 10px; font-size: 0.8rem; }

/* ===== Error ===== */
.error-msg {
  background: rgba(255,77,109,0.12);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  padding: 8px 12px;
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ===== Forms ===== */
label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
input[type="text"],
input[type="url"],
input[type="password"],
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color var(--transition);
}
input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ===== Login ===== */
.screen {
  min-height: 100vh;
}

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.login-logo h1 { font-size: 1.4rem; font-weight: 700; }
.logo-icon {
  color: var(--accent);
  font-size: 1.6rem;
}
.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
}
.topbar-left {
  display: flex; align-items: center; gap: 8px;
}
.logo-icon-sm { color: var(--accent); font-size: 1.1rem; }
.topbar-title { font-size: 1.1rem; font-weight: 700; }
.topbar-right { display: flex; gap: 4px; }

/* ===== Views ===== */
.view { padding: 24px; max-width: 1100px; margin: 0 auto; }
.view-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.view-header h2 { font-size: 1.3rem; font-weight: 600; }

/* ===== Loading / Empty ===== */
.loading-state, .empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* ===== Experiment Cards ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.exp-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
}
.exp-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.exp-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.exp-card-header h3 {
  font-size: 1rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 70%;
}
.exp-card-meta {
  display: flex; gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-active    { background: rgba(57,255,20,0.15); color: var(--accent); }
.badge-paused    { background: rgba(255,214,10,0.15); color: var(--yellow); }
.badge-completed { background: rgba(136,136,170,0.15); color: var(--text-muted); }

/* ===== Detail ===== */
.detail-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin: 16px 0 20px;
}
.detail-title-row {
  display: flex; align-items: center; gap: 12px;
}
.detail-title-row h2 { font-size: 1.3rem; font-weight: 600; }
.detail-actions { display: flex; gap: 8px; }

/* ===== Confidence Box ===== */
.confidence-box {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.confidence-box.winner  { background: rgba(57,255,20,0.08);  border-color: var(--accent); color: var(--accent); }
.confidence-box.warning { background: rgba(255,214,10,0.08); border-color: var(--yellow); color: var(--yellow); }
.confidence-box.neutral { background: rgba(136,136,170,0.08); }

/* ===== Sample info ===== */
.sample-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ===== Results Table ===== */
.table-wrap { overflow-x: auto; margin-bottom: 28px; }
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.results-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.results-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.results-table tr:last-child td { border-bottom: none; }

.prob-best-winner {
  color: var(--accent);
  font-weight: 700;
}

/* ===== Bar Chart ===== */
.section-title {
  font-size: 0.95rem; font-weight: 600;
  margin-bottom: 12px;
}
.bar-chart {
  display: flex; flex-direction: column; gap: 10px;
}
.bar-row {
  display: flex; align-items: center; gap: 12px;
}
.bar-label {
  width: 120px;
  font-size: 0.85rem;
  text-align: right;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  flex: 1;
  height: 28px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  min-width: 2px;
}
.bar-fill.leader { background: var(--accent); }
.bar-fill.other  { background: #555577; }
.bar-value {
  font-size: 0.8rem;
  width: 60px;
  text-align: left;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ===== Modals ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%; max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: fadeUp 0.2s ease;
}
.modal-sm { max-width: 400px; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.modal-header h2 { font-size: 1.15rem; font-weight: 600; }
.modal-close-btn { font-size: 1.1rem; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 20px;
}

/* ===== Variant Rows ===== */
.variant-rows {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 4px;
}
.variant-row {
  display: flex; gap: 8px; align-items: center;
}
.variant-row input[type="text"]   { flex: 2; }
.variant-row input[type="number"] { flex: 1; }
.variant-row .btn { flex-shrink: 0; }

/* ===== Transitions ===== */
.view { animation: fadeIn 0.25s ease; }
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .view { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .view-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .card-grid { grid-template-columns: 1fr; }
  .detail-header { flex-direction: column; align-items: flex-start; }
  .bar-label { width: 80px; font-size: 0.75rem; }
  .results-table { font-size: 0.8rem; }
  .results-table th, .results-table td { padding: 8px 8px; }
}

/* ===== Tab Navigation ===== */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  background: var(--bg-card);
}

.tab {
  padding: 0.75rem 1.5rem;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}

.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===== Config Table ===== */
.config-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

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

.config-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.config-table td { font-size: 0.9rem; }

.config-table tr:hover { background: var(--bg-hover); }

.config-value {
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--accent);
}

.config-type-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  background: var(--bg-input);
  color: var(--text-muted);
}

.config-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.select-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.85rem;
}

.config-actions { display: flex; gap: 0.5rem; }
.config-actions .btn { font-size: 0.8rem; padding: 0.3rem 0.6rem; }

/* ===== History Modal ===== */
.modal-wide { max-width: 700px; }
/* ===== Auth Tabs ===== */
.auth-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.auth-tab {
  flex: 1;
  padding: 0.55rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s ease;
}
.auth-tab.active {
  background: var(--accent);
  color: #000;
  font-weight: 600;
}
.auth-tab:not(.active):hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
}

/* ===== Key Display ===== */
.key-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
}
.key-display code {
  flex: 1;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 0.8rem;
  color: var(--accent);
  word-break: break-all;
}
.copy-confirm {
  color: var(--accent);
  font-size: 0.82rem;
  margin-top: 0.4rem;
  font-weight: 500;
}

/* ===== Onboarding Code ===== */
.onboarding-code {
  background: #1e1e30;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 0.75rem;
}
.onboarding-code pre {
  padding: 1rem;
  overflow-x: auto;
  margin: 0;
}
.onboarding-code code {
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  color: #e8e8e8;
}
/* ===== Admin Panel ===== */
.admin-only { }
.config-table select.select-input {
  min-width: 80px;
}
/* ===== Stat Cards (Economy) ===== */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
}
.stat-label { color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; margin-bottom: .4rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-sub { color: var(--text-muted); font-size: .78rem; margin-top: .2rem; }
.stat-healthy { color: var(--accent); }
.stat-warning { color: var(--yellow); }
.stat-danger { color: var(--red); }

/* ===== Funnel Chart ===== */
.funnel-chart { display: flex; flex-direction: column; gap: .5rem; }
.funnel-bar-row { display: flex; align-items: center; gap: .75rem; }
.funnel-bar-label { min-width: 120px; font-size: .82rem; color: var(--text-muted); text-align: right; }
.funnel-bar-track { flex: 1; height: 28px; background: var(--bg-input); border-radius: 4px; overflow: hidden; position: relative; }
.funnel-bar-fill { height: 100%; border-radius: 4px; transition: width .5s ease; display: flex; align-items: center; padding-left: .6rem; font-size: .75rem; font-weight: 600; }
.funnel-bar-fill.green { background: var(--accent); color: #000; }
.funnel-bar-fill.yellow { background: var(--yellow); color: #000; }
.funnel-bar-fill.red { background: var(--red); color: #fff; }
.funnel-bar-value { min-width: 80px; font-size: .8rem; color: var(--text-muted); }

@media(max-width:860px) {
  .econ-summary { grid-template-columns: repeat(2,1fr) !important; }
}