:root {
  color-scheme: dark;
  --page-bg: #000000;
  --surface-bg: #202020;
  --surface-hover: #2a2a2a;
  --panel-bg: #151515;
  --border-color: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-primary: rgba(255, 255, 255, 0.95);
  --text-secondary: rgba(255, 255, 255, 0.65);
  --text-muted: rgba(255, 255, 255, 0.45);
  --button-primary-bg: #f4f4f4;
  --button-primary-fg: #111111;
  --danger: #ef4444;
  --danger-strong: #dc2626;
  --success: #10a37f;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

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

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

button:disabled,
textarea:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.hidden,
[hidden] {
  display: none !important;
}

.chat-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--page-bg);
}

.brand-button {
  position: fixed;
  top: 18px;
  left: 24px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 2px;
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 700;
}

.brand-button:hover {
  color: #ffffff;
}

.brand-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--button-primary-bg);
  color: var(--button-primary-fg);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.welcome-panel {
  position: absolute;
  top: 36%;
  left: 50%;
  width: min(760px, calc(100vw - 48px));
  transform: translate(-50%, -50%);
  text-align: center;
}

.welcome-panel h1 {
  margin: 0;
  color: var(--text-primary);
  font-size: 32px;
  font-weight: 560;
  line-height: 1.22;
}

.messages {
  position: absolute;
  inset: 84px 0 114px;
  display: none;
  flex-direction: column;
  gap: 26px;
  width: 100%;
  overflow-y: auto;
  padding: 10px 24px 22px;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.conversation-started .messages {
  display: flex;
}

.conversation-started .welcome-panel {
  display: none;
}

.message-group {
  width: min(820px, calc(100vw - 48px));
  align-self: center;
  display: grid;
  gap: 18px;
}

.bubble {
  line-height: 1.65;
}

.user-bubble {
  justify-self: end;
  max-width: 70%;
  display: grid;
  gap: 4px;
  border-radius: 22px;
  padding: 11px 15px;
  background: var(--surface-hover);
  color: var(--text-primary);
}

.user-bubble p,
.bot-bubble p {
  margin: 0;
}

.bubble-meta {
  color: var(--text-muted);
  font-size: 12px;
}

.bot-bubble {
  justify-self: stretch;
  color: var(--text-primary);
}

.bot-bubble.failed {
  color: var(--text-primary);
}

.result {
  position: relative;
  display: grid;
  gap: 14px;
  padding-bottom: 38px;
}

.result h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 650;
  line-height: 1.35;
}

.result-summary {
  color: var(--text-secondary);
}

.ai-result-badge {
  position: absolute;
  right: 0;
  bottom: 0;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(250, 204, 21, 0.42);
  border-radius: 8px;
  background: #facc15;
  color: #111111;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.blocked-result {
  position: relative;
  display: inline-block;
  max-width: min(560px, 100%);
  min-height: 74px;
  padding: 12px 12px 42px;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text-primary);
}

.blocked-result .ai-result-badge {
  right: 10px;
  bottom: 9px;
}

.blocked-result-text {
  margin: 0;
  line-height: 1.65;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-chip,
.score-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-bg);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 650;
}

