/* ===========================================================================
   Executive Dashboard — design system
   Hand-written, build-step-free, self-contained. Light + dark themes.
   =========================================================================== */

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;

  /* Brand */
  --brand: #4f46e5;
  --brand-600: #4338ca;
  --brand-700: #3730a3;
  --brand-soft: rgba(79, 70, 229, 0.12);

  /* Light theme surfaces */
  --bg: #f4f5fb;
  --bg-elev: #ffffff;
  --sidebar-bg: #111827;
  --sidebar-fg: #cbd5e1;
  --sidebar-fg-strong: #ffffff;
  --sidebar-active: rgba(99, 102, 241, 0.22);
  --card-bg: #ffffff;
  --border: #e6e8f0;
  --border-strong: #d3d7e4;

  /* Text */
  --text: #1e2433;
  --text-muted: #6b7280;
  --text-faint: #9aa1af;

  /* Status */
  --green: #16a34a; --green-bg: rgba(22, 163, 74, 0.12);
  --red: #dc2626;   --red-bg: rgba(220, 38, 38, 0.12);
  --amber: #d97706; --amber-bg: rgba(217, 119, 6, 0.14);
  --blue: #2563eb;  --blue-bg: rgba(37, 99, 235, 0.12);
  --gray: #64748b;  --gray-bg: rgba(100, 116, 139, 0.12);

  /* (stat card styles appended near KPI section) */
/* Chart palette (exposed to JS) */
  --chart-1: #4f46e5; --chart-2: #06b6d4; --chart-3: #22c55e;
  --chart-4: #f59e0b; --chart-5: #ef4444; --chart-6: #8b5cf6;
  --chart-7: #ec4899; --chart-8: #14b8a6;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.16);
  --sidebar-w: 252px;
  --topbar-h: 64px;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --bg-elev: #131a2c;
  --sidebar-bg: #0a0e1a;
  --sidebar-fg: #9aa6bd;
  --sidebar-fg-strong: #ffffff;
  --sidebar-active: rgba(99, 102, 241, 0.28);
  --card-bg: #131a2c;
  --border: #232c43;
  --border-strong: #2e3852;
  --text: #e6e9f2;
  --text-muted: #97a0b5;
  --text-faint: #6b7488;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transition: transform 0.22s ease;
}
.sidebar__brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  color: var(--sidebar-fg-strong);
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sidebar__brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #06b6d4);
  display: grid; place-items: center; color: #fff; font-weight: 800;
}
.sidebar__nav { padding: 14px 12px; overflow-y: auto; flex: 1; }
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint); padding: 16px 12px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin: 2px 0; border-radius: 10px;
  color: var(--sidebar-fg); font-weight: 500; font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: var(--sidebar-fg-strong); }
.nav-link.active { background: var(--sidebar-active); color: var(--sidebar-fg-strong); }
.nav-link svg { width: 18px; height: 18px; flex: none; opacity: 0.9; }
.sidebar__footer { padding: 14px; border-top: 1px solid rgba(255,255,255,0.06); }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-size: 17px; font-weight: 650; }
.topbar__spacer { flex: 1; }
.topbar__user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}

.content { padding: 24px; flex: 1; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--text-muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

/* hamburger (mobile) */
.icon-btn {
  display: none; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  cursor: pointer; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg); }

