/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg0: #0a0d13;
  --bg1: #0f1117;
  --bg2: #161b24;
  --bg3: #1e2636;
  --bg4: #252d3d;
  --border: #2a3347;
  --border2: #374157;
  --text0: #e8eaf0;
  --text1: #b0bac8;
  --text2: #6b7a94;
  --text3: #3d4a60;
  --accent: #3b8cff;
  --accent2: #1a6dff;
  --green: #22c55e;
  --green-bg: #0d2818;
  --green-border: #165a2e;
  --amber: #f59e0b;
  --amber-bg: #271d08;
  --amber-border: #5a4210;
  --red: #ef4444;
  --red-bg: #250d0d;
  --red-border: #5a1a1a;
  --purple: #a855f7;
  --purple-bg: #1a0d27;
  --cyan: #06b6d4;
  --cyan-bg: #061e27;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
  --sans: 'Inter', system-ui, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--sans);
  background:
    radial-gradient(circle at top, rgba(59, 140, 255, 0.14), transparent 32%),
    linear-gradient(180deg, #0a0d13 0%, #07090e 100%);
  color: var(--text0);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

body[data-runtime="web"] #app {
  max-width: 1440px;
  margin: 0 auto;
}

.titlebar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; height: 48px;
  background: rgba(15, 17, 23, 0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

body[data-runtime="electron"] .titlebar { -webkit-app-region: drag; }
body[data-runtime="electron"][data-platform="darwin"] .titlebar {
  padding-left: 84px;
}
body[data-runtime="electron"] .titlebar-logo,
body[data-runtime="electron"] .titlebar-runtime,
body[data-runtime="electron"] .titlebar-badge { -webkit-app-region: no-drag; }

.titlebar-logo {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--purple) 100%);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
  -webkit-app-region: no-drag;
  flex-shrink: 0;
}

