:root {
  color-scheme: dark;
  --bg: #0e100f;
  --panel: #151817;
  --panel-hover: #1b1f1d;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f2f5f3;
  --muted: #949b97;
  --accent: #b7f7ce;
  --accent-strong: #8eeeb1;
  --user: #252b28;
  --danger: #ff9d9d;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must always win, even over display:flex/grid rules
   below (e.g. .admin-panel). Without this, hidden sections render anyway. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% -25%, rgba(89, 142, 108, 0.12), transparent 36%),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.gate-shell {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  min-height: 100dvh;
}

.gate-topbar {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 24px;
}

.gate-main {
  display: grid;
  min-height: 0;
  padding: 36px 20px 64px;
  place-items: center;
}

.access-card {
  background: rgba(21, 24, 23, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 22px;
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.34),
    0 1px 0 rgba(255, 255, 255, 0.04) inset;
  overflow: hidden;
  width: min(100%, 420px);
}

.access-card-header {
  align-items: center;
  display: flex;
  flex-direction: column;
  padding: 34px 34px 26px;
  text-align: center;
}

.access-icon {
  align-items: center;
  background: rgba(183, 247, 206, 0.08);
  border: 1px solid rgba(183, 247, 206, 0.17);
  border-radius: 14px;
  color: var(--accent);
  display: flex;
  height: 48px;
  justify-content: center;
  margin-bottom: 20px;
  width: 48px;
}

.access-icon svg {
  height: 23px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  width: 23px;
}

.access-card h1 {
  font-size: 27px;
  letter-spacing: -0.035em;
  margin: 0;
}

.access-card-header p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin: 10px 0 0;
  max-width: 310px;
}

.access-card-content {
  padding: 0 34px 30px;
}

.access-form,
.field {
  display: flex;
  flex-direction: column;
}

.access-form {
  gap: 20px;
}

.field {
  gap: 8px;
}

.field label {
  color: #dbe0dd;
  font-size: 13px;
  font-weight: 600;
}

.field input {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 11px;
  color: var(--text);
  height: 48px;
  outline: none;
  padding: 0 14px;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
  width: 100%;
}

.field input::placeholder {
  color: #707873;
}

.field input:focus {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(183, 247, 206, 0.45);
  box-shadow: 0 0 0 3px rgba(183, 247, 206, 0.07);
}

.field[data-invalid] input {
  border-color: rgba(255, 157, 157, 0.62);
  box-shadow: 0 0 0 3px rgba(255, 157, 157, 0.06);
}

.field[data-disabled] {
  opacity: 0.62;
}

.field-error {
  color: var(--danger);
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
}

.access-submit {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 11px;
  color: #102017;
  cursor: pointer;
  display: flex;
  font-size: 14px;
  font-weight: 700;
  gap: 8px;
  height: 46px;
  justify-content: center;
  transition:
    background 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
}

.access-submit:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.access-submit:disabled {
  cursor: wait;
  opacity: 0.72;
  transform: none;
}

.button-spinner {
  animation: spin 700ms linear infinite;
  border: 2px solid rgba(16, 32, 23, 0.25);
  border-radius: 999px;
  border-top-color: #102017;
  display: none;
  height: 15px;
  width: 15px;
}

.access-form[data-pending] .button-label {
  display: none;
}

.access-form[data-pending] .button-spinner {
  display: block;
}

.access-card-footer {
  align-items: center;
  border-top: 1px solid var(--border);
  color: #777f7a;
  display: flex;
  font-size: 11px;
  gap: 7px;
  justify-content: center;
  padding: 15px 20px;
}

.access-card-footer svg {
  height: 14px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  width: 14px;
}

.app-shell {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  align-items: center;
  backdrop-filter: blur(16px);
  background: rgba(14, 16, 15, 0.78);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  align-items: center;
  color: var(--text);
  display: flex;
  font-size: 15px;
  font-weight: 650;
  gap: 10px;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--accent);
  border-radius: 9px;
  color: #102017;
  display: flex;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.brand-mark svg {
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.7;
  width: 20px;
}

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

.mode-switcher {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  padding: 3px;
}

.mode-button {
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  padding: 6px 11px;
}

.mode-button.active {
  background: var(--accent);
  color: #102017;
}