.score-chip {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

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

.highlight-item,
.metric-item,
.advice-block,
.stat-item {
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
}

.highlight-item {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.highlight-item strong {
  overflow-wrap: anywhere;
  color: var(--text-primary);
  font-size: 20px;
  line-height: 1.25;
}

.item-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

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

.metric-item {
  padding: 12px;
}

.metric-head {
  display: grid;
  grid-template-columns: minmax(70px, 0.35fr) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.metric-head strong {
  overflow-wrap: anywhere;
  color: var(--text-primary);
}

.metric-detail {
  margin-top: 7px !important;
  color: var(--text-secondary);
  font-size: 13px;
}

.advice-block {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typingPulse 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.composer {
  position: absolute;
  top: calc(36% + 62px);
  left: 50%;
  z-index: 10;
  width: min(760px, calc(100vw - 48px));
  min-height: 58px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 38px;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 30px;
  background: var(--surface-bg);
  transform: translateX(-50%);
}

.composer-note {
  grid-column: 2 / -1;
  margin: -3px 4px 0 0;
  color: rgba(255, 255, 255, 0.58);
  font-size: 12px;
  line-height: 1.35;
}

.conversation-started .composer {
  top: auto;
  bottom: calc(20px + env(safe-area-inset-bottom));
}

.plus-button,
.send-button,
.icon-button {
  display: grid;
  place-items: center;
  border-radius: 50%;
}

.plus-button {
  width: 34px;
  height: 34px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 24px;
  line-height: 1;
}

.plus-button:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.composer textarea {
  width: 100%;
  max-height: 160px;
  min-height: 34px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  padding: 6px 0;
  line-height: 1.45;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.composer textarea::placeholder {
  color: var(--text-muted);
}

.send-button {
  width: 38px;
  height: 38px;
  background: var(--button-primary-bg);
  color: var(--button-primary-fg);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.send-button:disabled {
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.35);
}

.account-dock {
  position: fixed;
  right: 22px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 30;
}

.conversation-started .account-dock {
  bottom: calc(86px + env(safe-area-inset-bottom));
}

.account-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 5px 10px 5px 6px;
  border-radius: 999px;
  background: var(--surface-bg);
  color: var(--text-primary);
}

.account-button:hover,
.account-menu button:hover {
  background: var(--surface-hover);
}

.account-avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--button-primary-bg);
  color: var(--button-primary-fg);
  font-size: 13px;
  font-weight: 800;
}

.account-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: 220px;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--surface-bg);
}

.account-profile {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 6px;
}

.account-profile strong,
.account-profile span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.account-menu button {
  width: 100%;
  min-height: 38px;
  border-radius: 10px;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  padding: 0 10px;
}

.auth-dialog {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--surface-bg);
  padding: 18px;
}

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

.auth-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.icon-button {
  width: 34px;
  height: 34px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 24px;
}

.icon-button:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.auth-form input,
.user-actions input,
.inline-form input,
.table-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  outline: none;
  background: #111111;
  color: var(--text-primary);
  padding: 0 12px;
}

.auth-form input:focus,
.user-actions input:focus,
.inline-form input:focus,
.table-input:focus {
  border-color: var(--border-strong);
}

.auth-submit,
.primary-button,
.ghost-button,
.danger-button,
.primary-link-button,
.ghost-link-button {
  min-height: 40px;
  border-radius: 12px;
  padding: 0 14px;
  font-weight: 700;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.auth-submit,
.primary-button,
.primary-link-button {
  background: var(--button-primary-bg);
  color: var(--button-primary-fg);
}

.ghost-button,
.ghost-link-button {
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-primary);
}

.ghost-button:hover,
.ghost-link-button:hover {
  background: var(--surface-hover);
}

.danger-button {
  background: var(--danger);
  color: #ffffff;
}

.danger-button:hover {
  background: var(--danger-strong);
}

.compact-button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 13px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: #fca5a5;
  font-size: 13px;
}

.form-error.ok {
  color: #86efac;
}

.legal-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.legal-links button {
  background: transparent;
  color: var(--text-secondary);
  padding: 0;
  font-weight: 650;
}

.legal-links button:hover {
  color: var(--text-primary);
}

