:root {
  --bg: #0b0d13;
  --bg-elev: #11141d;
  --card: #161a24;
  --card-hover: #1b1f2b;
  --border: #232838;
  --border-strong: #2f3548;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(99,102,241,.14);
  --accent-hover: #818cf8;
  --text: #eef0f6;
  --text-dim: #c2c7d6;
  --muted: #7d839b;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --shadow: 0 8px 28px rgba(0,0,0,.45);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.25);
  --sidebar-w: 248px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(99,102,241,.10), transparent 60%),
    radial-gradient(1000px 500px at -10% 110%, rgba(139,92,246,.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-hover); text-decoration: none; }
code { font-family: var(--mono); font-size: 12px; background: rgba(0,0,0,.35); padding: 2px 6px; border-radius: 6px; color: var(--text-dim); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #3a4256; }

/* ── Layout ─────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 22px 18px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(99,102,241,.4);
  font-size: 18px; color: #fff;
}
.brand .logo svg { width: 23px; height: 23px; }
.brand .brand-text { line-height: 1.2; }
.brand .brand-text strong { font-size: 15px; font-weight: 700; letter-spacing: .2px; }
.brand .brand-text span { font-size: 11px; color: var(--muted); }
.side-nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav .nav-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 14px 12px 6px; font-weight: 600; }
.side-nav button {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-family: var(--font); font-size: 13.5px; font-weight: 500;
  padding: 10px 12px; border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
  width: 100%; text-align: left;
}
.side-nav button svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.side-nav button:hover { background: rgba(255,255,255,.04); color: var(--text); }
.side-nav button.active { background: var(--accent-soft); color: var(--accent-hover); }
.side-nav button.active svg { opacity: 1; }
.side-nav button .count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.06); color: var(--muted);
  padding: 1px 8px; border-radius: 10px; min-width: 22px; text-align: center;
}
.side-nav button.active .count { background: rgba(99,102,241,.25); color: var(--accent-hover); }
.side-foot { padding: 14px; border-top: 1px solid var(--border); }
.side-foot .auth-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.side-foot input#adminToken {
  flex: 1; min-width: 0;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 12px; font-family: var(--mono);
}
.side-foot input#adminToken:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.status-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px rgba(255,255,255,.04); }
.status-dot.ok { background: var(--success); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.status-dot.err { background: var(--danger); box-shadow: 0 0 0 3px rgba(239,68,68,.18); }
.mode-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  padding: 3px 9px; border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}

/* ── Main ───────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 18px 32px;
  background: rgba(11,13,19,.72); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .page-title { font-size: 19px; font-weight: 700; }
.topbar .page-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.topbar .spacer { flex: 1; }
.content { padding: 26px 32px 48px; max-width: 1280px; width: 100%; margin: 0 auto; }
.tab { display: none; animation: fade .25s ease; }
.tab.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Toolbar / Buttons ──────────────────────────────── */
.toolbar { display: flex; gap: 10px; margin-bottom: 18px; align-items: center; flex-wrap: wrap; }
.toolbar h2 { font-size: 15px; font-weight: 600; flex: 1; color: var(--text-dim); }
.search {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 8px 14px 8px 36px; border-radius: 20px; width: 280px; font-size: 13px; font-family: var(--font);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237d839b' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l4 4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center;
}
.search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* General input class (for toolbar filter inputs, selects outside modals) */
.input {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font);
  transition: .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.input { appearance: auto; }

button.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border: none; padding: 9px 16px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; font-weight: 600; font-family: var(--font);
  transition: transform .12s, box-shadow .2s, filter .2s; box-shadow: 0 4px 14px rgba(99,102,241,.28);
}
button.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
button.btn:active { transform: translateY(0); }
button.btn svg { width: 16px; height: 16px; }
button.btn.danger { background: linear-gradient(135deg, #ef4444, #dc2626); box-shadow: 0 4px 14px rgba(239,68,68,.28); }
button.btn.ghost { background: transparent; border: 1px solid var(--border-strong); color: var(--text-dim); box-shadow: none; }
button.btn.ghost:hover { border-color: var(--accent); color: var(--accent-hover); background: var(--accent-soft); filter: none; }
button.btn.sm { padding: 6px 12px; font-size: 12px; box-shadow: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); cursor: pointer; transition: .15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: rgba(255,255,255,.03); }
.icon-btn.danger:hover { color: var(--danger); border-color: rgba(239,68,68,.4); background: rgba(239,68,68,.08); }

/* ── Metric cards ───────────────────────────────────── */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 26px; }
.metric-card {
  background: linear-gradient(160deg, var(--card), var(--bg-elev));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 18px 16px; position: relative; overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.metric-card::after { content: ''; position: absolute; right: -20px; top: -20px; width: 90px; height: 90px; border-radius: 50%; background: var(--accent-soft); filter: blur(6px); }
.metric-card .mc-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; margin-bottom: 12px; background: var(--accent-soft); color: var(--accent-hover); position: relative; z-index: 1; }
.metric-card .mc-icon svg { width: 20px; height: 20px; }
.metric-card .metric-value { font-size: 30px; font-weight: 800; line-height: 1; position: relative; z-index: 1; }
.metric-card .metric-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; margin-top: 6px; font-weight: 600; position: relative; z-index: 1; }

