:root {
  --caos-primary: #1e3a8a;
  --caos-primary-dark: #0f172a;
  --caos-primary-light: #eef2ff;
  --caos-accent: #2563eb;
  --caos-success: #15803d;
  --caos-surface: #ffffff;
  --caos-bg: #f4f6fb;
  --caos-border: #e6e9f2;
  --caos-text: #1f2937;
  --caos-text-muted: #6b7280;

  --bs-primary: #1e3a8a;
  --bs-primary-rgb: 30, 58, 138;
  --bs-body-font-family: 'Inter', Arial, Helvetica, sans-serif;
  --bs-body-color: var(--caos-text);
  --bs-body-bg: var(--caos-bg);
  --bs-border-color: var(--caos-border);
  --bs-border-radius: 0.65rem;
  --bs-border-radius-sm: 0.5rem;
  --bs-border-radius-lg: 0.9rem;
}

* { -webkit-font-smoothing: antialiased; }

body {
  background-color: var(--caos-bg);
  color: var(--caos-text);
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.01em;
}

main.container { max-width: 1180px; }

/* ---------- Page header rhythm ---------- */
main > h1:first-of-type,
main > .d-flex:first-of-type h1 {
  margin-bottom: 0.35rem;
}
main > h1:first-of-type + p.text-muted,
main > .d-flex:first-of-type + p.text-muted {
  margin-top: -0.1rem;
}
/* Only section headers that sit directly in the page flow get the divider
   treatment — headers nested inside a card (a card's own title, a dashboard
   tile's title) must NOT pick this up, so the selector is scoped to a
   direct child of <main> rather than any h2.h5/h2.h6 anywhere on the page. */
main > h2.h5, main > h2.h6 {
  margin-top: 2.25rem;
  margin-bottom: 1.1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--caos-border);
  color: var(--caos-primary);
  font-weight: 700;
  font-size: 1.05rem;
}
main > h2.h5:first-child, main > h2.h6:first-child { margin-top: 0; }

/* ---------- Page head (list-page title + primary action) ---------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
/* Forms use the same full card width as everything else on the page
   (hero banner, alerts, list tables) — no artificial narrowing. */
.form-page, .form-page-wide { max-width: none; width: 100%; }
.form-page-narrow { max-width: 350px; width: 100%; margin-left: auto; margin-right: auto; }

/* ---------- Navbar ---------- */
nav.navbar {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--caos-border);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  color: var(--caos-primary-dark) !important;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--caos-primary), var(--caos-accent));
  color: #fff;
  font-size: 1rem;
  box-shadow: 0 3px 10px rgba(30, 58, 138, 0.35);
}
.navbar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--caos-text);
  font-weight: 600;
  font-size: 0.92rem;
  border-radius: 999px;
  padding: 0.45rem 0.9rem !important;
  margin: 0 0.1rem;
  transition: background-color .12s ease, color .12s ease;
}
.navbar-nav .nav-link:hover { background: var(--caos-primary-light); color: var(--caos-primary); }
.navbar-nav .nav-link.active { background: var(--caos-primary); color: #fff !important; }
.navbar-nav .nav-link i { font-size: 0.95rem; }
.dropdown-menu {
  border: 1px solid var(--caos-border);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  border-radius: 0.75rem;
  padding: 0.5rem;
  margin-top: 0.4rem;
}
.dropdown-item { border-radius: 0.5rem; padding: 0.45rem 0.75rem; font-size: 0.92rem; font-weight: 500; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--caos-primary-light); color: var(--caos-primary); }
.avatar-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--caos-primary-light);
  color: var(--caos-primary);
  font-weight: 700;
  font-size: 0.85rem;
}

