:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #fbfaf7;
  --text: #171717;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --line: #e7e3da;
  --line-strong: #d7d1c6;
  --accent: #1f5eff;
  --accent-soft: #edf3ff;
  --ok: #147a4c;
  --ok-bg: #eef8f2;
  --warn: #946200;
  --warn-bg: #fff6df;
  --danger: #b42318;
  --danger-bg: #fff1ef;
  --shadow: 0 18px 50px rgba(23, 23, 23, 0.08);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button,
a,
input,
select,
textarea,
summary {
  outline-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(31, 94, 255, 0.24);
  outline-offset: 2px;
}

button {
  border: 0;
  cursor: pointer;
}

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

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

p,
h1,
h2,
h3,
h4 {
  margin-top: 0;
}

p { line-height: 1.55; }

.app-root { min-height: 100vh; }

.no-script {
  max-width: 680px;
  margin: 64px auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 30px;
  padding: 26px;
  box-shadow: var(--shadow);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  color: #fff;
  background: var(--text);
  font-weight: 760;
  letter-spacing: -0.03em;
}

.brand-title {
  font-weight: 760;
  letter-spacing: -0.03em;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.88rem;
}

.login-card h1 {
  font-size: clamp(2rem, 10vw, 3.2rem);
  line-height: 0.96;
  letter-spacing: -0.065em;
  margin-bottom: 14px;
}

.login-card .lead {
  color: var(--muted);
  margin-bottom: 22px;
}

