:root {
  color: #17211d;
  background: #f4f6f4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  --ink: #17211d;
  --muted: #627069;
  --line: #d8dedb;
  --surface: #ffffff;
  --green: #176b4d;
  --green-soft: #e8f2ed;
  --blue: #235c81;
  --amber: #966600;
  --red: #a13b34;
}

* { box-sizing: border-box; }

body { margin: 0; min-width: 320px; background: #f4f6f4; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-shell { width: min(420px, 100%); margin: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.login-shell > header { padding: 22px 22px 18px; border-bottom: 1px solid var(--line); }
.login-shell > header h1 { margin-top: 5px; }
.login-shell > header > p:last-child { margin-top: 8px; color: var(--muted); font-size: 13px; }
.login-form { padding: 22px; }
.login-form input { width: 100%; min-height: 42px; border: 1px solid #c8d0cc; border-radius: 5px; padding: 9px 10px; }
.login-error { min-height: 20px; color: var(--red); font-size: 12px; }

button, input, textarea { font: inherit; letter-spacing: 0; }

button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  min-height: 76px;
  padding: 14px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 5;
}

h1, h2, p { margin: 0; }
h1 { font-size: 21px; line-height: 1.2; font-weight: 720; }
.topbar p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.topbar nav { display: flex; align-items: center; gap: 10px; }
.topbar a { color: var(--blue); text-decoration: none; font-size: 14px; font-weight: 650; }

.notification-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
}

.notification-count {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  padding: 0 5px;
  background: var(--green);
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

.notification-count[hidden] { display: none; }

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 20px;
}

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

.report-reader {
  width: min(900px, calc(100% - 32px));
  margin: 26px auto 64px;
}

.report-reader[hidden], #assistant-dashboard[hidden] { display: none; }
.report-reader-heading { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 18px; align-items: start; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.report-reader-heading > button { min-height: 40px; white-space: nowrap; }
.report-reader-heading h2 { margin-top: 4px; font-size: 24px; line-height: 1.32; overflow-wrap: anywhere; }
#report-reader-meta { margin-top: 7px; color: var(--muted); font-size: 13px; }
.report-chat-jump { margin-top: 13px; min-height: 36px; padding-block: 7px; color: var(--green); }
.report-chat-jump[hidden] { display: none; }
.report-reader-content { max-height: none; padding: 24px 0 0; overflow: visible; font-size: 16px; line-height: 1.75; }
.report-reader-mode .topbar #qwen-chat-link,
.report-reader-mode .topbar #refresh-button,
.report-reader-mode .topbar p { display: none; }

.report-item-actions { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0 4px; }
.report-item-actions button { min-height: 34px; padding: 6px 10px; color: var(--green); font-size: 12px; }

.report-chat { margin-top: 42px; border-top: 2px solid #aebbb5; padding-top: 24px; scroll-margin-top: 92px; }
.report-chat[hidden] { display: none; }
.report-chat-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding-bottom: 16px; }
.report-chat-heading h2 { font-size: 20px; }
.report-chat-state { flex: none; color: var(--muted); font-size: 12px; font-weight: 700; }
.report-chat-messages { border-top: 1px solid var(--line); }
.report-chat-exchange { border-bottom: 1px solid var(--line); }
.report-chat-question { padding: 16px 18px; background: #edf3f0; }
.report-chat-question > p { margin-top: 8px; white-space: pre-wrap; line-height: 1.6; overflow-wrap: anywhere; }
.report-chat-answer { padding: 17px 18px 20px; background: var(--surface); }
.report-chat-message-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; font-weight: 750; }
.report-chat-answer-content { max-height: none; padding: 10px 0 0; overflow: visible; font-size: 15px; }
.report-chat-answer-content h2 { margin-top: 8px; }
.report-chat-progress { margin-top: 10px; color: var(--blue); font-size: 13px; }
.report-chat-progress.failed { color: var(--red); }
.report-chat-progress.cancelled { color: var(--muted); }
.report-chat-form { gap: 10px; padding-top: 18px; }
.report-chat-form textarea { min-height: 96px; max-height: 260px; background: var(--surface); line-height: 1.55; }
.report-chat-selection { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--green); font-size: 12px; font-weight: 750; }
.report-chat-selection[hidden] { display: none; }
.report-chat-selection .icon-button { width: 30px; height: 30px; padding: 0; font-size: 17px; }
.report-chat-form-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.report-chat-form-actions span { color: var(--muted); font-size: 11px; }
.report-chat-form-actions button { min-width: 104px; min-height: 40px; }