/* ---------- Buttons ---------- */
.btn { padding: 0.5rem 1.05rem; font-size: 0.95rem; font-weight: 600; border-radius: 0.6rem; }
.btn-sm { padding: 0.32rem 0.75rem; font-size: 0.83rem; border-radius: 0.5rem; }
.btn-primary {
  background: linear-gradient(135deg, var(--caos-primary), var(--caos-accent));
  border-color: var(--caos-primary);
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.25);
}
.btn-primary:hover, .btn-primary:focus {
  background: linear-gradient(135deg, var(--caos-primary-dark), var(--caos-primary));
  border-color: var(--caos-primary-dark);
}
.btn-outline-primary { color: var(--caos-primary); border-color: #c7d2fe; }
.btn-outline-primary:hover { background: var(--caos-primary); border-color: var(--caos-primary); }
.text-primary { color: var(--caos-primary) !important; }
.bg-primary { background-color: var(--caos-primary) !important; }

/* ---------- Forms ---------- */
.form-control, .form-select {
  padding: 0.55rem 0.8rem;
  font-size: 0.95rem;
  border-color: var(--caos-border);
  border-radius: 0.55rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--caos-accent);
  box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.15);
}
.form-control-sm, .form-select-sm { border-radius: 0.45rem; }
.form-label, label.form-label { font-weight: 600; font-size: 0.84rem; color: var(--caos-text-muted); margin-bottom: 0.3rem; }
.form-text em { font-style: normal; font-weight: 600; color: var(--caos-text); }
.form-control[type="file"] {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  line-height: 1.6;
}
.form-control[type="file"]::file-selector-button {
  margin-right: 0.7rem;
  padding: 0.3rem 0.7rem;
  border-radius: 0.4rem;
  border: 0;
  background: var(--caos-primary-light);
  color: var(--caos-primary);
  font-weight: 600;
  font-size: 0.82rem;
}
.form-control[type="file"]::file-selector-button:hover { background: #dde3fb; }

/* ---------- Cards ---------- */
.card {
  background: var(--caos-surface);
  border: 1px solid var(--caos-border);
  border-radius: var(--bs-border-radius-lg);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}
.card-body { padding: 1.5rem; }
.card-title { color: var(--caos-primary); font-weight: 700; }

.dashboard-tile {
  display: block;
  text-decoration: none;
  color: inherit;
  height: 100%;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.dashboard-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
  border-color: #c7d2fe;
}
.dashboard-tile .card-body { padding: 1.6rem 1.5rem; }
.tile-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  font-size: 1.35rem;
  margin-bottom: 0.9rem;
}

/* ---------- Hero (dashboard) ---------- */
.hero-banner {
  background: linear-gradient(135deg, var(--caos-primary-dark), var(--caos-primary) 60%, var(--caos-accent));
  color: #fff;
  border-radius: var(--bs-border-radius-lg);
  padding: 2.25rem 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
  position: relative;
  overflow: hidden;
}
.hero-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(255,255,255,0.14), transparent 55%);
}
.hero-banner::before {
  content: "\f61c"; /* bootstrap-icons hexagon */
  font-family: "bootstrap-icons" !important;
  position: absolute;
  right: -1.25rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9rem;
  color: rgba(255, 255, 255, 0.08);
  line-height: 1;
  pointer-events: none;
}
.hero-banner h1 { color: #fff; font-size: 1.7rem; margin-bottom: 0.25rem; }
.hero-banner .hero-sub { color: rgba(255,255,255,0.82); font-size: 0.95rem; }
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.28);
  color: #fff;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  margin: 0.15rem 0.3rem 0.15rem 0;
}

