:root {
  --primary: #123c69;
  --accent: #19a7ce;
  --ink: #142033;
  --muted: #5b677a;
  --line: #d9e1ec;
  --surface: #ffffff;
  --soft: #f4f7fb;
  --danger: #b42318;
  --success: #0f7a4f;
  --radius: 8px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--soft);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a.button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover,
a.button:hover {
  border-color: var(--primary);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #087f8c;
  outline-offset: 2px;
}

.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.ghost {
  background: transparent;
}

.link-button {
  border: 0;
  min-height: auto;
  padding-inline: 0;
  color: var(--primary);
  justify-content: flex-start;
}

.small {
  min-height: 30px;
  padding: 4px 8px;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 50;
  background: #fff;
  padding: 10px;
  border: 2px solid var(--primary);
}

.skip-link:focus {
  top: 12px;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 460px);
  align-items: center;
  gap: 40px;
  padding: clamp(24px, 6vw, 72px);
  background: linear-gradient(125deg, #091425, #123c69 58%, #f4f7fb 58%);
}

.auth-brand {
  color: #fff;
  max-width: 640px;
}

.auth-brand h1 {
  font-size: 3rem;
  margin: 18px 0 8px;
  letter-spacing: 0;
}

.auth-brand p {
  font-size: 1.2rem;
  line-height: 1.6;
  max-width: 48ch;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: var(--accent);
  color: #07111f;
  display: inline-grid;
  place-items: center;
  font-weight: 900;
}

.auth-card {
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 24px 70px rgba(9, 20, 37, 0.22);
  border-radius: 12px;
  padding: 28px;
}

.auth-card h2 {
  margin: 0 0 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 108px;
  resize: vertical;
}

.auth-card label + label,
.auth-card button,
.panel label + label,
.integration-card label + label {
  margin-top: 14px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  background: #091425;
  color: #dce7f5;
  padding: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  width: 100%;
  border: 0;
  background: transparent;
  color: #fff;
  justify-content: flex-start;
  padding: 10px 6px 18px;
}

.brand small {
  display: block;
  color: #9fb1c9;
}

.main-menu {
  display: grid;
  gap: 4px;
}

.sidebar-heading { display:flex; align-items:center; gap:12px; }
.sidebar-heading .brand { min-width:0; }
.menu-toggle { display:none; flex-shrink:0; }

.nav-item {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  border-color: transparent;
  color: #c8d5e6;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.nav-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.11);
  font-weight: 900;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
}

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 900;
  margin: 0 0 6px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-pill,
.status {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.content {
  display: grid;
  gap: 18px;
}

.kpi-grid,
.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.kpi,
.report-card,
.panel,
.integration-card,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.kpi,
.report-card {
  padding: 18px;
}

.kpi span,
.report-card span {
  color: var(--muted);
  font-weight: 700;
}

.kpi strong,
.report-card strong {
  display: block;
  font-size: 2rem;
  margin-top: 8px;
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.panel,
.integration-card {
  padding: 18px;
}

.panel header,
.integration-card header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.panel h2,
.integration-card h2,
.column h2 {
  margin: 0;
  font-size: 1.05rem;
}

.toolbar,
.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.column {
  background: #eaf0f8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 420px;
}

.planning-card {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
  cursor: context-menu;
}

.planning-card div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.planning-card p {
  margin: 8px 0;
  color: var(--muted);
}

.planning-card small {
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #eef3f9;
  color: #334155;
  font-size: 0.82rem;
  text-transform: uppercase;
}

tr:hover td {
  background: #f8fbff;
}

.empty,
.empty-state {
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.integration-grid,
.role-grid,
.template-list,
.organization-grid,
.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.portal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: context-menu;
  display: grid;
  gap: 12px;
}

.portal-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.portal-card h2,
.portal-card p {
  margin: 0;
}

.portal-card header p,
.portal-card > p,
.portal-card dd {
  color: var(--muted);
}

.portal-card dl {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px 12px;
  margin: 0;
}

.portal-card dt {
  font-weight: 800;
}

.portal-card dd {
  margin: 0;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef3f9;
  color: #334155;
  font-size: 0.82rem;
  font-weight: 700;
}

.architecture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.architecture-grid article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbff;
  padding: 12px;
}

.architecture-grid span {
  display: block;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.45;
}

.organization-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: context-menu;
}