.clear-button {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  font-size: 13px;
  gap: 7px;
  padding: 7px 10px;
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.clear-button:hover {
  background: var(--panel-hover);
  border-color: var(--border);
}

.clear-button svg {
  height: 16px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
  width: 16px;
}

.chat {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 48px max(20px, calc((100% - 760px) / 2)) 28px;
  scroll-behavior: smooth;
}

.empty-state {
  align-items: center;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  margin: 0 auto;
  max-width: 640px;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-icon {
  align-items: center;
  background: rgba(183, 247, 206, 0.08);
  border: 1px solid rgba(183, 247, 206, 0.16);
  border-radius: 16px;
  color: var(--accent);
  display: flex;
  height: 54px;
  justify-content: center;
  margin-bottom: 22px;
  width: 54px;
}

.empty-icon svg {
  fill: currentColor;
  height: 28px;
  width: 28px;
}

.empty-state h1 {
  font-size: clamp(28px, 5vw, 38px);
  letter-spacing: -0.045em;
  margin: 0;
}

.empty-state p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  margin: 12px 0 28px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestions button {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: #c4cac6;
  cursor: pointer;
  font-size: 13px;
  padding: 9px 14px;
  transition:
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.suggestions button:hover {
  background: var(--panel-hover);
  color: var(--text);
  transform: translateY(-1px);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.message {
  animation: message-in 220ms ease both;
  display: grid;
  gap: 12px;
  grid-template-columns: 30px minmax(0, 1fr);
}

.message.user {
  display: flex;
  justify-content: flex-end;
}

.avatar {
  align-items: center;
  background: var(--accent);
  border-radius: 9px;
  color: #102017;
  display: flex;
  font-size: 13px;
  font-weight: 750;
  height: 30px;
  justify-content: center;
  margin-top: 1px;
  width: 30px;
}

.message-content {
  color: #e3e8e5;
  font-size: 15px;
  line-height: 1.7;
  max-width: 100%;
  overflow-wrap: anywhere;
  padding-top: 3px;
  white-space: pre-wrap;
}

.markdown {
  white-space: normal;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown > :last-child {
  margin-bottom: 0;
}

.markdown p,
.markdown ul,
.markdown ol,
.markdown blockquote,
.markdown pre,
.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin: 0 0 14px;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  color: var(--text);
  letter-spacing: -0.025em;
  line-height: 1.3;
}

.markdown h1 {
  font-size: 1.55em;
}

.markdown h2 {
  font-size: 1.35em;
}

.markdown h3 {
  font-size: 1.18em;
}

.markdown ul,
.markdown ol {
  padding-left: 24px;
}

.markdown li + li {
  margin-top: 5px;
}

.markdown blockquote {
  border-left: 3px solid rgba(183, 247, 206, 0.45);
  color: var(--muted);
  padding-left: 14px;
}

.markdown code {
  background: rgba(255, 255, 255, 0.07);
  border-radius: 5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
  padding: 2px 5px;
}

.markdown pre {
  background: #0a0c0b;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  padding: 14px 16px;
  white-space: pre;
}

.markdown pre code {
  background: transparent;
  padding: 0;
}

.markdown a {
  color: var(--accent);
  text-decoration-color: rgba(183, 247, 206, 0.45);
  text-underline-offset: 3px;
}

.generated-image {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: block;
  height: auto;
  max-height: 70vh;
  max-width: min(100%, 640px);
  object-fit: contain;
}

.user .message-content {
  background: var(--user);
  border: 1px solid var(--border);
  border-radius: 18px 18px 5px 18px;
  color: var(--text);
  max-width: min(82%, 620px);
  padding: 10px 15px;
}

.message.error .avatar {
  background: rgba(255, 157, 157, 0.12);
  color: var(--danger);
}

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

.streaming .message-content::after {
  animation: blink 850ms steps(1) infinite;
  background: var(--accent);
  border-radius: 1px;
  content: "";
  display: inline-block;
  height: 1em;
  margin-left: 3px;
  vertical-align: -0.13em;
  width: 2px;
}

.composer-area {
  background: linear-gradient(transparent, var(--bg) 28%);
  padding: 24px max(16px, calc((100% - 780px) / 2)) 18px;
  position: sticky;
  bottom: 0;
}

.composer {
  align-items: center;
  background: rgba(25, 29, 27, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(255, 255, 255, 0.04) inset;
  display: flex;
  gap: 12px;
  padding: 12px 12px 12px 17px;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: rgba(183, 247, 206, 0.38);
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.28),
    0 0 0 3px rgba(183, 247, 206, 0.05);
}

.composer textarea {
  background: transparent;
  border: 0;
  color: var(--text);
  line-height: 24px;
  max-height: 180px;
  min-height: 24px;
  outline: none;
  overflow-y: auto;
  padding: 0;
  resize: none;
  width: 100%;
}

.composer textarea::placeholder {
  color: #777f7a;
}

.send-button {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 11px;
  color: #102017;
  cursor: pointer;
  display: flex;
  flex: 0 0 auto;
  height: 36px;
  justify-content: center;
  transition:
    background 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
  width: 36px;
}

.send-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.send-button:disabled {
  cursor: default;
  opacity: 0.28;
  transform: none;
}

.send-button svg {
  height: 19px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 19px;
}

.stop-icon,
.is-streaming .send-icon {
  display: none;
}

.is-streaming .stop-icon {
  display: block;
}

.composer-hint {
  color: #686f6b;
  font-size: 11px;
  margin: 9px 0 0;
  text-align: center;
}

.sr-only {
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

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

@media (max-width: 640px) {
  .app-shell {
    grid-template-rows: 56px minmax(0, 1fr) auto;
  }

  .topbar {
    padding: 0 14px;
  }

  .gate-shell {
    grid-template-rows: 56px minmax(0, 1fr);
  }

  .gate-topbar {
    padding: 0 14px;
  }

  .gate-main {
    padding: 24px 14px 48px;
  }

  .access-card-header {
    padding: 30px 24px 24px;
  }

  .access-card-content {
    padding: 0 24px 26px;
  }

  .clear-button span,
  .composer-hint {
    display: none;
  }

  .mode-button {
    padding-inline: 9px;
  }

  .clear-button {
    padding: 8px;
  }

  .chat {
    padding-top: 28px;
  }

  .suggestions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .user .message-content {
    max-width: 90%;
  }

  .composer-area {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Provisioning dashboard --- */
.admin-panel {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.admin-panel-header h1 {
  font-size: 1.5rem;
  margin: 0 0 4px;
}

.admin-muted {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.admin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-card h2 {
  font-size: 1.05rem;
  margin: 0;
}

.admin-inline-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.admin-inline-form .field {
  flex: 1 1 240px;
}

.admin-inline-form .access-submit {
  width: auto;
  padding-inline: 20px;
  flex: 0 0 auto;
}

.admin-reveal {
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-reveal-title {
  color: var(--accent);
  font-weight: 600;
  margin: 0;
}

.admin-reveal-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0;
}

.admin-reveal-grid dt {
  color: var(--muted);
}

.admin-reveal-grid dd {
  margin: 0;
  word-break: break-all;
}

.admin-reveal-grid code {
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.9rem;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

.admin-table th {
  color: var(--muted);
  font-weight: 600;
}

.admin-actions {
  text-align: right;
}

.admin-ghost,
.admin-danger {
  background: var(--panel-hover);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font: inherit;
  cursor: pointer;
}

.admin-ghost:hover {
  border-color: var(--accent);
}

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

.admin-danger:hover {
  border-color: var(--danger);
}

.admin-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* --- Candidate review panel --- */
.admin-review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-review h3 {
  font-size: 0.95rem;
  margin: 18px 0 8px;
}

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

.admin-stat {
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.admin-stat-value {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
}

.admin-stat-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.admin-stat-sub {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 4px;
}

.admin-prompt {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.admin-prompt summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.85rem;
}

.admin-prompt pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 10px 0 2px;
  font-size: 0.85rem;
  color: var(--text);
  max-height: 320px;
  overflow: auto;
}

.admin-recent {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.admin-recent-row {
  display: grid;
  grid-template-columns: 168px 130px 1fr;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.admin-recent-row:last-child {
  border-bottom: none;
}

.admin-recent-ts {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.admin-recent-ev {
  color: var(--accent);
}

.admin-recent-snip {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
