/* ==========================================================================
   Design tokens
   Deep teal #0F766E · Mint #14B8A6 · Navy #0F172A · Off-white #F8FAFC · Slate #64748B
   ========================================================================== */
:root,
[data-bs-theme="light"] {
  --fi-teal: #0F766E;
  --fi-teal-600: #0d6560;
  --fi-mint: #14B8A6;
  --fi-navy: #0F172A;
  --fi-offwhite: #F8FAFC;
  --fi-slate: #64748B;

  --fi-bg: #F8FAFC;
  --fi-surface: #FFFFFF;
  --fi-surface-2: #F1F5F9;
  --fi-border: #E2E8F0;
  --fi-text: #0F172A;
  --fi-text-muted: #64748B;
  --fi-accent-soft: rgba(20, 184, 166, 0.12);
  --fi-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);

  --bs-primary: #0F766E;
  --bs-primary-rgb: 15, 118, 110;
  --bs-link-color: #0F766E;
  --bs-link-color-rgb: 15, 118, 110;
  --bs-link-hover-color: #0d6560;
  --bs-body-bg: var(--fi-bg);
  --bs-body-color: var(--fi-text);
  --bs-secondary-color: var(--fi-slate);
  --bs-border-color: var(--fi-border);
  --bs-font-sans-serif: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-font-size: 0.9rem;
  --bs-border-radius: 0.5rem;
}

[data-bs-theme="dark"] {
  --fi-bg: #0B1220;
  --fi-surface: #111A2E;
  --fi-surface-2: #16213A;
  --fi-border: #23304A;
  --fi-text: #E2E8F0;
  --fi-text-muted: #94A3B8;
  --fi-accent-soft: rgba(20, 184, 166, 0.16);
  --fi-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);

  --bs-primary: #14B8A6;
  --bs-primary-rgb: 20, 184, 166;
  --bs-link-color: #2DD4BF;
  --bs-link-color-rgb: 45, 212, 191;
  --bs-link-hover-color: #5EEAD4;
  --bs-body-bg: var(--fi-bg);
  --bs-body-color: var(--fi-text);
  --bs-secondary-color: #94A3B8;
  --bs-border-color: var(--fi-border);
  --bs-tertiary-bg: var(--fi-surface-2);
}

body { background: var(--fi-bg); color: var(--fi-text); -webkit-font-smoothing: antialiased; }
a { text-decoration: none; }

/* Buttons */
.btn-primary { --bs-btn-bg: var(--fi-teal); --bs-btn-border-color: var(--fi-teal); --bs-btn-hover-bg: var(--fi-teal-600); --bs-btn-hover-border-color: var(--fi-teal-600); --bs-btn-active-bg: var(--fi-teal-600); --bs-btn-disabled-bg: var(--fi-teal); --bs-btn-disabled-border-color: var(--fi-teal); }
[data-bs-theme="dark"] .btn-primary { --bs-btn-bg: #0F766E; --bs-btn-border-color: #14B8A6; }
.btn-outline-primary { --bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary); --bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary); --bs-btn-active-bg: var(--bs-primary); }
.btn { font-weight: 500; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border-radius: 8px; color: var(--fi-text-muted); border: 0; }
.btn-icon:hover { background: var(--fi-surface-2); color: var(--fi-text); }
.btn-ghost { border: 0; color: var(--fi-text); display: inline-flex; align-items: center; gap: .5rem; }
.btn-ghost:hover { background: var(--fi-surface-2); }
.btn-light { --bs-btn-bg: var(--fi-surface-2); --bs-btn-border-color: var(--fi-border); --bs-btn-color: var(--fi-text); }
.form-control:focus, .form-select:focus { border-color: var(--fi-mint); box-shadow: 0 0 0 .2rem rgba(20, 184, 166, .2); }
.form-check-input:checked { background-color: var(--fi-teal); border-color: var(--fi-teal); }

