/* ThreeStack Team Portal - internal sales KB */

:root {
  --color-navy-900: #0a1628;
  --color-navy-800: #0f2240;
  --color-slate-600: #475569;
  --color-slate-500: #64748b;
  --color-slate-400: #94a3b8;
  --color-slate-300: #cbd5e1;
  --color-slate-200: #e2e8f0;
  --color-slate-100: #f1f5f9;
  --color-slate-50: #f8fafc;
  --color-white: #ffffff;
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-cyan: #06b6d4;
  --color-success: #10b981;
  --color-danger: #ef4444;
  --header-height: 4rem;
  --sidebar-width: 300px;
  --doc-toc-width: 220px;
  --doc-read-ratio: 94%;
  --doc-read-max: 80rem;
  --radius-md: 0.75rem;
  --shadow-md: 0 4px 16px rgba(10, 22, 40, 0.08);
  --portal-page-bg: var(--color-slate-50);
  --portal-surface: var(--color-white);
  --portal-surface-muted: var(--color-slate-50);
  --portal-text: var(--color-navy-900);
  --portal-text-muted: var(--color-slate-600);
  --portal-border: var(--color-slate-200);
  --portal-input-bg: var(--color-white);
  --portal-ae-page-bg: #f4f8fc;
  --portal-admin-page-bg: #f8f7f5;
  --portal-table-header-bg: var(--portal-surface-muted);
  --portal-table-cell-bg: var(--portal-surface);
  --portal-table-stripe-bg: var(--color-slate-100);
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--portal-text);
  background: var(--portal-page-bg);
}

