/* ==========================================================================
   Simpy Tools design system - tokens + base components
   Source of truth: Simpy-Station-Simulation (sim_tool/web/index.html,
   sim_tool/reporting/html_report.py). See DESIGN.md.
   Theme is selected with <html data-theme="light|dark">.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg: #e2e8f0;            /* page background */
  --card: #ffffff;          /* panels, cards, inputs */
  --card-alt: #f8fafc;      /* nested cards, zebra rows, chart stripes */
  --surface: #e2e8f0;       /* table headers, tab tracks, tags, hover */
  /* Lines */
  --border: #94a3b8;        /* default border - deliberately strong */
  --border-soft: #cbd5e1;   /* row dividers, meter tracks */
  /* Text */
  --text: #020617;
  --muted: #334155;
  /* Accents */
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --warn: #d97706;          /* bottleneck / attention */
  --danger: #b91c1c;
  --cycle: #dc2626;         /* cycle boundary lines */
  --pill-bg: #dbeafe;
  --pill-text: #1e3a8a;
  --pill-border: #3b82f6;
  /* Shape */
  --radius: 4px;            /* cards, panels, inputs, modals */
  --radius-sm: 3px;         /* buttons, tags, tab buttons */
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-kpi: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-float: 0 4px 12px rgba(0, 0, 0, 0.16);
  /* Type */
  --font: Inter, "Segoe UI", "Helvetica Neue", Arial, "DejaVu Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --card: #111827;
  --card-alt: #161f33;
  --surface: #1e293b;
  --border: #293548;
  --border-soft: #1f2a3d;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --warn: #f59e0b;
  --danger: #f87171;
  --pill-bg: #1e3a8a;
  --pill-text: #bfdbfe;
  --pill-border: #3b82f6;
}

/* ---- Base -------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---- App header (sticky) ------------------------------------------------ */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-logo { height: 28px; width: auto; object-fit: contain; display: block; }
.brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: -0.01em; }
.brand span { font-size: 0.78rem; color: var(--muted); }

/* ---- Tabs (segmented) --------------------------------------------------- */
.tabs {
  display: inline-flex; gap: 4px; padding: 3px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.tab-btn {
  border: none; background: transparent; padding: 6px 14px; border-radius: var(--radius-sm);
  font: 600 0.84rem var(--font); color: var(--muted); cursor: pointer;
}
.tab-btn.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.tab-view { display: none; }
.tab-view.active { display: block; }

/* ---- Buttons ------------------------------------------------------------ */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
button, .btn {
  font: 500 0.83rem var(--font);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover, .btn:hover { background: var(--surface); }
button.primary, .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); }
button.sm, .btn.sm { padding: 4px 8px; font-size: 0.76rem; }
button.danger, .btn.danger { color: var(--danger); border-color: #fecaca; }
button.danger:hover { background: rgba(220, 38, 38, 0.12); }
button:disabled { opacity: 0.45; cursor: default; }

/* ---- Layout ------------------------------------------------------------- */
.container { max-width: 1440px; margin: 0 auto; padding: 20px 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 12px; font-size: 1rem; display: flex; align-items: center; justify-content: space-between; }
.panel h3 { margin: 0 0 10px; font-size: 0.95rem; }
.panel-alt { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--card-alt); }
.subtitle, .lead { color: var(--muted); font-size: 0.88rem; margin: 0 0 12px; }
.section-num { color: var(--accent); font-weight: 700; margin-right: 8px; }

/* ---- Forms -------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label, .label {
  font-size: 0.72rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.03em;
}
input, select, textarea {
  font: 0.83rem var(--font);
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); border: none; padding: 0; background: none; }

/* ---- KPI cards ---------------------------------------------------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-kpi);
}
.kpi-card.warn { border-top-color: var(--warn); }
.kpi-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.kpi-value { font-size: 1.55rem; font-weight: 700; margin: 4px 0; color: var(--accent); line-height: 1.2; overflow-wrap: anywhere; }
.kpi-card.warn .kpi-value { color: var(--warn); }
.kpi-sub { font-size: 0.78rem; color: var(--muted); }

/* ---- Tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th, .data-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.data-table thead th {
  background: var(--surface); color: var(--muted); font-size: 0.73rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table tbody tr:hover td { background: var(--surface); }
.data-table tr.selected td { background: var(--pill-bg); }
.num, .r { text-align: right !important; font-variant-numeric: tabular-nums; }

/* ---- Tags, pills, chips, meters ----------------------------------------- */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 2px 9px; font-size: 0.78rem;
}
.pill {
  display: inline-block; white-space: nowrap;
  background: var(--pill-bg); color: var(--pill-text); border: 1px solid var(--pill-border);
  border-radius: 999px; padding: 2px 8px; font-size: 0.75rem; font-weight: 600;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: -1px; }
.meter { display: inline-block; width: 64px; height: 6px; border-radius: 1px; background: var(--border-soft); overflow: hidden; vertical-align: middle; margin-right: 8px; }
.meter > span { display: block; height: 100%; }

/* ---- Banners & toasts --------------------------------------------------- */
.error-banner {
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 0.86rem;
}
.toast {
  position: fixed; right: 80px; bottom: 22px; max-width: 380px; z-index: 60;
  padding: 10px 14px; font-size: 13px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--warn); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}

/* ---- Floating action buttons (bottom-right stack) ------------------------ */
/* Order bottom->top: help (accent), AI / app action, theme. 52px pitch. */
.fab {
  position: fixed; right: 22px; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; padding: 0; z-index: 50;
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow-float);
}
.fab:hover { background: var(--surface); transform: translateY(-1px); }
.fab.primary { background: var(--accent); color: #fff; border: none; font-size: 1.15rem; font-weight: 700; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.fab.primary:hover { background: var(--accent-hover); }
.fab-1 { bottom: 22px; }
.fab-2 { bottom: 74px; }
.fab-3 { bottom: 126px; }
.fab svg { width: 19px; height: 19px; }
.theme-fab .icon-sun { display: none; }
[data-theme="dark"] .theme-fab .icon-sun { display: block; color: #fbbf24; }
[data-theme="dark"] .theme-fab .icon-moon { display: none; }

/* ---- Modal -------------------------------------------------------------- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 100; padding: 24px;
  background: rgba(15, 23, 42, 0.55); align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  width: 100%; max-width: 820px; max-height: 84vh; display: flex; flex-direction: column;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.28);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 18px 24px; overflow-y: auto; line-height: 1.55; font-size: 0.9rem; }
code, kbd {
  font-family: var(--mono); font-size: 0.84em;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1px 5px;
}

/* ---- Cycle stepper (above any time-sliced chart) ------------------------- */
.stepper-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.cycle-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cycle-nav select { width: auto; padding: 4px 6px; font-size: 0.8rem; }
.cycle-label { min-width: 150px; text-align: center; font-size: 0.82rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.cycle-slider { width: 100%; margin: 2px 0 6px; }
.hint { font-size: 0.78rem; color: var(--muted); }
