/* ==========================================================================
   Efficient ERP — UI stylesheet
   Theme tokens arrive from /theme.css as html[data-theme="…"] { --bg … }.
   Fallback tokens below keep install/error pages styled without the DB.
   ========================================================================== */
:root {
  --bg: #f3f5f9; --surface: #fff; --surface-2: #f8fafc; --surface-3: #eef2f7; --border: #e2e8f0; --border-strong: #cbd5e1;
  --text: #0f172a; --muted: #64748b; --primary: #2563eb; --primary-text: #fff;
  --sidebar-bg: #0f172a; --sidebar-text: #cbd5e1; --sidebar-muted: #64748b; --sidebar-active: #1e293b; --sidebar-hover: #16213a;
  --topbar-bg: #fff; --success: #16a34a; --warning: #d97706; --danger: #dc2626; --info: #0891b2;
  --row-hover: #eef4ff; --row-alt: #fafbfd; --radius: 8px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --font: "Plus Jakarta Sans", "DM Sans", system-ui, -apple-system, "Segoe UI", "Noto Sans Bengali", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --fs: 13px; --row-h: 30px; --ctl-h: 30px; --gap: 12px;
  --primary-soft: color-mix(in srgb, var(--primary) 12%, transparent);
  --primary-softer: color-mix(in srgb, var(--primary) 6%, transparent);
  --sidebar-w: 248px; --topbar-h: 48px; --tabbar-h: 36px;
}
[data-density="comfortable"] { --fs: 14px; --row-h: 36px; --ctl-h: 36px; --gap: 16px; }
* { box-sizing: border-box; }
html, body { height: 100%; }
html { font-size: calc(var(--fs) * var(--scale, 1)); -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
code, pre, .mono { font-family: var(--mono); font-size: .92em; }
.ic { flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
::selection { background: var(--primary-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 35%, transparent); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: color-mix(in srgb, var(--muted) 60%, transparent); }
::-webkit-scrollbar-corner { background: transparent; }

/* ---------- Buttons & controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: var(--ctl-h); padding: 0 12px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: calc(var(--radius) - 2px); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s; }
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, #000); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-icon { width: var(--ctl-h); padding: 0; justify-content: center; }
.btn-sm { height: 26px; padding: 0 8px; font-size: .92em; }
.btn-lg { height: 42px; padding: 0 22px; font-size: 1.05em; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: calc(var(--radius) - 2px) 0 0 calc(var(--radius) - 2px); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 calc(var(--radius) - 2px) calc(var(--radius) - 2px) 0; }
.btn-group .btn.active { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 40%, transparent); z-index: 1; }

input, select, textarea { font: inherit; color: var(--text); }
.input, .form-grid input:not([type=checkbox]):not([type=radio]):not([type=color]), .form-grid select, .form-grid textarea, .ctl {
  width: 100%; height: var(--ctl-h); padding: 0 9px; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius) - 3px); outline: none; transition: border-color .12s, box-shadow .12s; }
.form-grid textarea, textarea.ctl { height: auto; min-height: 70px; padding: 7px 9px; resize: vertical; }
.input:focus, .form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus, .ctl:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=color] { width: 44px; height: var(--ctl-h); padding: 2px; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface); cursor: pointer; }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; padding-right: 26px !important; }

.form-grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); }
.form-grid.cols-1 { --cols: 1; } .form-grid.cols-2 { --cols: 2; } .form-grid.cols-3 { --cols: 3; } .form-grid.cols-4 { --cols: 4; }
.form-grid label, .fld { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: .93em; color: var(--muted); min-width: 0; }
.form-grid label.check, .fld.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); padding-top: 18px; }
.form-grid h3 { margin: 6px 0 -4px; font-size: 1em; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.fld .req { color: var(--danger); margin-left: 2px; }
.fld .help { font-weight: 400; font-size: .88em; color: var(--muted); }
.fld .err { font-weight: 500; font-size: .88em; color: var(--danger); }
.fld.invalid .ctl, .fld.invalid .combo-input { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 14%, transparent); }
.fld-section { grid-column: 1 / -1; font-weight: 700; font-size: .85em; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--border); padding: 8px 0 4px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-full { grid-column: 1 / -1; }
.fld .ctl[readonly] { background: var(--surface-2); color: var(--muted); }
.input-group { display: flex; } .input-group .ctl { border-radius: 5px 0 0 5px; } .input-group .btn { border-radius: 0 5px 5px 0; margin-left: -1px; }

/* combobox (lookup) */
.combo { position: relative; }
.combo-input { width: 100%; height: var(--ctl-h); padding: 0 26px 0 9px; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface); outline: none; }
.combo-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.combo-clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); cursor: pointer; padding: 3px; display: flex; }
.combo-list { position: fixed; z-index: 4600; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; min-width: 180px; padding: 4px; }
.combo-list div { padding: 6px 9px; border-radius: 4px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-list div.active, .combo-list div:hover { background: var(--primary-soft); color: var(--primary); }
.combo-list .empty { color: var(--muted); cursor: default; } .combo-list .empty:hover { background: none; color: var(--muted); }

/* ---------- Alerts / badges / cards ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius); border: 1px solid; margin-bottom: 12px; }
.alert-info { background: color-mix(in srgb, var(--info) 8%, var(--surface)); border-color: color-mix(in srgb, var(--info) 35%, transparent); }
.alert-success { background: color-mix(in srgb, var(--success) 8%, var(--surface)); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.alert-danger { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.alert-warning { background: color-mix(in srgb, var(--warning) 9%, var(--surface)); border-color: color-mix(in srgb, var(--warning) 35%, transparent); }
.badge { display: inline-flex; align-items: center; height: 19px; padding: 0 7px; border-radius: 10px; font-size: .82em; font-weight: 600; background: var(--surface-3); color: var(--muted); white-space: nowrap; }
.badge-success { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.badge-danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-warning { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.card-body { padding: 14px; }
.code-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px; overflow: auto; max-height: 340px; font-size: 12px; }
kbd { font-family: var(--mono); font-size: .8em; padding: 1px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); color: var(--muted); }

/* ==========================================================================
   SHELL
   ========================================================================== */
body.shell { overflow: hidden; }
.app { display: flex; height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; flex: none; transition: width .18s ease; position: relative; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; height: var(--topbar-h); padding: 0 14px; flex: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #fff; flex: none;
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 55%, #9333ea)); box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 45%, transparent); }
.brand-text { min-width: 0; line-height: 1.15; }
.brand-text b { display: block; font-size: 14px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { font-size: 11px; color: var(--sidebar-muted); white-space: nowrap; }
.side-search { margin: 4px 12px 8px; position: relative; flex: none; }
.side-search input { width: 100%; height: 30px; border-radius: 6px; border: 1px solid color-mix(in srgb, var(--sidebar-text) 14%, transparent); background: color-mix(in srgb, var(--sidebar-text) 6%, transparent);
  color: var(--sidebar-text); padding: 0 8px 0 30px; outline: none; font-size: 12.5px; }
.side-search input::placeholder { color: var(--sidebar-muted); }
.side-search input:focus { border-color: var(--primary); }
.side-search .ic { position: absolute; left: 9px; top: 7px; color: var(--sidebar-muted); }
.nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 2px 8px 12px; }
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav-item > a, .nav-item > .nav-group { display: flex; align-items: center; gap: 9px; padding: 0 10px; height: 32px; border-radius: 6px; color: var(--sidebar-text);
  cursor: pointer; user-select: none; white-space: nowrap; font-size: 13px; }
.nav-item > a:hover, .nav-item > .nav-group:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item > a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--primary); }
.nav-item .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-item .chev { transition: transform .15s; color: var(--sidebar-muted); }
.nav-item.open > .nav-group .chev { transform: rotate(90deg); }
.nav-item > ul { display: none; padding-left: 14px; margin-left: 14px; border-left: 1px solid color-mix(in srgb, var(--sidebar-text) 12%, transparent); }
.nav-item.open > ul { display: block; }
.nav-item .nb { font-size: 10px; padding: 1px 6px; border-radius: 8px; background: var(--primary); color: var(--primary-text); }
.nav-sep { height: 1px; margin: 6px 10px; background: color-mix(in srgb, var(--sidebar-text) 12%, transparent); }
.nav-group-root > .nav-group { font-weight: 600; }
.nav mark { background: color-mix(in srgb, var(--primary) 40%, transparent); color: #fff; border-radius: 2px; }
.side-foot { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-top: 1px solid color-mix(in srgb, var(--sidebar-text) 10%, transparent); flex: none; }
.side-foot .btn { color: var(--sidebar-text); }
.side-foot .btn:hover { background: var(--sidebar-hover); color: #fff; }
.side-foot .ver { font-size: 11px; color: var(--sidebar-muted); margin-left: auto; white-space: nowrap; }

/* collapsed sidebar */
.app.collapsed .sidebar { width: 56px; }
.app.collapsed .brand-text, .app.collapsed .side-search, .app.collapsed .nav-item .lbl, .app.collapsed .nav-item .chev, .app.collapsed .side-foot .ver, .app.collapsed .nav-item .nb { display: none; }
.app.collapsed .nav-item > ul { display: none !important; }
.app.collapsed .nav-item > a, .app.collapsed .nav-item > .nav-group { justify-content: center; padding: 0; }
.app.collapsed .nav { overflow: visible; }
.flyout { position: fixed; z-index: 2000; background: var(--sidebar-bg); color: var(--sidebar-text); border: 1px solid color-mix(in srgb, var(--sidebar-text) 15%, transparent); border-radius: 8px; padding: 6px; min-width: 220px; box-shadow: var(--shadow); max-height: 80vh; overflow: auto; }
.flyout .fly-title { font-weight: 700; padding: 6px 10px; color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: 6px; padding: 0 10px; background: var(--topbar-bg); border-bottom: 1px solid var(--border); flex: none; position: relative; z-index: 15; }
.topbar .spacer { flex: 1; }
.cmd-btn { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); color: var(--muted); cursor: pointer; min-width: 220px; font: inherit; }
.cmd-btn:hover { border-color: var(--border-strong); }
.cmd-btn kbd { margin-left: auto; }
.tb-select { height: 30px; border: 1px solid var(--border); border-radius: 6px; background-color: var(--surface); padding: 0 8px; max-width: 220px; cursor: pointer; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 3px 8px 3px 3px; border-radius: 20px; cursor: pointer; border: 1px solid transparent; }
.user-chip:hover { background: var(--surface-3); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: var(--primary-soft); color: var(--primary); flex: none; }
.user-chip .un { font-weight: 600; font-size: 12.5px; line-height: 1.1; }
.user-chip .ub { font-size: 11px; color: var(--muted); }

/* top menu mode */
.topnav { display: none; align-items: center; gap: 2px; height: 100%; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav > .tn-item { position: relative; }
.topnav > .tn-item > button { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 6px; border: 0; background: transparent; color: var(--text); cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.topnav > .tn-item > button:hover, .topnav > .tn-item > button.open { background: var(--surface-3); }
[data-menu-pos="top"] .sidebar { display: none; }
[data-menu-pos="top"] .topnav { display: flex; }
[data-menu-pos="top"] .brand-top { display: flex; }
.brand-top { display: none; align-items: center; gap: 8px; margin-right: 8px; font-weight: 700; white-space: nowrap; }
[data-menu-pos="right"] .app { flex-direction: row-reverse; }
[data-menu-pos="right"] .nav-item > a.active { box-shadow: inset -3px 0 0 var(--primary); }

/* tabs */
.tabbar { height: var(--tabbar-h); display: flex; align-items: flex-end; background: var(--surface-2); border-bottom: 1px solid var(--border); flex: none; padding: 0 4px; gap: 2px; }
.tabs { flex: 1; display: flex; align-items: flex-end; gap: 2px; overflow-x: auto; scrollbar-width: none; scroll-behavior: smooth; height: 100%; padding-top: 4px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: flex; align-items: center; gap: 6px; height: 31px; padding: 0 6px 0 11px; border: 1px solid transparent; border-bottom: 0; border-radius: 7px 7px 0 0;
  color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap; max-width: 220px; position: relative; font-size: 12.5px; font-weight: 500; flex: none; }
.tab:hover { background: var(--surface-3); color: var(--text); }
.tab.active { background: var(--bg); color: var(--text); border-color: var(--border); margin-bottom: -1px; height: 32px; }
.tab.active::before { content: ""; position: absolute; left: 8px; right: 8px; top: -1px; height: 2px; border-radius: 2px; background: var(--primary); }
.tab .t-title { overflow: hidden; text-overflow: ellipsis; }
.tab .t-close { width: 18px; height: 18px; border-radius: 4px; display: grid; place-items: center; color: var(--muted); opacity: .6; }
.tab .t-close:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); opacity: 1; }
.tab.pinned .t-close { display: none; }
.tab.pinned { padding-right: 11px; }
.tab.loading .t-icon { animation: spin 0.9s linear infinite; }
.tab.dragging { opacity: .4; }
.tab.drop-before { box-shadow: inset 2px 0 0 var(--primary); }
.tab-tools { display: flex; align-items: center; height: 100%; gap: 2px; }
.tab-tools .btn { height: 26px; width: 26px; }
@keyframes spin { to { transform: rotate(360deg); } }
.panes { flex: 1; position: relative; background: var(--bg); min-height: 0; }
.pane { position: absolute; inset: 0; display: none; }
.pane.active { display: block; }
.pane iframe { width: 100%; height: 100%; border: 0; display: block; background: var(--bg); }

/* dropdown & context menus */
.dropdown { position: fixed; z-index: 4600; min-width: 190px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.14); padding: 5px; animation: pop .1s ease-out; }
.dropdown .dd-item { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 5px; cursor: pointer; white-space: nowrap; color: var(--text); font-size: 13px; }
.dropdown .dd-item:hover { background: var(--surface-3); }
.dropdown .dd-item.danger { color: var(--danger); }
.dropdown .dd-item.disabled { opacity: .45; pointer-events: none; }
.dropdown .dd-item .dd-key { margin-left: auto; color: var(--muted); font-size: 11px; }
.dropdown .dd-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.dropdown .dd-head { padding: 6px 10px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
@keyframes pop { from { opacity: 0; transform: translateY(-3px) scale(.98); } to { opacity: 1; transform: none; } }

/* command palette */
.palette-back { position: fixed; inset: 0; background: rgba(2,6,23,.45); z-index: 4000; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; backdrop-filter: blur(2px); }
.palette { width: min(640px, 92vw); background: var(--surface); border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.35); overflow: hidden; border: 1px solid var(--border); }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 14px 16px; font-size: 15px; outline: none; background: transparent; }
.palette .pal-list { max-height: 50vh; overflow: auto; padding: 6px; }
.palette .pal-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.palette .pal-item.active { background: var(--primary-soft); }
.palette .pal-item .path { color: var(--muted); font-size: .88em; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50%; }
.palette .pal-foot { padding: 7px 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11.5px; display: flex; gap: 14px; }