/* Icons (Lucide, thin outline) */
[data-lucide], svg.lucide { width: 18px; height: 18px; stroke-width: 1.6; vertical-align: -3px; }
.icon-sm, svg.icon-sm { width: 15px !important; height: 15px !important; }
.icon-xs, svg.icon-xs { width: 13px !important; height: 13px !important; }
.icon-lg, svg.icon-lg { width: 28px !important; height: 28px !important; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: 0 0 248px; background: var(--fi-navy); color: #CBD5E1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 1040;
}
.sidebar-admin { background: #0a1020; }
.sidebar-brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.25rem; color: #fff; font-weight: 600; font-size: 1.02rem; }
.sidebar-brand small { color: var(--fi-mint); font-weight: 500; font-size: .75rem; margin-left: .25rem; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--fi-teal), var(--fi-mint)); display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.brand-mark svg { width: 18px; height: 18px; }
.brand-logo { height: 32px; width: auto; border-radius: 6px; }
.sidebar-nav { padding: .25rem .75rem 1rem; flex: 1; }
.nav-section { text-transform: uppercase; letter-spacing: .06em; font-size: .68rem; color: #64748B; padding: 1rem .6rem .35rem; font-weight: 600; }
.nav-link-item { display: flex; align-items: center; gap: .7rem; padding: .48rem .65rem; border-radius: 7px; color: #CBD5E1; font-size: .87rem; margin-bottom: 1px; }
.nav-link-item:hover { background: rgba(148, 163, 184, .1); color: #fff; }
.nav-link-item.active { background: rgba(20, 184, 166, .16); color: #5EEAD4; }
.nav-link-item.active svg { color: var(--fi-mint); }
.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(148, 163, 184, .12); }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem;
  background: var(--fi-surface); border-bottom: 1px solid var(--fi-border); position: sticky; top: 0; z-index: 1030;
}
.topbar-context { flex: 1; min-width: 0; color: var(--fi-text-muted); font-size: .87rem; }
.org-name, .org-switch { font-weight: 500; color: var(--fi-text); }
.topbar-actions { display: flex; align-items: center; gap: .35rem; }
.credit-pill { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .7rem; border-radius: 99px; background: var(--fi-accent-soft); color: var(--bs-primary); font-weight: 600; font-size: .82rem; margin-right: .35rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--fi-teal); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 600; }
.dot-badge { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: #F97316; border: 2px solid var(--fi-surface); }
.app-content { padding: 1.5rem 1.75rem 3rem; max-width: 1480px; width: 100%; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: -260px; transition: left .2s ease; }
  body.sidebar-open .sidebar { left: 0; }
  .sidebar-backdrop { display: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1035; }
  .app-content { padding: 1rem; }
  .topbar { padding: 0 .75rem; }
}

/* ==========================================================================
   Page structure — sections and dividers rather than boxes everywhere
   ========================================================================== */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-title { font-size: 1.45rem; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-subtitle { color: var(--fi-text-muted); margin: .25rem 0 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumb { font-size: .78rem; margin-bottom: .35rem; --bs-breadcrumb-divider-color: var(--fi-text-muted); }
.breadcrumb-item a { color: var(--fi-text-muted); }

.section { margin-bottom: 2rem; }
.section + .section { padding-top: 1.75rem; border-top: 1px solid var(--fi-border); }
.section-title { font-size: 1rem; font-weight: 600; margin-bottom: .9rem; display: flex; align-items: center; gap: .5rem; justify-content: space-between; }
.section-title .muted { font-weight: 400; color: var(--fi-text-muted); font-size: .82rem; }

.surface { background: var(--fi-surface); border: 1px solid var(--fi-border); border-radius: 12px; box-shadow: var(--fi-shadow); }
.surface-body { padding: 1.25rem 1.35rem; }
.surface-header { padding: .9rem 1.35rem; border-bottom: 1px solid var(--fi-border); display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.surface-header h2, .surface-header h3 { font-size: .95rem; font-weight: 600; margin: 0; }

/* Compact KPI strip */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); background: var(--fi-surface); border: 1px solid var(--fi-border); border-radius: 12px; overflow: hidden; margin-bottom: 1.75rem; box-shadow: var(--fi-shadow); }
.kpi { padding: 1rem 1.2rem; border-right: 1px solid var(--fi-border); }
.kpi:last-child { border-right: 0; }
.kpi-label { font-size: .75rem; color: var(--fi-text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; display: flex; align-items: center; gap: .35rem; }
.kpi-value { font-size: 1.55rem; font-weight: 650; margin-top: .2rem; letter-spacing: -.02em; }
.kpi-meta { font-size: .78rem; color: var(--fi-text-muted); }

/* Inline metadata lists */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem 1.5rem; }
.meta-item .meta-label { font-size: .74rem; color: var(--fi-text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.meta-item .meta-value { font-weight: 500; margin-top: .15rem; word-break: break-word; }
.meta-value.not-supplied { color: var(--fi-text-muted); font-weight: 400; font-style: italic; }
.dl-inline { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.dl-inline dt { color: var(--fi-text-muted); font-weight: 500; }
.dl-inline dd { margin: 0; }

/* Badges */
.badge { font-weight: 500; }
.badge-soft-success { background: rgba(16, 185, 129, .14); color: #047857; }
.badge-soft-danger { background: rgba(239, 68, 68, .13); color: #b91c1c; }
.badge-soft-warning { background: rgba(245, 158, 11, .16); color: #b45309; }
.badge-soft-info { background: rgba(20, 184, 166, .14); color: #0F766E; }
.badge-soft-secondary { background: rgba(100, 116, 139, .14); color: #475569; }
.badge-soft-navy { background: rgba(15, 23, 42, .08); color: var(--fi-text); }
[data-bs-theme="dark"] .badge-soft-success { color: #6EE7B7; }
[data-bs-theme="dark"] .badge-soft-danger { color: #FCA5A5; }
[data-bs-theme="dark"] .badge-soft-warning { color: #FCD34D; }
[data-bs-theme="dark"] .badge-soft-info { color: #5EEAD4; }
[data-bs-theme="dark"] .badge-soft-secondary { color: #CBD5E1; }
[data-bs-theme="dark"] .badge-soft-navy { background: rgba(148, 163, 184, .14); }

/* Search hero */
.search-panel { background: var(--fi-surface); border: 1px solid var(--fi-border); border-radius: 14px; padding: 1.35rem; box-shadow: var(--fi-shadow); margin-bottom: 1.75rem; }
.search-panel .form-control-lg { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; text-transform: uppercase; }
.search-hint { font-size: .8rem; color: var(--fi-text-muted); margin-top: .5rem; }

/* Result header */
.result-hero { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; padding-bottom: 1.25rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--fi-border); }
.result-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.5rem; font-weight: 650; letter-spacing: .03em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Timeline (newest first) */
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--fi-border); }
.timeline li { position: relative; padding: 0 0 1.1rem 2rem; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 5px; width: 14px; height: 14px; border-radius: 50%; background: var(--fi-surface); border: 2px solid var(--fi-slate); }
.timeline li.latest::before { border-color: var(--fi-mint); background: var(--fi-mint); box-shadow: 0 0 0 4px var(--fi-accent-soft); }
.timeline .t-title { font-weight: 600; }
.timeline .t-meta { color: var(--fi-text-muted); font-size: .82rem; }

/* Maps */
.map-box { height: 380px; border-radius: 12px; border: 1px solid var(--fi-border); overflow: hidden; background: var(--fi-surface-2); }
.map-box.sm { height: 240px; }
.map-empty { display: flex; align-items: center; justify-content: center; text-align: center; color: var(--fi-text-muted); padding: 2rem; height: 100%; }

/* Empty / error states */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--fi-text-muted); }
.empty-state .empty-icon { width: 52px; height: 52px; border-radius: 14px; background: var(--fi-accent-soft); color: var(--bs-primary); display: inline-flex; align-items: center; justify-content: center; margin-bottom: .75rem; }
.empty-state h3 { font-size: 1rem; color: var(--fi-text); font-weight: 600; }
.notice { display: flex; gap: .75rem; padding: .9rem 1rem; border-radius: 10px; border: 1px solid var(--fi-border); background: var(--fi-surface-2); }
.notice svg { flex: 0 0 auto; margin-top: 2px; }
.notice-warning { background: rgba(245, 158, 11, .09); border-color: rgba(245, 158, 11, .35); }
.notice-info { background: var(--fi-accent-soft); border-color: rgba(20, 184, 166, .35); }
.notice-danger { background: rgba(239, 68, 68, .08); border-color: rgba(239, 68, 68, .3); }

/* Tables */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .65rem .75rem; border-bottom-color: var(--fi-border); }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--fi-text-muted); font-weight: 600; background: var(--fi-surface-2); border-bottom: 1px solid var(--fi-border); white-space: nowrap; }
.table-surface { background: var(--fi-surface); border: 1px solid var(--fi-border); border-radius: 12px; overflow: hidden; box-shadow: var(--fi-shadow); }
.table-surface .dt-container { padding: .75rem 1rem; }
div.dt-container .dt-search input, div.dt-container .dt-length select { border-color: var(--fi-border); }
div.dt-container div.dt-processing { background: var(--fi-surface); color: var(--fi-text); border: 1px solid var(--fi-border); }
.table-filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; padding: .85rem 1rem 0; }
.table-filters .form-control, .table-filters .form-select { width: auto; min-width: 140px; }

/* Auth */
.auth-shell { display: flex; min-height: 100vh; }
.auth-aside { width: 44%; background: radial-gradient(1200px 600px at -10% -10%, rgba(20, 184, 166, .35), transparent), var(--fi-navy); color: #E2E8F0; padding: 3rem; flex-direction: column; justify-content: space-between; }
.auth-brand { display: flex; align-items: center; gap: .7rem; font-weight: 600; font-size: 1.15rem; color: #fff; margin-bottom: 4rem; }
.auth-headline { font-size: 2rem; font-weight: 650; color: #fff; max-width: 440px; line-height: 1.25; margin-bottom: 2rem; }
.auth-points { list-style: none; padding: 0; }
.auth-points li { display: flex; gap: .75rem; padding: .55rem 0; color: #CBD5E1; }
.auth-points svg { color: var(--fi-mint); }
.auth-foot { color: #64748B; font-size: .8rem; margin: 0; }
.auth-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-title { font-size: 1.6rem; font-weight: 650; }
.otp-input { text-align: center; font-size: 1.6rem; letter-spacing: .6em; font-family: ui-monospace, monospace; }
.dev-banner { background: rgba(245, 158, 11, .12); color: #92400e; border: 1px dashed rgba(245, 158, 11, .6); padding: .5rem .75rem; border-radius: 8px; font-size: .8rem; margin-bottom: 1.25rem; }
[data-bs-theme="dark"] .dev-banner { color: #FCD34D; }

/* Misc */
.error-page { text-align: center; padding: 4rem 1rem; max-width: 560px; margin: 0 auto; }
.error-code { font-size: 4rem; font-weight: 700; color: var(--fi-mint); line-height: 1; margin-bottom: 1rem; }
.code-block { background: #0B1220; color: #E2E8F0; border-radius: 10px; padding: 1rem 1.1rem; font-size: .8rem; overflow-x: auto; position: relative; }
.code-block pre { margin: 0; color: inherit; white-space: pre; }
.code-block .copy-btn { position: absolute; top: .5rem; right: .5rem; }
.secret-reveal code { font-size: .95rem; word-break: break-all; }
.list-tight { list-style: none; padding: 0; margin: 0; }
.list-tight li { padding: .55rem 0; border-bottom: 1px solid var(--fi-border); display: flex; justify-content: space-between; gap: 1rem; }
.list-tight li:last-child { border-bottom: 0; }
.chart-box { position: relative; height: 260px; }
.flash-alert { margin-bottom: 1.25rem; }
.nav-tabs { border-bottom-color: var(--fi-border); }
.nav-tabs .nav-link { color: var(--fi-text-muted); border: 0; border-bottom: 2px solid transparent; }
.nav-tabs .nav-link.active { color: var(--bs-primary); background: transparent; border-bottom-color: var(--bs-primary); }
.quick-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.quick-actions .btn { display: inline-flex; align-items: center; gap: .4rem; }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix th:first-child, .perm-matrix td:first-child { text-align: left; }

/* JSON tree (admin mapping editor) */
.json-tree { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; max-height: 560px; overflow: auto; background: var(--fi-surface-2); border-radius: 10px; padding: .75rem; border: 1px solid var(--fi-border); }
.json-tree ul { list-style: none; margin: 0; padding-left: 1rem; }
.json-tree .jt-key { color: var(--bs-primary); cursor: pointer; }
.json-tree .jt-key:hover { text-decoration: underline; }
.json-tree .jt-str { color: #b45309; }
.json-tree .jt-num { color: #7c3aed; }
.json-tree .jt-type { color: var(--fi-text-muted); }
[data-bs-theme="dark"] .json-tree .jt-str { color: #FCD34D; }
[data-bs-theme="dark"] .json-tree .jt-num { color: #C4B5FD; }
.mapping-table input { font-family: ui-monospace, monospace; font-size: .78rem; }
.mapping-table .child-row td:first-child { padding-left: 2rem; }
.preview-output { max-height: 420px; overflow: auto; }

/* Polish */
.btn:not(.btn-lg):not(.btn-sm):not(.btn-icon) { font-size: .875rem; }
.list-tight li { align-items: center; }
.list-tight li > .badge { align-self: center; flex: 0 0 auto; }
code { color: var(--fi-teal); }
[data-bs-theme="dark"] code { color: #5EEAD4; }
.code-block code, .code-block pre { color: #E2E8F0; }
.kpi-label { line-height: 1.3; }
.env-list li { padding: .45rem 0; border-bottom: 1px solid var(--fi-border); }
.env-list li:last-child { border-bottom: 0; }
