/* Simple BI: the app shell and shared components. Pages keep their own small styles on top. */
:root {
  --bg:#f4f6fb; --panel:#fff; --ink:#111827; --ink-2:#374151; --muted:#6b7280; --line:#e5e7eb; --line-2:#eef0f5;
  --accent:#4f46e5; --accent-2:#7c3aed; --accent-soft:#eef2ff; --accent-ink:#3730a3;
  --grad:linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --ok:#047857; --okbg:#ecfdf5; --err:#b42318; --errbg:#fef3f2; --warn:#b54708; --warnbg:#fffaeb;
  --radius:14px; --radius-sm:9px;
  --shadow-sm:0 1px 2px rgba(16,24,40,.05);
  --shadow:0 1px 3px rgba(16,24,40,.06), 0 6px 18px -6px rgba(16,24,40,.10);
  --shadow-lg:0 12px 32px -8px rgba(30,27,75,.22);
  --ring:0 0 0 3px rgba(99,102,241,.28);
  --header-h:60px;
  color-scheme:light;
}
*, *::before, *::after { box-sizing:border-box; }
html { -webkit-text-size-adjust:100%; scroll-behavior:smooth; }
body {
  margin:0; min-height:100vh; display:flex; flex-direction:column;
  font:14px/1.55 "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings:"cv11", "ss01"; -webkit-font-smoothing:antialiased;
  background:var(--bg); color:var(--ink);
  background-image:radial-gradient(1200px 400px at 100% -10%, rgba(124,58,237,.07), transparent 60%),
                   radial-gradient(900px 360px at -10% -20%, rgba(79,70,229,.07), transparent 60%);
  background-attachment:fixed;
}
a { color:var(--accent); text-decoration:none; transition:color .15s; }
a:hover { color:var(--accent-2); }
img, svg { vertical-align:middle; }
:focus-visible { outline:none; box-shadow:var(--ring); border-radius:6px; }
::selection { background:#c7d2fe; }
.skip { position:absolute; left:-999px; top:8px; z-index:100; background:var(--ink); color:#fff; padding:8px 14px; border-radius:8px; }
.skip:focus { left:12px; color:#fff; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }

/* ---------------------------------------------------------------- header */
header.top {
  position:sticky; top:0; z-index:40; height:var(--header-h);
  display:flex; align-items:center; gap:14px; padding:0 clamp(12px, 3vw, 28px);
  background:rgba(255,255,255,.82); backdrop-filter:saturate(180%) blur(14px); -webkit-backdrop-filter:saturate(180%) blur(14px);
  border-bottom:1px solid rgba(229,231,235,.8);
}
header.top .brand { display:inline-flex; align-items:center; gap:10px; font-weight:750; font-size:16.5px; letter-spacing:-.01em; color:var(--ink); white-space:nowrap; }
header.top .brand:hover { color:var(--ink); }
.brand-mark { width:32px; height:32px; border-radius:9px; display:grid; place-items:center; background:var(--grad); box-shadow:0 4px 12px rgba(79,70,229,.35); flex:none; }
.brand-mark svg { width:18px; height:18px; }
header.top .spacer { flex:1; }

nav.main { display:flex; align-items:center; gap:2px; margin-left:10px; }
nav.main a { display:inline-flex; align-items:center; gap:7px; color:var(--ink-2); padding:7px 12px; border-radius:10px; font-weight:500; white-space:nowrap; transition:background .15s, color .15s; }
nav.main a svg { width:17px; height:17px; opacity:.75; }
nav.main a:hover { background:#f3f4f6; color:var(--ink); }
nav.main a.active { background:var(--accent-soft); color:var(--accent-ink); font-weight:650; }
nav.main a.active svg { opacity:1; color:var(--accent); }

.user-menu { position:relative; }
.user-menu > summary { list-style:none; display:flex; align-items:center; gap:9px; cursor:pointer; padding:4px 6px 4px 4px; border-radius:999px; border:1px solid transparent; transition:background .15s, border-color .15s; }
.user-menu > summary::-webkit-details-marker { display:none; }
.user-menu > summary:hover, .user-menu[open] > summary { background:#fff; border-color:var(--line); box-shadow:var(--shadow-sm); }
.avatar { width:32px; height:32px; border-radius:50%; display:grid; place-items:center; background:var(--grad); color:#fff; font-weight:700; font-size:12.5px; letter-spacing:.02em; flex:none; }
.user-menu .who-name { font-weight:600; max-width:160px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.user-menu .chev { width:14px; height:14px; color:var(--muted); transition:transform .2s; }
.user-menu[open] .chev { transform:rotate(180deg); }
.user-pop { position:absolute; right:0; top:calc(100% + 8px); width:250px; background:#fff; border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow-lg); padding:6px; animation:pop .14s ease-out; }
.user-pop .head { padding:10px 12px; border-bottom:1px solid var(--line-2); margin-bottom:4px; }
.user-pop .head b { display:block; }
.user-pop .head span { color:var(--muted); font-size:12.5px; word-break:break-all; }
.user-pop a, .user-pop button { display:flex; width:100%; align-items:center; gap:10px; padding:9px 12px; border-radius:9px; border:0; background:none; font:inherit; color:var(--ink-2); cursor:pointer; text-align:left; }
.user-pop a:hover, .user-pop button:hover { background:#f3f4f6; color:var(--ink); }
.user-pop svg { width:16px; height:16px; color:var(--muted); }
.user-pop form { margin:0; }
@keyframes pop { from { opacity:0; transform:translateY(-4px) scale(.98); } to { opacity:1; transform:none; } }

.nav-toggle { display:none; width:40px; height:40px; border-radius:10px; border:1px solid var(--line); background:#fff; cursor:pointer; place-items:center; color:var(--ink); }
.nav-toggle svg { width:20px; height:20px; }

@media (max-width: 820px) {
  .nav-toggle { display:grid; order:-1; }
  nav.main {
    position:fixed; left:0; right:0; top:var(--header-h); margin:0; flex-direction:column; align-items:stretch; gap:2px;
    background:#fff; padding:10px 12px 14px; border-bottom:1px solid var(--line); box-shadow:var(--shadow-lg);
    transform:translateY(-8px); opacity:0; visibility:hidden; transition:opacity .18s, transform .18s, visibility .18s;
  }
  body.nav-open nav.main { transform:none; opacity:1; visibility:visible; }
  nav.main a { padding:12px 14px; font-size:15px; }
  .user-menu .who-name, .user-menu .chev { display:none; }
}

/* ---------------------------------------------------------------- page */
main { width:100%; max-width:1280px; margin:0 auto; padding:clamp(16px, 3vw, 30px) clamp(12px, 3vw, 28px) 40px; flex:1; }
@keyframes fadein { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:none; } }
footer.foot { color:var(--muted); font-size:12.5px; text-align:center; padding:18px 12px 24px; }
h1 { font-size:clamp(20px, 2.4vw, 26px); line-height:1.25; font-weight:750; letter-spacing:-.02em; margin:0 0 6px; }
h2 { font-size:15.5px; font-weight:650; letter-spacing:-.01em; margin:0 0 10px; }
h3 { font-size:11.5px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); margin:16px 0 8px; font-weight:650; }
h1 + .muted { margin-top:0; }
p { margin:0 0 10px; }
.muted { color:var(--muted); }
.row { display:flex; gap:12px; align-items:center; flex-wrap:wrap; }
.between { justify-content:space-between; }
@media (max-width: 640px) { .row.between > .btn, .row.between > a.btn { width:100%; justify-content:center; } }

.card { background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); padding:clamp(14px, 2vw, 20px); margin-top:16px; box-shadow:var(--shadow); }
.card > h2:first-child { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:6px; white-space:nowrap;
  border:1px solid var(--line); background:#fff; color:var(--ink); padding:8px 15px; border-radius:var(--radius-sm);
  cursor:pointer; font:inherit; font-weight:550; line-height:1.3; box-shadow:var(--shadow-sm);
  transition:background .15s, border-color .15s, box-shadow .15s, transform .08s, color .15s;
}
.btn:hover { background:#f9fafb; border-color:#d1d5db; color:var(--ink); }
.btn:active { transform:translateY(1px); }
.btn:focus-visible { box-shadow:var(--ring); }
.btn.primary { background:var(--grad); border-color:transparent; color:#fff; box-shadow:0 4px 12px -2px rgba(79,70,229,.45); }
.btn.primary:hover { filter:brightness(1.07); color:#fff; box-shadow:0 6px 16px -2px rgba(79,70,229,.5); }
.btn.danger { color:var(--err); border-color:#fecdca; }
.btn.danger:hover { background:var(--errbg); color:var(--err); border-color:#fda29b; }
.btn.small { padding:5px 11px; font-size:12.5px; border-radius:8px; }
.btn[disabled], .btn:disabled { opacity:.55; cursor:not-allowed; transform:none; }
button.link { background:none; border:none; padding:0; color:var(--accent); cursor:pointer; font:inherit; }
button.link:hover { color:var(--accent-2); text-decoration:underline; }
button.link.danger, .link.danger { color:var(--err); }
.actions { display:flex; gap:8px; margin-top:20px; flex-wrap:wrap; }

/* ---------------------------------------------------------------- badges and chips */
.badge { display:inline-flex; align-items:center; gap:5px; padding:2px 9px; border-radius:999px; font-size:12px; font-weight:600; line-height:1.6; }
.badge::before { content:""; width:6px; height:6px; border-radius:50%; background:currentColor; opacity:.8; }
.badge.ok { background:var(--okbg); color:var(--ok); }
.badge.err { background:var(--errbg); color:var(--err); }
.badge.draft { background:#f3f4f6; color:#4b5563; }
.chip { display:inline-block; padding:2px 9px; border-radius:999px; font-size:12px; background:#f1f3f9; color:var(--ink-2); margin:2px 3px 2px 0; white-space:nowrap; border:1px solid #e6e9f2; }
.chip.admin { background:#fff4ea; color:#93370d; border-color:#fedcc0; }
.chip.dim { background:#eff6ff; color:#1d4ed8; border-color:#dbeafe; font-weight:600; }
.chip.mea { background:#ecfdf5; color:#047857; border-color:#d1fae5; font-weight:600; }

/* ---------------------------------------------------------------- messages */
.flash, .alert { display:flex; align-items:flex-start; gap:10px; padding:11px 14px; border-radius:12px; margin-bottom:16px; border:1px solid; font-weight:500; }
.flash { background:var(--okbg); color:var(--ok); border-color:#a7f3d0; box-shadow:var(--shadow-sm); }
.flash::before { content:"✓"; display:grid; place-items:center; width:20px; height:20px; border-radius:50%; background:var(--ok); color:#fff; font-size:12px; font-weight:800; flex:none; margin-top:1px; }
.flash .x { margin-left:auto; border:0; background:none; color:inherit; cursor:pointer; font-size:18px; line-height:1; opacity:.6; padding:0 2px; }
.flash .x:hover { opacity:1; }
.flash.hide { opacity:0; transform:translateY(-6px); transition:opacity .3s, transform .3s; }
.alert { background:var(--errbg); color:var(--err); border-color:#fecdca; }
.field-error { color:var(--err); font-size:13px; margin-top:5px; }

/* ---------------------------------------------------------------- forms */
label { display:block; font-weight:600; font-size:13.5px; color:var(--ink-2); margin:14px 0 6px; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], textarea, select {
  width:100%; font:inherit; color:var(--ink); padding:9px 12px; border:1px solid #d6dae3; border-radius:var(--radius-sm); background:#fff;
  box-shadow:var(--shadow-sm); transition:border-color .15s, box-shadow .15s;
}
select { width:auto; max-width:100%; padding:8px 34px 8px 11px; appearance:none; -webkit-appearance:none; cursor:pointer;
  background:#fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath d='M5.3 7.3a1 1 0 0 1 1.4 0L10 10.6l3.3-3.3a1 1 0 1 1 1.4 1.4l-4 4a1 1 0 0 1-1.4 0l-4-4a1 1 0 0 1 0-1.4z'/%3E%3C/svg%3E") no-repeat right 10px center / 16px; }
select[multiple] { background-image:none; padding-right:11px; }
label > select, .grid2 select, .grid3 select, form > select { width:100%; }
input::placeholder, textarea::placeholder { color:#9ca3af; }
input:hover, textarea:hover, select:hover { border-color:#b9bfcc; }
input:focus, textarea:focus, select:focus { outline:none; border-color:#818cf8; box-shadow:var(--ring); }
input[type=search] { padding-left:34px; background:#fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M9 3.5a5.5 5.5 0 1 0 3.4 9.8l3.2 3.2a1 1 0 0 0 1.4-1.4l-3.2-3.2A5.5 5.5 0 0 0 9 3.5zM5.5 9a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0z' clip-rule='evenodd'/%3E%3C/svg%3E") no-repeat 11px center / 16px; }
textarea { min-height:80px; resize:vertical; }
input[type=checkbox], input[type=radio] { accent-color:var(--accent); width:16px; height:16px; }
.check { display:flex; gap:9px; align-items:flex-start; font-weight:400; margin:6px 0; padding:6px 8px; border-radius:8px; color:var(--ink); }
.check:hover { background:#f8f9fc; }
.check input { margin-top:2px; flex:none; }
.check small { display:block; color:var(--muted); }
.picklist { border:1px solid var(--line); border-radius:var(--radius-sm); max-height:300px; overflow:auto; padding:4px 6px; background:#fcfcfe; }
.grid2 { display:grid; grid-template-columns:1fr 1fr; gap:0 20px; align-items:start; }
.grid2.tight { gap:0 12px; }
.grid3 { display:grid; grid-template-columns:repeat(3, 1fr); gap:0 12px; }
.grid-test { display:grid; grid-template-columns:300px 1fr; gap:0 20px; align-items:start; }
@media (max-width: 900px) { .grid2, .grid3, .grid-test { grid-template-columns:1fr; } }

/* ---------------------------------------------------------------- tables */
table { border-collapse:separate; border-spacing:0; width:100%; margin-top:8px; }
:where(table:not(.rs)) th, :where(table:not(.rs)) td { text-align:left; padding:10px 12px; border-bottom:1px solid var(--line-2); vertical-align:middle; }
:where(table:not(.rs)) thead th { background:#f8f9fc; color:var(--muted); font-size:12px; font-weight:650; text-transform:uppercase; letter-spacing:.04em; border-bottom:1px solid var(--line); white-space:nowrap; }
:where(table:not(.rs)) thead th:first-child { border-top-left-radius:10px; }
:where(table:not(.rs)) thead th:last-child { border-top-right-radius:10px; }
:where(table:not(.rs)) tbody tr { transition:background .12s; }
:where(table:not(.rs)) tbody tr:hover { background:#fafbff; }
:where(table:not(.rs)) tbody tr:last-child td { border-bottom:0; }
td.num, th.num { text-align:right; font-variant-numeric:tabular-nums; }
.card > table:first-child, .card > .tbl-scroll:first-child { margin-top:0; }
.tbl-scroll { width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.tbl-scroll > table { margin-top:8px; }
table.fieldtable td { border-bottom:1px dashed var(--line); padding:6px 8px; vertical-align:top; }
.scroll { overflow:auto; max-height:65vh; }
.pager { margin-top:14px; }
.pager nav > div:first-child { display:none; }
.pager svg { width:16px; height:16px; }

/* ---------------------------------------------------------------- tabs */
nav.tabs { display:flex; gap:2px; border-bottom:1px solid var(--line); margin:18px 0 4px; overflow-x:auto; scrollbar-width:none; }
nav.tabs::-webkit-scrollbar { display:none; }
nav.tabs a { padding:9px 15px; color:var(--muted); border-bottom:2px solid transparent; margin-bottom:-1px; white-space:nowrap; font-weight:500; }
nav.tabs a:hover { color:var(--ink); }
nav.tabs a.active { color:var(--accent); border-bottom-color:var(--accent); font-weight:650; }

/* ---------------------------------------------------------------- misc */
dl { display:grid; grid-template-columns:140px 1fr; gap:6px 14px; margin:0; }
dt { color:var(--muted); } dd { margin:0; min-width:0; overflow-wrap:anywhere; }
@media (max-width: 520px) { dl { grid-template-columns:1fr; gap:0; } dd { margin-bottom:8px; } }
code { background:#f1f3f9; padding:1px 6px; border-radius:5px; font-size:.92em; }
.mono, code, pre { font-family:ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace; }
.mono { font-size:12.5px; }
pre.sql { background:#0f172a; color:#e2e8f0; padding:14px; border-radius:12px; overflow:auto; font-size:12.5px; white-space:pre-wrap; }
.folder { margin-bottom:10px; }
.folder-name { font-weight:600; padding:4px 0; cursor:pointer; }
details.joinrow { border-bottom:1px solid var(--line); padding:8px 0; }
details.joinrow summary { cursor:pointer; line-height:1.9; }
hr { border:0; border-top:1px solid var(--line); margin:18px 0; }

/* ---------------------------------------------------------------- home page */
.hero { display:flex; align-items:center; gap:18px; flex-wrap:wrap; padding:clamp(18px, 3vw, 28px); border-radius:20px; color:#fff; background:var(--grad); box-shadow:var(--shadow-lg); position:relative; overflow:hidden; }
.hero::after { content:""; position:absolute; right:-60px; top:-80px; width:280px; height:280px; border-radius:50%; background:rgba(255,255,255,.10); }
.hero::before { content:""; position:absolute; right:120px; bottom:-120px; width:220px; height:220px; border-radius:50%; background:rgba(255,255,255,.07); }
.hero h1 { color:#fff; margin:0; }
.hero p { margin:4px 0 0; color:rgba(255,255,255,.85); }
.hero .avatar { width:56px; height:56px; font-size:20px; background:rgba(255,255,255,.2); box-shadow:inset 0 0 0 2px rgba(255,255,255,.35); }
@media (max-width: 380px) { .grid-cards { grid-template-columns:1fr; } }

/* ---------------------------------------------------------------- login */
body.guest { background:#0f0c29; background-image:radial-gradient(900px 500px at 15% 10%, rgba(124,58,237,.55), transparent 60%), radial-gradient(800px 500px at 90% 90%, rgba(79,70,229,.55), transparent 60%); }
body.guest header.top { background:transparent; border-bottom:0; backdrop-filter:none; }
body.guest header.top .brand { color:#fff; }
body.guest footer.foot { color:rgba(255,255,255,.55); }
.login-card { max-width:400px; margin:min(8vh, 64px) auto 0; padding:30px; border-radius:20px; box-shadow:0 30px 60px -12px rgba(0,0,0,.45); border:1px solid rgba(255,255,255,.6); }
.login-card .btn.primary { width:100%; padding:11px; font-size:15px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation:none !important; transition:none !important; } }
@media print { header.top, footer.foot, .nav-toggle { display:none !important; } body { background:#fff; } .card { box-shadow:none; } }

/* ---------------------------------------------------------------- side panels under the sticky header */
.ftree, .az-groups, .rd-tree, .rd-props, .tree { top:calc(var(--header-h) + 12px) !important; max-height:calc(100vh - var(--header-h) - 24px) !important; overflow:auto; }
.ftree, .az-groups, .tree, .dside, .dpanel { box-shadow:var(--shadow); border-radius:var(--radius) !important; }
@media (max-width: 900px) {
  .ftree, .az-groups, .tree { position:static !important; max-height:260px !important; }
}
/* the model table designer stacks on small screens */
@media (max-width: 1000px) {
  .designer, .designer.no-panel { grid-template-columns:1fr !important; height:auto !important; }
  .designer .dside { max-height:240px; }
  .designer .cwrap { height:60vh; }
}

/* ---------------------------------------------------------------- one page header for every list page */
html { scrollbar-gutter:stable; }
.page-head { display:flex; align-items:center; justify-content:space-between; gap:14px; flex-wrap:wrap; min-height:56px; margin:0 0 18px; }
.page-head h1 { margin:0 0 2px; }
.page-head p { margin:0; color:var(--muted); max-width:70ch; }
.page-head .btn { flex:none; }
.page-head + *, .page-tabs + * { margin-top:0 !important; }
@media (max-width: 640px) { .page-head .btn { width:100%; } }

/* path back to a parent page, above the page header */
.crumbs { display:flex; align-items:center; gap:7px; flex-wrap:wrap; font-size:13px; color:var(--muted); margin:-6px 0 8px; }
.crumbs b { color:var(--ink-2); font-weight:600; }
.crumbs + h1 { margin-top:4px; }
/* Administration: the list of things to administer */
.adm td:first-child { width:52px; padding-right:0; }
.adm .ico { width:38px; height:38px; border-radius:11px; display:grid; place-items:center; background:var(--accent-soft); color:var(--accent); }
.adm .ico svg { width:20px; height:20px; }
.adm tr.go { cursor:pointer; }
.adm tr.soon .ico { background:#f3f4f6; color:#9ca3af; }
.adm tr.soon b { color:var(--muted); }
.adm td b { display:block; font-size:14.5px; }
.adm td .d { color:var(--muted); font-size:13px; }
.adm td:last-child { text-align:right; white-space:nowrap; }
@media (max-width: 560px) { .adm td:last-child { display:none; } }

/* favourite star */
.fav { width:32px; height:32px; border:0; background:none; border-radius:9px; display:grid; place-items:center; cursor:pointer; flex:none; color:#c3c8d4; transition:color .15s, background .15s, transform .12s; }
.fav svg { width:19px; height:19px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linejoin:round; }
.fav:hover { background:#fff7e6; color:#f59e0b; }
.fav.on { color:#f59e0b; }
.fav.on svg { fill:currentColor; }
.fav:active { transform:scale(.88); }