a { color: var(--color-accent); }
a:hover { color: var(--color-accent-hover); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.portal-auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: linear-gradient(135deg, var(--color-navy-900) 0%, var(--color-navy-800) 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--radius-md);
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.auth-card h1 { margin: 0 0 0.5rem; font-size: 1.5rem; color: var(--portal-text); }
.auth-card .lead { color: var(--portal-text-muted); margin: 0 0 1.5rem; }
.auth-card label { display: block; font-weight: 600; font-size: 0.875rem; margin: 1rem 0 0.35rem; color: var(--portal-text); }
.auth-card input,
.auth-card select,
.portal-input,
.stack-form input,
.stack-form select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--portal-border);
  border-radius: 0.5rem;
  font: inherit;
  background: var(--portal-input-bg);
  color: var(--portal-text);
}
.auth-error { color: var(--color-danger); background: #fef2f2; padding: 0.75rem; border-radius: 0.5rem; }
.auth-success { color: #065f46; background: #ecfdf5; padding: 0.75rem; border-radius: 0.5rem; }
.auth-hint { font-size: 0.875rem; color: var(--portal-text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  background: transparent;
}
.btn--primary { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn--primary:hover { background: var(--color-accent-hover); color: #fff; border-color: var(--color-accent-hover); }
.btn--ghost {
  border-color: var(--color-slate-400);
  color: var(--portal-text);
  background: var(--portal-surface);
}
.btn--ghost:hover { background: var(--color-slate-100); border-color: var(--color-slate-500); }
.btn--secondary {
  background: var(--portal-surface);
  color: var(--portal-text);
  border: 1px solid var(--color-slate-400);
  box-shadow: 0 1px 2px rgba(10, 22, 40, 0.06);
}
.btn--secondary:hover {
  background: var(--color-slate-100);
  border-color: var(--color-slate-500);
  color: var(--portal-text);
}
.btn--sm { padding: 0.4rem 0.65rem; font-size: 0.8125rem; }
.btn--block { width: 100%; margin-top: 1.25rem; }

.portal-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-navy-900);
  color: #fff;
  height: var(--header-height);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.portal-header__inner {
  width: 100%;
  margin: 0;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #fff;
  text-decoration: none;
}

.portal-brand__mark {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  background: var(--color-cyan);
  color: var(--color-navy-900);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.875rem;
}

.portal-brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.portal-brand__text small { opacity: 0.75; font-size: 0.75rem; }

.portal-header__actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-shrink: 0;
}
.portal-header__cluster {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.portal-header__cluster--user {
  padding-left: 1.25rem;
  margin-left: 0.25rem;
  border-left: 1px solid rgba(255, 255, 255, 0.22);
}
.portal-user {
  font-size: 0.875rem;
  font-weight: 600;
  opacity: 0.95;
  white-space: nowrap;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.portal-header .btn--ghost,
.portal-header .theme-toggle {
  border-color: rgba(255, 255, 255, 0.45);
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}
.portal-header .btn--ghost:hover,
.portal-header .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.75);
  color: #fff;
}

.portal-shell {
  width: 100%;
  margin: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - var(--header-height));
  align-items: start;
}

.portal-sidebar {
  background: var(--portal-surface);
  border-right: 1px solid var(--portal-border);
  padding: 1.25rem 0;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  width: var(--sidebar-width);
  flex-shrink: 0;
}

.portal-nav__section {
  padding: 0 0.85rem;
  margin-bottom: 0.5rem;
}
.portal-nav__section + .portal-nav__section {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--portal-border);
}
.portal-nav__label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--portal-text);
  margin: 0 0 0.5rem;
  padding: 0.4rem 0.65rem;
  font-weight: 800;
  background: linear-gradient(90deg, rgba(6, 182, 212, 0.14), rgba(6, 182, 212, 0.04));
  border-left: 3px solid var(--color-cyan);
  border-radius: 0 0.35rem 0.35rem 0;
}
.portal-nav ul { list-style: none; margin: 0; padding: 0 0 0.25rem; }
.portal-nav__link {
  display: block;
  padding: 0.5rem 0.65rem 0.5rem 0.85rem;
  border-radius: 0.4rem;
  border-left: 2px solid transparent;
  color: var(--portal-text);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.35;
}
.portal-nav__link:hover {
  background: var(--color-slate-100);
  border-left-color: var(--color-slate-300);
  color: var(--portal-text);
}
.portal-nav__link.is-active,
.portal-nav__link[aria-current="page"] {
  background: var(--color-navy-900);
  color: #fff;
  font-weight: 600;
  border-left: none;
  box-shadow: 0 2px 10px rgba(10, 22, 40, 0.18);
}
.portal-nav__link.is-active:hover,
.portal-nav__link[aria-current="page"]:hover {
  background: var(--color-navy-800);
  color: #fff;
}
.portal--ae .portal-nav__link.is-active,
.portal--ae .portal-nav__link[aria-current="page"] {
  background: var(--color-accent);
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.28);
}
.portal--ae .portal-nav__link.is-active:hover,
.portal--ae .portal-nav__link[aria-current="page"]:hover {
  background: var(--color-accent-hover);
}
.portal--admin .portal-nav__link.is-active,
.portal--admin .portal-nav__link[aria-current="page"] {
  background: #1f2937;
  box-shadow: 0 2px 10px rgba(31, 41, 55, 0.22);
}
.portal-sidebar--ae .portal-nav__label {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.12), rgba(37, 99, 235, 0.03));
  border-left-color: var(--color-accent);
}
.portal-sidebar--admin .portal-nav__label {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.16), rgba(245, 158, 11, 0.04));
  border-left-color: #f59e0b;
}

.portal-main {
  padding: 1.5rem 2.5rem 3rem;
  min-width: 0;
  width: 100%;
}

.portal-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.8125rem;
  color: var(--portal-text-muted);
  border-top: 1px solid var(--portal-border);
  background: var(--portal-surface);
}

.portal-hero { margin-bottom: 1.5rem; }
.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-cyan);
  font-weight: 700;
  margin: 0 0 0.5rem;
}
.portal-hero h1 { margin: 0 0 0.5rem; font-size: 2rem; color: var(--portal-text); }
.lead { color: var(--portal-text-muted); margin: 0; max-width: 60ch; }

.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
}
.card--accent { border-color: rgba(6, 182, 212, 0.35); }
.card--wide { grid-column: 1 / -1; }
.card h2 { margin: 0 0 0.75rem; font-size: 1.1rem; color: var(--portal-text); }
.card p, .card li { color: var(--portal-text); }
.card-list { margin: 0; padding-left: 1.1rem; }
.card-list--plain { list-style: none; padding: 0; }
.card-list li { margin: 0.35rem 0; }
.tool-label { display: block; font-size: 0.8rem; color: var(--portal-text-muted); }

