:root {
  color-scheme: light;
  --background: #f4f5f3;
  --surface: #ffffff;
  --surface-muted: #eef0ed;
  --text: #202522;
  --muted: #667069;
  --line: #d8ddd9;
  --accent: #1f6f50;
  --accent-dark: #18583f;
  --danger: #a23838;
  --warning: #8b6518;
  --radius: 10px;
  font-family: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background: var(--background);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button, input, select, textarea { min-height: 42px; }

button {
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: .65rem 1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}

button:hover { background: var(--accent-dark); }
button:active { transform: translateY(1px); }
button:disabled { cursor: wait; opacity: .65; }

button.secondary, .icon-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

button.secondary:hover, .icon-button:hover { background: var(--surface-muted); }

input, select, textarea {
  width: 100%;
  border: 1px solid #bfc7c1;
  border-radius: 7px;
  padding: .6rem .7rem;
  background: var(--surface);
  color: var(--text);
}

textarea { resize: vertical; }
label { display: block; margin-top: .9rem; margin-bottom: .35rem; font-weight: 650; }
:focus-visible { outline: 3px solid rgba(31, 111, 80, .28); outline-offset: 2px; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-panel {
  width: min(100%, 430px);
  padding: clamp(1.5rem, 5vw, 2.5rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.login-panel button { width: 100%; margin-top: 1.25rem; }
.login-panel h1, .topbar h1 { margin: .15rem 0 .65rem; font-size: clamp(1.55rem, 4vw, 2.1rem); }
.eyebrow { margin: 0; color: var(--accent); font-size: .75rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.muted, .field-help { color: var(--muted); }
.field-help { margin: .3rem 0 0; font-size: .82rem; }

.app-shell { width: min(100% - 2rem, 1240px); margin: 0 auto; padding-bottom: 3rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.6rem 0 1.2rem; }
.session-actions { display: flex; align-items: center; gap: .75rem; }
.session-status { text-align: right; }
.session-status p { margin: 0; }
#session-context { margin-bottom: .2rem; font-size: .84rem; font-weight: 650; }
.connection-status { margin: 0; color: var(--warning); font-size: .78rem; }
.connection-status.connected { color: var(--accent); }
.scope-bar { display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.scope-bar label { margin-top: 0; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 2rem; overflow-x: auto; }
.tab { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; color: var(--muted); white-space: nowrap; }
.tab:hover { background: var(--surface-muted); color: var(--text); }
.tab.active { border-bottom-color: var(--accent); color: var(--text); }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.section-heading h2 { margin: .2rem 0 0; font-size: 1.45rem; }
.refresh-controls { display: flex; align-items: center; gap: .75rem; }
.refresh-status { margin: 0; color: var(--muted); font-size: .78rem; text-align: right; }
.refresh-status.error { color: var(--danger); }
.filters { display: grid; grid-template-columns: repeat(3, minmax(140px, 1fr)) auto; gap: .8rem; align-items: end; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.filters label { margin-top: 0; }
.filter-actions { display: flex; gap: .5rem; }

.state { padding: 2rem 1rem; color: var(--muted); text-align: center; }
.state.error, .message.error { color: var(--danger); }
.message { padding: .65rem .8rem; border-radius: 6px; background: var(--surface-muted); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .8rem 1rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7f9f7; }
.table-action { min-height: 34px; padding: .4rem .7rem; }
.pagination-controls { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: .75rem; }
.pagination-controls p { margin: 0; }

.badge { display: inline-block; border-radius: 999px; padding: .25rem .55rem; background: var(--surface-muted); font-size: .78rem; font-weight: 700; }
.badge.good { background: #dceee5; color: #17573e; }
.badge.warn { background: #f2e8cc; color: #745211; }
.badge.bad { background: #f3dddd; color: #7f2b2b; }

.agent-list { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.agent-row { display: grid; grid-template-columns: minmax(180px, 1fr) 150px minmax(180px, 1fr); gap: 1rem; padding: 1rem; border-bottom: 1px solid var(--line); align-items: center; }
.agent-row:last-child { border-bottom: 0; }
.agent-row strong, .agent-row span { overflow-wrap: anywhere; }

dialog { width: min(940px, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); }
dialog::backdrop { background: rgba(22, 27, 24, .55); }
.dialog-header { position: sticky; top: 0; display: flex; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.dialog-header h2 { margin: .2rem 0 0; font-size: 1.25rem; }
#detail-content { padding: 1.25rem; }
.metadata { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin: 0 0 1.5rem; }
.metadata div { border-top: 1px solid var(--line); padding-top: .65rem; }
.metadata dt { color: var(--muted); font-size: .78rem; }
.metadata dd { margin: .25rem 0 0; overflow-wrap: anywhere; font-weight: 650; }
.evidence-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.evidence { min-width: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-muted); }
.evidence img { display: block; width: 100%; max-height: 360px; object-fit: contain; background: #252a27; }
.evidence p, .evidence a, .evidence button { margin: .7rem; overflow-wrap: anywhere; }
.review-section { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.review-section form { max-width: 560px; }
.review-section button { margin-top: 1rem; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .scope-bar, .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-actions { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .app-shell { width: min(100% - 1rem, 1240px); }
  .topbar { align-items: flex-start; }
  .scope-bar, .filters, .metadata, .evidence-list, .agent-row { grid-template-columns: 1fr; }
  .filter-actions { flex-direction: column; }
  .section-heading { align-items: flex-start; }
  .refresh-controls { align-items: flex-end; flex-direction: column-reverse; }
  .agent-row { gap: .5rem; }
  dialog { width: calc(100% - .5rem); max-height: calc(100dvh - .5rem); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