.mock-note,
.demo-boundary {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 0.9rem;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

label,
.legend {
  color: #303030;
  font-size: 0.86rem;
  font-weight: 680;
}

.hint,
.field-hint {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

input[type="text"],
input[type="search"],
input[type="email"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
}

textarea {
  min-height: 116px;
  resize: vertical;
  line-height: 1.45;
}

input[type="range"] { width: 100%; }

.checkbox-field,
.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.checkbox-field input,
.switch-field input {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn,
.inline-btn {
  min-height: 44px;
  border-radius: 999px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 720;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(31, 94, 255, 0.18);
}

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.danger-btn {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #ffd2ce;
}

.inline-btn {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
}

.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover,
.danger-btn:hover,
.inline-btn:hover {
  transform: translateY(-1px);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 246, 242, 0.92);
  backdrop-filter: blur(14px);
}

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

.user-chip {
  display: none;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--text);
  font-size: 0.78rem;
  font-weight: 760;
}

.user-meta {
  display: grid;
  line-height: 1.1;
}

.user-name { font-weight: 700; font-size: 0.86rem; }
.user-role { color: var(--muted); font-size: 0.76rem; }

.shell-body {
  display: grid;
  grid-template-columns: 1fr;
  width: 100%;
}

.sidebar {
  display: none;
}

.mobile-nav {
  position: sticky;
  bottom: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.nav-link {
  min-height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 720;
}

.nav-link.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.main-content {
  min-width: 0;
  padding: 18px 14px 88px;
}

.screen {
  max-width: 1180px;
  margin: 0 auto;
}

.screen-header {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 780;
}

.screen-title {
  font-size: clamp(1.8rem, 8vw, 3.8rem);
  line-height: 0.96;
  letter-spacing: -0.065em;
  margin-bottom: 8px;
}

.screen-description {
  color: var(--muted);
  max-width: 760px;
  margin-bottom: 0;
}

.header-actions,
.toolbar,
.action-row,
.card-actions,
.detail-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
}

.search-filter {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: 100%;
}

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

.kpi-card,
.card,
.panel,
.detail-card,
.empty-state,
.validation-card,
.upload-zone,
.chat-shell,
.settings-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.kpi-card {
  padding: 14px;
}

.kpi-value {
  display: block;
  font-size: 1.7rem;
  line-height: 1;
  letter-spacing: -0.05em;
  font-weight: 800;
}

.kpi-label {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

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

.agent-card {
  padding: 16px;
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.agent-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: 0 14px 34px rgba(23, 23, 23, 0.06);
}

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

.agent-card h3 {
  margin: 0 0 5px;
  font-size: 1.06rem;
  letter-spacing: -0.025em;
}

.agent-card p {
  color: var(--muted);
  margin-bottom: 14px;
  font-size: 0.92rem;
}

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

.meta-pill,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.78rem;
  font-weight: 720;
  white-space: nowrap;
}

.meta-pill {
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.badge-ready { color: var(--ok); background: var(--ok-bg); }
.badge-draft { color: var(--warn); background: var(--warn-bg); }
.badge-needs_review { color: #7c3aed; background: #f4efff; }
.badge-disabled { color: var(--muted); background: #f3f4f6; }
.badge-deleted { color: var(--danger); background: var(--danger-bg); }
.badge-uploaded { color: var(--accent); background: var(--accent-soft); }
.badge-processing { color: var(--warn); background: var(--warn-bg); }
.badge-failed { color: var(--danger); background: var(--danger-bg); }

.empty-state {
  padding: 28px;
  text-align: center;
}

.empty-state h2,
.empty-state h3 {
  letter-spacing: -0.04em;
  margin-bottom: 8px;
}

.empty-state p { color: var(--muted); }

.wizard-shell,
.detail-layout,
.playground-layout {
  display: grid;
  gap: 14px;
}

.panel,
.detail-card,
.settings-card {
  padding: 16px;
}

.panel-title,
.detail-card h2,
.settings-card h2 {
  font-size: 1.12rem;
  letter-spacing: -0.035em;
  margin-bottom: 10px;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.step {
  min-height: 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 760;
}

.step.is-active {
  border-color: rgba(31, 94, 255, 0.35);
  background: var(--accent-soft);
  color: var(--accent);
}

.wizard-form {
  display: grid;
  gap: 16px;
}

.form-grid,
.settings-grid,
.review-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.advanced-details {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  overflow: hidden;
}

.advanced-details summary {
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 760;
}

.advanced-body {
  padding: 0 16px 16px;
  display: grid;
  gap: 14px;
}

.validation-card {
  padding: 14px;
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #ffd2ce;
}

.success-card {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: #bee8cf;
}

.warning-card {
  color: var(--warn);
  background: var(--warn-bg);
  border-color: #ffdf8d;
}

.info-card {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #cfe0ff;
}

.upload-zone {
  padding: 16px;
  display: grid;
  gap: 12px;
  background: var(--surface-2);
}

.file-input {
  width: 100%;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 16px;
}

.document-list,
.audit-list,
.option-list {
  display: grid;
  gap: 10px;
}

.document-row,
.audit-row,
.option-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.document-row-header,
.audit-row-header,
.option-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.document-name,
.audit-action,
.option-title {
  font-weight: 760;
}

.document-meta,
.audit-details,
.option-description {
  color: var(--muted);
  font-size: 0.84rem;
}

.detail-hero {
  display: grid;
  gap: 12px;
}

.detail-hero h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 7vw, 3.2rem);
  line-height: 0.98;
  letter-spacing: -0.06em;
}

.detail-section {
  display: grid;
  gap: 12px;
}

.definition-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.definition-row {
  display: grid;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.definition-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.definition-row dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.definition-row dd {
  margin: 0;
  line-height: 1.45;
}

.chat-shell {
  min-height: 560px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.chat-header h2 {
  font-size: 1.08rem;
  margin-bottom: 4px;
  letter-spacing: -0.03em;
}

.chat-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-messages {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  overflow: auto;
}

.message {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.48;
}

.message.user {
  justify-self: end;
  color: #fff;
  background: var(--accent);
  border-bottom-right-radius: 6px;
}

.message.assistant {
  justify-self: start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.message-meta {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.citation-pill {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.76rem;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.chat-form textarea {
  min-height: 64px;
}

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

.select-agent-button {
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 12px;
}

.select-agent-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.skeleton-grid {
  display: grid;
  gap: 12px;
}

.skeleton-card,
.skeleton-line {
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, #ece8df, #f8f6f0, #ece8df);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

.skeleton-card { height: 156px; }
.skeleton-line { height: 16px; }

.toast-region {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 76px;
  z-index: 100;
  display: grid;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.toast.ok { border-color: #bee8cf; color: var(--ok); }
.toast.ko { border-color: #ffd2ce; color: var(--danger); }
.toast.info { border-color: #cfe0ff; color: var(--accent); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 23, 23, 0.34);
}

.modal-card {
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.modal-card h2 {
  letter-spacing: -0.04em;
  margin-bottom: 8px;
}

.modal-card p { color: var(--muted); }

.range-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.code-note {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  padding: 3px 6px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (min-width: 680px) {
  .field-row,
  .form-grid,
  .settings-grid,
  .review-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-filter {
    grid-template-columns: minmax(280px, 1fr) 220px;
  }

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

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

  .chat-form {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

  .user-chip { display: flex; }
}

@media (min-width: 980px) {
  .app-shell {
    grid-template-rows: auto 1fr;
  }

  .shell-body {
    grid-template-columns: 252px 1fr;
  }

  .sidebar {
    position: sticky;
    top: 68px;
    align-self: start;
    height: calc(100vh - 68px);
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 16px;
    padding: 16px;
    border-right: 1px solid var(--line);
  }

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

  .side-nav .nav-link {
    justify-content: start;
    place-items: center start;
    padding: 0 14px;
  }

  .sidebar-note {
    font-size: 0.84rem;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--surface-2);
  }

  .mobile-nav { display: none; }

  .main-content { padding: 28px 26px 56px; }

  .screen-header {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

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

  .detail-layout,
  .playground-layout {
    grid-template-columns: minmax(0, 1.2fr) 410px;
    align-items: start;
  }

  .wizard-shell {
    grid-template-columns: minmax(0, 760px) 1fr;
    align-items: start;
  }

  .sticky-panel {
    position: sticky;
    top: 88px;
  }

  .toast-region {
    left: auto;
    right: 22px;
    bottom: 22px;
    width: min(420px, calc(100vw - 44px));
  }
}

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