.stat-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin: 0; }
.stat-list div { background: var(--portal-surface-muted); padding: 0.75rem; border-radius: 0.5rem; }
.stat-list dt { font-size: 0.75rem; color: var(--portal-text-muted); margin: 0; }
.stat-list dd { margin: 0.15rem 0 0; font-weight: 700; font-size: 1.1rem; color: var(--portal-text); }

.doc-breadcrumb { font-size: 0.875rem; color: var(--portal-text-muted); margin-bottom: 1.25rem; }
.doc-breadcrumb a { text-decoration: none; }

.doc-content {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--radius-md);
  padding: clamp(1.25rem, 2.5vw, 2.5rem) clamp(1rem, 3vw, 2.75rem) clamp(1.75rem, 3vw, 2.75rem);
  box-shadow: var(--shadow-md);
  width: min(var(--doc-read-max), var(--doc-read-ratio));
  max-width: min(var(--doc-read-max), var(--doc-read-ratio));
  min-width: 0;
  margin-inline: auto;
  justify-self: center;
  grid-column: 2;
  grid-row: 2;
}
.doc-layout:not(:has(.doc-toc)) .doc-content {
  grid-column: 1;
}
.doc-content h1 { font-size: 2rem; margin-top: 0; color: var(--portal-text); }
.doc-content h2 { margin-top: 2rem; border-bottom: 1px solid var(--portal-border); padding-bottom: 0.35rem; color: var(--portal-text); }
.doc-content h3 { margin-top: 1.5rem; color: var(--portal-text); }
.doc-content p, .doc-content li { color: var(--portal-text); }
.doc-content pre {
  background: var(--color-navy-900);
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  font-size: 0.875rem;
}
.doc-content code { background: var(--color-slate-100); color: var(--portal-text); padding: 0.1rem 0.35rem; border-radius: 0.25rem; font-size: 0.9em; }
.doc-content pre code { background: transparent; padding: 0; }
.doc-content blockquote {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--color-cyan);
  background: var(--portal-surface-muted);
  color: var(--portal-text-muted);
}
.doc-content hr { border: 0; border-top: 1px solid var(--portal-border); margin: 2rem 0; }

.doc-content .md-table-wrap,
.md-table-wrap { overflow-x: auto; margin: 1rem 0; -webkit-overflow-scrolling: touch; }
.doc-content table,
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0;
}
.doc-content table th,
.doc-content table td,
.md-table th,
.md-table td {
  border: 1px solid var(--portal-border);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
}
.doc-content table th,
.md-table th {
  background: var(--portal-table-header-bg);
  font-weight: 600;
  color: var(--portal-text);
}
.doc-content table td,
.md-table td {
  background: var(--portal-table-cell-bg);
  color: var(--portal-text);
}
.doc-content table tr:nth-child(even) td,
.md-table tr:nth-child(even) td {
  background: var(--portal-table-stripe-bg);
}
.doc-content table tbody tr:hover td,
.md-table tbody tr:hover td {
  background: rgba(37, 99, 235, 0.06);
}

.admin-header { margin-bottom: 1rem; }
.admin-header h1 { color: var(--portal-text); }
.admin-header p { color: var(--portal-text-muted); }
.admin-grid { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 1rem; }
.stack-form label { display: block; font-weight: 600; font-size: 0.875rem; margin: 0.75rem 0 0.35rem; color: var(--portal-text); }
.stack-form input, .stack-form select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--portal-border);
  border-radius: 0.5rem;
  font: inherit;
  background: var(--portal-input-bg);
  color: var(--portal-text);
}
.table-wrap { overflow-x: auto; }
.admin-actions { white-space: nowrap; }
.admin-actions__group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.admin-actions__note { font-size: 0.8125rem; color: var(--portal-text-muted); }
.inline-form { display: inline; }

