:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #eef3f7;
  --ink: #182026;
  --text: #20262b;
  --muted: #65737f;
  --line: #d8e0e6;
  --line-strong: #b9c6cf;
  --blue: #1f66ad;
  --blue-dark: #174f88;
  --green: #137a52;
  --red: #b42318;
  --amber: #a05a00;
  --sidebar: #151b22;
  --sidebar-soft: #202a33;
  --shadow: 0 1px 2px rgba(20, 28, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

a {
  color: inherit;
}

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

button,
.button-link {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
  text-decoration: none;
}

button:hover:not(:disabled),
.button-link:hover {
  border-color: var(--blue);
  color: var(--blue);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button:focus-visible,
.button-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(31, 102, 173, 0.2);
  outline-offset: 2px;
}

button.primary,
.primary-link {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

button.primary:hover:not(:disabled),
.primary-link:hover {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
  color: #ffffff;
}

button.danger {
  border-color: #dfa9a4;
  color: var(--red);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 9px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.auth-shell {
  display: grid;
  grid-template-columns: minmax(360px, 0.85fr) minmax(480px, 1.15fr);
  min-height: 100vh;
  background: #f3f6f8;
}

.auth-brand-panel {
  position: relative;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  background: #151b22;
  color: #f7fafc;
  padding: 42px;
}

.auth-brand-panel::after {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: 46%;
  height: 4px;
  background: #32a071;
  content: '';
}

.auth-brand {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  text-decoration: none;
}

.auth-brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #41505d;
  border-radius: 8px;
  background: #202a33;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
}

.auth-brand > span:last-child {
  display: grid;
  gap: 2px;
}

.auth-brand strong {
  font-size: 16px;
}

.auth-brand small {
  color: #9eacb7;
  font-size: 12px;
}

.auth-brand-copy {
  position: relative;
  z-index: 1;
  max-width: 500px;
  margin: auto 0;
  padding: 70px 0;
}

.auth-brand-copy .eyebrow {
  color: #6fd0a2;
}

.auth-brand-copy h1 {
  max-width: 460px;
  margin: 8px 0 18px;
  font-size: 38px;
  line-height: 1.12;
}

.auth-brand-copy > p:last-child {
  max-width: 470px;
  margin: 0;
  color: #aebac4;
  font-size: 15px;
  line-height: 1.65;
}

.auth-security-list {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  border: 1px solid #34424e;
  border-radius: 8px;
  background: #34424e;
  overflow: hidden;
}

.auth-security-list div {
  min-width: 0;
  background: #1b232b;
  padding: 13px;
}

.auth-security-list dt {
  color: #7f909d;
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.auth-security-list dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 650;
}

.auth-form-panel {
  display: grid;
  min-width: 0;
  place-items: center;
  padding: 40px;
}

.auth-form-wrap {
  width: min(460px, 100%);
}

.auth-form,
.auth-loading {
  display: grid;
  gap: 17px;
}

.auth-loading {
  min-height: 260px;
  place-items: center;
  align-content: center;
  color: var(--muted);
}

.auth-loader {
  width: 30px;
  height: 30px;
  border: 3px solid #d7e0e6;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
}

@keyframes auth-spin {
  to { transform: rotate(360deg); }
}

.auth-heading {
  display: grid;
  gap: 6px;
  margin-bottom: 4px;
}

.auth-heading h2 {
  margin: 0;
  color: var(--ink);
  font-size: 28px;
  line-height: 1.2;
}

.auth-heading p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.auth-form label {
  color: #48545e;
  font-size: 13px;
}

.auth-form input {
  min-height: 44px;
  border-color: #c7d2d9;
  padding: 10px 12px;
}

.auth-password-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.verification-input {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 17px;
}

.auth-submit {
  min-height: 44px;
  margin-top: 2px;
  font-weight: 750;
}

.auth-feedback {
  margin-top: 16px;
  border: 1px solid #efb6b0;
  border-radius: 8px;
  background: #fff1f0;
  color: #8d251c;
  padding: 11px 12px;
  font-size: 13px;
  line-height: 1.45;
}

.auth-feedback.is-success {
  border-color: #a9d8c1;
  background: #edf8f2;
  color: #116641;
}

.auth-footnote {
  margin: 22px 0 0;
  color: #7a8791;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.mfa-setup-layout {
  display: grid;
  grid-template-columns: 174px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.qr-frame {
  display: grid;
  width: 174px;
  height: 174px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 8px;
}

.qr-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.mfa-manual {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f7;
  padding: 14px;
}

.mfa-manual span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.mfa-manual code {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}

.mfa-manual button {
  align-self: flex-start;
}

.recovery-codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.recovery-codes code {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  color: var(--ink);
  font-size: 13px;
  text-align: center;
}

.auth-action-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.landing-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(244, 246, 248, 0.92), rgba(244, 246, 248, 1)),
    #eaf0f5;
}

.landing-shell {
  width: min(760px, 100%);
}

.landing-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 28px;
}