.doc-card {
  width: min(760px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 40px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.doc-content {
  overflow-y: auto;
  padding-right: 6px;
  color: var(--text-secondary);
  line-height: 1.68;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.doc-content h3,
.doc-content h4,
.doc-content h5,
.doc-content h6 {
  margin: 18px 0 8px;
  color: var(--text-primary);
  line-height: 1.35;
}

.doc-content h3:first-child,
.doc-content p:first-child {
  margin-top: 0;
}

.doc-content p {
  margin: 8px 0;
}

.doc-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.confirm-card {
  width: min(420px, calc(100vw - 28px));
}

.confirm-text {
  margin: 0 0 16px;
  color: var(--text-primary);
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--surface-bg);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 14px;
}

body:has(.admin-shell) {
  overflow: auto;
  background: var(--page-bg);
}

.admin-shell {
  min-height: 100vh;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
  color: var(--text-primary);
}

.topbar,
.admin-content,
.admin-auth {
  border: 1px solid var(--border-color);
  background: var(--panel-bg);
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px;
  border-radius: 18px 18px 0 0;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.admin-auth {
  border-top: 0;
  border-radius: 0 0 18px 18px;
  padding: 16px 20px;
}

.admin-content {
  border-top: 0;
  border-radius: 0 0 18px 18px;
  padding: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.stat-item {
  padding: 16px;
}

.stat-item strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.stat-item span {
  display: block;
  margin-top: 8px;
  color: var(--text-secondary);
}

.admin-section {
  margin-top: 18px;
}

.first-section {
  margin-top: 0;
}

.settings-section {
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: #111111;
  padding: 16px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.settings-row strong,
.settings-row span {
  display: block;
}

.settings-row span {
  margin-top: 5px;
  color: var(--text-secondary);
  font-size: 13px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sensitive-textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  outline: none;
  background: #0d0d0d;
  color: var(--text-primary);
  padding: 12px;
  line-height: 1.5;
}

.sensitive-textarea:focus {
  border-color: var(--border-strong);
}

.section-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.section-count {
  color: var(--text-secondary);
  font-size: 13px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.inline-check {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
}

.inline-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--success);
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: var(--surface-bg);
  border: 1px solid var(--border-color);
  transition: background 0.18s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform 0.18s ease, background 0.18s ease;
}

.switch input:checked + span {
  background: var(--button-primary-bg);
}

.switch input:checked + span::after {
  transform: translateX(22px);
  background: var(--button-primary-fg);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: #111111;
}

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

.audit-table {
  min-width: 1240px;
}

.log-table {
  min-width: 1360px;
}

.sensitive-table {
  min-width: 1040px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-bg);
}

tr:last-child td {
  border-bottom: 0;
}

.admin-action-error {
  margin-top: 10px;
}

.user-actions {
  display: grid;
  grid-template-columns: minmax(116px, 1fr) auto minmax(116px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.user-actions input {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.table-input {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.mono-cell {
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.action-hint {
  color: var(--text-muted);
  font-size: 13px;
}

.content-cell {
  max-width: 320px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-badge.pending {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-secondary);
}

.status-badge.approved {
  background: rgba(16, 163, 127, 0.18);
  color: #86efac;
}

.status-badge.rejected {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.approve-button {
  background: var(--success);
  color: #ffffff;
}

.reject-button {
  background: var(--danger);
  color: #ffffff;
}

.audit-row.approved td:first-child {
  border-left: 3px solid var(--success);
}

.audit-row.rejected td:first-child {
  border-left: 3px solid var(--danger);
}

.audit-log-text {
  min-height: 240px;
  max-height: 560px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: #111111;
  color: var(--text-secondary);
  padding: 14px;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 13px/1.62 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

@media (max-width: 860px) {
  .brand-button {
    top: 16px;
    left: 20px;
    font-size: 20px;
  }

  .welcome-panel {
    top: 34%;
    width: calc(100vw - 48px);
  }

  .composer {
    width: calc(100vw - 48px);
  }

  .messages {
    padding-left: 20px;
    padding-right: 20px;
  }

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

  .user-actions {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .brand-button {
    left: 18px;
    font-size: 18px;
  }

  .brand-icon {
    width: 26px;
    height: 26px;
  }

  .welcome-panel {
    top: 32%;
    width: calc(100vw - 28px);
  }

  .welcome-panel h1 {
    font-size: 26px;
  }

  .composer {
    width: calc(100vw - 28px);
    grid-template-columns: 32px minmax(0, 1fr) 36px;
    border-radius: 28px;
  }

  .conversation-started .composer {
    bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .messages {
    inset: 76px 0 170px;
    padding: 8px 14px 18px;
  }

  .message-group {
    width: 100%;
  }

  .user-bubble {
    max-width: 86%;
  }

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

  .metric-head {
    grid-template-columns: 1fr auto;
  }

  .metric-head .item-label {
    grid-column: 1 / -1;
  }

  .account-dock,
  .conversation-started .account-dock {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .account-button {
    min-height: 38px;
  }

  .account-label {
    max-width: 120px;
  }

  .toast {
    bottom: calc(126px + env(safe-area-inset-bottom));
  }

  .admin-shell {
    padding: 0;
  }

  .topbar,
  .admin-auth,
  .admin-content {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

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