.add-user-panel {
  display: block;
  min-width: 0;
}
.add-user-panel__body {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--portal-border);
}
.add-user-panel[open] .add-user-panel__body {
  width: 100%;
}
.users-table__header .add-user-panel[open] {
  flex: 1 1 100%;
}
.add-user-panel__intro {
  margin: 0 0 1rem;
  color: var(--portal-text-muted);
  font-size: 0.9rem;
  max-width: 62ch;
}
.users-table__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--portal-border);
}
.users-table__header h2 { margin: 0; }
.users-table__header p {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: var(--portal-text-muted);
}
.add-user-form__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1.25rem;
}
.add-user-form__section-label {
  grid-column: 1 / -1;
  margin: 0.5rem 0 0;
  padding: 0.45rem 0.65rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 800;
  color: var(--portal-text);
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.14), rgba(245, 158, 11, 0.03));
  border-left: 3px solid #f59e0b;
  border-radius: 0 0.35rem 0.35rem 0;
}
.add-user-form__section-label:first-child { margin-top: 0; }
.add-user-form .form-field label {
  display: block;
  font-weight: 600;
  font-size: 0.8125rem;
  margin: 0 0 0.35rem;
  color: var(--portal-text);
}
.add-user-form .form-field .portal-input,
.add-user-form .form-field input,
.add-user-form .form-field select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--portal-border);
  border-radius: 0.5rem;
  font: inherit;
  background: var(--portal-input-bg);
  color: var(--portal-text);
}
.add-user-form .form-field .form-hint {
  margin: 0.3rem 0 0;
}
.add-user-form__actions {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--portal-border);
  display: flex;
  justify-content: flex-end;
}

.password-card { margin-bottom: 1rem; }

.portal-checklist-item {
  margin: 0.35rem 0;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--portal-border);
  border-radius: 0.45rem;
  background: var(--portal-surface-muted);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.portal-checklist-item--checked {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.35);
}
.portal-checklist-item__label {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  cursor: pointer;
  margin: 0;
  font-weight: 500;
  color: var(--portal-text);
}
.portal-checklist-item--readonly .portal-checklist-item__label {
  cursor: default;
}
.portal-checklist-item__input {
  width: 1rem;
  height: 1rem;
  margin-top: 0.15rem;
  flex-shrink: 0;
  accent-color: var(--color-accent);
}
.portal-checklist-item__text {
  flex: 1;
  line-height: 1.45;
}
.portal-checklist-item__text a {
  font-weight: 600;
}
.checklist-progress-banner {
  margin: 0 0 1.25rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.5rem;
  background: rgba(37, 99, 235, 0.1);
  border: 1px solid rgba(37, 99, 235, 0.25);
  color: var(--portal-text);
  font-size: 0.875rem;
  font-weight: 600;
}
.checklist-progress-banner--readonly {
  background: var(--portal-surface-muted);
  border-color: var(--portal-border);
  font-weight: 500;
  color: var(--portal-text-muted);
}
.progress-meter {
  height: 0.45rem;
  border-radius: 999px;
  background: var(--color-slate-100);
  overflow: hidden;
  min-width: 6rem;
}
.progress-meter--inline {
  display: inline-block;
  vertical-align: middle;
  width: 5rem;
  margin-right: 0.35rem;
}
.progress-meter__bar {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-accent), var(--color-cyan));
}
.progress-meter__label {
  font-size: 0.8125rem;
  color: var(--portal-text-muted);
  white-space: nowrap;
}
.progress-meter-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-decoration: none;
  color: inherit;
}
.progress-meter-link:hover .progress-meter__label {
  color: var(--color-accent);
}
.progress-doc-list {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.8125rem;
  color: var(--portal-text-muted);
}
.progress-doc-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.table-subtext {
  font-size: 0.8125rem;
  color: var(--portal-text-muted);
  margin-top: 0.15rem;
}
[data-theme="dark"] .portal-checklist-item--checked {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(52, 211, 153, 0.45);
}
[data-theme="dark"] .checklist-progress-banner {
  background: rgba(37, 99, 235, 0.18);
  border-color: rgba(96, 165, 250, 0.35);
}

.account-grid { align-items: start; }
.form-hint {
  margin: 0.25rem 0 0.75rem;
  font-size: 0.8125rem;
  color: var(--portal-text-muted);
}
.password-panel {
  display: block;
  min-width: 0;
}
.password-panel summary,
.account-panel summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
}
.password-panel summary::-webkit-details-marker,
.account-panel summary::-webkit-details-marker {
  display: none;
}
.password-panel[open] summary,
.account-panel[open] summary {
  margin-bottom: 0.5rem;
}
.password-panel__form {
  margin-top: 0.5rem;
}
.password-set-form {
  display: grid;
  gap: 0.5rem;
  min-width: 12rem;
}
.password-set-form .portal-input {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--portal-border);
  border-radius: 0.4rem;
  font: inherit;
  background: var(--portal-input-bg);
  color: var(--portal-text);
}
.user-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(245, 158, 11, 0.18);
  color: #b45309;
}
[data-theme="dark"] .user-badge {
  background: rgba(245, 158, 11, 0.22);
  color: #fbbf24;
}

