/* PY Runner - dark dashboard theme */
:root {
  --bg: #0d1117;
  --bg-elev: #131a24;
  --panel: #161e2b;
  --panel-2: #1b2534;
  --border: #263247;
  --border-strong: #33425c;
  --text: #e6ebf3;
  --muted: #8f9bb3;
  --faint: #5f6b82;
  --primary: #4f8cff;
  --primary-hover: #6a9dff;
  --success: #22c55e;
  --danger: #ef4444;
  --danger-hover: #f25f5f;
  --warning: #f5a524;
  --info: #38bdf8;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sidebar-w: 236px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); }
code { background: var(--panel-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.hidden, [hidden] { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1 1 auto; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--primary); color: #fff; padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 16px; }
.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 9px 10px; border-radius: var(--radius-sm); font-weight: 500; }
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: rgba(79, 140, 255, .14); color: var(--text); }
.nav a.active .nav-icon svg { stroke: var(--primary); }
.nav-icon { display: inline-flex; width: 18px; height: 18px; }
.sidebar-footer { margin-top: auto; padding: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, .85); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 20; min-height: 60px;
}
.topbar h1 { font-size: 18px; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-toggle { display: none; }
.view { padding: 22px 24px 40px; outline: none; max-width: 1500px; width: 100%; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 25; }
  .menu-toggle { display: inline-flex; }
  .view { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .topbar-actions .btn .label { display: none; }
}

/* ---------- cards & grids ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card + .card { margin-top: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.split { grid-template-columns: 300px minmax(0, 1fr); align-items: start; }
@media (max-width: 1100px) { .grid.two, .grid.split { grid-template-columns: minmax(0, 1fr); } }
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat .label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat.running .value { color: var(--success); }
.stat.failed .value { color: var(--danger); }
.stat.stopped .value { color: var(--muted); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 18px; }
.kv > div { min-width: 0; }
.kv dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
dl { margin: 0; }

.meter { display: flex; flex-direction: column; gap: 6px; }
.meter + .meter { margin-top: 14px; }
.meter-bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.meter-fill { height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s ease; }
.meter-fill.warn { background: var(--warning); }
.meter-fill.crit { background: var(--danger); }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-strong);
  background: var(--panel-2); color: var(--text); padding: 7px 12px; border-radius: var(--radius-sm); font: inherit;
  font-weight: 500; cursor: pointer; white-space: nowrap; line-height: 1.3; min-height: 34px;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: transparent; border-color: rgba(239, 68, 68, .55); color: #ff8a8a; }
.btn.danger:hover:not(:disabled) { background: rgba(239, 68, 68, .12); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.success { background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .5); color: #6ee7a0; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--panel); }
.btn.sm { padding: 4px 8px; min-height: 28px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius-sm); background: transparent; border: 1px solid var(--border); color: var(--text); cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label, .field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 18px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 10px; min-height: 36px; width: 100%; font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(79, 140, 255, .2); }
input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--primary); }
input[type="file"] { padding: 6px; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.form-error { color: #ff8a8a; background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .35); padding: 8px 10px; border-radius: var(--radius-sm); }
.search { max-width: 280px; }

/* ---------- notices & badges ---------- */
.notice { border: 1px solid var(--border-strong); background: var(--panel-2); padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; }
.notice.warning { border-color: rgba(245, 165, 36, .45); background: rgba(245, 165, 36, .08); color: #ffd28a; }
.notice.danger { border-color: rgba(239, 68, 68, .45); background: rgba(239, 68, 68, .08); color: #ffb0b0; }
.notice.info { border-color: rgba(56, 189, 248, .4); background: rgba(56, 189, 248, .07); color: #b6e6fb; }
.notice.success { border-color: rgba(34, 197, 94, .4); background: rgba(34, 197, 94, .08); color: #a7f3c4; }
.notice .row { margin-top: 8px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid var(--border-strong); color: var(--muted); background: var(--panel-2); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.running { color: #6ee7a0; border-color: rgba(34, 197, 94, .45); background: rgba(34, 197, 94, .1); }
.badge.failed { color: #ff8a8a; border-color: rgba(239, 68, 68, .5); background: rgba(239, 68, 68, .1); }
.badge.starting, .badge.stopping, .badge.restarting { color: #ffd28a; border-color: rgba(245, 165, 36, .5); background: rgba(245, 165, 36, .1); }
.badge.starting::before, .badge.stopping::before, .badge.restarting::before { animation: pulse 1s infinite; }
.badge.healthy { color: #6ee7a0; }
.badge.unhealthy { color: #ff8a8a; }
.badge.info { color: #b6e6fb; border-color: rgba(56, 189, 248, .4); }
@keyframes pulse { 50% { opacity: .3; } }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: 0 0 auto; }
.dot.running { background: var(--success); }
.dot.failed { background: var(--danger); }
.dot.starting, .dot.stopping, .dot.restarting { background: var(--warning); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--bg-elev); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255, 255, 255, .02); }
td .sub { color: var(--muted); font-size: 12px; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.link-btn { background: none; border: none; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; padding: 0; text-align: left; }
.link-btn:hover { color: var(--primary); }

/* ---------- tree ---------- */
.tree { display: flex; flex-direction: column; gap: 2px; }
.tree-folder > .tree-row { font-weight: 600; }
.tree-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text); background: none; border: none; width: 100%; font: inherit; text-align: left; }
.tree-row:hover { background: var(--panel-2); }
.tree-row.active { background: rgba(79, 140, 255, .14); }
.tree-row svg { width: 16px; height: 16px; flex: 0 0 auto; stroke: var(--muted); }
.tree-row .count { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 500; }
.tree-children { padding-left: 18px; display: flex; flex-direction: column; gap: 1px; }
.tree-children .tree-row { font-weight: 400; font-size: 13px; padding: 5px 8px; }
.tree-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { background: none; border: none; color: var(--muted); padding: 10px 14px; font: inherit; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* ---------- console ---------- */
.console {
  background: #090c11; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; height: 520px; overflow: auto;
  font: 12.5px/1.55 var(--mono); color: #cfd8e6; white-space: pre-wrap; word-break: break-all; margin: 0;
}
.console.short { height: 320px; }
.console .err { color: #ff9b9b; }
.console .sys { color: var(--info); }
.console-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.file-view { max-height: 65vh; overflow: auto; background: #090c11; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; font: 12.5px/1.5 var(--mono); white-space: pre; margin: 0; }

/* ---------- activity ---------- */
.activity { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.activity li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.activity li:last-child { border-bottom: none; }
.activity .when { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; }

/* ---------- empty / loading ---------- */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); padding: 30px 0; justify-content: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .15s; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3, 6, 10, .7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--border-strong); border-radius: 12px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { max-width: 900px; }
.modal-header { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-body { padding: 18px; overflow: auto; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel-2); border: 1px solid var(--border-strong); border-left: 4px solid var(--primary); padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow); animation: slide .2s ease; overflow-wrap: anywhere; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---------- auth pages ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(79, 140, 255, .12), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 520px; }
.auth-card h1 { font-size: 20px; margin: 14px 0 12px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }

/* ---------- misc ---------- */
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px; gap: 10px; flex-wrap: wrap; }
.env-row { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(160px, 2fr) auto auto; gap: 8px; align-items: center; }
@media (max-width: 700px) { .env-row { grid-template-columns: 1fr; } .env-row .check { justify-self: start; } }
.env-list { display: flex; flex-direction: column; gap: 8px; }
.bot-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.bot-head .title { display: flex; flex-direction: column; gap: 6px; }
.bot-head h2 { font-size: 20px; }
.crumbs { color: var(--muted); font-size: 13px; }
.crumbs a { color: var(--muted); }
.mono-small { font: 12px var(--mono); color: var(--muted); }