/* ==========================================================================
   PAGES (inside tab iframes)
   ========================================================================== */
body.page { overflow: auto; }
.page-wrap { display: flex; flex-direction: column; height: 100vh; }
.page-wrap.scroll { height: auto; min-height: 100vh; }
.page-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); flex: none; flex-wrap: wrap; }
.page-head .ph-icon { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.page-head h1 { margin: 0; font-size: 1.22em; font-weight: 700; line-height: 1.2; }
.page-head .crumbs { font-size: .86em; color: var(--muted); }
.page-head .ph-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.page-body { flex: 1; min-height: 0; padding: 12px 16px; overflow: auto; }
.page-body.fill { display: flex; flex-direction: column; overflow: hidden; }
.error-page { display: grid; place-content: center; min-height: 100vh; text-align: center; padding: 20px; }
.error-code { font-size: 64px; font-weight: 800; color: var(--primary); line-height: 1; }
.error-msg { font-size: 16px; margin-top: 10px; max-width: 640px; }

.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.tabs-inline { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs-inline button { border: 0; background: none; padding: 8px 14px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; display: flex; gap: 6px; align-items: center; }
.tabs-inline button.active { color: var(--primary); border-bottom-color: var(--primary); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.stat { padding: 14px; display: flex; gap: 12px; align-items: center; }
.stat .s-ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.stat .s-val { font-size: 1.6em; font-weight: 800; line-height: 1.1; }
.stat .s-lbl { color: var(--muted); font-size: .9em; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; color: var(--text); transition: border-color .12s, transform .12s; }
.tile:hover { border-color: var(--primary); transform: translateY(-1px); }
.tile .ic { color: var(--primary); }

/* ==========================================================================
   DATA GRID
   ========================================================================== */
.eg { display: flex; flex-direction: column; min-height: 0; flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.eg-bar { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.eg-bar .eg-title { font-weight: 700; margin-right: 6px; display: flex; align-items: center; gap: 6px; }
.eg-bar .eg-q { width: 220px; height: 28px; }
.eg-bar .grow { flex: 1; }
.eg-bar .eg-sel { color: var(--primary); font-weight: 600; font-size: .92em; }
.eg-scroll { flex: 1; overflow: auto; position: relative; min-height: 120px; }
.eg table { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: max-content; min-width: 100%; }
.eg th, .eg td { height: var(--row-h); padding: 0 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; background: var(--surface); }
.eg thead th { position: sticky; top: 0; z-index: 3; background: var(--surface-2); font-weight: 600; font-size: .92em; color: var(--muted); user-select: none; }
.eg thead tr.eg-filter th { top: var(--row-h); padding: 3px 4px; background: var(--surface-2); }
.eg thead th .th-in { display: flex; align-items: center; gap: 4px; cursor: pointer; height: 100%; }
.eg thead th .th-in .lbl { overflow: hidden; text-overflow: ellipsis; }
.eg thead th .sort { color: var(--primary); display: none; }
.eg thead th.sorted .sort { display: inline-flex; }
.eg thead th.sorted { color: var(--text); }
.eg thead th .th-menu { margin-left: auto; opacity: 0; color: var(--muted); border-radius: 3px; display: flex; }
.eg thead th:hover .th-menu { opacity: 1; }
.eg thead th .th-menu:hover { background: var(--surface-3); color: var(--text); }
.eg .rz { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.eg .rz:hover, .eg .rz.active { background: color-mix(in srgb, var(--primary) 45%, transparent); }
.eg th.drop-before { box-shadow: inset 3px 0 0 var(--primary); }
.eg .fi { width: 100%; height: calc(var(--row-h) - 7px); border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; background: var(--surface); font-size: .92em; outline: none; min-width: 0; }
.eg .fi:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.eg .fi.has { border-color: var(--primary); background: var(--primary-softer); }
.eg tbody tr:nth-child(even) td { background: var(--row-alt); }
.eg.no-stripes tbody tr:nth-child(even) td { background: var(--surface); }
.eg tbody tr:hover td { background: var(--row-hover); }
.eg tbody tr.sel td { background: color-mix(in srgb, var(--primary) 13%, var(--surface)); }
.eg tbody tr { cursor: default; }
.eg td.num, .eg th.num { text-align: right; font-variant-numeric: tabular-nums; }
.eg td.c, .eg th.c { text-align: center; }
.eg .frz { position: sticky; z-index: 1; }
.eg thead .frz { z-index: 4; }
.eg .frz-last { box-shadow: 4px 0 6px -3px rgba(15,23,42,.18); border-right-color: var(--border-strong); }
.eg .chk { width: 34px; text-align: center; padding: 0; }
.eg tfoot td { position: sticky; bottom: 0; z-index: 2; background: var(--surface-3); font-weight: 700; border-top: 1px solid var(--border-strong); }
.eg tfoot .frz { z-index: 3; }
.eg-empty { padding: 40px; text-align: center; color: var(--muted); }
.eg-load { position: absolute; inset: 0; background: color-mix(in srgb, var(--surface) 55%, transparent); display: none; place-items: center; z-index: 10; }
.eg.loading .eg-load { display: grid; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
.eg-pager { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-top: 1px solid var(--border); font-size: .92em; color: var(--muted); flex-wrap: wrap; }
.eg-pager .grow { flex: 1; }
.eg-pager select, .eg-pager input { height: 26px; border: 1px solid var(--border); border-radius: 4px; background-color: var(--surface); padding: 0 6px; }
.eg-pager input { width: 54px; text-align: center; }
.eg .swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border-strong); vertical-align: -2px; margin-right: 5px; }
.eg .yes { color: var(--success); } .eg .no { color: var(--muted); opacity: .5; }
.eg td a.cell-link { font-weight: 600; cursor: pointer; }
.colchooser { max-height: 360px; overflow: auto; min-width: 230px; }
.colchooser label { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 4px; cursor: pointer; }
.colchooser label:hover { background: var(--surface-3); }

/* ---------- Drawer / modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(2,6,23,.38); z-index: 3500; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--dw, 560px), 100vw); background: var(--surface); z-index: 3600; display: flex; flex-direction: column; box-shadow: -10px 0 40px rgba(0,0,0,.2); animation: slidein .16s ease-out; }
.drawer.w-sm { --dw: 420px; } .drawer.w-md { --dw: 600px; } .drawer.w-lg { --dw: 860px; } .drawer.w-xl { --dw: 1120px; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 1.15em; flex: 1; }
.drawer-body { flex: 1; overflow: auto; padding: 16px; }
.drawer-foot { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface-2); align-items: center; }
.drawer-foot .grow { flex: 1; }
.modal { position: fixed; z-index: 3600; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(var(--mw, 460px), 94vw); max-height: 90vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .12s ease-out; }
.modal .drawer-body { padding: 18px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 5000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; min-width: 260px; max-width: 420px; padding: 11px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 8px 30px rgba(0,0,0,.18); border-left: 4px solid var(--info); animation: slidein .18s ease-out; }
.toast.success { border-left-color: var(--success); } .toast.error { border-left-color: var(--danger); } .toast.warning { border-left-color: var(--warning); }
.toast .ic { margin-top: 1px; } .toast.success .ic { color: var(--success); } .toast.error .ic { color: var(--danger); } .toast.warning .ic { color: var(--warning); }

/* ---------- Layout settings drawer ---------- */
.theme-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.theme-card { border: 2px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; background: var(--surface); text-align: left; padding: 0; font: inherit; color: var(--text); }
.theme-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.theme-card .tc-prev { height: 58px; display: flex; }
.theme-card .tc-side { width: 26%; }
.theme-card .tc-main { flex: 1; padding: 7px; display: flex; flex-direction: column; gap: 4px; }
.theme-card .tc-main i { display: block; height: 6px; border-radius: 3px; }
.theme-card .tc-name { padding: 6px 8px; font-size: 12px; font-weight: 600; border-top: 1px solid var(--border); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.set-row .sr-l b { display: block; font-weight: 600; } .set-row .sr-l small { color: var(--muted); }
.accent-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.accent-dot { width: 24px; height: 24px; border-radius: 50%; cursor: pointer; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong); }
.accent-dot.active { box-shadow: 0 0 0 2px var(--text); }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 20px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(16px); }

/* ---------- Tree editor (menu builder) ---------- */
.tree { list-style: none; margin: 0; padding: 0; }
.tree .tree { padding-left: 22px; border-left: 1px dashed var(--border-strong); margin-left: 13px; min-height: 6px; }
.tnode > .trow { display: flex; align-items: center; gap: 8px; padding: 0 8px; height: 34px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); margin: 3px 0; cursor: pointer; }
.tnode > .trow:hover { border-color: var(--border-strong); }
.tnode > .trow.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.tnode.inactive > .trow { opacity: .5; }
.tnode.inactive > .trow .t-lbl { text-decoration: line-through; }
.tnode > .trow .drag { cursor: grab; color: var(--muted); display: flex; }
.tnode > .trow .t-lbl { font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tnode > .trow .t-route { color: var(--muted); font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%; }
.tnode.sep > .trow { height: 22px; border-style: dashed; color: var(--muted); }
.tnode.drop-in > .trow { background: var(--primary-soft); border-color: var(--primary); }
.tnode.drop-before > .trow { box-shadow: 0 -3px 0 var(--primary); }
.tnode.drop-after > .trow { box-shadow: 0 3px 0 var(--primary); }
.tnode.collapsed > .tree { display: none; }
.tnode .tw { width: 16px; display: flex; color: var(--muted); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; min-height: 0; height: 100%; }
.split > * { min-height: 0; overflow: auto; }

/* ---------- Permission matrix ---------- */
.perm-mod { margin-bottom: 14px; }
.perm-mod h4 { margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.perm-table th { font-size: .86em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
.perm-table td.c, .perm-table th.c { text-align: center; width: 70px; }
.perm-table tr:hover td { background: var(--row-hover); }

/* ---------- Studio ---------- */
.studio { display: grid; grid-template-columns: 250px minmax(0, 1fr); height: 100%; min-height: 0; }
.studio-side { border-right: 1px solid var(--border); background: var(--surface); overflow: auto; padding: 8px; }
.studio-main { min-width: 0; min-height: 0; overflow: auto; padding: 14px 16px; }
.studio-main.fill { display: flex; flex-direction: column; overflow: hidden; }
.s-mod { margin-bottom: 4px; }
.s-mod > .s-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.s-mod > .s-head:hover { background: var(--surface-3); }
.s-mod.active > .s-head { background: var(--primary-soft); color: var(--primary); }
.s-list { padding-left: 12px; }
.s-list .s-it { display: flex; align-items: center; gap: 7px; padding: 4px 8px; border-radius: 5px; cursor: pointer; font-size: .95em; color: var(--muted); }
.s-list .s-it:hover { background: var(--surface-3); color: var(--text); }
.s-list .s-it.active { color: var(--primary); background: var(--primary-softer); }
.s-sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--muted); padding: 10px 8px 4px; }
.field-table { width: 100%; border-collapse: collapse; }
.field-table th { font-size: .82em; color: var(--muted); font-weight: 600; text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
.field-table td { padding: 3px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.field-table .ctl { height: 28px; padding: 0 6px; }
.field-table td.c { text-align: center; }
.field-table tr.dragging { opacity: .4; }
.field-table .drag { cursor: grab; color: var(--muted); }
.editor-wrap { flex: 1; min-height: 0; display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.editor-gutter { padding: 10px 8px 10px 10px; text-align: right; color: var(--muted); font-family: var(--mono); font-size: 12.5px; line-height: 1.55; background: var(--surface-2); border-right: 1px solid var(--border); user-select: none; overflow: hidden; white-space: pre; min-width: 46px; }
.editor { flex: 1; border: 0; outline: none; resize: none; padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; background: var(--surface); color: var(--text); white-space: pre; overflow: auto; tab-size: 4; }
.sql-result { margin-top: 10px; }

/* ---------- Login / install ---------- */
.login-page { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.login-art { background: radial-gradient(1200px 600px at 10% 10%, color-mix(in srgb, var(--primary) 55%, #0b1120), #0b1120 70%); color: #e2e8f0; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art::after { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px); background-size: 34px 34px; mask-image: linear-gradient(to bottom, #000, transparent); pointer-events: none; }
.login-art h2 { font-size: 34px; line-height: 1.15; margin: 0 0 14px; color: #fff; max-width: 520px; }
.login-art p { color: #94a3b8; max-width: 480px; font-size: 15px; }
.login-art .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; position: relative; z-index: 1; }
.login-art .chips span { border: 1px solid rgba(255,255,255,.14); padding: 5px 11px; border-radius: 20px; font-size: 12.5px; color: #cbd5e1; background: rgba(255,255,255,.04); }
.login-form-wrap { display: grid; place-items: center; padding: 30px; background: var(--surface); }
.login-form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-form h1 { margin: 0; font-size: 24px; }
.login-form .fld input { height: 40px; }
.login-form .btn { height: 42px; justify-content: center; }
.install-page { display: grid; place-items: start center; padding: 30px 14px; }
.install-card { width: min(760px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 24px 26px; }
.install-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.install-brand b { display: block; font-size: 18px; } .install-brand small { color: var(--muted); }
.req-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.req-list span { font-size: 12px; padding: 3px 9px; border-radius: 12px; font-weight: 600; }
.req-list .ok { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.req-list .bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; width: 270px !important; }
  .app.mobile-open .sidebar { transform: none; box-shadow: 10px 0 40px rgba(0,0,0,.3); }
  .app.collapsed .brand-text, .app.collapsed .side-search, .app.collapsed .nav-item .lbl, .app.collapsed .nav-item .chev { display: initial; }
  .cmd-btn { min-width: 0; } .cmd-btn span, .cmd-btn kbd, .user-chip .uinfo, .hide-sm { display: none; }
  .login-page { grid-template-columns: 1fr; } .login-art { display: none; }
  .form-grid { --cols: 1 !important; } .span-2, .span-3, .span-4 { grid-column: auto; }
  .split, .studio { grid-template-columns: 1fr; }
  [data-menu-pos="top"] .sidebar { display: flex; } [data-menu-pos="top"] .topnav { display: none; }
}
@media print { .page-head .ph-actions, .eg-bar, .eg-pager, .eg-filter { display: none !important; } .eg { border: 0; box-shadow: none; } .eg-scroll { overflow: visible; } }
.cmd-btn, .user-chip .un, .user-chip .ub { white-space: nowrap; }
[data-menu-pos="top"] .cmd-btn { min-width: 0; }
[data-menu-pos="top"] .cmd-btn span, [data-menu-pos="top"] .cmd-btn kbd { display: none; }