/* ----------------------------------------------------------------- Cards -- */
.grid { display: grid; gap: 18px; }
.grid-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; } .span-8 { grid-column: span 8; }
.span-9 { grid-column: span 9; } .span-12 { grid-column: span 12; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.card__head h3 { font-size: 14.5px; }
.card__head .spacer { flex: 1; }
.card__body { padding: 18px; }

/* KPI cards */
.kpi { padding: 18px 18px 16px; }
.kpi__label { color: var(--text-muted); font-size: 12.5px; font-weight: 550; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi__value { font-size: 28px; font-weight: 720; margin-top: 8px; letter-spacing: -0.02em; }
.kpi__delta { margin-top: 8px; font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.kpi__delta.up { color: var(--green); }
.kpi__delta.down { color: var(--red); }
.kpi__icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); float: right; }

/* Stat card (value + delta + sparkline + target/progress/badge) */
.stat { padding: 18px; display: flex; flex-direction: column; gap: 10px; height: 100%; min-height: 120px; }
.stat__head { display: flex; align-items: center; gap: 8px; }
.stat__label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.stat__row { display: flex; align-items: center; gap: 14px; flex: 1; min-height: 64px; }
.stat__main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; flex: 0 1 auto; }
.stat__value { font-size: 30px; font-weight: 720; letter-spacing: -0.02em; color: var(--text); line-height: 1.1; }
.stat__spark { flex: 1 1 45%; height: 100%; min-height: 56px; max-width: 62%; }
.stat__target { font-size: 12px; color: var(--text-muted); }
.stat__progress { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.stat__progress-bar { height: 100%; background: var(--brand); border-radius: 999px; transition: width 0.3s; }
.delta-chip { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.delta-chip.up { color: var(--green); background: var(--green-bg); }
.delta-chip.down { color: var(--red); background: var(--red-bg); }

/* Panel (grouped executive card) */
.panel { display: flex; flex-direction: column; height: 100%; }
.panel__title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel__body { padding: 16px 18px; display: flex; flex-direction: column; gap: 16px; flex: 1; min-height: 0; }
.panel__primary { display: flex; align-items: center; gap: 16px; }
.panel__pmain { flex: 0 1 auto; min-width: 0; }
.panel__pvalue { font-size: 30px; font-weight: 720; letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; line-height: 1.1; }
.panel__spark { flex: 1 1 45%; height: 96px; min-width: 110px; }
.panel__subs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: auto; }
.panel__sub { background: var(--bg); border-radius: 11px; padding: 12px 10px; text-align: center; }
.panel__sublabel { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.03em; }
.panel__subval { font-size: 18px; font-weight: 720; margin-top: 6px; color: var(--text); }
.panel__subtarget { font-size: 11px; margin-top: 4px; }
.panel__rowitem { display: flex; align-items: center; gap: 12px; }
.panel__rowitem--boxed { background: var(--bg); border-radius: 12px; padding: 14px 16px; }
.panel__rowmain { flex: 1; min-width: 0; }
.panel__rowvalrow { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.panel__rowval { font-size: 24px; font-weight: 720; color: var(--text); letter-spacing: -0.01em; }
.panel__rowval small { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.panel__rowval.neg { color: var(--red); }
.panel__rowspark { width: 130px; height: 46px; flex: none; }

/* ---------------------------------------------------------------- Charts -- */
.chart { width: 100%; min-height: 280px; }
.chart-sm { min-height: 220px; }
.chart-lg { min-height: 360px; }

.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; min-height: 200px; color: var(--text-muted); text-align: center; padding: 24px;
}
.state svg { width: 38px; height: 38px; opacity: 0.5; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--brand);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* htmx loading indicator */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

/* ---------------------------------------------------------------- Badges -- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { color: var(--green); background: var(--green-bg); }
.badge-red   { color: var(--red);   background: var(--red-bg); }
.badge-amber { color: var(--amber); background: var(--amber-bg); }
.badge-blue  { color: var(--blue);  background: var(--blue-bg); }
.badge-gray  { color: var(--gray);  background: var(--gray-bg); }

/* ----------------------------------------------------------------- Table -- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; color: var(--text-muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.03em; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.table tbody tr:hover { background: var(--bg); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* --------------------------------------------------------------- Buttons -- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 9px 15px; border-radius: 10px; font-weight: 600; font-size: 13.5px;
  border: 1px solid transparent; background: var(--bg-elev); color: var(--text);
  transition: all 0.15s; line-height: 1;
}
.btn:hover { box-shadow: var(--shadow-sm); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); color: #fff; }
.btn-outline { border-color: var(--border-strong); background: var(--bg-elev); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

/* ----------------------------------------------------------------- Forms -- */
.form-row { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label, .form-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--text); }
.form-input, input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="url"], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  font-size: 14px; font-family: inherit; transition: border 0.15s, box-shadow 0.15s;
}
.form-input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.help-text { color: var(--text-faint); font-size: 12px; margin-top: 5px; }
.errorlist { list-style: none; padding: 0; margin: 6px 0 0; color: var(--red); font-size: 12.5px; }
.field-checkbox { display: flex; align-items: center; gap: 8px; }
.field-checkbox input { width: auto; }