.organization-card header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
  margin-bottom: 8px;
}

.organization-card h2,
.organization-card p {
  margin: 0;
}

.organization-card p + p {
  margin-top: 8px;
}

.organization-swatch {
  width: 72px;
  height: 72px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--tenant-primary), var(--tenant-accent));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.toolbar.slim {
  background: transparent;
  border: 0;
  padding: 10px 0 0;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.permissions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  max-height: 340px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.permissions.compact {
  grid-template-columns: 1fr;
  max-height: 220px;
  font-size: 0.82rem;
}

.permission-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--soft);
}

.permission-panel h3 {
  margin: 0 0 6px;
}

.permission-panel p {
  margin: 0 0 12px;
  color: var(--muted);
}

.permission-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.permissions label,
.check,
.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.permissions input,
.check input,
.switch input {
  width: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.span-2,
.form-actions {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(9, 20, 37, 0.55);
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(980px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.32);
}

.modal-panel > header {
  position: sticky;
  top: 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 1;
}

.modal-panel > div {
  padding: 18px;
}

.icon-button {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
}

.context-menu {
  position: fixed;
  z-index: 45;
  min-width: 230px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(9, 20, 37, 0.2);
  padding: 6px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow: auto;
}

.context-menu button {
  width: 100%;
  justify-content: flex-start;
  border-color: transparent;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  background: #091425;
  color: #fff;
  padding: 12px 14px;
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.audit-list {
  display: grid;
  gap: 10px;
  padding-left: 20px;
}

.audit-list li {
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.audit-list span {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.record-view {
  display: grid;
  grid-template-columns: minmax(160px, 240px) 1fr;
  gap: 10px 18px;
}

.record-view dt {
  font-weight: 800;
  color: var(--muted);
}

.record-view dd {
  margin: 0;
}

.status-list {
  display: grid;
  gap: 10px;
}

.status-list.compact {
  margin-bottom: 14px;
}

.status-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.compact-table table {
  min-width: 720px;
}

.error {
  color: var(--danger);
}

.twofa-setup img {
  width: 220px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

.twofa-setup strong {
  overflow-wrap: anywhere;
}

.lucide,
[data-lucide] {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  vertical-align: middle;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

button,
h1,
h2,
h3,
td,
dd,
label,
.user-pill {
  overflow-wrap: anywhere;
}

label,
.form-grid > *,
.topbar-actions,
.brand > span,
.nav-item > span:last-child {
  min-width: 0;
}

.nav-icon,
.brand-mark {
  flex-shrink: 0;
}

.nav-item {
  text-align: left;
}

.topbar-actions {
  flex-wrap: wrap;
}

.modal-open {
  overflow: hidden;
}

.modal-panel {
  border-radius: var(--radius);
}

.modal-panel h2 {
  margin: 0;
  font-size: 1.25rem;
}

.app-error,
.form-error {
  color: #8a2118;
  background: #fff1ef;
  border: 1px solid #ba4437;
  padding: 14px;
  overflow-wrap: anywhere;
}

.app-error {
  position: sticky;
  top: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-error p {
  margin: 0;
}

.form-error {
  margin: 16px 18px 0;
  border-radius: var(--radius);
}

.portal-heading,
.portal-filters {
  display: flex;
  gap: 16px;
  align-items: end;
  flex-wrap: wrap;
}

.portal-heading {
  justify-content: space-between;
  align-items: center;
}

.portal-heading p {
  color: var(--muted);
  margin: 0;
}

.portal-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}

.portal-tabs button {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  min-height: 44px;
}

.portal-tabs button.active {
  border-bottom-color: #087f8c;
  color: #075d68;
  background: #e9f5f4;
}

.portal-filters {
  padding-block: 4px 16px;
  border-bottom: 1px solid var(--line);
}

.portal-filters label:first-child {
  flex: 1 1 260px;
}

.portal-filters label:last-child {
  flex: 0 1 300px;
}

.portal-results {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  min-width: 0;
}

.portal-results > section { min-width: 0; }
.topbar .eyebrow { color: #076978; }
.portal-table th, .portal-table td { min-width: 120px; }
.portal-table th:first-child, .portal-table td:first-child { min-width: 180px; }

.portal-results h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.portal-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0;
  padding-block: 8px 20px;
  border-bottom: 1px solid var(--line);
}

.portal-summary > div {
  border-left: 3px solid #087f8c;
  padding-left: 12px;
}

.portal-summary > div:nth-child(2) { border-color: #3b6c9b; }
.portal-summary > div:nth-child(3) { border-color: #28734f; }
.portal-summary > div:nth-child(4) { border-color: #a97812; }

.portal-summary dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.portal-summary dd {
  margin: 4px 0 0;
  font-size: 1.75rem;
  font-weight: 700;
}

.portal-table table {
  min-width: 700px;
}

.cell-detail {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.request-preview {
  display: block;
  max-width: 36ch;
  max-height: 4.5em;
  overflow: hidden;
  line-height: 1.5;
  white-space: pre-line;
}

.preserve-lines {
  white-space: pre-wrap;
}

[tabindex]:focus-visible {
  outline: 3px solid #087f8c;
  outline-offset: 2px;
}

.toast {
  max-width: min(500px, calc(100vw - 36px));
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 8px 16px;
    overflow: visible;
  }

  .sidebar-heading .brand { padding:4px 0; }
  .sidebar-heading .brand-mark { width:38px; height:38px; font-size:16px; }
  .menu-toggle { display:inline-flex; color:#fff; background:transparent; border-color:#61748e; }
  .menu-toggle:hover { color:#fff; background:#21364b; }
  .sidebar .main-menu { display:none; }
  .sidebar.menu-open .main-menu { display:grid; padding-top:12px; padding-bottom:8px; }

  .main-menu {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }

  .auth-view {
    grid-template-columns: 1fr;
    background: #091425;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .permission-columns {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions { flex-wrap:wrap; width:100%; }
  .topbar .user-pill { margin-right:auto; }
}

@media (max-width: 560px) {
  .main { padding: 16px; }
  .auth-view { padding: 20px; }
  .auth-brand h1 { font-size: 2.5rem; }
  .topbar h1 { font-size: 1.75rem; }
  .auth-card { padding: 20px; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .integration-grid, .role-grid, .template-list, .organization-grid { grid-template-columns: minmax(0, 1fr); }
  .portal-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .portal-filters label:last-child { flex: 1 1 100%; }
  .portal-tabs button { flex: 1 1 40%; }
  .modal { padding: 8px; }
  .modal-panel { max-height: calc(100dvh - 16px); }
  .record-view { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .record-view dd { margin-bottom: 12px; }
  .organization-card { grid-template-columns: minmax(0, 1fr); }
  .organization-card header { flex-wrap: wrap; }
}
:root { letter-spacing: 0; }
.report-filters { display:flex; flex-wrap:wrap; align-items:end; gap:12px; padding:12px 0; border-bottom:1px solid #d7e0e5; }
.report-filters label { flex:1 1 160px; min-width:0; max-width:260px; }
.report-filters select,.report-filters input { width:100%; min-width:0; }
.report-summary { display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); margin:0 0 16px; padding:16px 0; gap:16px; border-bottom:1px solid #d7e0e5; }
.report-summary dt { font-size:12px; color:#4c6070; }
.report-summary dd { margin:5px 0 0; font-size:22px; font-weight:700; color:#214761; }
.details-list { display:grid; grid-template-columns:140px minmax(0,1fr); gap:10px 16px; }
.details-list dd { margin:0; overflow-wrap:anywhere; }
.details-list dt { color:#4c6070; }