/* ── Card / Table ───────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 13px 18px; color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.015); }
td { padding: 14px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-dim); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: rgba(255,255,255,.025); }
td strong { color: var(--text); font-weight: 600; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Chips ──────────────────────────────────────────── */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.plain::before { display: none; }
.chip.green { background: rgba(34,197,94,.14); color: var(--success); }
.chip.red { background: rgba(239,68,68,.14); color: var(--danger); }
.chip.orange { background: rgba(245,158,11,.14); color: var(--warning); }
.chip.yellow { background: rgba(245,158,11,.14); color: var(--warning); }
.chip.blue { background: rgba(99,102,241,.16); color: var(--accent-hover); }
.chip.gray { background: rgba(255,255,255,.05); color: var(--muted); }

/* ── Empty / loading ────────────────────────────────── */
.empty { text-align: center; color: var(--muted); padding: 56px 24px; }
.empty svg { width: 42px; height: 42px; opacity: .4; margin-bottom: 12px; }
.empty .empty-title { font-size: 14px; font-weight: 600; color: var(--text-dim); margin-bottom: 4px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Catalog ────────────────────────────────────────── */
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.cat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow-sm); transition: border-color .15s, transform .12s; }
.cat-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.cat-head { display: flex; align-items: center; gap: 10px; }
.cat-logo { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-hover); font-weight: 700; font-size: 15px; flex-shrink: 0; }
.cat-title { font-size: 14.5px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 6px; }
.cat-cat { font-size: 11px; color: var(--muted); }
.cat-desc { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; flex: 1; }
.cat-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cat-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.cat-foot .spacer { flex: 1; }
.verified-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; color: var(--success); }
.verified-badge svg { width: 13px; height: 13px; }
.cmd-preview { font-family: var(--mono); font-size: 11.5px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; color: var(--text-dim); word-break: break-all; }

/* ── Modal ──────────────────────────────────────────── */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(5,7,12,.66); backdrop-filter: blur(4px); z-index: 100; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; animation: fade .2s ease; }
.modal { background: var(--card); border: 1px solid var(--border-strong); border-radius: 16px; padding: 26px; min-width: 440px; max-width: 560px; width: 100%; box-shadow: var(--shadow); animation: pop .22s cubic-bezier(.18,.89,.32,1.28); max-height: 90vh; overflow-y: auto; }
@keyframes pop { from { opacity: 0; transform: scale(.95) translateY(8px); } to { opacity: 1; transform: none; } }
.modal h3 { margin-bottom: 6px; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.modal .modal-desc { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.modal label {
  display: block; color: var(--text-dim); font-size: 12px;
  margin-bottom: 6px; margin-top: 16px; font-weight: 600;
}
.modal label:first-of-type { margin-top: 0; }
.modal input, .modal select, .modal textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font); transition: .15s;
}
.modal input:focus, .modal select:focus, .modal textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal input::placeholder, .modal textarea::placeholder { color: var(--muted); opacity: .7; }
.modal textarea { resize: vertical; min-height: 80px; font-family: var(--mono); }
.modal .modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* Required-field marker + inline field hint (consistent across all modals) */
.req { color: var(--danger); font-weight: 700; margin-left: 2px; }
.field-hint { display: block; color: var(--muted); font-size: 11px; font-weight: 400; margin: 5px 0 0; line-height: 1.4; }
.modal label .field-opt { color: var(--muted); font-size: 11px; font-weight: 500; text-transform: none; letter-spacing: 0; margin-left: 4px; }