.summary-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: #1c2924;
  color: #fff;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
}

.summary-band div { min-width: 0; padding: 18px 20px; border-right: 1px solid #3a4641; }
.summary-band div:last-child { border-right: 0; }
.summary-band span { display: block; color: #b9c6bf; font-size: 12px; }
.summary-band strong { display: block; margin-top: 8px; font-size: 18px; overflow-wrap: anywhere; }

.command-band {
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: var(--surface);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.pause-control { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 650; }
.pause-control input { width: 18px; height: 18px; accent-color: var(--red); }
.command-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.command-center { padding-block: 16px; }
.command-center .section-heading { margin-bottom: 12px; }
.command-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.command-grid button, .command-link { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; text-align: center; }
.command-link { border: 1px solid var(--green); border-radius: 6px; padding: 9px 13px; background: var(--green-soft); color: var(--green); font-weight: 700; text-decoration: none; }
.command-link:hover { background: #dcebe3; }
.command-link[hidden] { display: none; }

.mobile-push-layout { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 28px; align-items: start; }
.mobile-push-actions { display: grid; gap: 8px; }
.mobile-push-actions > * { min-height: 42px; width: 100%; }
.mobile-push-actions [hidden] { display: none; }

button {
  border: 1px solid #bfc8c3;
  border-radius: 6px;
  padding: 9px 13px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 650;
}
button:hover { border-color: #829088; background: #f7f9f8; }
button:disabled { opacity: 0.55; cursor: wait; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; }
button.primary:hover { background: #105c40; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr); gap: 16px; margin-top: 16px; }
.lower-grid { grid-template-columns: 1fr 1fr; }

.panel { margin-top: 16px; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.dashboard-grid .panel { margin-top: 0; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.eyebrow { color: var(--green); font-size: 10px; font-weight: 800; }
h2 { margin-top: 3px; font-size: 17px; line-height: 1.25; }
.count { color: var(--muted); font-size: 12px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
th { color: var(--muted); font-size: 11px; text-align: left; font-weight: 700; padding: 0 8px 9px; border-bottom: 1px solid var(--line); }
td { padding: 11px 8px; border-bottom: 1px solid #edf0ee; vertical-align: middle; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
.status { font-weight: 700; }
.status.success { color: var(--green); }
.status.failed { color: var(--red); }
.status.running { color: var(--blue); }
.status.skipped { color: var(--amber); }

.delivery-list { margin: 0; }
.delivery-list div { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; padding: 11px 0; border-bottom: 1px solid #edf0ee; }
.delivery-list div:last-child { border-bottom: 0; }
.delivery-list dt { color: var(--muted); font-size: 12px; }
.delivery-list dd { margin: 0; font-size: 13px; font-weight: 650; overflow-wrap: anywhere; }
.delivery-list a { color: var(--green); text-decoration: none; }

.items-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 22px; }
.signal-item { min-width: 0; padding: 14px 0; border-top: 1px solid #edf0ee; }
.signal-item:nth-child(-n + 2) { border-top: 0; padding-top: 0; }
.signal-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; color: var(--muted); font-size: 11px; }
.signal-id { color: var(--blue); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 750; }
.signal-item h3 { margin: 7px 0 6px; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.signal-item a { color: var(--green); font-size: 12px; text-decoration: none; }

.sources-list { display: grid; gap: 0; }
.source-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 80px; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid #edf0ee; font-size: 13px; }
.source-row:last-child { border-bottom: 0; }
.source-row strong { overflow-wrap: anywhere; }
.source-row span { color: var(--muted); }
.source-state { text-align: right; font-weight: 700; }
.source-state.on { color: var(--green); }

form { display: grid; gap: 13px; }
form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
textarea, input[type="number"], input[type="search"], select { width: 100%; border: 1px solid #c8d0cc; border-radius: 5px; background: #fbfcfb; color: var(--ink); padding: 9px 10px; resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid #9fc8b5; outline-offset: 1px; }
.score-field { grid-template-columns: minmax(0, 1fr) 80px; align-items: center; }
form button { justify-self: start; }

.segmented-control { display: inline-flex; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; }
.segmented-control button { border: 0; border-right: 1px solid var(--line); border-radius: 0; padding: 7px 11px; white-space: nowrap; font-size: 12px; }
.segmented-control button:last-child { border-right: 0; }
.segmented-control button.selected { background: var(--green-soft); color: var(--green); }

.workflow-list { display: grid; }
.workflow-item { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 18px; align-items: center; padding: 13px 0; border-bottom: 1px solid #edf0ee; }
.workflow-item:last-child { border-bottom: 0; }
.workflow-item h3 { margin: 6px 0; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.workflow-item a, .compact-result a { color: var(--green); font-size: 12px; text-decoration: none; }
.workflow-controls select { min-height: 39px; font-size: 12px; }

.inline-form { gap: 8px; }
.inline-form > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.inline-form button { justify-self: stretch; }
.compact-results { display: grid; margin-top: 12px; }
.compact-result { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 12px; padding: 11px 0; border-bottom: 1px solid #edf0ee; font-size: 12px; }
.compact-result:last-child { border-bottom: 0; }
.compact-result strong { overflow-wrap: anywhere; }
.compact-result span { color: var(--muted); grid-column: 1; }
.compact-result a { grid-column: 2; grid-row: 1 / span 2; align-self: center; }

.task-list { display: grid; }
.task-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid #edf0ee; }
.task-item:last-child { border-bottom: 0; }
.task-item > div { min-width: 0; display: grid; gap: 4px; }
.task-item strong { color: var(--blue); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; }
.task-item span { font-size: 13px; overflow-wrap: anywhere; }
.task-item small { color: var(--muted); font-size: 11px; }
.task-item button { padding: 6px 9px; color: var(--red); font-size: 12px; }

.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.security-status-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.security-status-grid > div { min-width: 0; display: grid; gap: 6px; padding: 16px; border-right: 1px solid var(--line); }
.security-status-grid > div:last-child { border-right: 0; }
.security-status-grid span { color: var(--muted); font-size: 12px; }
.security-status-grid strong { font-size: 15px; }
.security-status-grid small { color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }

td .view-report { padding: 6px 9px; font-size: 12px; }

dialog { width: min(900px, calc(100% - 30px)); max-height: 84vh; padding: 0; border: 1px solid #aeb9b3; border-radius: 8px; box-shadow: 0 18px 55px rgba(23, 33, 29, 0.22); }
dialog::backdrop { background: rgba(23, 33, 29, 0.44); }
dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.report-content { padding: 18px 20px 28px; max-height: calc(84vh - 68px); overflow: auto; overflow-wrap: anywhere; font-size: 15px; line-height: 1.68; }
.report-content h2 { margin: 2px 0 18px; font-size: 22px; }
.report-content h3 { margin: 24px 0 10px; padding-bottom: 7px; border-bottom: 1px solid var(--line); font-size: 17px; }
.report-content h4 { margin: 20px 0 8px; font-size: 15px; }
.report-content p { margin: 8px 0; }
.report-content a { color: #0969aa; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.report-content a:hover { color: #064d7d; }
.report-content ul, .report-content ol { margin: 8px 0 14px; padding-left: 24px; }
.report-content li { margin: 6px 0; }
.report-content pre { margin: 14px 0; padding: 12px 14px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #f4f7f5; white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.55; }
.report-content .quote { padding-left: 12px; border-left: 3px solid var(--green); color: var(--muted); }
.report-content hr { margin: 20px 0; border: 0; border-top: 1px solid var(--line); }

.notification-history-dialog { width: min(680px, calc(100% - 30px)); max-height: 88vh; }
.notification-history-list { max-height: calc(88vh - 70px); padding: 0 18px 10px; overflow-y: auto; }
.notification-history-item { padding: 17px 0; border-bottom: 1px solid var(--line); }
.notification-history-item:last-child { border-bottom: 0; }
.notification-history-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.notification-history-heading strong { min-width: 0; font-size: 15px; line-height: 1.4; overflow-wrap: anywhere; }
.notification-status { flex: none; color: var(--muted); font-size: 11px; font-weight: 750; }
.notification-status.dispatched { color: var(--green); }
.notification-status.queued, .notification-status.dispatching { color: var(--amber); }
.notification-status.failed { color: var(--red); }
.notification-history-meta { margin-top: 5px; color: var(--muted); font-size: 11px; }
.notification-history-preview { margin-top: 11px; color: #34413b; white-space: pre-line; font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; }
.view-notification-report { margin-top: 12px; padding: 7px 10px; color: var(--green); font-size: 12px; }

#toast { position: fixed; right: 18px; bottom: 18px; max-width: min(360px, calc(100% - 36px)); padding: 11px 14px; border-radius: 6px; background: #1c2924; color: #fff; font-size: 13px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: 160ms ease; }
#toast.visible { opacity: 1; transform: translateY(0); }
#toast.error { background: var(--red); }
.empty { color: var(--muted); font-size: 13px; padding: 14px 0; }

@media (max-width: 820px) {
  main { width: min(100% - 22px, 720px); margin-top: 12px; }
  .summary-band { grid-template-columns: 1fr 1fr; }
  .summary-band div:nth-child(2) { border-right: 0; }
  .summary-band div:nth-child(-n + 2) { border-bottom: 1px solid #3a4641; }
  .command-band, .dashboard-grid { display: grid; grid-template-columns: 1fr; }
  .mobile-push-layout { grid-template-columns: 1fr; gap: 16px; }
  .mobile-push-actions { grid-template-columns: 1fr 1fr; }
  .command-buttons { justify-content: flex-start; }
  .items-list { grid-template-columns: 1fr; }
  .signal-item:nth-child(2) { border-top: 1px solid #edf0ee; padding-top: 14px; }
  .security-status-grid { grid-template-columns: 1fr; }
  .security-status-grid > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .security-status-grid > div:last-child { border-bottom: 0; }
}

@media (max-width: 520px) {
  .topbar { padding: 12px 14px; }
  .topbar a { display: none; }
  .topbar nav { gap: 7px; }
  .notification-button { padding-inline: 9px; }
  .report-reader { width: calc(100% - 28px); margin-top: 18px; }
  .report-reader-heading { grid-template-columns: 1fr; gap: 14px; }
  .report-reader-heading > button { justify-self: start; }
  .report-reader-heading h2 { font-size: 21px; }
  .report-reader-content { padding-top: 18px; font-size: 15px; }
  .report-item-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .report-item-actions button { min-width: 0; padding-inline: 5px; }
  .report-chat { margin-top: 34px; padding-top: 20px; scroll-margin-top: 78px; }
  .report-chat-heading { align-items: flex-start; }
  .report-chat-heading h2 { font-size: 18px; }
  .report-chat-question, .report-chat-answer { padding-inline: 12px; }
  .report-chat-answer-content { font-size: 14px; }
  .notification-history-dialog { width: calc(100% - 18px); max-height: 90vh; }
  .notification-history-list { max-height: calc(90vh - 70px); padding-inline: 14px; }
  .notification-history-heading { gap: 10px; }
  .summary-band strong { font-size: 15px; }
  .summary-band div { padding: 14px; }
  .command-buttons { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .command-buttons button { min-width: 0; padding-inline: 8px; }
  .command-buttons button.primary { grid-column: 1 / -1; }
  .command-grid { grid-template-columns: 1fr 1fr; }
  .mobile-push-actions { grid-template-columns: 1fr; }
  .panel { padding: 15px; }
  .source-row { grid-template-columns: minmax(0, 1fr) 82px 54px; }
  .workflow-item { grid-template-columns: 1fr; gap: 8px; }
  .workflow-controls select { max-width: none; }
  .inline-form > div { grid-template-columns: 1fr; }
  table { min-width: 560px; }
}
