/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d0f1a;
  --bg-card:     #151829;
  --bg-input:    #1a1d30;
  --bg-hover:    #1e2238;
  --sidebar:     #111422;
  --border:      #252840;
  --border-light:#2e3354;
  --primary:     #6c63ff;
  --primary-h:   #7b73ff;
  --secondary:   #00d2ff;
  --success:     #22c55e;
  --danger:      #ef4444;
  --warning:     #f59e0b;
  --text:        #e2e4f0;
  --text-muted:  #7b82a8;
  --text-soft:   #a0a8c8;
  /* Aliases for component compatibility */
  --surface:     #151829;
  --surface-2:   #1a1d30;
  --surface-3:   #1e2238;
  --radius:      8px;
  --radius-md:   12px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --shadow-sm:   0 2px 8px rgba(0,0,0,.25);
}

html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: .85em;
       background: var(--bg-input); color: var(--secondary); padding: 2px 6px; border-radius: 4px; }

/* ─── Relation Ref Badges ────────────────────────────────────────────────────── */
.ref-badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: .75rem; font-weight: 500; border: none; cursor: default;
}
.ref-badge-empty {
  background: var(--bg-input); color: var(--text-muted);
  border: 1px solid var(--border);
}
.ref-badge-filled {
  background: rgba(249,115,22,.15); color: #fb923c;
  border: 1px solid rgba(249,115,22,.3); cursor: pointer; transition: all .15s;
}
.ref-badge-filled:hover { background: rgba(249,115,22,.25); transform: translateY(-1px); }

.col-type-hint {
  font-size: .68rem; color: var(--text-muted); font-weight: 400;
  margin-left: 4px; opacity: .7;
}

/* ─── Linked Records Panel ───────────────────────────────────────────────────── */
.linked-records-list { display: flex; flex-direction: column; gap: 2px; }
.linked-record-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: var(--radius); background: var(--bg-input); border: 1px solid var(--border);
  transition: border-color .15s;
}
.linked-record-row:hover { border-color: var(--primary); }
.linked-id {
  font-size: .75rem; font-weight: 600; color: var(--text-muted);
  font-family: monospace; min-width: 40px;
}
.linked-label { font-size: .85rem; color: var(--text); flex: 1; }
.linked-record-photo {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  flex-shrink: 0; border: 1px solid var(--border);
}
.linked-record-photo-ph {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-hover); color: var(--text-muted);
  font-size: .68rem; font-weight: 600; font-family: monospace; border: 1px solid var(--border);
}
.linked-record-fields { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.linked-field { font-size: .82rem; color: var(--text-muted); }
.linked-field b { color: var(--text); font-weight: 600; }

/* Conditional formatting — column-targeted rule wrapper (row-level rules are
   applied as inline styles directly on the <tr>, no class needed there) */
.fmt-rule-cell {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  line-height: 1.5;
}

/* ─── Nav Dropdown ──────────────────────────────────────────────────────────── */
.nav-user-wrap { position: relative; }
.nav-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0;
  background: #151829; border: 1px solid var(--border-light);
  border-radius: var(--radius-md); min-width: 190px;
  box-shadow: 0 16px 48px rgba(0,0,0,.9); z-index: 9999; overflow: hidden;
}
.nav-dropdown-item {
  display: block; padding: 10px 16px; color: var(--text-soft);
  font-size: .83rem; text-decoration: none; transition: background .15s;
}
.nav-dropdown-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-dropdown-item.danger { color: var(--danger); }
.nav-dropdown-item.danger:hover { background: rgba(239,68,68,.1); }
.nav-dropdown-divider { border-top: 1px solid var(--border); margin: 4px 0; }