/* Multi-select rendered as a checkbox list (dashboard builder) */
.checkbox-list ul { list-style: none; margin: 0; padding: 8px; border: 1px solid var(--border-strong);
  border-radius: 10px; max-height: 180px; overflow-y: auto; background: var(--bg-elev); }
.checkbox-list li { padding: 5px 4px; border-radius: 7px; }
.checkbox-list li:hover { background: var(--bg); }
.checkbox-list li label { display: flex; align-items: center; gap: 9px; margin: 0; font-weight: 500; cursor: pointer; }
.checkbox-list li input { width: auto; margin: 0; }
.checkbox-list:empty::after,
.checkbox-list ul:empty::after { content: "No options available yet."; color: var(--text-faint); font-size: 13px; }
/* Native multi-selects (if any remain) get a usable height */
select[multiple], select.form-multiselect, select.form-multiselect[multiple] { min-height: 120px; }

/* --------------------------------------------------------------- Generic -- */
.flex { display: flex; } .items-center { align-items: center; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.text-sm { font-size: 12.5px; }
.text-right { text-align: right; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.stat-pill { display: inline-flex; align-items: baseline; gap: 6px; }

/* Alerts / messages */
.alert { padding: 12px 16px; border-radius: 11px; margin-bottom: 14px; font-size: 13.5px; border: 1px solid transparent; }
.alert-success { background: var(--green-bg); color: var(--green); border-color: rgba(22,163,74,0.25); }
.alert-error { background: var(--red-bg); color: var(--red); border-color: rgba(220,38,38,0.25); }
.alert-warning { background: var(--amber-bg); color: var(--amber); }
.alert-info { background: var(--blue-bg); color: var(--blue); }

/* Cards grid for dashboard list */
.dash-card { display: block; padding: 20px; transition: transform 0.15s, box-shadow 0.15s; }
.dash-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.dash-card__type { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--brand); }
.dash-card__title { font-size: 17px; margin: 8px 0 6px; color: var(--text); }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 16px 18px; }
.filter-bar .form-row { margin: 0; }
.filter-bar .form-input, .filter-bar select, .filter-bar input { min-width: 150px; }