/* AE experience */
.portal--ae { background: var(--portal-ae-page-bg); }
.portal-header--ae { background: linear-gradient(90deg, #0a1628 0%, #12345c 100%); }
.portal-sidebar--ae { background: var(--portal-surface); border-right: 1px solid var(--portal-border); }
.portal-main--ae .portal-hero,
.portal-main--ae .portal-grid,
.portal-main--ae .ae-hero {
  max-width: 1100px;
}
.sidebar-cta { padding: 0 1rem 1rem; }
.sidebar-cta__label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--portal-text);
  margin: 0 0 0.5rem;
  padding: 0.4rem 0.65rem;
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.12), rgba(37, 99, 235, 0.03));
  border-left: 3px solid var(--color-accent);
  border-radius: 0 0.35rem 0.35rem 0;
}
.btn--accent { background: var(--color-cyan); color: #062033; }
.btn--accent:hover { filter: brightness(0.95); color: #062033; }
.btn--lg { padding: 0.85rem 1.25rem; font-size: 1rem; }
.btn--danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn--danger:hover { background: #dc2626; color: #fff; border-color: #dc2626; }

.ae-hero {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.5rem;
  background: linear-gradient(135deg, #0a1628, #153e75);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 2rem;
  margin-bottom: 1.5rem;
}
.ae-hero h1 { margin: 0 0 0.5rem; font-size: 2rem; }
.ae-hero .lead { color: rgba(255,255,255,0.85); max-width: 52ch; }
.ae-hero__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }
.ae-hero .btn--ghost {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.1);
}
.ae-hero .btn--ghost:hover {
  color: #fff;
  border-color: #fff;
  background: rgba(255, 255, 255, 0.2);
}
.ae-hero__stats { display: grid; gap: 0.75rem; align-content: center; }
.ae-hero__stats div { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); border-radius: 0.75rem; padding: 1rem; }
.ae-hero__stats strong { display: block; font-size: 1.5rem; }
.ae-hero__stats span { font-size: 0.85rem; opacity: 0.85; }

.ae-section { margin-bottom: 1.5rem; }
.ae-section__header h2 { margin: 0 0 0.25rem; color: var(--portal-text); }
.ae-section__header p { margin: 0 0 1rem; color: var(--portal-text-muted); }

.learning-path { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.learning-path__item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
}
.learning-path__step {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--color-accent);
  display: grid;
  place-items: center;
  font-weight: 800;
}
.learning-path__title { font-weight: 700; color: var(--portal-text); text-decoration: none; }
.learning-path__title:hover { color: var(--color-accent); }
.learning-path__hint { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--portal-text-muted); }
.learning-path__body { min-width: 0; }

.quick-links { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.quick-link {
  display: block;
  text-align: center;
  padding: 0.85rem;
  border-radius: 0.5rem;
  background: var(--portal-surface-muted);
  border: 1px solid var(--portal-border);
  text-decoration: none;
  font-weight: 600;
  color: var(--portal-text);
}
.quick-link:hover { background: rgba(37, 99, 235, 0.08); color: var(--color-accent); }

/* Doc reader: TOC left, content + trails fill remaining width */
.doc-layout {
  display: grid;
  grid-template-columns: var(--doc-toc-width) minmax(0, 1fr);
  column-gap: 1.5rem;
  row-gap: 1.25rem;
  width: 100%;
  align-items: start;
}
.doc-layout:not(:has(.doc-toc)) {
  grid-template-columns: minmax(0, 1fr);
}
.doc-layout__grid {
  display: contents;
}
.doc-toc {
  grid-column: 1;
  grid-row: 1 / span 3;
  position: sticky;
  top: calc(var(--header-height) + 1rem);
  max-height: calc(100vh - var(--header-height) - 2rem);
  width: var(--doc-toc-width);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--radius-md);
  padding: 1rem;
}
.doc-toc__title {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--portal-text-muted);
  font-weight: 700;
  flex-shrink: 0;
}
.doc-toc__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--color-slate-300) transparent;
  margin: 0 -0.35rem;
  padding: 0 0.35rem 0.15rem;
}
.doc-toc__scroll::-webkit-scrollbar {
  width: 6px;
}
.doc-toc__scroll::-webkit-scrollbar-thumb {
  background: var(--color-slate-300);
  border-radius: 999px;
}
.doc-toc__scroll::-webkit-scrollbar-thumb:hover {
  background: var(--color-slate-500);
}

