:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --sidebar-bg: #0b1220;
  --sidebar-surface: #131d33;
  --sidebar-border: #1e293b;
  --sidebar-text: #cbd5e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --emerald: #059669;
  --emerald-soft: rgba(5, 150, 105, 0.12);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --rose: #dc2626;
  --rose-soft: rgba(220, 38, 38, 0.11);
  --indigo: #4f46e5;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.07);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #070d19;
  --surface: #0f172a;
  --surface-2: #152138;
  --border: #1e293b;
  --border-strong: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 26px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }

/* ================= LOGIN GATE ================= */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #172554 0%, #0b1220 50%, #020617 100%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 430px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 18px;
  padding: 36px 32px;
  color: #f8fafc;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-brand img { width: 52px; height: 42px; object-fit: contain; background: #fff; border-radius: 10px; padding: 5px; }
.login-brand h1 { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.login-brand p { font-size: 12px; color: #94a3b8; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: #cbd5e1; margin-bottom: 6px; }
.login-card input {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid #334155;
  background: #0b1220; color: #fff; font-size: 14px; outline: none; margin-bottom: 16px;
}
.login-card input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25); }
.login-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600;
  color: #34d399; background: rgba(16, 185, 129, 0.14); border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 4px 10px; border-radius: 999px; margin-bottom: 18px;
}
.login-err {
  background: rgba(220, 38, 38, 0.18); border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fecaca; padding: 10px 12px; border-radius: 9px; font-size: 12.5px; margin-bottom: 14px;
}

/* ================= APP SHELL ================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 254px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 30;
}
.sb-header {
  display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sb-header img { width: 38px; height: 32px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.sb-title { font-size: 14.5px; font-weight: 700; color: #fff; line-height: 1.15; }
.sb-sub { font-size: 11px; color: #60a5fa; font-weight: 600; }

.sb-nav { flex: 1; padding: 12px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.sb-section { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #64748b; padding: 12px 10px 4px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: transparent;
  color: var(--sidebar-text); padding: 9.5px 12px; border-radius: 9px; font-size: 13px; font-weight: 500;
  cursor: pointer; text-align: left; transition: all 0.15s ease;
}
.nav-btn:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-btn.active { background: linear-gradient(90deg, rgba(37, 99, 235, 0.92), rgba(59, 130, 246, 0.85)); color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35); }
.nav-btn .ico { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; }
.nav-btn .pill {
  margin-left: auto; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.12); color: #e2e8f0;
}
.nav-btn .pill.warn { background: rgba(220, 38, 38, 0.85); color: #fff; }

.sb-footer { padding: 12px 14px; border-top: 1px solid var(--sidebar-border); background: rgba(0, 0, 0, 0.2); }
.vault-pill {
  display: flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 600;
  padding: 7px 10px; border-radius: 8px; margin-bottom: 10px;
}
.vault-pill.open { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.vault-pill.locked { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.sb-user-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.sb-user-name { font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ================= MAIN AREA ================= */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 60px; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.tb-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tb-title { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.tb-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-right { display: flex; align-items: center; gap: 8px; }

.content { padding: 22px 24px 40px; max-width: 1520px; width: 100%; margin: 0 auto; }

/* ================= CARDS & GRID ================= */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 18px 20px; margin-bottom: 18px;
}
.card-hdr { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--primary)); }
.kpi-lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.kpi-val { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin: 5px 0 3px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); }