/* Empty list */
.empty-block { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-block svg { width: 48px; height: 48px; opacity: 0.4; margin-bottom: 12px; }

/* Dropdown (Alpine) */
.dropdown { position: relative; }
.dropdown__menu {
  /* Fixed positioning (coords set by window.dropdownMenu) so the menu is never
     clipped by an ancestor's overflow (e.g. scrollable table wrappers). */
  position: fixed; min-width: 180px; max-width: 90vw;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 1000;
}
.dropdown__item { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 8px; color: var(--text); font-size: 13.5px; cursor: pointer; }
.dropdown__item:hover { background: var(--bg); }

/* Modal (Alpine) */
.modal-overlay { position: fixed; inset: 0; background: rgba(8, 12, 24, 0.55); z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--bg-elev); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; }
.modal__head { padding: 18px 20px; border-bottom: 1px solid var(--border); font-weight: 650; }
.modal__body { padding: 20px; }
.modal__foot { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { padding: 10px 16px; font-weight: 600; font-size: 13.5px; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ------------------------------------------------------------ Responsive -- */
@media (max-width: 1100px) {
  .span-3 { grid-column: span 6; } .span-4 { grid-column: span 6; }
  .span-8 { grid-column: span 12; } .span-9 { grid-column: span 12; }
  .span-6 { grid-column: span 12; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .icon-btn { display: inline-flex; }
  .grid-12 > [class*="span-"] { grid-column: span 12; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}

/* Scrim for mobile sidebar */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 35; }

/* ---------------------------------------------------- GridStack builder -- */
.grid-stack { background: transparent; min-height: 200px; }
.grid-stack-item-content {
  inset: 0; background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
  display: flex;
}
.tile { display: flex; flex-direction: column; width: 100%; height: 100%; min-width: 0; }
.tile__head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: var(--bg-elev);
  cursor: move; user-select: none;
}
.tile__title { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile__type { font-size: 10px; }
.tile__spacer { flex: 1; }
.tile__btn {
  border: none; background: transparent; color: var(--text-muted); cursor: pointer;
  padding: 4px; border-radius: 6px; display: inline-flex; align-items: center;
}
.tile__btn:hover { background: var(--bg); color: var(--text); }
.tile__btn--danger:hover { color: var(--red); }
.tile__body { flex: 1; padding: 12px; overflow: auto; min-height: 0; }
.tile__body .chart { width: 100%; height: 100%; }
.tile__body .kpi__value { font-size: 24px; }
.grid-stack-item .ui-resizable-handle { opacity: 0.35; transition: opacity 0.15s; }
.grid-stack-item:hover .ui-resizable-handle { opacity: 1; }
.grid-stack-placeholder > .placeholder-content {
  border: 2px dashed var(--brand); border-radius: var(--radius); background: var(--brand-soft);
}

/* Login page */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-aside {
  background: linear-gradient(150deg, #111827, #1e1b4b 55%, #312e81);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-aside h2 { font-size: 30px; line-height: 1.2; max-width: 420px; }
.auth-main { display: grid; place-items: center; padding: 40px; background: var(--bg-elev); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
@media (max-width: 880px) { .auth-wrap { grid-template-columns: 1fr; } .auth-aside { display: none; } }

/* ===========================================================================
   Sync manager — module catalog + advanced model browser
   =========================================================================== */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.text-xs { font-size: 11px; }
.spinner-sm { width: 14px; height: 14px; border-width: 2px; display: inline-block; vertical-align: middle; }

.syncgroup { margin-bottom: 22px; }
.syncgroup__label {
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted); margin: 0 2px 10px;
}
.modgrid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.modcard {
  position: relative; display: flex; flex-direction: column;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.modcard:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.modcard.is-on { border-color: var(--green); }
.modcard.is-paused { opacity: .85; }
.modcard__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.modcard__title { font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.modcard__model { font-size: 12px; color: var(--text-muted); margin: 2px 0 6px; }
.modcard__desc { font-size: 13px; color: var(--text-muted); line-height: 1.45; flex: 1; }
.modcard__foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.modcard__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.modcard__actions form { margin: 0; }

/* Toggle switch */
.switch { position: relative; display: inline-flex; cursor: pointer; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 40px; height: 22px; border-radius: 999px; background: var(--gray-bg);
  border: 1px solid var(--border); transition: background .15s; position: relative;
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s;
}
.switch input:checked + .switch__track { background: var(--brand); border-color: var(--brand); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Sticky "enable selected" bar */
.sync-actionbar {
  position: sticky; bottom: 16px; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--card-bg); border: 1px solid var(--brand);
  border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow-lg);
  margin-top: 8px;
}

/* Accordion catalog (group -> tables) */
.acc { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; background: var(--card-bg); overflow: hidden; }
.acc__head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 13px 16px; background: transparent; border: 0; cursor: pointer;
  text-align: left; font: inherit; color: inherit;
}
.acc__head:hover { background: var(--bg-elev); }
.acc__chev { color: var(--text-faint); width: 14px; flex: none; font-size: 12px; }
.acc__title { font-weight: 650; font-size: 15px; }
.acc__meta { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.acc__meta .ok { color: var(--green); font-weight: 600; }
.acc__body { border-top: 1px solid var(--border); }

.trow { display: flex; align-items: center; gap: 14px; padding: 11px 16px; border-bottom: 1px solid var(--border); }
.trow:last-child { border-bottom: 0; }
.trow.is-on { background: var(--green-bg); }
.trow.is-paused { opacity: .75; }
.trow__main { flex: 1 1 auto; min-width: 0; }
.trow__title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.trow__model { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.trow__desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.trow__deps { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.trow__status { flex: 0 0 auto; text-align: right; }
.trow__ctl { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.trow__ctl form { margin: 0; }
@media (max-width: 680px) {
  .trow { flex-wrap: wrap; }
  .trow__status, .trow__ctl { flex-basis: 100%; }
}

/* Advanced browser */
.browse-controls { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.browse-controls .input { flex: 1; }
.browse-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 14px; }
@media (max-width: 820px) { .browse-cols { grid-template-columns: 1fr; } }
.browse-models, .browse-fields {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; max-height: 460px; overflow-y: auto; overflow-x: hidden; background: var(--bg-elev);
}
.modlist { display: flex; flex-direction: column; gap: 2px; }
.modlist__row {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; min-width: 0; text-align: left; background: transparent; border: 0;
  padding: 7px 9px; border-radius: var(--radius-sm); cursor: pointer;
}
.modlist__row > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modlist__row:hover { background: var(--card-bg); }

.fieldform { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.fieldform label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.fieldform .input { width: 100%; box-sizing: border-box; }
.fieldpick__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.fieldgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 2px 16px; }
.fieldgrid__item { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 0; cursor: pointer; min-width: 0; }
.fieldgrid__item input { flex: 0 0 auto; margin: 0; }
.fieldgrid__item .mono { font-size: 12px; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fieldgrid__item .text-xs { flex: 0 0 auto; color: var(--text-faint); }

/* ===========================================================================
   SQL Workspace
   =========================================================================== */
.sqllab { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 860px) { .sqllab { grid-template-columns: 1fr; } }

.sqllab__schema {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg);
  max-height: 78vh; overflow: auto; position: sticky; top: 12px;
}
.sqllab__schead { font-weight: 650; font-size: 13px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.sqllab__schlist { padding: 6px; }
.schema-table { border-radius: var(--radius-sm); }
.schema-table__row { display: flex; align-items: center; gap: 4px; }
.schema-table__name {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
  background: transparent; border: 0; cursor: pointer; text-align: left;
  padding: 6px 8px; border-radius: var(--radius-sm); color: inherit; font: inherit;
}
.schema-table__name:hover { background: var(--bg-elev); }
.schema-table__name .mono { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.schema-table__chev { color: var(--text-faint); flex: none; font-size: 11px; }
.schema-table__use {
  flex: none; width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg-elev); cursor: pointer; color: var(--text-muted); line-height: 1;
}
.schema-table__use:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.schema-cols { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 8px 10px 22px; }
.schema-col {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 9px; cursor: pointer; color: var(--text-muted);
}
.schema-col:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

.sqllab__main { min-width: 0; }
.sql-editor {
  width: 100%; min-height: 190px; resize: vertical; box-sizing: border-box;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px; line-height: 1.55; tab-size: 2;
  padding: 14px 16px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--card-bg); color: var(--text);
}
.sql-editor:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.sql-toolbar { display: flex; align-items: center; gap: 10px; margin: 10px 0 16px; }

.sql-results { min-width: 0; }
.sql-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.sql-result-table { max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.sql-result-table table { font-size: 12.5px; }
.sql-result-table thead th { position: sticky; top: 0; background: var(--bg-elev); z-index: 1; }

.sql-save { margin-top: 16px; }
.sql-save__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.sql-save__grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.sql-save__grid .input { width: 100%; box-sizing: border-box; }
.sql-save__foot { padding: 0 16px 16px; }

.dropdown__sep { height: 1px; background: var(--border); margin: 4px 0; }
.dropdown__pin { display: flex; gap: 6px; align-items: center; padding: 4px 10px; }
.dropdown__pin .input-sm { font-size: 12px; padding: 4px 6px; }
.input-sm { padding: 4px 8px; font-size: 12px; }

/* Sync backfill: progress bar + chunk-settings popover */
.progress { width: 150px; max-width: 100%; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; margin: 6px 0 2px; }
.progress__bar { height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }
.trow__ctl { position: relative; flex-wrap: wrap; }
.job-cfg {
  position: absolute; top: 100%; right: 0; z-index: 50; margin-top: 6px;
  background: var(--card-bg); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 12px; width: 230px;
}
.job-cfg__title { font-weight: 650; font-size: 12px; margin-bottom: 8px; }
.job-cfg label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--text-muted); margin-bottom: 8px; }
.job-cfg .input-sm { width: 100%; box-sizing: border-box; }

/* ===========================================================================
   Database dump import
   =========================================================================== */
.field { display: block; margin-bottom: 16px; }
.field__label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.dropzone {
  display: block; border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 26px; text-align: center; cursor: pointer; background: var(--bg-elev);
  transition: border-color .15s, background .15s; margin-bottom: 14px;
}
.dropzone:hover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.is-busy { opacity: .6; pointer-events: none; }
.dz-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone__inner { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-muted); }
.dropzone__inner svg { color: var(--brand); }

.dump-tables__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.dump-tables {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 2px 14px; max-height: 360px; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px;
}
.dump-table { display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 4px 0; cursor: pointer; min-width: 0; }
.dump-table .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dump-table .text-xs { flex: 0 0 auto; margin-left: auto; }
.dump-progress__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.dump-progress__head .spinner-sm { margin-right: 6px; }
