:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #173454;
  background: #f4f8fd;
  --blue: #1768e5;
  --blue-dark: #0f4cae;
  --navy: #193d6b;
  --muted: #6b8198;
  --line: #dfe9f5;
  --soft: #edf4ff;
  --success: #177a54;
  --warning: #966500;
  --danger: #a83535;
  --shadow: 0 18px 50px rgba(31, 75, 125, .08);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #f4f8fd; }
button, input, select { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.dev-banner {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  min-height: 34px;
  padding: 7px 34px;
  color: #516d89;
  background: #e8f1fc;
  border-bottom: 1px solid #d8e6f5;
  font-size: 12px;
}
.dev-banner strong { color: var(--blue); letter-spacing: .12em; font-size: 10px; }
.brand { color: var(--blue); font-size: 20px; font-weight: 850; letter-spacing: -.6px; }
.brand span { display: block; color: #8b9eb2; font-size: 9px; letter-spacing: .13em; margin-top: 2px; }
.brand-link { min-width: 172px; }
.eyebrow { color: #6d8aa6; font-size: 10px; font-weight: 800; letter-spacing: .15em; margin: 0 0 9px; }
h1, h2, h3, p { margin-top: 0; }
h1 { color: #14355a; font-size: clamp(28px, 4vw, 42px); letter-spacing: -1.3px; line-height: 1.1; margin-bottom: 13px; }
h2 { color: #173b63; font-size: 20px; letter-spacing: -.3px; margin-bottom: 0; }
h3 { color: #173b63; font-size: 15px; margin: 0; }
.lead { color: var(--muted); font-size: 14px; line-height: 1.7; max-width: 680px; }
.hint, .section-note, .dialog-copy { color: var(--muted); font-size: 12px; line-height: 1.65; }

.login-page { display: grid; place-items: center; min-height: calc(100vh - 34px); padding: 36px 20px; }
.login-card {
  width: min(100%, 500px); padding: 38px; border: 1px solid var(--line);
  border-radius: 20px; background: #fff; box-shadow: var(--shadow);
}
.login-card h1 { margin-top: 25px; }
.login-card .brand { margin-bottom: 30px; }
label { display: block; color: #355674; font-size: 12px; font-weight: 750; margin: 17px 0 7px; }
input, select {
  width: 100%; padding: 12px 13px; color: #173454; border: 1px solid #cbdbea;
  border-radius: 9px; outline: none; background: #fff;
}
input:focus, select:focus { border-color: #7eafe9; box-shadow: 0 0 0 3px #dcecff; }
.button {
  border: 1px solid #cfdeef; border-radius: 9px; padding: 10px 14px;
  color: #2b4c6c; background: #fff; font-weight: 750;
}
.button:hover { border-color: #8fb6e5; }
.button:disabled { opacity: .55; cursor: wait; }
.button-primary { color: #fff; border-color: var(--blue); background: var(--blue); }
.button-primary:hover { border-color: var(--blue-dark); background: var(--blue-dark); }
.button-secondary { background: #f8fbff; }
.login-card .button-primary { width: 100%; margin-top: 20px; }
.form-error { min-height: 18px; color: var(--danger); font-size: 12px; margin: 10px 0 0; }
.form-success {
  min-height: 18px; color: var(--success); font-size: 12px; margin: 10px 0 0;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
code { padding: 2px 5px; border-radius: 5px; color: #24518c; background: #edf4ff; }

.admin-shell { min-height: calc(100vh - 34px); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 16px 34px; border-bottom: 1px solid var(--line); background: #fff;
}
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.signed-in { color: var(--muted); font-size: 12px; margin-right: 8px; }
.signed-in strong { color: #244a70; }
.content { width: min(1360px, calc(100% - 48px)); margin: 0 auto; padding: 40px 0 60px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 28px; }
.hero h1 { margin-bottom: 10px; }
.hero-meta { display: grid; justify-items: end; gap: 9px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 40px; }
.summary-card {
  display: grid; gap: 7px; min-height: 124px; padding: 19px;
  border: 1px solid var(--line); border-radius: 13px; background: #fff;
  box-shadow: 0 7px 20px rgba(36, 83, 135, .04);
}
.summary-card strong { color: #193f6c; font-size: 30px; letter-spacing: -.8px; }
.summary-card > span:last-child { color: var(--muted); font-size: 11px; }
.summary-label { color: #7991a9; font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.summary-card-warning { background: #fffaf0; border-color: #f0dfb9; }
.summary-card-warning strong { color: var(--warning); font-size: 22px; }
.summary-card-alert { background: #fff5f3; border-color: #f1d0ca; }
.summary-card-alert strong { color: #b44d3d; }
.superadmin-overview { display: grid; gap: 14px; }
.command-summary-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.command-summary-grid .summary-card { min-height: 116px; padding: 16px; }
.command-summary-grid .summary-card strong { font-size: 26px; }
.command-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .85fr); gap: 14px; }
.command-grid-wide { grid-template-columns: minmax(0, 1.35fr) minmax(310px, .65fr); }
.command-panel { padding: 20px; }
.command-panel .section-heading { margin-bottom: 10px; }
.operations-table { min-width: 650px; }
.operations-table td { padding-top: 11px; padding-bottom: 11px; }
.operations-table td small, .workspace-health-table td small {
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.system-panel { min-height: 290px; }
.system-status-list { display: grid; gap: 2px; }
.system-status-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #edf2f7;
}
.system-status-row:last-child { border-bottom: 0; }
.system-status-row strong, .system-status-row small { display: block; }
.system-status-row strong { color: #315978; font-size: 12px; }
.system-status-row small { color: var(--muted); font-size: 10px; margin-top: 3px; }
.workspace-health-table { min-width: 690px; }
.workspace-health-table td { padding-top: 11px; padding-bottom: 11px; }
.audit-panel { min-height: 300px; }
.audit-list { display: grid; gap: 0; }
.audit-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #edf2f7;
}
.audit-row:last-child { border-bottom: 0; }
.audit-row strong, .audit-row small { display: block; }
.audit-row strong { color: #315978; font-size: 11px; overflow-wrap: anywhere; }
.audit-row small { color: var(--muted); font-size: 10px; margin-top: 3px; }
.audit-row time { flex: 0 0 auto; color: #8a9caf; font-size: 10px; }
.section-block { margin-top: 34px; }
.section-heading {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px; margin-bottom: 15px;
}
.section-heading.compact { align-items: center; }
.section-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.section-actions .section-note { margin: 0; text-align: right; }
.apps-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.app-card {
  display: flex; gap: 15px; min-height: 174px; padding: 20px;
  border: 1px solid var(--line); border-radius: 14px; background: #fff;
  box-shadow: 0 7px 20px rgba(36, 83, 135, .04);
}
.app-icon {
  display: grid; place-items: center; flex: 0 0 39px; width: 39px;
  height: 39px; border-radius: 11px; color: #fff; font-size: 17px; font-weight: 850;
}
.app-icon-blue { background: #4a91ee; }
.app-icon-navy { background: var(--navy); }
.app-icon-gold { color: #704e0a; background: #f3d98f; }
.app-card-body { min-width: 0; }
.app-card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.app-card p { color: var(--muted); font-size: 12px; line-height: 1.65; margin: 14px 0; }
.text-link { color: var(--blue); font-size: 12px; font-weight: 800; }
.text-link:hover { color: var(--blue-dark); text-decoration: underline; }
.status-chip {
  display: inline-flex; align-items: center; min-height: 22px; padding: 4px 8px;
  border-radius: 7px; font-size: 10px; font-weight: 800; white-space: nowrap;
}
.status-ready { color: var(--success); background: #e9f8f1; }
.status-warning { color: var(--warning); background: #fff2d2; }
.status-danger { color: var(--danger); background: #ffeded; }
.status-neutral { color: #617991; background: #edf3fa; }
.split-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: 14px; }
.panel {
  padding: 22px; border: 1px solid var(--line); border-radius: 14px;
  background: #fff; box-shadow: 0 7px 20px rgba(36, 83, 135, .04);
  min-width: 0;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { color: #7890a7; font-size: 10px; font-weight: 800; letter-spacing: .08em; text-align: left; white-space: nowrap; }
th, td { padding: 13px 9px; border-bottom: 1px solid #edf2f7; vertical-align: middle; }
td { color: #355674; }
td strong { display: block; color: #183b62; font-size: 12px; }
td small { display: block; color: #8a9caf; font-size: 10px; margin-top: 3px; }
.empty-state { padding: 25px; color: var(--muted); text-align: center; font-size: 12px; }
.integration-panel { display: flex; flex-direction: column; }
.integration-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 0 20px; border-bottom: 1px solid #edf2f7;
}
.integration-row p { color: var(--muted); font-size: 11px; line-height: 1.55; margin: 7px 0 0; }
.boundary {
  margin-top: auto; padding: 15px; border-radius: 10px; color: #5d7590;
  background: #f2f7fd; font-size: 11px; line-height: 1.65;
}
.boundary strong { display: block; color: #385978; font-size: 11px; margin-bottom: 5px; }
.boundary p { margin: 0; }
.data-ops-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.data-op-card { display: flex; flex-direction: column; gap: 14px; }
.data-op-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.data-op-heading h3 { color: #183b62; font-size: 15px; }
.data-op-heading p { color: var(--muted); font-size: 11px; line-height: 1.55; margin: 6px 0 0; }
.data-command {
  display: block; padding: 11px 12px; border: 1px solid #dce8f4; border-radius: 8px;
  color: #315978; background: #f7fbff; font-size: 11px; overflow-wrap: anywhere;
}

dialog {
  width: min(100% - 28px, 500px); padding: 0; border: 0; border-radius: 15px;
  background: #fff; box-shadow: 0 25px 80px rgba(20, 52, 85, .25);
}
dialog::backdrop { background: rgba(22, 48, 77, .35); }
dialog form { padding: 25px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-heading h2 { margin-bottom: 0; }
.icon-button {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: 8px; color: #56718e;
  background: #fff; font-size: 20px; line-height: 1;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.toast {
  position: fixed; right: 22px; bottom: 22px; max-width: min(420px, calc(100% - 44px));
  padding: 13px 16px; border: 1px solid #c8def8; border-radius: 10px;
  color: #254d76; background: #edf6ff; box-shadow: var(--shadow);
  font-size: 12px; line-height: 1.55;
}
.access-denied {
  width: min(100% - 48px, 680px); margin: 80px auto; padding: 34px;
  border: 1px solid #f0dfb9; border-radius: 15px; background: #fffaf0;
}
.access-denied p { color: var(--muted); line-height: 1.65; }

@media (max-width: 950px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .command-summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .command-grid, .command-grid-wide, .apps-grid, .split-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .dev-banner, .topbar { padding-left: 18px; padding-right: 18px; }
  .dev-banner { align-items: flex-start; flex-direction: column; gap: 5px; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 15px; }
  .topbar-actions { justify-content: flex-start; }
  .content { width: min(100% - 30px, 600px); padding-top: 27px; }
  .hero { align-items: flex-start; flex-direction: column; gap: 12px; }
  .hero-meta { justify-items: start; }
  .summary-grid { gap: 9px; }
  .command-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .summary-card { min-height: 110px; padding: 14px; }
  .summary-card strong { font-size: 24px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  .section-heading.compact { align-items: flex-start; flex-direction: row; }
  .section-note { margin: 0; }
  .panel { padding: 16px; }
  .login-card { padding: 27px 21px; }
}

.access-control-block, .template-control-block { margin-top: 18px; }
.access-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(340px, .75fr); gap: 14px; }
.access-layout .panel { padding: 0; }
.toolbar { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.toolbar input { flex: 1; min-width: 0; padding: 10px 11px; }
.toolbar .muted { white-space: nowrap; }
.account-table { min-width: 640px; }
.account-table tbody tr { cursor: pointer; }
.account-table tbody tr:hover, .account-table tbody tr.selected { background: #f2f8ff; }
.account-table td { padding-top: 14px; padding-bottom: 14px; }
.detail-panel { min-height: 420px; }
.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding-bottom: 17px; border-bottom: 1px solid var(--line);
}
.detail-head h3 { color: #183b62; font-size: 18px; }
.detail-head p { color: var(--muted); font-size: 11px; margin-top: 5px; overflow-wrap: anywhere; }
.detail-section { padding: 16px 0; border-bottom: 1px solid #edf2f7; }
.detail-section:last-child { border-bottom: 0; }
.detail-section h4 {
  margin: 0 0 10px; color: #5d7895; font-size: 10px; letter-spacing: .08em;
  text-transform: uppercase;
}
.detail-form { display: grid; gap: 9px; }
.detail-form label { display: grid; gap: 5px; color: #5d7895; font-size: 11px; }
.detail-form select, .detail-form input { width: 100%; padding: 8px 9px; }
.detail-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.access-chips, .permission-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.access-chip, .permission-chip {
  display: inline-flex; align-items: center; padding: 4px 7px; border-radius: 999px;
  font-size: 10px; line-height: 1.2;
}
.access-chip.granted { color: #236b53; background: #e8f7ef; }
.access-chip.denied { color: #8c6370; background: #f8edf0; }
.permission-chip.allowed { color: #286b58; background: #e9f7f0; }
.permission-chip.blocked { color: #8a6b73; background: #f5f0f1; }
.membership-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 118px; gap: 8px;
  align-items: center; margin-bottom: 8px;
}
.membership-row strong { color: #345875; font-size: 11px; }
.membership-row small { display: block; margin-top: 2px; }
.system-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; }
.system-row span:first-child { color: #42647f; font-size: 11px; }
.system-state { font-size: 10px; font-weight: 800; }
.system-state.granted { color: #26745b; }
.system-state.denied { color: #9a6b77; }
.client-access-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid #edf2f7;
}
.client-access-row:last-child { border-bottom: 0; }
.client-access-row strong { display: block; color: #42647f; font-size: 11px; margin-bottom: 5px; }
.template-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.template-summary-card { padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.template-summary-card span { display: block; color: var(--muted); font-size: 10px; }
.template-summary-card strong { display: block; color: #183b62; font-size: 22px; margin-top: 6px; }
.template-panel { padding: 0; }
.template-tabs { display: flex; gap: 6px; padding: 14px 18px 0; border-bottom: 1px solid var(--line); }
.template-tab {
  padding: 9px 12px; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  color: #748da7; background: transparent; font-size: 11px;
}
.template-tab.active { color: #1b5c95; border-bottom-color: #2b7ac2; font-weight: 800; }
.template-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 17px; }
.template-card {
  display: flex; flex-direction: column; gap: 8px; padding: 14px;
  border: 1px solid #e4edf5; border-radius: 11px; background: #fbfdff;
}
.template-card h3 { color: #214d70; font-size: 13px; }
.template-card p { color: var(--muted); font-size: 11px; line-height: 1.5; }
.template-card .meta { display: flex; flex-wrap: wrap; gap: 5px; }
.template-card .meta span {
  padding: 4px 6px; border-radius: 5px; color: #58758f;
  background: #edf4fa; font-size: 9px;
}
.template-boundary { margin-top: 12px; }
.toast-error { color: #8b3d48; background: #fff0f0; border-color: #f1c5cb; }
@media (max-width: 950px) {
  .access-layout { grid-template-columns: 1fr; }
  .data-ops-grid { grid-template-columns: 1fr; }
  .detail-panel { min-height: 0; }
}
@media (max-width: 680px) {
  .template-summary { grid-template-columns: 1fr 1fr; }
  .template-summary-card:last-child { grid-column: 1 / -1; }
  .template-list { grid-template-columns: 1fr; padding: 13px; }
  .membership-row { grid-template-columns: minmax(0, 1fr) 105px; }
  .section-actions { align-items: flex-start; flex-direction: column; width: 100%; }
  .section-actions .section-note { text-align: left; }
}

/* AI model settings card */
.ai-model-form { display: grid; gap: 14px; max-width: 640px; }
.ai-model-form label { color: var(--text, #17324d); display: grid; font-size: 13px; font-weight: 600; gap: 6px; }
.ai-model-form input[type="text"], .ai-model-form input[type="password"], .ai-model-form input:not([type]),
.ai-model-form select { border: 1px solid #cfdbe8; border-radius: 10px; font: inherit; padding: 10px 12px; }
.ai-model-form small { color: #5b6b82; font-size: 12px; font-weight: 400; }
.ai-model-form .ai-model-check { align-items: flex-start; display: flex; gap: 10px; }
.ai-model-form .ai-model-check input { flex: none; height: 18px; margin-top: 2px; width: 18px; }
.ai-model-form .ai-model-check span { display: grid; gap: 4px; }
.ai-model-feedback { font-size: 13px; margin: 0; min-height: 1.2em; }

/* Sidebar layout: one view at a time */
.admin-layout { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: calc(100vh - 100px); }
.admin-nav { align-self: start; background: #fff; border-right: 1px solid var(--line); height: calc(100vh - 100px);
  overflow-y: auto; padding: 18px 14px; position: sticky; top: 0; }
.admin-nav-label { color: #8b9eb2; font-size: 10px; font-weight: 800; letter-spacing: .12em; margin: 18px 10px 6px;
  text-transform: uppercase; }
.admin-nav-label:first-child { margin-top: 4px; }
.admin-nav-item { align-items: center; background: transparent; border: 0; border-radius: 10px; color: #4d6580;
  display: flex; font-size: 14px; font-weight: 650; gap: 11px; margin: 2px 0; padding: 10px 12px; text-align: left;
  width: 100%; }
.admin-nav-item span { color: #8b9eb2; flex: none; text-align: center; width: 18px; }
.admin-nav-item:hover { background: #f1f6fd; color: var(--blue); }
.admin-nav-item.active { background: var(--soft); color: var(--blue); }
.admin-nav-item.active span { color: var(--blue); }
.admin-menu-toggle { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; color: var(--blue);
  display: none; font-weight: 750; padding: 10px 14px; width: 100%; }
.admin-layout .content { margin: 0; max-width: 1180px; padding: 32px clamp(16px, 3vw, 40px) 60px; width: 100%; }
.admin-view { display: none; }
.admin-view.active { display: block; }
@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-nav { border-bottom: 1px solid var(--line); border-right: 0; height: auto; padding: 10px 16px; position: static; }
  .admin-menu-toggle { display: block; }
  .admin-nav-list { display: none; margin-top: 8px; }
  .admin-nav.open .admin-nav-list { display: block; }
}

.view-title { font-size: clamp(24px, 3vw, 34px); letter-spacing: -.03em; margin: 6px 0 8px; }
.ai-platform { margin-bottom: 18px; }
.ai-platform .command-summary-grid { margin: 14px 0 18px; }
.ai-platform td small, .ai-pack-list small { color: #6b8198; display: block; }
.ai-pack-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); list-style: none;
  margin: 0; padding: 0; }
.ai-pack-list li { background: #f8fbff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