/* ---------- Tables ---------- */
.table-responsive {
  background: var(--caos-surface);
  border: 1px solid var(--caos-border);
  border-radius: var(--bs-border-radius);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  overflow: hidden;
}
.table { margin-bottom: 0; }
.table > :not(caption) > * > * {
  padding: 0.8rem 1rem;
  font-size: 0.92rem;
  vertical-align: middle;
}
.table > thead > tr > th {
  background: #fafbfe;
  color: var(--caos-text-muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  font-weight: 700;
  border-bottom: 1px solid var(--caos-border);
}
.table > tbody > tr { border-bottom: 1px solid var(--caos-border); }
.table > tbody > tr:last-child { border-bottom: none; }
.table > tbody > tr:hover { background-color: #f8f9ff; }
.table-bordered > :not(caption) > * { border-width: 1px; border-color: var(--caos-border); }

/* Action cells (buttons/forms bunched in the last column of a data table)
   need real breathing room between elements — without this they render
   edge-to-edge, which is a big part of what reads as "cluttered". */
.table td:last-child {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.table td:last-child form { display: inline-flex; margin: 0; }
.table td .btn, .table td form .btn { white-space: nowrap; }

/* ---------- Rule checklist (Governance Rules gates) ---------- */
.rule-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.rule-item {
  background: var(--caos-surface);
  border: 1px solid var(--caos-border);
  border-radius: var(--bs-border-radius);
  padding: 1rem 1.15rem;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.03);
}
.rule-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.rule-item-title { font-weight: 700; font-size: 0.95rem; }
.rule-item-desc { color: var(--caos-text-muted); font-size: 0.87rem; margin: 0.3rem 0 0; }
.rule-item-source { color: var(--caos-text-muted); font-size: 0.83rem; margin: 0.4rem 0 0; }
.rule-item-source em { font-style: normal; font-weight: 600; color: var(--caos-text); }
.rule-item-action {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--caos-border);
}
.rule-item-action .form-control { max-width: 280px; }

/* ---------- Document section browser ---------- */
.doc-section {
  border-left: 2px solid var(--caos-border);
  padding-left: 1rem;
  margin: 1rem 0;
}
.doc-section[data-depth="0"] {
  border-left-color: var(--caos-primary);
  background: var(--caos-surface);
  border: 1px solid var(--caos-border);
  border-left: 3px solid var(--caos-primary);
  border-radius: var(--bs-border-radius);
  padding: 1.1rem 1.25rem;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}
.doc-section-head { display: flex; align-items: baseline; gap: 0.5rem; }
.doc-section-review-link { margin-left: auto; font-size: 0.78rem; white-space: nowrap; }
.doc-section-number { color: var(--caos-primary); font-weight: 700; font-size: 0.85rem; white-space: nowrap; }
.doc-section[data-depth="0"] .doc-section-heading { font-weight: 700; font-size: 1.02rem; }
.doc-section-heading { font-weight: 600; font-size: 0.92rem; }
.doc-section-tags { margin: 0.35rem 0; }
.section-tag { font-weight: 600; border: 1px solid var(--caos-border); }
.doc-section-body { color: var(--caos-text-muted); font-size: 0.88rem; margin: 0.4rem 0 0; white-space: pre-line; }
.doc-section-children { margin-top: 0.5rem; }

/* ---------- Signup document walkthrough ---------- */
.doc-scroll-container {
  max-height: 55vh;
  overflow-y: auto;
  background: var(--caos-surface);
  border: 1px solid var(--caos-border);
  border-radius: var(--bs-border-radius);
  padding: 1.5rem 1.75rem;
}
.doc-scroll-container h4 { color: var(--caos-primary); }
.doc-scroll-container p { line-height: 1.7; }
.wizard-steps {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.wizard-step {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--caos-border);
}
.wizard-step.is-done { background: var(--caos-success); }
.wizard-step.is-current { background: var(--caos-primary); transform: scale(1.3); }

/* ---------- Badges ---------- */
.badge {
  font-weight: 600;
  padding: 0.4em 0.75em;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.badge-count { font-size: 0.75rem; }

/* ---------- Alerts ---------- */
.alert { border: none; border-radius: 0.65rem; border-left: 4px solid transparent; }
.alert-success { background: #ecfdf5; color: #065f46; border-left-color: #10b981; }
.alert-danger { background: #fef2f2; color: #991b1b; border-left-color: #ef4444; }
.alert-info { background: #eff6ff; color: #1e40af; border-left-color: #3b82f6; }
.alert-light { background: #f8fafc; border-left-color: #cbd5e1; }

/* ---------- Nav pills (list filters) ---------- */
.nav-pills .nav-link {
  color: var(--caos-text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
}
.nav-pills .nav-link.active { background: var(--caos-primary); }

footer { color: var(--caos-text-muted); font-size: 0.85rem; }
