:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --text: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --accent: #b45309;
  --danger: #b42318;
  --good: #087443;
  --info: #175cd3;
  --shadow: 0 14px 38px rgba(26, 36, 58, 0.1);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --surface: #182233;
  --surface-2: #202c40;
  --text: #f5f7fb;
  --muted: #aab6c6;
  --line: #334155;
  --primary: #2dd4bf;
  --primary-strong: #5eead4;
  --accent: #f59e0b;
  --danger: #f97066;
  --good: #32d583;
  --info: #84adff;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.app-loading,
.loading-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.loading-shell {
  min-height: unset;
  display: flex;
  gap: 16px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
}

.auth-visual {
  padding: 52px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #172033;
  color: #f8fafc;
}

.auth-visual h1 {
  max-width: 760px;
  margin: 28px 0 12px;
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: 0;
}

.auth-visual p {
  max-width: 620px;
  color: #cbd5e1;
  line-height: 1.6;
}

.auth-points {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 28px;
}

.auth-point {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.auth-form-wrap {
  display: grid;
  align-items: center;
  padding: 42px;
}

.auth-form {
  width: min(480px, 100%);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-form h2 {
  margin: 0 0 6px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 18px 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 12px;
}

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

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

.nav {
  display: grid;
  gap: 4px;
}

.nav button,
.tab-button,
.icon-button,
.button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: var(--radius);
}

.nav button {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  text-align: left;
  color: var(--muted);
}

.nav button:hover,
.nav button.active {
  color: var(--text);
  background: var(--surface-2);
}

.nav .glyph {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(15, 118, 110, 0.12);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.role-pill,
.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 68px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg), var(--surface) 72%);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.topbar p,
.muted {
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.content {
  padding: 24px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

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

.panel,
.metric,
.record-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
}

.panel {
  padding: 18px;
}

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

.panel-header h2,
.panel-header h3,
.section-title {
  margin: 0;
  font-size: 17px;
}

.metric {
  padding: 16px;
  min-height: 118px;
}

.metric small {
  display: block;
  color: var(--muted);
  margin-bottom: 12px;
}

.metric strong {
  display: block;
  font-size: 32px;
  line-height: 1;
}

.metric span {
  color: var(--muted);
  display: block;
  margin-top: 10px;
  font-size: 13px;
}

.button,
.icon-button,
.tab-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

[data-theme="dark"] .button.primary {
  color: #06201d;
}

.button.warning {
  border-color: color-mix(in srgb, var(--accent), transparent 65%);
  color: var(--accent);
}

.button.danger {
  border-color: color-mix(in srgb, var(--danger), transparent 65%);
  color: var(--danger);
}

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

.tab-button.active {
  background: var(--surface-2);
  border-color: var(--primary);
}

.icon-button {
  width: 38px;
  padding: 0;
}

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

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

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

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 11px;
  outline: none;
}

.field textarea {
  min-height: 112px;
  resize: vertical;
  line-height: 1.5;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary), transparent 78%);
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

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

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: var(--surface-2);
}

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

.status-Draft {
  color: var(--muted);
}

.status-Needs,
.status-Corrections {
  color: var(--accent);
}

.status-Moderation,
.status-Submitted,
.status-Reviewed {
  color: var(--info);
}

.status-Approved {
  color: var(--good);
}

.status-Archived {
  color: var(--muted);
}

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

.record-card {
  padding: 14px;
}

.record-card h3,
.record-card h4 {
  margin: 0 0 6px;
}

.record-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) minmax(360px, 1.18fr);
  gap: 16px;
  align-items: start;
}

.preview {
  max-height: 680px;
  overflow: auto;
}

.unit {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.unit h4 {
  margin: 0 0 8px;
}

.criteria-list {
  display: grid;
  gap: 7px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.criteria-list li {
  border-left: 3px solid var(--primary);
  padding: 7px 9px;
  background: var(--surface-2);
  border-radius: 0 var(--radius) var(--radius) 0;
  line-height: 1.45;
}

.chat-window {
  display: grid;
  grid-template-rows: minmax(300px, 58vh) auto;
  gap: 12px;
}

.messages {
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.message {
  max-width: 82%;
  margin-bottom: 10px;
  padding: 11px 12px;
  border-radius: var(--radius);
  line-height: 1.5;
  white-space: pre-wrap;
}

.message.user {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
}

[data-theme="dark"] .message.user {
  color: #06201d;
}

.message.ai {
  background: var(--surface-2);
}

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

.chart-bars {
  display: grid;
  gap: 10px;
}

.bar {
  display: grid;
  grid-template-columns: minmax(130px, 0.42fr) minmax(120px, 1fr) 42px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-2);
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--primary);
}

.readiness-meter {
  height: 11px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}

.readiness-meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--danger), var(--accent), var(--primary));
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  z-index: 20;
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  line-height: 1.45;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 18%);
}

.activity {
  display: grid;
  gap: 10px;
}

.activity-item {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  align-items: start;
}

.activity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 7px;
  background: var(--primary);
}

.activity-item strong {
  display: block;
}

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

.mobile-menu {
  display: none;
}

@media (max-width: 1120px) {
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.cols-3,
  .split {
    grid-template-columns: 1fr;
  }
}

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

  .auth-visual {
    min-height: 330px;
    padding: 28px;
  }

  .auth-visual h1 {
    font-size: 34px;
  }

  .auth-points,
  .grid.cols-2,
  .grid.cols-4,
  .form-grid.two {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    z-index: 10;
    transform: translateX(-103%);
    transition: transform 0.18s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-flex;
  }

  .content,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 19px;
  }

  .chat-compose {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }
}
