:root {
  color-scheme: light;
  --ink: #171b19;
  --muted: #65706a;
  --surface: #ffffff;
  --canvas: #f1f4f0;
  --line: #d7ddd8;
  --green: #087a52;
  --green-soft: #e4f4ec;
  --cyan: #087f8c;
  --cyan-soft: #e1f3f5;
  --amber: #8a5d00;
  --amber-soft: #fff2cc;
  --red: #b42318;
  --red-soft: #fde8e5;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button, input, textarea { font: inherit; }

button {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  padding: 9px 15px;
  font-weight: 700;
}

button:hover { background: #2b322f; }
button:disabled { cursor: wait; opacity: 0.55; }

button.secondary {
  background: transparent;
  border-color: #59625d;
  color: #fff;
}

button.secondary:hover { background: #2b322f; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 24px; line-height: 1.2; }
h2 { margin-bottom: 0; font-size: 19px; }

.eyebrow {
  margin-bottom: 4px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 28px;
  box-shadow: 0 14px 42px rgba(23, 27, 25, 0.09);
}

.auth-panel h1 { font-size: 30px; margin-bottom: 14px; }
.auth-copy { color: var(--muted); }
.auth-panel label { display: block; margin-bottom: 6px; font-weight: 700; }

.auth-panel input {
  width: 100%;
  min-height: 44px;
  margin-bottom: 12px;
  border: 1px solid #aeb7b1;
  border-radius: 6px;
  padding: 9px 11px;
}

.auth-panel button { width: 100%; }
.form-status { min-height: 22px; margin: 10px 0 0; color: var(--red); }
.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--ink);
  color: #fff;
  padding: 16px max(20px, calc((100vw - 1240px) / 2));
  border-bottom: 3px solid var(--cyan);
}

.topbar .eyebrow { color: #79d4dc; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.good { background: var(--green-soft); color: #07583d; }
.status-pill.warn { background: var(--amber-soft); color: #704b00; }
.status-pill.bad { background: var(--red-soft); color: #8f1d14; }
.status-pill.neutral { background: #e6e9e7; color: #39423e; }

main {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card, .agent-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.metric-card { min-width: 0; padding: 16px; }
.metric-card span, .metric-card small { display: block; color: var(--muted); }

.metric-card strong {
  display: block;
  margin: 5px 0;
  font-size: 25px;
  overflow-wrap: anywhere;
}

.command-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 16px;
  border-left: 5px solid var(--green);
  background: #e9f4ed;
  padding: 18px 20px;
}

.command-band p:last-child { margin-bottom: 0; color: #3f5148; }
.command-actions { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.command-actions span { color: #375047; font-size: 13px; }
.section-block { margin-top: 24px; }

.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;
}

.chat-hub {
  display: grid;
  grid-template-columns: minmax(210px, 280px) minmax(0, 1fr);
  min-height: 560px;
  margin-top: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.chat-agents {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: #e8ece9;
  padding: 18px 12px;
}

.chat-section-heading { padding: 0 6px 12px; }
.chat-agent-list { display: grid; gap: 5px; }

.chat-agent-button {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 50px;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  padding: 7px 9px;
  text-align: left;
}

.chat-agent-button:hover { background: #dce3de; }
.chat-agent-button.active { border-color: #9ab9ac; background: #d9eee3; }

.chat-agent-button .agent-copy { min-width: 0; }
.chat-agent-button strong, .chat-agent-button small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-agent-button small { color: var(--muted); font-weight: 500; }

.agent-presence, .chat-presence {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #98a29c;
}

.chat-agent-button.active-agent .agent-presence, .chat-presence { background: var(--green); }

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto auto;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.chat-header > div {
  display: grid;
  grid-template-columns: auto minmax(0, auto);
  column-gap: 8px;
  align-items: center;
}

.chat-header strong { min-width: 0; overflow-wrap: anywhere; }
.chat-header small { grid-column: 2; color: var(--muted); }

.quiet-button {
  min-height: 34px;
  border-color: #9da8a1;
  background: transparent;
  color: #435049;
  padding: 5px 9px;
  font-size: 12px;
}

.quiet-button:hover { background: #edf1ee; }

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  max-height: 540px;
  overflow-y: auto;
  background: #f7f9f7;
  padding: 18px;
}

.chat-empty { margin: auto; color: var(--muted); text-align: center; }

.chat-message { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.chat-message.user { align-items: flex-end; }
.chat-message small { color: var(--muted); font-size: 11px; }

.chat-bubble {
  max-width: min(720px, 86%);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-message.user .chat-bubble { border-color: #0b6e4c; background: var(--green); color: #fff; }
.chat-message.pending .chat-bubble { color: var(--muted); font-style: italic; }

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px;
}

.chat-composer textarea {
  width: 100%;
  min-height: 48px;
  max-height: 150px;
  resize: vertical;
  border: 1px solid #aeb7b1;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

.chat-composer textarea:focus { outline: 2px solid #8dcab2; outline-offset: 1px; }
.chat-status { min-height: 21px; margin: 0; padding: 0 12px 9px; color: var(--muted); font-size: 12px; }

.agent-chat-button {
  width: 100%;
  min-height: 34px;
  margin-top: 12px;
  border-color: #9db5aa;
  background: transparent;
  color: #176246;
  padding: 5px 9px;
  font-size: 12px;
}

.agent-chat-button:hover { background: var(--green-soft); }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading > p {
  max-width: 560px;
  margin-bottom: 0;
  color: var(--muted);
  text-align: right;
}

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

.agent-card { min-width: 0; padding: 15px; }
.agent-card.active { border-top: 4px solid var(--green); }
.agent-card.resting { border-top: 4px solid #9aa49e; }
.agent-head { display: flex; align-items: start; justify-content: space-between; gap: 8px; }
.agent-name { font-size: 17px; font-weight: 800; }
.agent-role { color: var(--muted); font-size: 13px; }

.agent-state {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.agent-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 14px;
}

.agent-metrics div { min-width: 0; }
.agent-metrics span, .agent-metrics strong { display: block; }
.agent-metrics span { color: var(--muted); font-size: 11px; }
.agent-metrics strong { font-size: 14px; }
.skill-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.skill-chip {
  max-width: 100%;
  border-radius: 999px;
  background: var(--cyan-soft);
  color: #145f66;
  padding: 4px 8px;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.compact-section { min-width: 0; }
.data-list { margin: 0; border-top: 1px solid var(--line); }

.data-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.data-row dt { color: var(--muted); }
.data-row dd { margin: 0; font-weight: 800; text-align: right; }

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

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  background: #e8ece9;
  color: #46504b;
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:last-child td { border-bottom: 0; }
.activity-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }

.activity-item {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 130px minmax(170px, 1fr);
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.activity-item span:nth-child(2) { color: var(--muted); }
.activity-item time { color: var(--muted); text-align: right; }

@media (max-width: 900px) {
  .overview-grid, .agent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chat-hub { grid-template-columns: 200px minmax(0, 1fr); }
  .topbar { position: static; align-items: flex-start; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 640px) {
  main { width: min(100% - 20px, 1240px); padding-top: 14px; }
  .topbar, .command-band, .section-heading { align-items: stretch; flex-direction: column; }
  .topbar { padding: 14px; }
  .topbar-actions { justify-content: flex-start; }
  .overview-grid, .agent-grid, .two-column { grid-template-columns: 1fr; }
  .chat-hub { grid-template-columns: 1fr; min-height: 680px; }
  .chat-agents { border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-agent-list { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 3px; }
  .chat-agent-button { flex: 0 0 180px; }
  .chat-header { align-items: flex-start; }
  .chat-composer { grid-template-columns: 1fr; }
  .chat-composer button { width: 100%; }
  .command-actions { align-items: stretch; flex-direction: column; min-width: 0; }
  .section-heading > p { text-align: left; }
  .activity-item { grid-template-columns: 1fr; gap: 3px; }
  .activity-item time { text-align: left; }
  .auth-panel { padding: 22px; }
}