/* ─── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

/* ─── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 100; height: 56px; padding: 0 24px;
  background: rgba(13,15,26,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.navbar-brand { display: flex; align-items: center; gap: 10px; font-size: 1.05rem;
  font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.brand-icon { font-size: 1.4rem; color: var(--primary); }
.brand-icon-lg { font-size: 3rem; color: var(--primary); display: block; }
.navbar-right { display: flex; align-items: center; gap: 16px; }
.nav-app-name { font-size: .8rem; color: var(--text-muted);
  background: var(--bg-input); padding: 3px 10px; border-radius: 20px;
  border: 1px solid var(--border); }
.nav-user { display: flex; align-items: center; gap: 8px; color: var(--text-soft); font-size: .85rem; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: .7rem;
  font-weight: 700; color: #fff; }
.role-badge { font-size: .7rem; background: var(--bg-input); color: var(--text-muted);
  padding: 2px 8px; border-radius: 20px; border: 1px solid var(--border); }

/* ─── Page Wrapper ──────────────────────────────────────────────────────────── */
.page-wrapper { max-width: 1400px; margin: 0 auto; padding: 28px 24px; }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); border: 1px solid transparent;
  font-size: .85rem; font-weight: 500; cursor: pointer; transition: all .15s;
  text-decoration: none; white-space: nowrap; line-height: 1;
}
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--bg-input); color: var(--text-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn {
  background: none; border: none; cursor: pointer; padding: 5px 7px; border-radius: 6px;
  color: var(--text-muted); font-size: .85rem; transition: all .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.danger:hover { background: rgba(239,68,68,.15); color: var(--danger); }

/* ─── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: .82rem;
  font-weight: 500; color: var(--text-soft); }
.form-control {
  width: 100%; padding: 9px 12px; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .85rem; transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,.2); }
.form-control:disabled { opacity: .5; cursor: not-allowed; }
.form-control::placeholder { color: var(--text-muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; }

/* ─── Searchable relation dropdown (Add/Edit Record modal) ────────────────── */
.rel-search-wrap { position: relative; }
.rel-search-menu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  max-height: 220px; overflow-y: auto; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 4px;
}
.rel-search-menu.open { display: block; }
.rel-search-item {
  padding: 8px 10px; border-radius: 6px; font-size: .85rem; cursor: pointer; color: var(--text);
}
.rel-search-item:hover, .rel-search-item.active { background: rgba(108,99,255,.14); }
.rel-search-item.rel-search-clear { color: var(--text-muted); font-style: italic; }
.rel-search-empty { padding: 8px 10px; font-size: .82rem; color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.form-section-title { font-size: .78rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .8px; margin-bottom: 12px; }
.req { color: var(--danger); margin-left: 2px; }
.hint { font-size: .78rem; color: var(--text-muted); margin-top: 5px; display: block; }

/* ─── Checkboxes & Toggles ──────────────────────────────────────────────────── */
.checkbox-row { display: flex; flex-wrap: wrap; gap: 14px; }
.checkbox-label { display: flex; align-items: center; gap: 7px; cursor: pointer;
  font-size: .83rem; color: var(--text-soft); }
.checkbox-label input[type="checkbox"] { accent-color: var(--primary); width: 15px; height: 15px; }

.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toggle-label {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color .15s;
}
.toggle-label:hover { border-color: var(--border-light); }
.toggle-label input[type="checkbox"] { accent-color: var(--primary); width: 15px; height: 15px;
  margin-top: 3px; flex-shrink: 0; }
.toggle-text { flex: 1; }
.toggle-text strong { display: block; font-size: .83rem; color: var(--text); }
.toggle-text small { font-size: .75rem; color: var(--text-muted); }
.toggle-label.disabled-toggle { opacity: .45; cursor: not-allowed; }

/* ─── Auth Page ─────────────────────────────────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-container { width: 100%; max-width: 420px; padding: 24px; }
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 { font-size: 1.6rem; font-weight: 700; margin: 12px 0 8px; }
.auth-logo p { color: var(--text-muted); font-size: .88rem; }
.auth-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 28px; box-shadow: var(--shadow); }
.auth-card h2 { font-size: 1.2rem; margin-bottom: 20px; }
.auth-hint { text-align: center; color: var(--text-muted); font-size: .78rem; margin-top: 14px; }
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: .83rem; margin-bottom: 16px; }
.alert-danger { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }

/* ─── Dashboard ─────────────────────────────────────────────────────────────── */
.dashboard-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.dashboard-header h2 { font-size: 1.4rem; font-weight: 700; }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.app-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 20px; transition: border-color .2s, box-shadow .2s; display: flex; flex-direction: column;
}
.app-card:hover { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.app-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.app-icon { width: 44px; height: 44px; border-radius: 10px; background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
  font-weight: 700; color: #fff; }
.app-card-actions { display: flex; gap: 4px; }
.app-name { font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.app-desc { color: var(--text-muted); font-size: .82rem; margin-bottom: 14px; flex: 1;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.app-meta { display: flex; justify-content: space-between; color: var(--text-muted);
  font-size: .78rem; margin-bottom: 16px; }
.app-card-footer { display: flex; gap: 8px; }

/* ─── Empty State ───────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 80px 20px; }
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); margin-bottom: 20px; }

/* ─── Builder Layout ────────────────────────────────────────────────────────── */
.builder-layout, .data-layout {
  display: flex; height: calc(100vh - 56px); overflow: hidden; position: relative;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.builder-sidebar, .data-sidebar {
  width: 240px; min-width: 240px; background: var(--sidebar);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  transition: width .16s ease, min-width .16s ease, opacity .1s ease;
}

/* ─── Tables bar hide/unhide ──────────────────────────────────────────────────
   "Hide" lives inline in the sidebar header (a normal button, no overlap risk).
   "Unhide" is a small fixed tab pinned to the viewport, driven off a class on
   <body> — so it stays reachable no matter what page state the sidebar is in,
   and isn't affected by the sidebar's own overflow/clipping. Remembered
   per-browser via localStorage, same behavior on data.php and builder.php. */
.builder-layout.sidebar-hidden .builder-sidebar,
.data-layout.sidebar-hidden .data-sidebar {
  width: 0; min-width: 0; opacity: 0; overflow: hidden;
  border-right: none; pointer-events: none;
}
.tables-bar-hide-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 1px solid var(--border); border-radius: var(--radius, 6px);
  color: var(--text-muted); font-size: .72rem; font-weight: 600;
  padding: 4px 8px; cursor: pointer; line-height: 1; white-space: nowrap;
}
.tables-bar-hide-btn:hover { background: var(--bg-hover); color: var(--text); }
.tables-bar-unhide-tab {
  display: none; align-items: center; gap: 6px;
  position: fixed; top: 66px; left: 12px; z-index: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  color: var(--text-soft); font-size: .74rem; font-weight: 600;
  padding: 7px 14px 7px 12px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.tables-bar-unhide-tab:hover { background: var(--bg-hover); color: var(--text); }
body.tables-bar-hidden .tables-bar-unhide-tab { display: inline-flex; }
.sidebar-header {
  padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-header h4 { font-size: .88rem; font-weight: 600; color: var(--text-soft); }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); margin-top: auto; }
.table-list { list-style: none; padding: 0; }
.table-list-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px;
  border-radius: var(--radius); cursor: pointer; color: var(--text-soft);
  font-size: .83rem; transition: background .15s; position: relative;
}
.table-list-item:hover { background: var(--bg-hover); }
.table-list-item.active { background: rgba(108,99,255,.15); color: var(--primary); }
.table-list-item a { color: inherit; text-decoration: none; display: flex; align-items: center;
  gap: 8px; flex: 1; }
.table-icon { opacity: .6; font-size: .9rem; }
.table-label { flex: 1; }
.table-actions-inline { display: none; gap: 2px; }
.table-list-item:hover .table-actions-inline { display: flex; }
.table-actions-inline button {
  background: none; border: none; cursor: pointer; padding: 2px 5px;
  border-radius: 4px; color: var(--text-muted); font-size: .8rem;
}
.table-actions-inline button:hover { background: var(--border); color: var(--text); }
.table-list-empty { padding: 20px 10px; color: var(--text-muted); font-size: .82rem;
  text-align: center; font-style: italic; }

/* ─── Table Groups ("heads") — collapsible sidebar sections ─────────────────── */
#table-groups-wrap { flex: 1; overflow-y: auto; padding: 8px; }
.table-group { margin-bottom: 2px; }
.table-group-header {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  border-radius: var(--radius); cursor: pointer; font-size: .78rem;
  font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em;
}
.table-group-header:hover { background: var(--bg-hover); color: var(--text-soft); }
.tg-caret { display: inline-block; transition: transform .15s; font-size: .7rem; }
.table-group.collapsed .tg-caret { transform: rotate(-90deg); }
.tg-name { flex: 1; }
.tg-count {
  font-size: .7rem; font-weight: 600; background: var(--border); border-radius: 10px;
  padding: 1px 7px; text-transform: none; letter-spacing: 0;
}
.tg-actions { display: none; gap: 2px; }
.table-group-header:hover .tg-actions { display: flex; }
.tg-actions button {
  background: none; border: none; cursor: pointer; padding: 2px 5px;
  border-radius: 4px; color: var(--text-muted); font-size: .78rem;
}
.tg-actions button:hover { background: var(--border); color: var(--text); }
.table-group.collapsed .group-drop-zone { display: none; }
.table-group.force-open .group-drop-zone { display: block !important; }
.group-drop-zone { min-height: 6px; } /* keeps empty groups droppable as a target */
.tbl-drag-handle { cursor: grab; opacity: 0; font-size: .8rem; color: var(--text-muted); width: 12px; }
.table-list-item:hover .tbl-drag-handle { opacity: .6; }
.sortable-ghost { opacity: .35; }
.sortable-chosen { background: rgba(108,99,255,.1); }

/* ─── Screen widget cards (shared by screens.php and dashboard.php) ─────────── */
.screen-grid          { display:grid;grid-template-columns:repeat(6,1fr);gap:14px; }
.screen-widget-full   { grid-column:span 6; }
.screen-widget-half   { grid-column:span 3; }
.screen-widget-third  { grid-column:span 2; }
@media(max-width:900px){ .screen-widget-half,.screen-widget-third{grid-column:span 6;} }

.wcard            { background:var(--surface);border:1px solid var(--border);border-radius:12px;
                    overflow:hidden;display:flex;flex-direction:column; }
.wcard-head       { display:flex;justify-content:space-between;align-items:center;
                    padding:11px 15px;border-bottom:1px solid var(--border);background:var(--surface-2); }
.wcard-head h4    { margin:0;font-size:.88rem; }
.wcard-head a     { font-size:.73rem;color:var(--primary);text-decoration:none;white-space:nowrap; }
.wcard-body       { padding:0;overflow-x:auto; }
.wcard-table      { width:100%;border-collapse:collapse;font-size:.77rem; }
.wcard-table th   { text-align:left;padding:7px 12px;color:var(--text-muted);font-weight:700;
                    font-size:.68rem;text-transform:uppercase;letter-spacing:.03em;
                    border-bottom:1px solid var(--border);white-space:nowrap; }
.wcard-table td   { padding:7px 12px;border-bottom:1px solid var(--border);white-space:nowrap; }
.wcard-table tr:last-child td { border-bottom:none; }
.wcard-table tr[onclick]:hover td { background:var(--bg-hover); }
.wcard-empty      { padding:24px;text-align:center;color:var(--text-muted);font-size:.8rem; }

.branch-panels    { display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:14px; }
.branch-panel-title { display:flex;align-items:center;gap:6px;font-size:.8rem;font-weight:700;
                    padding:9px 13px;background:rgba(99,102,241,.06);border-bottom:1px solid var(--border); }

/* ─── Builder Main ──────────────────────────────────────────────────────────── */
.builder-main, .data-main {
  flex: 1; overflow-y: auto; padding: 24px; background: var(--bg);
}
.builder-placeholder { text-align: center; padding: 100px 20px; color: var(--text-muted); }
.placeholder-icon { font-size: 3rem; margin-bottom: 16px; opacity: .4; }
.builder-placeholder h3 { font-size: 1.1rem; margin-bottom: 8px; color: var(--text-soft); }

.columns-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.columns-header h3 { font-size: 1.1rem; font-weight: 600; }
.columns-header-actions { display: flex; gap: 8px; }

.data-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.data-header h3 { font-size: 1.1rem; font-weight: 600; }
.data-header-actions { display: flex; align-items: center; gap: 10px; }

/* ─── Data Table ────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto; overflow-y: auto; max-height: 75vh;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  cursor: grab; user-select: none; position: relative; --peek-fade-w: 52px;
}
.table-wrap:active { cursor: grabbing; }
/* Right-edge scroll hint fade */
.table-wrap::after {
  content: ''; position: absolute; top: 0; right: 0;
  width: var(--peek-fade-w); height: 100%;
  background: linear-gradient(to right, transparent, color-mix(in srgb, var(--bg, #fff) 88%, transparent));
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  pointer-events: none; opacity: 0; transition: opacity .35s; z-index: 5;
}
.table-wrap.peek-active::after { opacity: 1; }
/* Bouncing arrow badge */
.table-wrap .scroll-hint-arrow {
  position: absolute; top: 50%; right: 12px; transform: translateY(-50%);
  font-size: 1rem; pointer-events: none; z-index: 6;
  opacity: 0; transition: opacity .25s;
  background: var(--primary, #6c63ff); color: #fff;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(108,99,255,.35);
}
.table-wrap.peek-active .scroll-hint-arrow {
  opacity: 1;
  animation: scrollHintBounce .5s ease-in-out infinite alternate;
}
@keyframes scrollHintBounce {
  from { transform: translateY(-50%) translateX(0); }
  to   { transform: translateY(-50%) translateX(6px); }
}
.data-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
/* position:sticky here only works because .table-wrap above is height-bounded
   (max-height + overflow-y:auto) — without that, .table-wrap's overflow-x:auto
   (needed for horizontal drag-scroll) still makes it the sticky containing
   block, but with no bounded height there's nothing for the header to stick
   *within*, so it just scrolls away with the page instead of staying fixed. */
.data-table th {
  padding: 9px 12px; text-align: left; font-size: .72rem; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px;
  background: var(--sidebar); border-bottom: 2px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; z-index: 10;
  box-shadow: 0 2px 6px rgba(0,0,0,.14);
}
.data-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle; max-width: 220px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

/* ─── Grouped Report View (group → sub-group → rows, with SUM/COUNT) ────────── */
.group-header-row, .subgroup-header-row {
  cursor: pointer; user-select: none;
}
.group-header-row td, .subgroup-header-row td {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.group-header-row td {
  background: color-mix(in srgb, var(--primary, #6c63ff) 13%, var(--sidebar));
  font-weight: 700; font-size: .85rem;
}
.subgroup-header-row td {
  background: color-mix(in srgb, var(--primary, #6c63ff) 7%, var(--sidebar));
  font-weight: 600; font-size: .8rem; padding-left: 30px;
}
.group-header-row:hover td, .subgroup-header-row:hover td { filter: brightness(0.97); }
.grp-caret { display: inline-block; width: 14px; transition: transform .15s; font-size: .75rem; }
.grp-header-line {
  display: flex; align-items: center; justify-content: flex-start;
  gap: 10px; flex-wrap: wrap; text-align: left;
}
.grp-label { flex: 0 0 auto; }
.grp-count {
  font-size: .72rem; font-weight: 600; color: var(--text-muted);
  background: var(--border); border-radius: 10px; padding: 1px 8px;
}
.grp-aggs {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-left: 0 !important; margin-right: auto; text-align: left;
}
.grp-agg-item { font-size: .74rem; color: var(--text-muted); font-weight: 500; }
.grp-agg-item strong { color: var(--text); font-weight: 700; }
tr.grp-header-row.collapsed .grp-caret { transform: rotate(-90deg); }

/* ─── "Sum columns" totals bar (all-records aggregate, above the table) ──────── */
.sums-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 16px;
  background: color-mix(in srgb, var(--primary, #6c63ff) 7%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--primary, #6c63ff) 30%, var(--border));
  border-radius: 8px; padding: 9px 14px; margin-bottom: 12px; font-size: .82rem;
}
.sums-bar .sb-label {
  font-weight: 700; color: var(--primary, #6c63ff); font-size: .68rem;
  text-transform: uppercase; letter-spacing: .5px; white-space: nowrap;
}
.sums-bar .sb-item { color: var(--text-muted); white-space: nowrap; }
.sums-bar .sb-item strong { color: var(--text); font-weight: 700; margin-left: 3px; }

/* View toggle (flat ⇄ grouped) */
.view-mode-toggle {
  display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.view-mode-toggle button {
  background: var(--surface); border: none; padding: 5px 12px; font-size: .76rem;
  cursor: pointer; color: var(--text-muted);
}
.view-mode-toggle button.active { background: var(--primary); color: #fff; }
.view-mode-toggle button:not(:last-child) { border-right: 1px solid var(--border); }

/* Truncated text cell */
.cell-text {
  display: block; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 200px; cursor: default;
}
.cell-text.expanded {
  white-space: normal; word-break: break-word; max-width: 360px;
  cursor: default; background: var(--bg-input); padding: 6px 8px;
  border-radius: 6px; font-size: .78rem; line-height: 1.5;
}
.cell-expand-btn {
  display: inline-block; cursor: pointer; color: var(--primary);
  font-size: .68rem; margin-left: 4px; user-select: none;
  background: rgba(108,99,255,.12); padding: 1px 5px; border-radius: 4px;
  border: none; vertical-align: middle;
}
.cell-expand-btn:hover { background: rgba(108,99,255,.25); }

/* Number cells right-aligned */
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; font-size: .8rem; }

/* Row index */
.row-idx { color: var(--text-muted); font-size: .72rem; user-select: none; }

/* PDF history link */
.pdf-hist-link { font-size: .72rem; color: var(--primary); text-decoration: none; }
.pdf-hist-link:hover { text-decoration: underline; }


.type-badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: .72rem; font-weight: 500; text-transform: uppercase; letter-spacing: .4px;
}
.type-text, .type-email, .type-phone, .type-url, .type-longtext { background: rgba(59,130,246,.15); color: #60a5fa; }
.type-number { background: rgba(34,197,94,.15); color: #4ade80; }
.type-date, .type-datetime, .type-change_timestamp { background: rgba(168,85,247,.15); color: #c084fc; }
.type-boolean { background: rgba(245,158,11,.15); color: #fbbf24; }
.type-image, .type-file, .type-video { background: rgba(236,72,153,.15); color: #f472b6; }
.type-latlong { background: rgba(20,184,166,.15); color: #2dd4bf; }
.type-relation, .type-relation_ref { background: rgba(249,115,22,.15); color: #fb923c; }

.check-yes { color: var(--success); font-weight: 700; }
.check-no  { color: var(--border-light); }
.enum-badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .78rem;
  background: rgba(108,99,255,.13); color: var(--primary); font-weight: 500; }

/* Geo-status badge shown on latlong fields while HERE() is pending */
.geo-status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 20px; font-size: .75rem; font-weight: 500;
  background: rgba(245,158,11,.12); color: #b45309; border: 1px solid rgba(245,158,11,.3);
  margin-left: 6px; transition: background .3s, color .3s;
}
.geo-status-badge.geo-ok {
  background: rgba(34,197,94,.12); color: #15803d; border-color: rgba(34,197,94,.3);
}
.geo-status-badge.geo-error {
  background: rgba(239,68,68,.10); color: #dc2626; border-color: rgba(239,68,68,.25);
}
.geo-status-badge.geo-warn {
  background: rgba(245,158,11,.12); color: #b45309; border-color: rgba(245,158,11,.3);
}

.badge-all { display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: .72rem; background: rgba(108,99,255,.15); color: var(--primary); }
.role-tag  { display: inline-block; padding: 2px 7px; border-radius: 20px; margin: 1px;
  font-size: .72rem; background: var(--bg-input); color: var(--text-muted);
  border: 1px solid var(--border); }

.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }

/* ─── Modals ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-md); width: 100%; max-width: 520px;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.modal-md { max-width: 520px; }
.modal-lg { max-width: 720px; }
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.3rem;
  cursor: pointer; padding: 0 4px; line-height: 1; border-radius: 4px; }
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0;
}

/* ─── Relation Sub-fields ───────────────────────────────────────────────────── */
.relation-sub { background: rgba(249,115,22,.06); border: 1px solid rgba(249,115,22,.2);
  border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }

/* ─── Cell types ────────────────────────────────────────────────────────────── */
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); }
.link-cell { color: var(--primary); font-size: .82rem; }
.latlong-row { display: flex; gap: 8px; align-items: center; }

/* ─── File preview ──────────────────────────────────────────────────────────── */
.file-preview { margin-bottom: 8px; font-size: .8rem; }
.file-preview a { color: var(--primary); }

/* ─── Toast ─────────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 10000;
  display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 18px; border-radius: var(--radius); font-size: .83rem; font-weight: 500;
  color: #fff; box-shadow: var(--shadow); min-width: 220px; max-width: 360px;
  animation: slideUp .25s ease; border-left: 3px solid;
}
.toast-success { background: rgba(22,163,74,.95); border-color: var(--success); }
.toast-error   { background: rgba(185,28,28,.95); border-color: var(--danger); }
.toast-info    { background: rgba(37,99,235,.95); border-color: #60a5fa; }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }