/* Edifice-Django visual parity layer.
   Tokens ported verbatim from v1 src/app/globals.css (Tailwind theme vars);
   Inter is the v1 typeface. Class-based dark mode mirrors v1's `.dark`
   exactly — see the note above :root.dark below. */

:root {
  --background: #f4f6fb;
  --foreground: #111827;
  --brand-primary: #4f46e5;
  --brand-primary-dark: #1a1f5e;
  --brand-primary-light: #eef2ff;
  --brand-gold: #06b6d4;
  --success: #10b981;
  --danger: #ef4444;
  --accent-pink: #818cf8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --surface-muted: #f3f4f6;
  --surface-page: #f4f6fb;
  --sidebar-bg: #1a1f5e;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-on-primary: #ffffff;
  --muted: #6b7280;
  --border: #e8eaf2;
  --shadow-card: 0 2px 12px rgba(26, 31, 94, 0.06);
  --shadow-shell: 0 4px 32px rgba(26, 31, 94, 0.1);
  --radius-card: 16px;
  --radius-shell: 20px;
  --accent-info-bg: #eef2ff;
  --accent-info-text: #4f46e5;
  --accent-info-border: #c7d2fe;
  --accent-warning-bg: #fffbeb;
  --accent-warning-text: #b45309;
  --accent-warning-border: #fde68a;
  --accent-danger-bg: #fff1f2;
  --accent-danger-text: #be123c;
  --accent-danger-border: #fecdd3;
  --accent-success-bg: #ecfdf5;
  --accent-success-text: #047857;
  --accent-success-border: #a7f3d0;
  --header-gradient: linear-gradient(135deg, #eef2ff 0%, #ffffff 55%, #ecfeff 100%);
  --insight-bg: #eef2ff;
  --surface-contrast: #1a1f5e;
  --text-on-contrast: #ffffff;
}

/* Dark palette is driven solely by the `.dark` class on <html> — the same
   mechanism frontend/js/lib/theme-utils.ts's applyResolvedTheme uses
   (classList.toggle("dark", ...) + colorScheme, never a [data-theme]
   attribute). templates/base.html and app_shell.html's inline init script
   set that class synchronously before paint from the shared
   'edifice-theme' localStorage key, resolving "system" against
   prefers-color-scheme itself — so no separate @media block is needed
   here, and one would actively fight an explicit "light" choice made
   while the OS prefers dark. */
:root.dark {
  --background: #0f1229;
  --foreground: #e8eaf2;
  --brand-primary: #818cf8;
  --brand-primary-dark: #4f46e5;
  --brand-primary-light: #1e1b4b;
  --brand-gold: #22d3ee;
  --surface: #1a1f3a;
  --surface-alt: #232948;
  --surface-muted: #2a3050;
  --surface-page: #0f1229;
  --sidebar-bg: #12163a;
  --text-primary: #e8eaf2;
  --text-secondary: #94a3b8;
  --text-on-primary: #0f1229;
  --muted: #94a3b8;
  --border: #2d3454;
  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-shell: 0 4px 32px rgba(0, 0, 0, 0.45);
  --accent-info-bg: #1e1b4b;
  --accent-info-text: #a5b4fc;
  --accent-info-border: #4338ca;
  --accent-warning-bg: #422006;
  --accent-warning-text: #fcd34d;
  --accent-warning-border: #92400e;
  --accent-danger-bg: #3f1020;
  --accent-danger-text: #fda4af;
  --accent-danger-border: #9f1239;
  --accent-success-bg: #052e1c;
  --accent-success-text: #6ee7b7;
  --accent-success-border: #065f46;
  --header-gradient: linear-gradient(135deg, #1e1b4b 0%, #0f1229 55%, #083344 100%);
  --insight-bg: #1e1b4b;
  --surface-contrast: #cbd5e1;
  --text-on-contrast: #0f1229;
}

* { box-sizing: border-box; margin: 0; }

body {
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { letter-spacing: -0.01em; }
a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }

/* ---------- public shell ---------- */
.pub-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.pub-header-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; height: 64px;
}
.brand {
  font-weight: 800; font-size: 1.15rem; color: var(--brand-primary-dark);
  letter-spacing: -0.02em;
}
:root.dark .brand { color: var(--brand-primary); }
.pub-nav { display: flex; gap: 20px; align-items: center; font-size: .92rem; }
.pub-nav a { color: var(--text-secondary); }
.pub-nav a:hover { color: var(--brand-primary); text-decoration: none; }
.pub-nav .cta {
  background: var(--brand-primary); color: #fff; padding: .45rem .95rem;
  border-radius: 10px; font-weight: 600;
}
.pub-nav .cta:hover { background: var(--brand-primary-dark); color: #fff; text-decoration: none; }
.pub-hero { background: var(--header-gradient); }
.pub-footer {
  border-top: 1px solid var(--border); color: var(--muted);
  font-size: .85rem; padding: 24px; text-align: center; margin-top: 48px;
}
.pub-wrap { max-width: 1080px; margin: 0 auto; padding: 40px 24px 64px; }

/* ---------- app shell (rich chrome — parity with frontend/js/Layout) ---------- */
.shell-page { min-height: 100vh; background: var(--surface-page); padding: 8px; }
.app-layout {
  display: flex; max-width: 1600px; margin: 0 auto; overflow: hidden;
  min-height: calc(100vh - 16px); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-shell);
  box-shadow: var(--shadow-shell);
}

.sidebar {
  width: 210px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-brand { display: flex; align-items: center; padding: 14px 16px; }
.sidebar-brand img { height: 32px; width: auto; display: block; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 12px; }
.sidebar .side-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-secondary); padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border-radius: 8px; font-size: .86rem; color: var(--text-secondary);
  margin-bottom: 2px; transition: background-color .15s ease, color .15s ease;
}
.nav-item svg { flex-shrink: 0; }
.nav-item:hover { background: var(--surface-alt); color: var(--text-primary); text-decoration: none; }
.nav-item.active { background: var(--brand-primary-light); color: var(--brand-primary); font-weight: 600; }

.sidebar-account { border-top: 1px solid var(--border); padding: 12px; }
.account-link {
  display: flex; align-items: center; gap: 8px; padding: 4px;
  border-radius: 8px; margin-bottom: 6px;
}
.account-link:hover { background: var(--surface-alt); text-decoration: none; }
.avatar-circle, .avatar-img {
  width: 32px; height: 32px; border-radius: 999px; flex-shrink: 0;
}
.avatar-circle {
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .72rem;
}
.avatar-img { object-fit: cover; }
.account-meta { min-width: 0; flex: 1; }
.account-meta .name {
  font-size: .75rem; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account-meta .role { font-size: .63rem; color: var(--text-secondary); text-transform: capitalize; }
.account-actions { display: flex; justify-content: flex-end; gap: 4px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 30px; width: 30px; border-radius: 6px; color: var(--text-secondary);
  background: transparent; border: 0; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--brand-primary); text-decoration: none; }

.ai-insight-card {
  position: relative; overflow: hidden; border-radius: 12px;
  border: 1px solid var(--border); background: var(--insight-bg);
  padding: 14px; margin-top: 8px;
}
.ai-insight-card .dismiss {
  position: absolute; top: 8px; right: 8px; background: none; border: 0;
  color: var(--text-secondary); cursor: pointer; padding: 2px; line-height: 0;
}
.ai-insight-card .dismiss:hover { color: var(--text-primary); }
.ai-insight-card h3 { font-size: .94rem; font-weight: 700; color: var(--text-primary); }
.ai-insight-card p { margin-top: 4px; font-size: .76rem; color: var(--text-secondary); line-height: 1.4; }
.ai-insight-card .btn-contrast {
  margin-top: 8px; display: block; width: 100%; border-radius: 8px;
  padding: 8px; text-align: center; font-size: .76rem; font-weight: 600;
}
.btn-contrast { background: var(--surface-contrast); color: var(--text-on-contrast); }
.btn-contrast:hover { opacity: .9; text-decoration: none; }

.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border); padding: 10px 16px;
}
.topbar-search { position: relative; flex: 1; min-width: 180px; max-width: 360px; display: flex; gap: 6px; }
.topbar-search select { width: auto; height: 36px; font-size: .78rem; padding: 0 6px; }
.topbar-search .search-wrap { position: relative; flex: 1; }
.topbar-search input { height: 36px; padding-left: 32px; font-size: .85rem; }
.topbar-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); pointer-events: none; }
.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.icon-btn-outline {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; width: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text-primary); position: relative;
}
.icon-btn-outline:hover { background: var(--brand-primary-light); color: var(--brand-primary); text-decoration: none; }
.theme-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: none; }
.today-chip {
  display: none; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface-alt); border-radius: 8px; padding: 6px 10px; font-size: .72rem;
}
.reports-btn {
  display: inline-flex; align-items: center; gap: 5px; background: var(--brand-primary);
  color: #fff; border-radius: 8px; padding: 7px 12px; font-size: .72rem; font-weight: 600;
}
.reports-btn:hover { background: var(--brand-primary-dark); color: #fff; text-decoration: none; }

.branch-row { display: flex; align-items: center; border-top: 1px solid var(--border); padding: 8px 16px; }
.branch-row select { width: auto; height: 32px; font-size: .76rem; }

.badge-dot {
  position: absolute; top: -4px; right: -4px; display: flex; align-items: center;
  justify-content: center; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 999px; background: var(--brand-gold); color: var(--text-primary);
  font-size: 9px; font-weight: 700;
}
.badge-dot.badge-rose { background: #f43f5e; color: #fff; }

.notif-wrap { position: relative; }
.notif-panel {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  width: 300px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow-shell); overflow: hidden;
}
.notif-panel.open { display: block; }
.notif-panel-head {
  background: var(--brand-primary-light); padding: 10px 12px; font-size: .85rem;
  font-weight: 600; color: var(--text-primary); border-bottom: 1px solid var(--border);
}
.notif-list { max-height: 280px; overflow-y: auto; list-style: none; margin: 0; padding: 0; }
.notif-list li { border-bottom: 1px solid var(--border); padding: 9px 12px; }
.notif-list li.unread { background: var(--surface-alt); }
.notif-list .empty { text-align: center; padding: 24px 12px; font-size: .72rem; color: var(--text-secondary); }
.notif-type { display: flex; align-items: center; gap: 6px; font-size: .74rem; font-weight: 600; color: var(--text-primary); }
.notif-type .dot { width: 6px; height: 6px; border-radius: 999px; background: var(--brand-primary); }
.notif-msg { margin-top: 2px; font-size: .68rem; color: var(--text-secondary); line-height: 1.4; }
.notif-panel-foot {
  display: block; border-top: 1px solid var(--border); padding: 8px; text-align: center;
  font-size: .72rem; font-weight: 600; color: var(--brand-primary);
}

.access-banner {
  margin: 12px 16px 0; border-radius: 10px; border: 1px solid; padding: 10px 14px;
  font-size: .82rem; display: flex; flex-wrap: wrap; align-items: center;
  gap: 10px; justify-content: space-between;
}
.access-banner.warn { background: var(--accent-warning-bg); color: var(--accent-warning-text); border-color: var(--accent-warning-border); }
.access-banner.danger { background: var(--accent-danger-bg); color: var(--accent-danger-text); border-color: var(--accent-danger-border); }
.access-banner a { font-weight: 700; color: inherit; text-decoration: underline; }

.shell-content { flex: 1; padding: 20px 24px 56px; }
.page-main { width: 100%; }
.page-header { margin-bottom: 22px; }
.page-header h1 { font-size: 1.55rem; font-weight: 700; }
.page-header .subtitle { color: var(--text-secondary); font-size: .95rem; }

@media (min-width: 600px) { .today-chip { display: flex; } }

@media (max-width: 960px) {
  .app-layout { flex-direction: column; border-radius: 12px; }
  .sidebar { width: 100%; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar-brand { padding: 10px 12px; }
  .sidebar-nav { display: flex; flex: none; padding: 0 8px; overflow-x: auto; }
  .sidebar .side-section { display: none; }
  .nav-item .nav-label { display: none; }
  .sidebar-account { display: none; }
  .shell-content { padding: 16px; }
}

/* ---------- components ---------- */
.card, .panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: 20px 22px;
}
.panel h2 { font-size: 1.05rem; margin-bottom: .6rem; }
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px; margin-bottom: 22px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: 16px 18px;
}
.kpi .num { display: block; font-size: 1.65rem; font-weight: 700;
  font-variant-numeric: tabular-nums; }
