/* ---------- theme ---------- */
:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1c2333;
  --text-muted: #67718a;
  --border: #dfe4ee;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0fe;
  --error: #d33c50;
  --success: #1d9d74;
  --shadow: 0 1px 3px rgb(20 30 60 / 0.08), 0 8px 24px rgb(20 30 60 / 0.06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d;
    --card: #1b2030;
    --text: #e6e9f2;
    --text-muted: #9aa3ba;
    --border: #2c3348;
    --accent: #7a73f0;
    --accent-hover: #928cf5;
    --accent-soft: #262b45;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

/* ---------- header ---------- */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 1.7rem; }
.brand h1 { font-size: 1.1rem; margin: 0; letter-spacing: 0.2px; }
.brand-sub { margin: 0; font-size: 0.78rem; color: var(--text-muted); }

.conn-status { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--text-muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #a9b1c6; }
.dot.connected { background: var(--success); }
.dot.searching { background: var(--accent); animation: pulse 1.2s infinite; }
.dot.error { background: var(--error); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin: 20px 0;
}
.card-title { margin: 0 0 16px; font-size: 1rem; font-weight: 650; }

/* ---------- form ---------- */
.form-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 16px;
}
.field { flex: 1 1 190px; min-width: 0; }
/* Numeric fields size to their content instead of stretching to a full column */
.field.narrow { flex: 0 0 auto; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 6px; }
.hint { font-weight: 400; color: var(--text-muted); font-size: 0.75rem; }

input[type="number"], select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
}
input:focus, select:focus, .ms-control:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Narrow numeric inputs: enough room for the expected digit count + spinner */
#epochInput { width: 100px; }
#datasetSizeInput { width: 150px; }

.optimizer-note { margin: 12px 0 0; font-size: 0.75rem; color: var(--text-muted); }

.field-error { min-height: 1em; margin: 4px 0 0; font-size: 0.75rem; color: var(--error); }
.invalid { border-color: var(--error) !important; }

.form-actions { display: flex; justify-content: center; margin-top: 14px; }
.btn-primary {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--accent); color: #fff; border: none;
  padding: 11px 48px; font-size: 0.95rem; font-weight: 600;
  border-radius: 10px; cursor: pointer;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.65; cursor: default; }
.btn-spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.4); border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- multiselect ---------- */
.multiselect { position: relative; }
.ms-control {
  display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
  min-height: 40px; padding: 5px 30px 5px 8px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); cursor: pointer;
}
.ms-control::after {
  content: "▾"; position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%); color: var(--text-muted); font-size: 1.15rem; line-height: 1;
}
.ms-placeholder { color: var(--text-muted); font-size: 0.88rem; padding-left: 3px; }
.ms-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.78rem; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
}
.ms-chip button {
  border: none; background: none; color: inherit; cursor: pointer;
  font-size: 0.85rem; padding: 0; line-height: 1;
}
.ms-panel {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
  max-height: 280px; display: flex; flex-direction: column;
}
.ms-panel[hidden] { display: none; }
.ms-search { padding: 8px; border-bottom: 1px solid var(--border); }
.ms-search input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border);
  border-radius: 7px; background: var(--card); color: var(--text); font-size: 0.85rem;
}
.ms-list { overflow-y: auto; padding: 4px; margin: 0; list-style: none; }
.ms-option {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 0.88rem;
}
.ms-option:hover { background: var(--accent-soft); }
.ms-option input { accent-color: var(--accent); }
.ms-option.disabled { opacity: 0.45; cursor: default; }
.ms-limit-note { padding: 6px 10px; font-size: 0.74rem; color: var(--text-muted); border-top: 1px solid var(--border); }

/* ---------- messages ---------- */
.messages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.msg-card {
  border: 1px solid var(--border); border-left: 5px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  min-height: 60px;
}
.msg-card h4 { margin: 0 0 6px; font-size: 0.85rem; }
.msg-lines { max-height: 180px; overflow-y: auto; font-size: 0.72rem; }
.msg-line { display: flex; gap: 8px; padding: 1px 0; }
.msg-line .t {
  flex: none;
  color: var(--text-muted); white-space: nowrap;
  font-family: "Roboto Condensed", "Arial Narrow", sans-serif;
  font-size: 0.68rem; letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}
.msg-line.error .m { color: var(--error); font-weight: 600; }

/* ---------- charts ---------- */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.chart-box h3 { margin: 0 0 8px; font-size: 0.88rem; font-weight: 600; }
.chart-wrap { position: relative; height: 360px; }
.chart-wrap > div { width: 100%; height: 100%; }

/* Shared legend under both charts (replaces Plotly's per-chart legends) */
.chart-legend {
  display: flex; flex-wrap: wrap; justify-content: left;
  gap: 6px 14px; margin-top: 18px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.chart-legend:empty { display: none; }
.legend-item {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-size: 0.82rem; color: var(--text);
  background: none; border: 0; padding: 4px 7px; border-radius: 7px;
  cursor: pointer;
}
.legend-item:hover { background: var(--accent-soft); }
.legend-swatch {
  width: 13px; height: 13px; border-radius: 4px; flex: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.legend-item.hidden { color: var(--text-muted); }
.legend-item.hidden .legend-swatch { opacity: 0.28; }
.legend-item.hidden .legend-label { text-decoration: line-through; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
.specs-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.specs-table th, .specs-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.specs-table th { cursor: pointer; user-select: none; white-space: nowrap; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.specs-table th .arrow { font-size: 0.7rem; }
.specs-table tbody tr:hover { background: var(--accent-soft); }
.specs-table tbody tr.highlight { background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 14px; min-width: 240px; max-width: 340px; font-size: 0.83rem;
  animation: slidein 0.25s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.warn { border-left-color: #e5a50a; }
.toast.error { border-left-color: var(--error); }
.toast b { display: block; font-size: 0.85rem; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }

/* ---------- footer ---------- */
.site-footer { padding: 18px 0 28px; color: var(--text-muted); font-size: 0.78rem; text-align: center; }