/* Generic form rows (used by the env-var / API-key install modal) */
.form-row { margin-top: 14px; }
.form-row:first-child { margin-top: 0; }
.form-label { display: block; color: var(--text-dim); font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.form-input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font); transition: .15s;
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-input::placeholder { color: var(--muted); opacity: .7; }

/* Inline checkbox label (OAuth toggle etc.) */
.check-inline { display: flex; align-items: center; gap: 9px; margin-top: 4px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text-dim); text-transform: none; letter-spacing: 0; }
.check-inline input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.modal-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; }
.modal-icon.warn { background: rgba(245,158,11,.14); color: var(--warning); }
.modal-icon svg { width: 20px; height: 20px; }

/* ── Details / Summary (OAuth accordion in server modal) ── */
.modal details { margin-top: 14px; }
.modal details summary {
  cursor: pointer; list-style: none; color: var(--accent-hover);
  font-size: 13px; font-weight: 600;
  padding: 10px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; display: flex; align-items: center; gap: 8px;
  user-select: none;
}
.modal details summary::-webkit-details-marker { display: none; }
.modal details summary::before { content: '▸'; font-size: 12px; transition: transform .2s; color: var(--muted); }
.modal details[open] summary::before { transform: rotate(90deg); }
.modal details > div {
  margin-top: 6px; padding: 14px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.modal details > div label:first-child { margin-top: 0; }

/* ── Toggle ─────────────────────────────────────────── */
.toggle-switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--border-strong); border-radius: 22px; transition: .2s; }
.toggle-slider:before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s; }
input:checked + .toggle-slider { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
input:checked + .toggle-slider:before { transform: translateX(16px); }

/* ── Styled checkboxes for list modals ──────────────── */
.form-check {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  transition: background .12s; border-bottom: 1px solid var(--border);
}
.form-check:last-child { border-bottom: none; }
.form-check:hover { background: rgba(255,255,255,.04); }
.form-check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; min-width: 18px; flex-shrink: 0;
  background: var(--bg); border: 2px solid var(--border-strong);
  border-radius: 5px; cursor: pointer; transition: background .15s, border-color .15s;
  position: relative; margin: 0;
}
.form-check input[type="checkbox"]:checked {
  background: var(--accent); border-color: var(--accent);
}
.form-check input[type="checkbox"]:checked::after {
  content: ''; position: absolute;
  left: 4px; top: 1px; width: 6px; height: 10px;
  border: 2px solid #fff; border-top: none; border-left: none;
  transform: rotate(45deg);
}
.form-check .fc-main { flex: 1; min-width: 0; font-size: 13px; color: var(--text); font-weight: 500; }
.form-check .fc-sub { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.form-check-list { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }

/* ── Inline toggle row (for enabled/rate-limit in perms modal) ── */
.pref-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px;
}
.pref-row .pref-label { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; }
.pref-row .pref-hint { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; font-weight: 400; }
.pref-row input[type="number"] {
  width: 120px; background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text); padding: 7px 10px; border-radius: 8px; font-size: 13px;
  font-family: var(--font);
}
.pref-row input[type="number"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Per-server rate-limit field inside the styled checkbox list.
   Two classes beats `.modal input { width:100% }`, keeping it compact + right-aligned. */
.form-check .fc-rate {
  width: 86px; flex: 0 0 auto; text-align: right;
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  padding: 6px 9px; border-radius: 7px; font-size: 12px; font-family: var(--font);
}
.form-check .fc-rate:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.fc-rate-hint {
  padding: 8px 12px; font-size: 11px; color: var(--muted);
  background: rgba(255,255,255,.02); border-top: 1px dashed var(--border);
}

/* Consistent number inputs everywhere - drop the ugly native dark spinners. */
.modal input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.modal input[type="number"]::-webkit-outer-spin-button,
.modal input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Section heading inside list modals (Servers / Tool Groups) */
.perm-section { margin-bottom: 18px; }
.perm-section:last-child { margin-bottom: 0; }
.perm-section-title {
  font-weight: 600; font-size: 12px; color: var(--muted); margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: .5px;
}
.pref-row input[type="number"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── Health check modal ─────────────────────────────── */
.health-grid { display: flex; gap: 10px; margin-bottom: 14px; }
.health-stat { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; text-align: center; }
.health-stat .hs-val { font-size: 20px; font-weight: 800; color: var(--text); }
.health-stat .hs-lbl { font-size: 10px; color: var(--muted); margin-top: 3px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }

/* ── Toasts ─────────────────────────────────────────── */
#toastHost { position: fixed; top: 18px; right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 10px; width: 360px; max-width: calc(100vw - 36px); }
.toast {
  position: relative; overflow: hidden;
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--card); border: 1px solid var(--border-strong); border-left-width: 4px;
  border-radius: var(--radius-sm); padding: 13px 14px; box-shadow: var(--shadow);
  animation: toastIn .3s cubic-bezier(.18,.89,.32,1.28);
}
.toast.out { animation: toastOut .25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(110%); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(110%); } }
.toast .t-icon { width: 22px; height: 22px; flex-shrink: 0; display: grid; place-items: center; }
.toast .t-icon svg { width: 20px; height: 20px; }
.toast .t-body { flex: 1; min-width: 0; }
.toast .t-title { font-weight: 600; font-size: 13.5px; color: var(--text); }
.toast .t-msg { font-size: 12.5px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.toast .t-close { background: none; border: none; color: var(--muted); cursor: pointer; padding: 2px; border-radius: 5px; line-height: 0; }
.toast .t-close:hover { color: var(--text); background: rgba(255,255,255,.06); }
.toast .t-bar { position: absolute; bottom: 0; left: 0; height: 3px; background: currentColor; opacity: .55; animation: tbar linear forwards; }
@keyframes tbar { from { width: 100%; } to { width: 0; } }
.toast.success { border-left-color: var(--success); } .toast.success .t-icon, .toast.success .t-bar { color: var(--success); }
.toast.danger  { border-left-color: var(--danger); }  .toast.danger .t-icon,  .toast.danger .t-bar  { color: var(--danger); }
.toast.warning { border-left-color: var(--warning); } .toast.warning .t-icon, .toast.warning .t-bar { color: var(--warning); }
.toast.info    { border-left-color: var(--info); }    .toast.info .t-icon,    .toast.info .t-bar    { color: var(--info); }

/* ── Tablet ──────────────────────────────────────────── */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; overflow-x: hidden; }
  .side-nav { flex-direction: row; flex-wrap: nowrap; flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav .nav-label { display: none; }
  .side-nav button .count { display: none; }
  .side-nav button { flex-shrink: 0; }
  .side-foot { flex: 0 0 100%; }
  .topbar { padding: 14px 20px; }
  .content { padding: 20px 20px 40px; }
}