.landing-card h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.05;
}

.landing-copy {
  max-width: 620px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 22px 0;
}

.button-link {
  display: inline-flex;
  align-items: center;
}

.endpoint-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.endpoint-list code {
  display: block;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 9px 10px;
  color: var(--ink);
}

.admin-page {
  overflow-x: hidden;
}

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

.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--sidebar);
  color: #f4f8fb;
  padding: 18px;
}

.sidebar-brand {
  display: grid;
  gap: 3px;
  text-decoration: none;
}

.sidebar-brand span {
  color: #a8b6c3;
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.sidebar-brand strong {
  font-size: 20px;
  line-height: 1.15;
}

.admin-nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 58px;
  border-color: transparent;
  background: transparent;
  color: #d6e0e7;
  text-align: left;
}

.nav-button:hover:not(:disabled),
.nav-button.is-active {
  border-color: #354554;
  background: var(--sidebar-soft);
  color: #ffffff;
}

.nav-button span {
  font-weight: 750;
}

.nav-button small {
  color: #98a8b5;
  font-size: 12px;
}

.sidebar-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: auto;
  border: 1px solid #2f3d49;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #c3d0da;
  padding: 10px;
  font-size: 12px;
  line-height: 1.45;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  margin-top: 5px;
  border-radius: 999px;
  background: #44c486;
}

.admin-workspace {
  min-width: 0;
}

.session-user {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 290px;
}

.session-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: #e2edf7;
  color: var(--blue-dark);
  font-weight: 800;
}

.session-identity {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.session-identity strong,
.session-identity small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-identity strong {
  font-size: 13px;
}

.session-identity small {
  color: var(--muted);
  font-size: 11px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 250, 252, 0.96);
  padding: 14px 18px;
}

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.brand p:not(.eyebrow) {
  margin: 4px 0 0;
  color: var(--muted);
}

.admin-main {
  display: grid;
  gap: 14px;
  padding: 16px 18px 22px;
}

.summary-strip {
  display: grid;
  grid-template-columns: minmax(260px, 390px) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.summary-copy,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-copy {
  padding: 14px;
}

.summary-copy h2 {
  margin: 0;
  font-size: 17px;
}

.summary-copy p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.panel {
  padding: 14px;
}

.admin-section {
  min-width: 0;
}

.is-hidden {
  display: none !important;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.panel-head span,
#tableSummary {
  color: var(--muted);
  font-size: 12px;
}

.pool-head {
  align-items: flex-start;
}

.stack {
  display: grid;
  gap: 11px;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.row-actions,
.option-row,
.bulk-left,
.bulk-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.option-row {
  justify-content: flex-start;
}

.checkline {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.checkline input {
  width: auto;
}

.result-tools {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.reference-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 230px);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
}

.reference-box textarea {
  min-height: 104px;
}

.reference-tools {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.reference-tools input[type="file"] {
  padding: 6px 7px;
  font-size: 12px;
}

.reference-actions {
  justify-content: flex-start;
}

#referenceUploadState {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.generation-workbench {
  display: grid;
  grid-template-columns: minmax(320px, 460px) minmax(420px, 1fr);
  gap: 16px;
  align-items: start;
}

.generation-controls,
.generation-output {
  min-width: 0;
}

.generation-output {
  display: grid;
  gap: 14px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.section-head.compact {
  margin-bottom: 10px;
}

.section-head h3 {
  margin: 0;
  font-size: 14px;
}

.section-head span {
  display: inline-block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.run-monitor,
.preview-panel {
  min-width: 0;
}

.run-state {
  border-radius: 999px;
  padding: 2px 8px;
  background: #eef2f6;
}

.run-state.running {
  background: #e8f1fb;
  color: var(--blue);
}

.run-state.ok {
  background: #e8f5ee;
  color: var(--green);
}

.run-state.bad {
  background: #fdebea;
  color: var(--red);
}

#generationRunLog {
  min-height: 178px;
  max-height: 260px;
  overflow: auto;
  margin: 0;
  border: 1px solid #cfd8de;
  border-radius: 8px;
  background: #111920;
  color: #dbe7ee;
  padding: 12px;
  white-space: pre-wrap;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.preview-actions .button-link {
  min-height: 32px;
}

.button-link.is-disabled {
  pointer-events: none;
  opacity: 0.52;
}

.preview-stage {
  display: grid;
  height: clamp(320px, 46vh, 540px);
  min-height: 320px;
  place-items: center;
  overflow: hidden;
  border: 1px solid #222d36;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0)),
    #101820;
  color: #aebbc6;
}

.preview-stage img,
.preview-stage video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #0d141a;
}

.preview-empty {
  border-style: dashed;
}

.preview-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 0;
}

.preview-meta div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 8px;
}

.preview-meta dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.preview-meta dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.metrics div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.metrics strong {
  display: block;
  font-size: 24px;
  line-height: 1.15;
}

.metrics span {
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 190px) minmax(120px, 150px);
  gap: 10px;
  margin-bottom: 10px;
}

.bulkbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 9px;
}

.table-wrap {
  min-height: 360px;
  max-height: calc(100vh - 330px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f3f7fa;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

tr.selected-row td {
  background: #f0f7ff;
}

.select-col {
  width: 42px;
}

.row-check {
  width: 16px;
  height: 16px;
}

.account-main {
  display: grid;
  gap: 3px;
  min-width: 230px;
}

.account-main strong {
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.25;
}

.small {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 750;
}

.pill.ok {
  background: #e8f5ee;
  color: var(--green);
}

.pill.warn {
  background: #fff4e1;
  color: var(--amber);
}

.pill.bad {
  background: #fdebea;
  color: var(--red);
}

.token-cell {
  min-width: 74px;
  font-weight: 750;
}

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

.table-actions button,
.bulkbar button,
.pager button {
  min-height: 30px;
  padding: 0 9px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

#pageInfo {
  color: var(--muted);
  font-size: 13px;
}

#outputLog {
  min-height: 460px;
  max-height: calc(100vh - 230px);
  overflow: auto;
  margin: 0;
  border: 1px solid #cfd8de;
  border-radius: 8px;
  background: var(--ink);
  color: #e6edf2;
  padding: 12px;
  white-space: pre-wrap;
}

@media (max-width: 1180px) {
  .admin-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .generation-workbench {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(5, minmax(110px, 1fr));
    overflow-x: auto;
    padding-bottom: 2px;
  }
}

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

  .auth-brand-panel {
    min-height: auto;
    padding: 24px;
  }

  .auth-brand-copy {
    padding: 44px 0;
  }

  .auth-brand-copy h1 {
    font-size: 32px;
  }

  .auth-form-panel {
    padding: 38px 24px;
  }

  .admin-shell {
    display: block;
  }

  .admin-sidebar {
    position: static;
    height: auto;
  }

  .admin-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .toolbar,
  .grid-two,
  .reference-box,
  .preview-meta {
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .bulkbar {
    align-items: stretch;
    flex-direction: column;
  }

  .bulk-left,
  .bulk-right,
  .row-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .auth-brand-panel,
  .auth-form-panel {
    padding-left: 16px;
    padding-right: 16px;
  }

  .auth-brand-copy h1 {
    font-size: 27px;
  }

  .auth-security-list,
  .auth-password-grid,
  .mfa-setup-layout,
  .recovery-codes {
    grid-template-columns: 1fr;
  }

  .qr-frame {
    width: min(220px, 100%);
    height: auto;
    aspect-ratio: 1;
    justify-self: center;
  }

  .auth-action-row {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .session-user {
    min-width: 0;
    width: 100%;
  }

  .admin-main,
  .topbar,
  .admin-sidebar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .admin-nav,
  .metrics {
    grid-template-columns: 1fr;
  }

  .landing-card {
    padding: 20px;
  }
}
