/* ══════════════════════════════════════════════════════════════════════════════
   Benjamin's Online Tools — Shared Design System
   ══════════════════════════════════════════════════════════════════════════════ */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --border: #dce0e6;
  --border-focus: #3b82f6;
  --text: #1a1d23;
  --text-secondary: #5a6170;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff4ff;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --font: 'DM Sans', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --sidebar-w: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ── Page layout ────────────────────────────────────────────────────────────── */
.page-layout { display: flex; min-height: 100vh; }
.page-main   { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: #1a2236; color: #c8cdd6;
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.06);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand h2 { font-size: 0.95rem; font-weight: 700; color: #fff; line-height: 1.3; }
.sidebar-brand p  { font-size: 0.72rem; color: #8892a4; margin-top: 0.3rem; }
.sidebar-nav { padding: 0.75rem 0; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 1.25rem; font-size: 0.85rem;
  color: #9ca3b4; text-decoration: none;
  transition: all 0.15s; border-left: 3px solid transparent;
}
.sidebar-nav a:hover { color: #fff; background: rgba(255,255,255,0.05); }
.sidebar-nav a.active {
  color: #fff; background: rgba(37,99,235,0.15);
  border-left-color: var(--accent); font-weight: 600;
}
.sidebar-nav .nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.sidebar-nav a:hover .nav-icon,
.sidebar-nav a.active .nav-icon { opacity: 1; }
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.72rem; color: #5a6478;
}
.sidebar-footer a { color: #7b8baa; }
.sidebar-footer a:hover { color: #fff; text-decoration: none; }

/* Sidebar mobile toggle */
.sidebar-toggle {
  display: none; position: fixed; top: 0.75rem; left: 0.75rem; z-index: 1000;
  background: #1a2236; color: #fff; border: none; border-radius: var(--radius);
  width: 40px; height: 40px; font-size: 1.3rem; cursor: pointer;
  box-shadow: var(--shadow-lg); align-items: center; justify-content: center;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 998;
}

/* ── Page header ────────────────────────────────────────────────────────────── */
.page-header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: #fff; padding: 2.5rem 1.5rem 2rem; text-align: center;
}
.page-header h1 {
  font-size: 1.75rem; font-weight: 700;
  margin-bottom: 0.5rem; letter-spacing: -0.02em;
}
.page-header p {
  font-size: 0.95rem; opacity: 0.85;
  max-width: 620px; margin: 0 auto;
}

/* ── Container ──────────────────────────────────────────────────────────────── */
.container { max-width: 960px; margin: 0 auto; padding: 1.5rem; flex: 1; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.75rem;
  margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.card h2 {
  font-size: 1.15rem; font-weight: 600; margin-bottom: 0.25rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.card h2 .step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 0.8rem; font-weight: 700; flex-shrink: 0;
}
.card .subtitle {
  color: var(--text-secondary); font-size: 0.88rem; margin-bottom: 1.25rem;
}
.card.completed { border-color: var(--success); }
.card.completed h2 .step-num { background: var(--success); }
.card.disabled { opacity: 0.45; pointer-events: none; }

/* ── Info boxes ─────────────────────────────────────────────────────────────── */
.info-box {
  border-radius: var(--radius); padding: 0.75rem 1rem;
  font-size: 0.85rem; margin-bottom: 1rem;
}
.info-box.success { background: var(--success-bg); border: 1px solid var(--success-border); color: #15803d; }
.info-box.warn    { background: var(--warn-bg); border: 1px solid var(--warn-border); color: #92400e; }
.info-box.error   { background: var(--error-bg); border: 1px solid var(--error-border); color: #991b1b; }
.info-box.info    { background: var(--accent-light); border: 1px solid #c7d7fe; color: #1e40af; }

/* ── Loading status bar ─────────────────────────────────────────────────────── */
.tool-status {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; border-radius: var(--radius);
  font-size: 0.88rem; margin-bottom: 1rem;
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: #92400e;
}
.tool-status.ready { background: var(--success-bg); border-color: var(--success-border); color: #15803d; }
.tool-status.error { background: var(--error-bg); border-color: var(--error-border); color: #991b1b; }
.spinner {
  width: 16px; height: 16px; border: 3px solid #ccc; border-top-color: #555;
  border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.hidden { display: none; }

/* ── Form elements ──────────────────────────────────────────────────────────── */
label {
  display: block; font-size: 0.85rem; font-weight: 600;
  margin-bottom: 0.35rem; color: var(--text-secondary);
}
input[type="number"], input[type="text"], select {
  font-family: var(--font); font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color 0.15s;
  width: 100%; max-width: 320px;
}
textarea {
  font-family: var(--mono); font-size: 0.82rem; line-height: 1.5;
  padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-alt); color: var(--text); outline: none;
  width: 100%; min-height: 180px; resize: vertical;
  transition: border-color 0.15s; box-sizing: border-box;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  font-family: var(--font); font-size: 0.9rem; font-weight: 600;
  padding: 0.55rem 1.25rem; border: none; border-radius: var(--radius);
  cursor: pointer; transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e6ec; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-success:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-row { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }

/* ── Video embed ────────────────────────────────────────────────────────────── */
.video-wrap {
  position: relative; padding-bottom: 56.25%; height: 0;
  overflow: hidden; border-radius: var(--radius); margin-bottom: 0.75rem;
}
.video-wrap iframe {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; border: none;
}

/* ── Instructions ───────────────────────────────────────────────────────────── */
.instructions { font-size: 0.88rem; line-height: 1.8; }
.instructions ol { padding-left: 1.5rem; }
.instructions li { margin-bottom: 0.25rem; }
.instructions code {
  background: var(--surface-alt); padding: 1px 6px;
  border-radius: 4px; font-family: var(--mono); font-size: 0.85em;
}

/* ── Inline code ────────────────────────────────────────────────────────────── */
code.col-tag {
  font-family: var(--mono); font-size: 0.85em;
  background: var(--surface-alt); padding: 1px 4px; border-radius: 3px;
}

/* ── Options grid (Ella / settings panels) ──────────────────────────────────── */
.options-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem;
}
@media (max-width: 600px) { .options-grid { grid-template-columns: 1fr; } }
.toggle-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.toggle-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.toggle-row label { margin: 0; font-weight: 500; font-size: 0.9rem; color: var(--text); }

/* ── Capillary mapping (RePlex) ─────────────────────────────────────────────── */
.cap-map {
  background: var(--accent-light); border: 1px solid #c7d7fe;
  border-radius: var(--radius); padding: 1rem 1.25rem;
  margin-top: 1rem; font-family: var(--mono);
  font-size: 0.85rem; line-height: 1.8;
}
.cap-map strong { color: var(--accent); }

/* ── Result tables (RePlex) ─────────────────────────────────────────────────── */
.result-section { margin-bottom: 1.5rem; }
.result-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.15rem; }
.result-section .desc { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 0.75rem; }
.result-table-wrap {
  overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead th {
  background: var(--surface-alt); font-weight: 600; text-align: left;
  padding: 0.6rem 0.9rem; border-bottom: 2px solid var(--border); white-space: nowrap;
}
tbody td {
  padding: 0.55rem 0.9rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }
td.val  { font-family: var(--mono); font-size: 0.82rem; }
td.calc { font-family: var(--mono); font-size: 0.78rem; color: var(--text-secondary); }

.pct-good { color: var(--success); font-weight: 600; }
.pct-warn { color: var(--warn); font-weight: 600; }
.pct-bad  { color: var(--error); font-weight: 600; }

/* ── Console output (dark panel) ────────────────────────────────────────────── */
#console-output {
  background: #1a2236; color: #d4d4d4; font-family: var(--mono);
  font-size: 0.82rem; padding: 1.25rem; border-radius: var(--radius);
  white-space: pre-wrap; word-break: break-word;
  max-height: 500px; overflow-y: auto; margin-bottom: 1.25rem; line-height: 1.6;
}

/* ── Error output ───────────────────────────────────────────────────────────── */
#error-output {
  display: none; background: var(--error-bg); border: 1px solid var(--error-border);
  border-radius: var(--radius); padding: 1rem; font-family: var(--mono);
  font-size: 0.82rem; white-space: pre-wrap; color: #991b1b; margin-bottom: 1rem;
}
#error-output.visible { display: block; }

/* ── Figure cards (Pyodide graph output) ────────────────────────────────────── */
#output-section { display: none; }
#output-section.visible { display: block; }
#figures-output { display: flex; flex-direction: column; gap: 1.25rem; }
.figure-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem;
  overflow: hidden; box-shadow: var(--shadow);
}
.figure-card h3 {
  font-size: 0.95rem; font-weight: 600;
  margin-bottom: 0.75rem; color: var(--text-secondary);
}
.figure-card img {
  max-width: 100%; height: auto; display: block; border-radius: var(--radius);
}

/* ── Contribution box (EC90) ────────────────────────────────────────────────── */
#contrib-box {
  display: none; margin-bottom: 1.5rem;
  background: var(--accent-light); border: 1px solid #c7d7fe;
  border-left: 4px solid var(--accent); border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
}
#contrib-box.visible { display: block; }
#contrib-box h3 { margin: 0 0 0.35rem; font-size: 1.05rem; font-weight: 600; color: #1e3a5f; }
#contrib-box > p { margin: 0 0 1rem; font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }
.contrib-btn-row { display: flex; gap: 0.5rem; margin-bottom: 0.25rem; }
#contrib-form { display: none; margin-top: 1.25rem; }
#contrib-form.visible { display: block; }
.contrib-field { margin-bottom: 0.85rem; }
.contrib-field label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text); margin-bottom: 0.3rem; }
.contrib-field input,
.contrib-field select,
.contrib-field textarea {
  width: 100%; padding: 0.5rem 0.75rem; font-size: 0.9rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-sizing: border-box; font-family: var(--font);
  outline: none; transition: border-color 0.15s; max-width: none;
}
.contrib-field input:focus,
.contrib-field textarea:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.contrib-field textarea { height: 68px; resize: vertical; }
#contrib-status { display: none; margin-top: 0.75rem; padding: 0.65rem 1rem; border-radius: var(--radius); font-size: 0.85rem; }
#contrib-status.ok    { display: block; background: var(--success-bg); color: #15803d; border: 1px solid var(--success-border); }
#contrib-status.error { display: block; background: var(--error-bg); color: #991b1b; border: 1px solid var(--error-border); }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.page-footer {
  text-align: center; padding: 2rem 1.5rem; font-size: 0.85rem;
  color: var(--text-secondary); border-top: 1px solid var(--border); margin-top: 2rem;
}
.page-footer a { color: var(--accent); }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: -260px; z-index: 999;
    transition: left 0.25s ease; height: 100vh;
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }
  .sidebar-toggle { display: flex; }
  .page-header { padding-left: 3.5rem; }
}
@media (max-width: 640px) {
  .page-header h1 { font-size: 1.35rem; }
  .card { padding: 1.25rem; }
}