/* Grouped TOC: h2 sections + h3 subsections */
.doc-toc__groups {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.doc-toc__group {
  background: var(--color-slate-50);
  border: 1px solid var(--portal-border);
  border-radius: 0.5rem;
  overflow: hidden;
}
.doc-toc__group:only-child .doc-toc__section {
  border-radius: 0.5rem;
}
.doc-toc__section {
  display: block;
  padding: 0.55rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--portal-text);
  text-decoration: none;
  background: var(--portal-surface);
  border-left: 3px solid var(--color-slate-400);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.doc-toc__section:hover {
  background: var(--color-slate-100);
  color: var(--portal-text);
  border-left-color: var(--color-slate-400);
}
.doc-toc__section.is-active {
  background: var(--color-navy-900);
  color: #fff;
  border-left-color: var(--color-cyan);
  box-shadow: 0 2px 8px rgba(10, 22, 40, 0.2);
}
.doc-toc__section.is-active:hover {
  background: var(--color-navy-800);
  color: #fff;
}
.portal--ae .doc-toc__section {
  border-left-color: rgba(6, 182, 212, 0.45);
}
.portal--ae .doc-toc__section.is-active {
  background: #0f2240;
  border-left-color: var(--color-cyan);
}
.portal--admin .doc-toc__section {
  border-left-color: rgba(245, 158, 11, 0.45);
}
.portal--admin .doc-toc__section.is-active {
  background: #1f2937;
  border-left-color: #f59e0b;
}
.doc-toc__group--active {
  border-color: rgba(37, 99, 235, 0.25);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.08);
}
.doc-toc__subs {
  list-style: none;
  margin: 0;
  padding: 0.35rem 0.5rem 0.45rem;
}
.doc-toc__sub { margin: 0; }
.doc-toc__sub a {
  display: block;
  padding: 0.3rem 0.45rem 0.3rem 0.65rem;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--portal-text-muted);
  text-decoration: none;
  border-radius: 0.3rem;
  border-left: 2px solid var(--color-slate-200);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.doc-toc__sub a:hover {
  color: var(--portal-text);
  background: var(--color-slate-100);
  border-left-color: var(--color-slate-400);
}
.doc-toc__sub a.is-active {
  background: var(--color-accent);
  color: #fff;
  font-weight: 600;
  border-left-color: var(--color-accent);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.28);
}
.doc-toc__sub a.is-active:hover {
  background: var(--color-accent-hover);
  color: #fff;
}
.portal--ae .doc-toc__sub a.is-active {
  background: var(--color-navy-900);
  border-left-color: var(--color-cyan);
  box-shadow: 0 2px 6px rgba(10, 22, 40, 0.22);
}
.portal--ae .doc-toc__sub a.is-active:hover {
  background: var(--color-navy-800);
}
.portal--admin .doc-toc__sub a.is-active {
  background: #374151;
  border-left-color: #f59e0b;
}

.doc-trail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  grid-column: 2;
  width: 100%;
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-md);
}
.doc-layout:not(:has(.doc-toc)) .doc-trail {
  grid-column: 1;
}
.doc-trail:first-child {
  grid-row: 1;
}
.doc-trail--bottom {
  grid-template-columns: 1fr 1fr;
  grid-row: 3;
}
.doc-trail__link {
  display: block;
  padding: 1.15rem 1.35rem;
  border-radius: 0.5rem;
  background: var(--portal-surface-muted);
  border: 1px solid var(--portal-border);
  text-decoration: none;
  color: var(--portal-text);
  min-height: 4.5rem;
}
.doc-trail__link span {
  display: block;
  font-size: 0.8rem;
  color: var(--portal-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}
.doc-trail__link strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.05rem;
  line-height: 1.35;
}
.doc-trail__link--next { text-align: right; }
.doc-trail__link:hover {
  background: rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.25);
}

