:root {
  color-scheme: light;
  --bg: #eef2f0;
  --surface: #ffffff;
  --surface-soft: #f7f9f8;
  --line: #d9e1dd;
  --line-strong: #b8c8c0;
  --text: #14231d;
  --muted: #62736b;
  --evergreen: #0f4b3e;
  --evergreen-2: #17624f;
  --blue: #255f9f;
  --amber: #9a6517;
  --red: #a33434;
  --red-soft: #f8e8e6;
  --green-soft: #e6f2ed;
  --shadow: 0 16px 40px rgba(25, 49, 40, 0.1);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

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

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: #fbfcfb;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.topbar p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.topbar-actions,
.button-row,
.module-header,
.metric-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}

.status-dot.ok::before {
  background: var(--evergreen-2);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.setup-panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow: auto;
  max-height: calc(100vh - 72px);
  position: sticky;
  top: 72px;
}

.panel-section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 15px;
  margin-bottom: 15px;
}

.panel-section h2,
.module h2 {
  font-size: 15px;
  line-height: 1.25;
}

.panel-section h3 {
  font-size: 13px;
  margin-bottom: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  margin-top: 10px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  min-height: 38px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--evergreen-2);
  box-shadow: 0 0 0 3px rgba(23, 98, 79, 0.12);
}

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

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  margin: 0;
  color: var(--text);
}

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

.button-row {
  flex-wrap: wrap;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 36px;
  padding: 8px 11px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
  white-space: normal;
}

button:hover {
  transform: translateY(-1px);
}

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

.secondary,
.ghost {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--evergreen);
}

.ghost {
  min-height: 32px;
}

.dashboard {
  padding: 18px;
  overflow: auto;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px;
  height: 132px;
  overflow: hidden;
}

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

.metric strong {
  display: block;
  font-size: 24px;
  margin-top: 8px;
  letter-spacing: 0;
}

.metric p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
  gap: 16px;
}

.module {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.matrix-module,
.rewrite-module {
  grid-column: 1 / -1;
}

.module-header {
  justify-content: space-between;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

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

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

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

th {
  color: var(--muted);
  font-weight: 700;
  background: #fbfcfb;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  line-height: 1.35;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  background: var(--green-soft);
  color: var(--evergreen);
  margin: 2px 4px 2px 0;
}

.pill.risk-high {
  background: var(--red-soft);
  color: var(--red);
}

.pill.risk-medium {
  background: #fff3df;
  color: var(--amber);
}

.stack,
.cards {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.cards {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.item-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
}

.item-card h3 {
  font-size: 14px;
  margin-bottom: 8px;
}

.item-card p,
.item-card li {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.item-card ul {
  padding-left: 18px;
  margin: 7px 0 0;
}

.claim-text,
.rewrite-text {
  color: var(--text);
  font-weight: 650;
  margin-bottom: 8px;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
  padding: 18px;
}

.source-link {
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.citation-meta {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  margin-top: 2px;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .setup-panel {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .matrix-module,
  .rewrite-module {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .topbar,
  .topbar-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-strip,
  .content-grid,
  .two-col {
    grid-template-columns: 1fr;
  }

  .dashboard,
  .setup-panel {
    padding: 12px;
  }

  th,
  td {
    min-width: 120px;
  }
}
