:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --text: #101114;
  --muted: #5a5f6a;
  --border: #e5e7eb;
  --shadow: 0 1px 2px rgba(0,0,0,0.05);
  --focus: #111827;
  --font-scale: 1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: calc(14px * var(--font-scale));
}

.font-large { --font-scale: 1.1; }

.density-compact .content { padding: 12px; }
.density-compact .table__head, .density-compact .table__row { padding: 8px 10px; }
.density-compact .card { padding: 12px; }
.density-compact .btn { padding: 8px 12px; }

.contrast-high {
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #000000;
  --muted: #111827;
  --border: #111827;
  --shadow: none;
}

*:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand__title { font-weight: 600; letter-spacing: 0.2px; }
.brand__meta { margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.topbar__right { display: flex; gap: 8px; align-items: center; }

.nav {
  display: flex;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.nav__item {
  text-decoration: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
}
.nav__item:hover { background: #f3f4f6; }

.content { padding: 18px; max-width: 100% ; margin: 0 auto; }

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

.h1 { font-size: 22px; margin: 0 0 6px; font-weight: 650; }
.h2 { font-size: 16px; margin: 0 0 10px; font-weight: 600; }
.h2--spaced { margin-top: 18px; }
.h3 { font-size: 13px; margin: 0; font-weight: 650; letter-spacing: 0.1px; }
.muted { color: var(--muted); font-size: 13px; }
.text-danger { color: #dc2626; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }
.link { color: inherit; text-decoration: none; }
.link:hover { text-decoration: underline; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.card--tight { padding: 12px; }

.btn {
  appearance: none;
  border: 1px solid #111827;
  background: #111827;
  color: white;
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { opacity: 0.92; }
.btn--ghost {
  background: transparent;
  color: #111827;
}

.pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f9fafb;
  font-size: 12px;
  color: #111827;
}
.badge--sev-low { border-left: 3px solid #9ca3af; }
.badge--sev-medium { border-left: 3px solid #6b7280; }
.badge--sev-high { border-left: 3px solid #111827; }
.badge--sev-critical { border-left: 3px solid #7f1d1d; }

.form { display: grid; gap: 10px; margin-top: 12px; }
.label { font-size: 13px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: white;
  color: var(--text);
}
.textarea { resize: vertical; min-height: 80px; }
.form__actions { display: flex; gap: 10px; margin-top: 6px; }

.notice {
  border: 1px solid var(--border);
  background: #f9fafb;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}
.notice--error {
  border-color: #fecaca;
  background: #fff1f2;
}
.divider { height: 1px; background: var(--border); margin: 8px 0; }

.filters {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}
.filters__field--actions { display: flex; justify-content: flex-end; }

.table {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--panel);
}
.table__head, .table__row {
  display: grid;
  grid-template-columns: 120px 140px 160px 200px 1fr;
  gap: 10px;
  padding: 12px 14px;
  align-items: center;
}
.table__head {
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.table__row {
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border);
}
.table__row:hover { background: #f9fafb; }
.table__row.is-selected { background: #f3f4f6; }
.table__title { font-weight: 600; }
.table__head--archive, .table__row--archive { grid-template-columns: 160px 140px 240px 1fr; }
.table__head--timeline, .table__row--timeline { grid-template-columns: 220px 1.2fr 200px 1fr; }

.empty { padding: 18px; }
.empty__title { font-weight: 600; margin-bottom: 6px; }

.grid {
  display: grid;
  grid-template-columns: 1.6fr 0.9fr;
  gap: 12px;
}
.grid--dash { grid-template-columns: 1fr 1fr; }
.grid--prefs { grid-template-columns: 1fr 1fr; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; margin-bottom: 12px; }
.kpi { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: #fcfcfd; }
.kpi__label { font-size: 12px; color: var(--muted); }
.kpi__value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.list__row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); text-decoration: none; color: inherit; }
.list__row--static { text-decoration: none; color: inherit; }
.list__row.is-selected { background: #f3f4f6; margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; border-radius: 12px; }
.list__row.is-warning { background: #fffbeb; margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; border-radius: 12px; }
.list__row.is-warning:hover { background: #fef3c7; }
.list__row.is-warning.is-selected { background: #fef3c7; }
.list__row:hover { background: #f9fafb; margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; border-radius: 12px; }
.list__title { font-weight: 600; }
.grid__main { min-width: 0; }
.grid__side { min-width: 0; }

.details { margin-top: 10px; }
.details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  user-select: none;
}

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.step {
  appearance: none;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  box-shadow: var(--shadow);
}
.step:hover { background: #fcfcfd; }
.step__num {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f9fafb;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
}
.step__title { font-weight: 650; }
.step__sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.step.is-active { border-color: #111827; }
.step.is-done .step__num { border-color: #111827; background: #111827; color: #fff; }

.fieldgrid { display: grid; gap: 10px; margin-top: 10px; }
.fieldrow {
  display: grid;
  grid-template-columns: 220px 1fr auto;
  gap: 10px;
  align-items: start;
}
.fieldrow__key { padding-top: 8px; }
.fieldrow__actions { padding-top: 2px; }

.code {
  margin-top: 8px;
  border: 1px solid var(--border);
  background: #fcfcfd;
  border-radius: 12px;
  padding: 10px 12px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
}
.code--text { white-space: pre-wrap; }

.prose { font-size: 14px; line-height: 1.6; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.history {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.history__top { display: flex; justify-content: space-between; gap: 8px; }

.diff { margin-top: 10px; overflow: auto; }
.diff table.diff { width: 100%; border-collapse: collapse; }
.diff table.diff td { padding: 2px 8px; vertical-align: top; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; font-size: 12px; }
.diff table.diff th { background: #f3f4f6; padding: 8px; text-align: left; font-size: 12px; color: var(--muted); }

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
  .grid--dash { grid-template-columns: 1fr; }
  .grid--prefs { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  
  /* Only apply default reduction to generic tables */
  .table__head:not([class*="--"]), 
  .table__row:not([class*="--"]) { 
    grid-template-columns: 120px 120px 1fr; 
  }
  
  .fieldrow { grid-template-columns: 1fr; }
  
  /* Generic column hiding */
  .table__head:not([class*="--"]) div:nth-child(3),
  .table__row:not([class*="--"]) div:nth-child(3),
  .table__head:not([class*="--"]) div:nth-child(4),
  .table__row:not([class*="--"]) div:nth-child(4) { display: none; }
}

.inbox { display: grid; grid-template-columns: 1.4fr 0.9fr; gap: 12px; }
.inbox__list { min-width: 0; }
.inbox__preview { min-width: 0; }

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

/* Deep Analysis / Chat styles */
.chat-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}
.chat-thread {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border);
  background: #fcfcfd;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-message {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
}
.chat-message--user {
  align-self: flex-end;
  background: #111827;
  color: white;
  border-bottom-right-radius: 2px;
}
.chat-message--assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: var(--text);
  border-bottom-left-radius: 2px;
  border: 1px solid var(--border);
}
.chat-message .citations {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-message .citation {
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
  background: rgba(0,0,0,0.05);
  padding: 2px 6px;
  border-radius: 4px;
}
.chat-message .citation:hover {
  background: rgba(0,0,0,0.1);
  color: var(--text);
}

/* Waiting/Busy state for status messages */
.status-waiting {
  background-color: #fef3c7; /* Light Amber / Yellow */
  color: #92400e; /* Darker Amber text */
  border: 1px solid #f59e0b;
  border-radius: 8px;
  padding: 8px 12px;
  display: inline-block;
  margin: 4px 0;
  font-weight: 500;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.8; }
  100% { opacity: 1; }
}