.doc-content a { font-weight: 600; }
.doc-content a[href^="/doc.php"] { color: var(--color-accent); }

/* Admin experience */
.portal--admin { background: var(--portal-admin-page-bg); }
.portal-header--admin { background: #1f2937; }
.portal-brand__mark--admin { background: #f59e0b; color: #1f2937; }
.portal-sidebar--admin { background: var(--portal-surface); border-right: 1px solid var(--portal-border); }
.portal-main--admin .portal-hero,
.portal-main--admin .admin-hero,
.portal-main--admin .admin-header,
.portal-main--admin .portal-grid {
  max-width: 1200px;
}
.eyebrow--admin { color: #f59e0b; }
.admin-hero { margin-bottom: 1.25rem; }
.admin-hero h1 { color: var(--portal-text); }
.admin-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.admin-stat { background: var(--portal-surface); border: 1px solid var(--portal-border); border-radius: var(--radius-md); padding: 1.25rem; }
.admin-stat strong { display: block; font-size: 2rem; color: var(--portal-text); }
.admin-stat span { color: var(--portal-text-muted); font-size: 0.9rem; }
.card--admin { border-color: var(--portal-border); }
.card--wide { grid-column: 1 / -1; }
.content-library { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.content-library__group h3 { margin: 0 0 0.5rem; font-size: 0.95rem; color: var(--portal-text); }
.content-library ul { margin: 0; padding-left: 1.1rem; }
.portal-footer--admin { background: var(--portal-surface); }

/* Theme toggle */
.theme-toggle { gap: 0.35rem; }
.theme-toggle__icon { font-size: 1rem; line-height: 1; }
.theme-toggle__icon--moon { display: none; }
[data-theme="dark"] .theme-toggle__icon--sun { display: none; }
[data-theme="dark"] .theme-toggle__icon--moon { display: inline; }

.auth-toolbar {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
}
.portal-auth .theme-toggle {
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}
.portal-auth .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.55);
}

/* Dark mode */
[data-theme="dark"] {
  --portal-page-bg: #0b1220;
  --portal-surface: #1e293b;
  --portal-surface-muted: #151d2e;
  --portal-text: #e2e8f0;
  --portal-text-muted: #94a3b8;
  --portal-border: #334155;
  --portal-input-bg: #0f172a;
  --portal-ae-page-bg: #0b1220;
  --portal-admin-page-bg: #0b1220;
  --color-slate-50: #151d2e;
  --color-slate-100: #243044;
  --color-slate-200: #334155;
  --color-slate-300: #64748b;
  --color-slate-400: #94a3b8;
  --portal-table-stripe-bg: #1a2438;
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .portal-nav__label,
[data-theme="dark"] .sidebar-cta__label {
  color: #f8fafc;
}
[data-theme="dark"] .portal-nav__label {
  background: linear-gradient(90deg, rgba(6, 182, 212, 0.32), rgba(6, 182, 212, 0.08));
  border-left-color: #22d3ee;
}
[data-theme="dark"] .portal-sidebar--ae .portal-nav__label,
[data-theme="dark"] .sidebar-cta__label {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.34), rgba(37, 99, 235, 0.1));
  border-left-color: #60a5fa;
}
[data-theme="dark"] .portal-sidebar--admin .portal-nav__label {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.38), rgba(245, 158, 11, 0.12));
  border-left-color: #fbbf24;
}
[data-theme="dark"] .add-user-form__section-label {
  color: #f8fafc;
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.38), rgba(245, 158, 11, 0.12));
  border-left-color: #fbbf24;
}