/* ── Mobile ──────────────────────────────────────────── */
@media (max-width: 540px) {
  .topbar { padding: 10px 14px; }
  .topbar .page-sub { display: none; }
  .content { padding: 14px 14px 40px; }
  .search { width: auto; min-width: 100px; flex: 1; }
  .toolbar { flex-wrap: wrap; }
  /* tables: enable horizontal scroll */
  .card { overflow-x: auto; }
  table { min-width: 480px; }
  /* metrics: 2 per row */
  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  /* modal - bottom sheet; !important overrides inline style="" attributes */
  .modal-backdrop { padding: 0 !important; align-items: flex-end !important; }
  .modal { border-radius: 18px 18px 0 0 !important; max-height: 92dvh !important; max-width: 100% !important; width: 100% !important; min-width: 0 !important; }
  .modal-head { padding: 14px 16px 12px !important; gap: 12px !important; }
  .modal-body { padding: 14px 16px !important; }
  .modal-footer,
  .modal .modal-footer { padding: 10px 16px !important; margin-top: 0 !important; }
  /* transport grid: 2×2 instead of 4×1 */
  [data-tgrid] { grid-template-columns: repeat(2, 1fr) !important; }
  .transport-card { padding: 12px 6px 10px !important; }
}

/* ── Small mobile ────────────────────────────────────── */
@media (max-width: 400px) {
  .side-nav button { font-size: 12px; padding: 7px 8px; }
  .topbar { padding: 8px 12px; }
  .content { padding: 10px 10px 40px; }
}