.titlebar-title {
  font-size: 13px; font-weight: 600; color: var(--text0);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.titlebar-subtitle {
  font-size: 11px; color: var(--text2);
  font-family: var(--mono);
  white-space: nowrap;
}

.titlebar-spacer { flex: 1; }

.titlebar-runtime {
  font-size: 10px;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text1);
  background: rgba(30, 38, 54, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.titlebar-runtime.web {
  border-color: rgba(59, 140, 255, 0.35);
  color: #9fc3ff;
}

.titlebar-runtime.electron {
  border-color: rgba(34, 197, 94, 0.35);
  color: #8ce2ad;
}

.titlebar-badge {
  font-size: 10px; font-family: var(--mono);
  padding: 2px 8px; border-radius: 20px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); -webkit-app-region: no-drag;
}

/* ── Tabs ────────────────────────────────────────────────── */
.tabs-bar {
  display: flex; align-items: center;
  padding: 0 16px; gap: 2px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

body[data-runtime="electron"][data-platform="darwin"] .tabs-bar {
  padding-left: 20px;
}

.tab-btn {
  padding: 10px 16px;
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  color: var(--text2); background: transparent; border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer; transition: all .15s;
  display: flex; align-items: center; gap: 6px;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text1); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-icon { font-size: 14px; }

/* ── Main Content ────────────────────────────────────────── */
.content {
  flex: 1; overflow: hidden;
  display: flex; flex-direction: column;
}

.panel { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.panel.active { display: flex; }

.panel-scroll { flex: 1; overflow-y: auto; padding: 16px; }
.panel-scroll::-webkit-scrollbar { width: 6px; }
.panel-scroll::-webkit-scrollbar-track { background: transparent; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  overflow: hidden;
}

.card-title {
  font-size: 10px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}
.card-title::before {
  content: ''; width: 3px; height: 12px;
  background: var(--accent); border-radius: 2px; display: block;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── Controls ────────────────────────────────────────────── */
.ctrl-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
}

.btn {
  padding: 5px 14px; font-size: 12px; font-family: var(--sans); font-weight: 500;
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius); cursor: pointer; color: var(--text0);
  transition: all .12s; white-space: nowrap;
}
.btn:hover { background: var(--bg4); border-color: var(--text3); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent2); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { border-color: var(--red-border); color: var(--red); }
.btn.success { border-color: var(--green-border); color: var(--green); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.ctrl-label { font-size: 11px; color: var(--text2); white-space: nowrap; }

select.ctrl-sel {
  padding: 4px 10px; font-size: 12px; font-family: var(--sans);
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius); color: var(--text0); cursor: pointer;
  outline: none;
}
select.ctrl-sel:focus { border-color: var(--accent); }

input[type=number].ctrl-num {
  width: 56px; padding: 4px 8px; font-size: 12px; font-family: var(--mono);
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius); color: var(--text0); outline: none;
  text-align: center;
}
input[type=number].ctrl-num:focus { border-color: var(--accent); }

.speed-wrap { display: flex; align-items: center; gap: 6px; }
input[type=range].speed-slider {
  width: 100px; accent-color: var(--accent); cursor: pointer;
}

/* ── Thread Chips ────────────────────────────────────────── */
.thread-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px 3px 6px;
  border-radius: 20px; font-size: 11px; font-family: var(--mono); font-weight: 500;
  border: 1px solid transparent; transition: all .25s;
  white-space: nowrap;
}
.chip-ready   { background: #0d1e33; border-color: #1a4a7a; color: #60aaff; }
.chip-running { background: var(--green-bg); border-color: var(--green-border); color: var(--green); }
.chip-waiting { background: var(--amber-bg); border-color: var(--amber-border); color: var(--amber); }
.chip-blocked { background: var(--red-bg); border-color: var(--red-border); color: var(--red); }
.chip-done    { background: var(--bg3); border-color: var(--border); color: var(--text2); }

.state-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.dot-ready   { background: #3b8cff; }
.dot-running { background: #22c55e; animation: dot-pulse 1.1s ease-in-out infinite; }
.dot-waiting { background: #f59e0b; animation: dot-pulse 1.4s ease-in-out infinite; }
.dot-blocked { background: #ef4444; }
.dot-done    { background: #4a5568; }

@keyframes dot-pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.7); }
}

.thread-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.thread-meta { font-size: 10px; color: var(--text2); font-family: var(--mono); }

/* ── CPU Cores ───────────────────────────────────────────── */
.cpu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }

.cpu-core {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 8px; text-align: center;
  background: var(--bg3); transition: all .2s;
  min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.cpu-core.busy {
  background: var(--green-bg); border-color: var(--green-border);
  box-shadow: 0 0 12px rgba(34,197,94,.12);
}
.core-label { font-size: 9px; color: var(--text3); font-family: var(--mono); text-transform: uppercase; }
.core-thread { font-size: 13px; font-weight: 600; font-family: var(--mono); color: var(--green); }
.core-idle { font-size: 10px; color: var(--text3); }

/* ── Mapping Canvas ──────────────────────────────────────── */
.map-canvas {
  width: 100%; height: 200px;
  background: var(--bg3); border-radius: var(--radius);
  overflow: hidden; position: relative;
}
.map-canvas svg { width: 100%; height: 100%; }

/* ── Log ─────────────────────────────────────────────────── */
.log-panel {
  font-size: 11px; font-family: var(--mono); line-height: 1.7;
  max-height: 130px; overflow-y: auto;
  background: var(--bg0); border-radius: var(--radius);
  padding: 8px 10px; border: 1px solid var(--border);
}
.log-panel::-webkit-scrollbar { width: 4px; }
.log-panel::-webkit-scrollbar-thumb { background: var(--bg4); }

.log-entry { display: flex; gap: 8px; }
.log-time { color: var(--text3); flex-shrink: 0; }
.log-info  { color: #60aaff; }
.log-ok    { color: var(--green); }
.log-warn  { color: var(--amber); }
.log-err   { color: var(--red); }
.log-sys   { color: var(--purple); }

/* ── Stats chips ─────────────────────────────────────────── */
.stats-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.stat-chip {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 14px; min-width: 80px;
}
.stat-val { font-size: 18px; font-weight: 600; color: var(--text0); font-family: var(--mono); display: block; }
.stat-lbl { font-size: 9px; color: var(--text2); text-transform: uppercase; letter-spacing: .06em; }

/* ── Semaphore ───────────────────────────────────────────── */
.sem-counter {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; font-family: var(--mono);
  border: 2px solid var(--border2); background: var(--bg3); color: var(--text0);
  transition: all .3s;
}
.sem-counter.zero { background: var(--red-bg); border-color: var(--red-border); color: var(--red); }
.sem-counter.full { background: var(--green-bg); border-color: var(--green-border); color: var(--green); }

.sem-block { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sem-info { font-size: 11px; color: var(--text1); }
.sem-info-sub { font-size: 10px; color: var(--text2); margin-top: 2px; }

/* ── Monitor buffer ──────────────────────────────────────── */
.buffer-cells { display: flex; gap: 4px; margin: 8px 0; }
.buffer-cell {
  width: 32px; height: 32px; border-radius: 6px;
  border: 1px solid var(--border2); background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: all .3s;
}
.buffer-cell.filled { background: var(--green-bg); border-color: var(--green-border); }

/* ── Gantt ───────────────────────────────────────────────── */
.gantt-wrap { overflow-x: auto; }
.gantt-row-wrap { margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.gantt-pid { font-size: 10px; font-family: var(--mono); color: var(--text1); width: 28px; flex-shrink: 0; }
.gantt-track { flex: 1; height: 22px; background: var(--bg3); border-radius: 4px; position: relative; overflow: hidden; min-width: 0; }
.gantt-seg {
  position: absolute; top: 2px; height: 18px; border-radius: 3px;
  transition: width .12s linear; display: flex; align-items: center;
  padding: 0 3px; font-size: 9px; font-family: var(--mono); overflow: hidden;
  border: 1px solid transparent;
}

/* ── Ready queue ─────────────────────────────────────────── */
.rq-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  border: 1px solid; transition: all .2s;
}
.rq-arrow { color: var(--text3); font-size: 12px; }

/* ── Progress bar ────────────────────────────────────────── */
.prog-bar-bg { background: var(--bg3); border-radius: 4px; height: 6px; overflow: hidden; flex: 1; }
.prog-bar-fill { height: 6px; border-radius: 4px; transition: width .2s; }

/* ── Scrollbar global ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ── Divider ─────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

/* ── Model description ───────────────────────────────────── */
.model-desc-box {
  background: var(--bg0); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  font-size: 12px; color: var(--text1); line-height: 1.7;
}
.model-desc-box b { color: var(--accent); }

/* ── Sync viz ────────────────────────────────────────────── */
.sync-canvas { width: 100%; height: 160px; background: var(--bg3); border-radius: var(--radius); overflow: hidden; }
.sync-canvas svg { width: 100%; height: 100%; }

/* ── Banker's algorithm ──────────────────────────────────── */
.banker-box {
  background: var(--bg0); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  font-size: 11px; font-family: var(--mono); color: var(--text1); line-height: 1.8;
}
.banker-box .safe { color: var(--green); }
.banker-box .unsafe { color: var(--red); }
.banker-box .highlight { color: var(--amber); }

/* ── Transitions ─────────────────────────────────────────── */
.fade-in { animation: fadeIn .2s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (max-width: 900px) {
  html, body { overflow: auto; }
  #app { min-height: 100vh; height: auto; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .tabs-bar { overflow-x: auto; }
  .map-canvas,
  .sync-canvas,
  .gantt-wrap { overflow-x: auto; }
}
