:root {
  --bg: #0b0f17;
  --bg-elev: #121826;
  --bg-card: #161e2e;
  --bg-input: #0e1420;
  --border: #253147;
  --border-focus: #3b82f6;
  --text: #e6edf7;
  --text-muted: #93a4be;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  height: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); }
.stack-xs { display: flex; flex-direction: column; gap: 6px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.stack-md { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at top, #172554 0%, var(--bg) 55%);
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand-row h1 { margin: 0; font-size: 19px; }
.brand-row p { margin: 2px 0 0; font-size: 12px; }
.brand-badge {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 14px;
  flex-shrink: 0;
}

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 16px; border-bottom: 1px solid var(--border);
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav-list { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text-muted); text-decoration: none;
  font-weight: 500; transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-item.active { background: rgba(59,130,246,0.16); color: #93c5fd; border: 1px solid rgba(59,130,246,0.3); }
.nav-icon { width: 18px; text-align: center; }

.sidebar-footer { padding: 12px 14px; border-top: 1px solid var(--border); }
.user-pill { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--text-muted); }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 58px; padding: 0 20px;
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.status-pills { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.banners-wrap { padding: 0 20px; }
.banners-wrap:empty { display: none; }
.view-root { padding: 20px; max-width: 1480px; width: 100%; }

/* Cards & Grids */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.card-title { margin: 0; font-size: 16px; font-weight: 600; }

.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.split-view { display: grid; grid-template-columns: 330px 1fr; gap: 16px; align-items: start; }

.stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Fields & Inputs */
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-muted); }
.field input, .field select, .field textarea, .input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  border-color: var(--border-focus);
}
textarea.code-editor {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  min-height: 360px;
  width: 100%;
  resize: vertical;
  background: #080c13;
  color: #dbeafe;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

/* Buttons & Pills */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  padding: 8px 13px; border-radius: 7px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; text-decoration: none;
}
.btn:hover:not(:disabled) { background: #1e293b; border-color: #3b4c6b; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: #059669; border-color: #059669; color: #fff; }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-warn { background: #b45309; border-color: #d97706; color: #fff; }
.btn-danger { background: #b91c1c; border-color: #dc2626; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-block { width: 100%; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg-card);
}
.pill-success { background: rgba(16,185,129,0.14); color: #34d399; border-color: rgba(16,185,129,0.35); }
.pill-warn { background: rgba(245,158,11,0.14); color: #fbbf24; border-color: rgba(245,158,11,0.35); }
.pill-danger { background: rgba(239,68,68,0.14); color: #f87171; border-color: rgba(239,68,68,0.35); }
.pill-info { background: rgba(59,130,246,0.14); color: #60a5fa; border-color: rgba(59,130,246,0.35); }
.pill-muted { color: var(--text-muted); }

/* Alerts & Banners */
.alert {
  padding: 11px 14px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13px; margin-top: 10px;
}
.alert-warn { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.4); color: #fde68a; }
.alert-danger { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.4); color: #fecaca; }
.alert-info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.4); color: #bfdbfe; }

/* List Sidebar inside Split View */
.file-list {
  max-height: 68vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
  margin-top: 10px;
}
.file-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 7px; cursor: pointer; text-decoration: none;
  color: var(--text); border: 1px solid transparent; font-size: 12.5px;
}
.file-row:hover { background: rgba(255,255,255,0.04); }
.file-row.active { background: rgba(59,130,246,0.15); border-color: rgba(59,130,246,0.4); }
.file-row .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Loot Entry Rows */
.loot-entry {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.loot-entry-nested {
  margin-left: 16px;
  border-left: 2px solid var(--primary);
  padding-left: 12px;
}
.prob-bar-wrap {
  height: 7px; background: #090d14; border-radius: 999px; overflow: hidden; flex: 1; min-width: 80px;
}
.prob-bar-fill {
  height: 100%; background: linear-gradient(90deg, #3b82f6, #10b981); transition: width 0.2s;
}
.prob-bar-fill.is-nothing { background: #64748b; }

/* Tabs */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.tab-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.tab-btn:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.tab-btn.active { background: rgba(59,130,246,0.16); border-color: rgba(59,130,246,0.35); color: #93c5fd; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td {
  padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left;
}
table.data-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; }

/* Logs */
.log-box {
  background: #070a10; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
  max-height: 430px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}

/* Toasts & Modal */
.toast-container {
  position: fixed; right: 18px; bottom: 18px; z-index: 90;
  display: flex; flex-direction: column; gap: 8px; max-width: 360px;
}
.toast {
  background: var(--bg-card); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  padding: 11px 14px; border-radius: 8px; box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  font-size: 13px; animation: slideIn 0.18s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.68); z-index: 80;
  display: grid; place-items: center; padding: 18px;
}
.modal-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto;
}

.loading-box { padding: 30px; text-align: center; color: var(--text-muted); }
.mobile-only { display: none; }

@media (max-width: 920px) {
  .split-view { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed; left: -260px; z-index: 60; transition: left 0.2s;
  }
  .sidebar.open { left: 0; }
}