/* Host Performance Bar */
.host-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 12px;
  background: linear-gradient(135deg, #0b1220 0%, #15223d 100%);
  color: #f8fafc; border-radius: var(--radius); padding: 15px 18px; margin-bottom: 18px;
  border: 1px solid #1e3a5f; box-shadow: var(--shadow-md);
}
.host-metric-lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: #94a3b8; font-weight: 700; }
.host-metric-val { font-size: 17px; font-weight: 700; margin: 3px 0 6px; display: flex; align-items: baseline; gap: 6px; }
.host-metric-val small { font-size: 11px; color: #94a3b8; font-weight: 500; }
.bar-track { height: 6px; background: rgba(255, 255, 255, 0.12); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: #3b82f6; transition: width 0.3s ease; }
.bar-fill.green { background: #10b981; }
.bar-fill.amber { background: #f59e0b; }
.bar-fill.red { background: #ef4444; }

/* ================= BUTTONS & BADGES ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; transition: all 0.14s ease; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: #94a3b8; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-emerald { background: var(--emerald); color: #fff; border-color: var(--emerald); }
.btn-emerald:hover { background: #047857; }
.btn-amber { background: var(--amber); color: #fff; border-color: var(--amber); }
.btn-danger { background: var(--rose); color: #fff; border-color: var(--rose); }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 9.5px; font-size: 12px; border-radius: 7px; }
.btn-xs { padding: 3.5px 7.5px; font-size: 11px; border-radius: 6px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8.5px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge-green { background: var(--emerald-soft); color: var(--emerald); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--rose-soft); color: var(--rose); }
.badge-slate { background: rgba(100, 116, 139, 0.14); color: var(--text-muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.live { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25); }
.dot.down { background: #ef4444; }

/* ================= TABLES ================= */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 10.5px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.actions-cell { display: flex; flex-wrap: wrap; gap: 5px; }

/* ================= FORMS ================= */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.field input, .field select, .field textarea {
  padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-family: var(--font); font-size: 13.5px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field textarea { resize: vertical; min-height: 76px; }
.hint { font-size: 11.5px; color: var(--text-muted); }

/* Prefix Preview Box */
.prefix-preview {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px;
  background: var(--primary-soft); border: 1px dashed var(--primary); margin-top: 8px; flex-wrap: wrap;
}
.prefix-preview code { font-family: var(--mono); font-size: 13.5px; font-weight: 700; color: var(--primary); }

/* Negotiated Deal Calculator Banner */
.deal-banner {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(5, 150, 105, 0.08));
  border: 1px solid rgba(37, 99, 235, 0.25); border-radius: 11px; padding: 14px 16px; margin: 14px 0;
}
.deal-stat-lbl { font-size: 10.5px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.deal-stat-val { font-size: 18px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* Launch Success Card */
.launch-kit {
  background: linear-gradient(135deg, #064e3b 0%, #0f172a 100%);
  color: #ecfdf5; border: 1px solid #10b981; border-radius: 14px; padding: 20px 22px; margin-bottom: 18px;
}
.launch-kit h3 { font-size: 17px; margin-bottom: 10px; }
.launch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 8px 12px; border-radius: 8px; margin-top: 8px; flex-wrap: wrap;
}
.launch-row code { font-family: var(--mono); font-size: 12px; color: #a7f3d0; word-break: break-all; }

/* Module Switches */
.module-group { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; background: var(--surface-2); }
.module-group-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; color: var(--primary); }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
.mod-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px;
}
.mod-name { font-size: 12.8px; font-weight: 600; }
.mod-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.switch { position: relative; display: inline-block; width: 42px; height: 23px; flex-shrink: 0; margin-top: 2px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0; background: #cbd5e1; border-radius: 99px; transition: 0.2s;
}
.slider::before {
  content: ''; position: absolute; width: 17px; height: 17px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.switch input:checked + .slider { background: var(--emerald); }
.switch input:checked + .slider::before { transform: translateX(19px); }

/* Kill-Switch Banner */
.kill-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 16px; border-radius: 10px; margin-bottom: 14px; border: 1px solid var(--border);
}
.kill-banner.on { background: var(--emerald-soft); border-color: rgba(5, 150, 105, 0.35); }
.kill-banner.off { background: var(--rose-soft); border-color: rgba(220, 38, 38, 0.4); }

/* Tabs & Pills */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
  padding: 9px 14px; border: none; background: transparent; color: var(--text-muted);
  font-weight: 600; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.search-input {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 13px; min-width: 240px; outline: none;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.65); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 80;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 720px; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.modal-hdr {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* Toast */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 120; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  padding: 11px 15px; border-radius: 10px; color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28); animation: slideUp 0.2s ease;
}
.toast.ok { background: #059669; }
.toast.err { background: #dc2626; }
.toast.info { background: #1e293b; }
@keyframes slideUp { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Fleet Cards */
.fleet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; }
.fleet-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow-sm);
}
.fleet-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: var(--surface-2); border-radius: 9px; padding: 9px 10px; }
.fleet-stat-k { font-size: 10px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.fleet-stat-v { font-size: 13.5px; font-weight: 700; margin-top: 2px; }

/* Contract Schedule Row */
.contract-card {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  margin-bottom: 14px; overflow: hidden; box-shadow: var(--shadow-sm);
}
.contract-head {
  padding: 15px 18px; display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.contract-metrics { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; }
.cm-pill { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 11px; }
.cm-pill span { display: block; font-size: 10px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.cm-pill strong { font-size: 13.5px; font-variant-numeric: tabular-nums; }

/* Responsive */
.menu-toggle { display: none; }
@media (max-width: 960px) {
  .sidebar { position: fixed; left: -270px; transition: left 0.2s ease; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}