.kpi .lbl { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-secondary); }
.btn, button[type="submit"], button:not([class]) {
  display: inline-block; background: var(--brand-primary); color: #fff;
  border: 0; border-radius: 10px; padding: .55rem 1.05rem; font-size: .95rem;
  font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn:hover, button[type="submit"]:hover { background: var(--brand-primary-dark); }
.btn.secondary { background: var(--surface-muted); color: var(--text-primary); }
.btn.danger { background: var(--danger); }
input, select, textarea {
  font-family: inherit; font-size: .95rem; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .5rem .65rem; width: 100%;
}
label { display: block; font-size: .84rem; font-weight: 600;
  margin: .8rem 0 .25rem; }
table { width: 100%; border-collapse: collapse; font-size: .92rem;
  background: var(--surface); border-radius: var(--radius-card); overflow: hidden; }
th { text-align: left; font-size: .74rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-secondary);
  padding: .6rem .75rem; border-bottom: 2px solid var(--border); }
td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.msg { padding: .6rem .8rem; border-radius: 10px; font-size: .9rem; margin-top: .8rem; }
.msg.err { background: var(--accent-danger-bg); color: var(--accent-danger-text);
  border: 1px solid var(--accent-danger-border); }
.msg.ok, .msg.success { background: var(--accent-success-bg);
  color: var(--accent-success-text); border: 1px solid var(--accent-success-border); }
.chip { display: inline-block; font-family: ui-monospace, monospace; font-size: .72rem;
  font-weight: 600; letter-spacing: .05em; padding: 2px 8px; border-radius: 6px;
  border: 1px solid currentColor; text-transform: uppercase; }
.chip.true, .chip.ok, .chip.solid { color: var(--success); background: var(--accent-success-bg); }
.chip.false, .chip.broken { color: var(--danger); background: var(--accent-danger-bg); }
.chip.risk, .chip.warn { color: var(--accent-warning-text); background: var(--accent-warning-bg); }
.scroll { overflow-x: auto; }
ul, ol { padding-left: 1.25rem; }
li { margin-bottom: .3rem; }

/* legacy class aliases used by earlier templates */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card); padding: 16px 18px; }
.tile .num { display: block; font-size: 1.65rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .lbl { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-secondary); }
.page-main h1 { font-size: 1.55rem; font-weight: 700; margin-bottom: .35rem; }
.rule, .sub { font-size: .88rem; color: var(--text-secondary); }

/* ---------- v1 component classes (globals.css parity) ---------- */
.text-display { font-size: 1.375rem; font-weight: 700; line-height: 1.25;
  color: var(--text-primary); }
.text-kpi { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.page-hero {
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--header-gradient); padding: .75rem 1rem;
}
.accent-bar-teal { border-left: 3px solid var(--primary, var(--brand-primary)); }
.accent-bar-gold { border-left: 3px solid var(--brand-gold); }
.module-icon-wrap {
  display: flex; height: 2.25rem; width: 2.25rem; align-items: center;
  justify-content: center; border-radius: 10px;
  background: var(--accent-info-bg); color: var(--accent-info-text);
  border: 1px solid var(--accent-info-border);
}
.hero-badge { display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--brand-primary); border-radius: 999px; padding: 4px 14px;
  font-size: .78rem; font-weight: 500; margin-bottom: 16px; }
.btn-outline { background: transparent; color: var(--text-primary);
  border: 1px solid var(--border); }
.btn-outline:hover { background: var(--surface-muted); }
.btn-lg { padding: .75rem 1.4rem; font-size: 1rem; }