[data-theme="dark"] .doc-toc__title {
  color: #cbd5e1;
}
[data-theme="dark"] .doc-toc__group {
  background: #111827;
  border-color: #475569;
}
[data-theme="dark"] .doc-toc__group--active {
  border-color: rgba(96, 165, 250, 0.55);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.2);
}
[data-theme="dark"] .doc-toc__section {
  color: #f1f5f9;
  background: #243044;
  border-left-color: #64748b;
}
[data-theme="dark"] .doc-toc__section:hover {
  background: #2f3f58;
  color: #fff;
  border-left-color: #94a3b8;
}
[data-theme="dark"] .portal--ae .doc-toc__section {
  border-left-color: rgba(34, 211, 238, 0.75);
}
[data-theme="dark"] .portal--ae .doc-toc__section.is-active {
  background: #1d4ed8;
  color: #fff;
  border-left-color: #22d3ee;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.45);
}
[data-theme="dark"] .portal--ae .doc-toc__section.is-active:hover {
  background: #1e40af;
}
[data-theme="dark"] .portal--admin .doc-toc__section {
  border-left-color: rgba(251, 191, 36, 0.75);
}
[data-theme="dark"] .portal--admin .doc-toc__section.is-active {
  background: #b45309;
  color: #fff;
  border-left-color: #fbbf24;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.35);
}
[data-theme="dark"] .portal--admin .doc-toc__section.is-active:hover {
  background: #92400e;
}
[data-theme="dark"] .doc-toc__section.is-active {
  background: #1e3a8a;
  color: #fff;
  border-left-color: #22d3ee;
}

[data-theme="dark"] .doc-content table tbody tr:hover td,
[data-theme="dark"] .md-table tbody tr:hover td {
  background: rgba(37, 99, 235, 0.12);
}
[data-theme="dark"] .auth-error {
  background: rgba(127, 29, 29, 0.35);
  color: #fca5a5;
}
[data-theme="dark"] .auth-success {
  background: rgba(6, 78, 59, 0.35);
  color: #6ee7b7;
}

[data-theme="dark"] .btn--ghost {
  background: #2a3548;
  border-color: #64748b;
  color: #f1f5f9;
}
[data-theme="dark"] .btn--ghost:hover {
  background: #38465e;
  border-color: #94a3b8;
  color: #fff;
}
[data-theme="dark"] .btn--secondary {
  background: #334155;
  border-color: #94a3b8;
  color: #f8fafc;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
[data-theme="dark"] .btn--secondary:hover {
  background: #475569;
  border-color: #cbd5e1;
  color: #fff;
}
[data-theme="dark"] .md-table .btn--ghost,
[data-theme="dark"] .md-table .btn--secondary {
  background: #3d4f66;
  border-color: #94a3b8;
  color: #f8fafc;
}
[data-theme="dark"] .md-table .btn--ghost:hover,
[data-theme="dark"] .md-table .btn--secondary:hover {
  background: #4b607c;
  border-color: #cbd5e1;
}

/* Doc reader: fluid width between breakpoints */
@media (max-width: 1200px) {
  :root {
    --doc-read-ratio: 96%;
    --doc-read-max: 100%;
  }
}

@media (max-width: 960px) {
  .portal-header {
    height: auto;
    min-height: var(--header-height);
  }
  .portal-shell { grid-template-columns: 1fr; }
  .portal-sidebar {
    position: static;
    height: auto;
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--color-slate-200);
  }
  .portal-header__inner {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-height);
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }
  .portal-header__actions {
    width: 100%;
    justify-content: space-between;
    gap: 0.75rem;
  }
  .portal-header__cluster--user {
    padding-left: 0.75rem;
    margin-left: 0;
  }
  .portal-main { padding: 1rem; }
  .admin-grid { grid-template-columns: 1fr; }
  .add-user-form__grid { grid-template-columns: 1fr; }
  .ae-hero { grid-template-columns: 1fr; }
  .doc-layout {
    grid-template-columns: 1fr;
    row-gap: 1rem;
  }
  .doc-layout__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .doc-toc,
  .doc-content,
  .doc-trail {
    grid-column: 1;
    grid-row: auto;
    width: 100%;
    justify-self: stretch;
    max-width: none;
  }
  .doc-content {
    padding: 1.35rem 1.15rem 2rem;
  }
  .doc-trail {
    padding: 1rem 1.1rem;
    gap: 0.85rem;
  }
  .doc-trail__link {
    padding: 0.95rem 1.1rem;
    min-height: auto;
  }
  .doc-toc {
    position: static;
    max-height: 12rem;
  }
  .learning-path__item { grid-template-columns: auto 1fr; }
  .learning-path__item .btn { grid-column: 1 / -1; }
  .admin-stats { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  .doc-trail,
  .doc-trail--bottom {
    grid-template-columns: 1fr;
  }
  .doc-trail__link--next {
    text-align: left;
  }
  .doc-content {
    padding: 1.15rem 0.9rem 1.75rem;
  }
  .doc-content h1 {
    font-size: 1.65rem;
  }
}
