:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --panel: #fffdf9;
  --panel-strong: #ffffff;
  --ink: #181a1f;
  --muted: #66706f;
  --line: #ddd7cd;
  --accent: #0d766f;
  --accent-dark: #09524d;
  --accent-soft: #e8f5f2;
  --warn-soft: #fff1e7;
  --shadow: 0 18px 50px rgba(35, 30, 22, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(245, 243, 238, 0) 240px),
    var(--bg);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.chat-shell {
  width: min(880px, calc(100% - 28px));
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  margin: 0 auto;
  padding: 18px 0 22px;
}

.app-header {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.app-header div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.app-header strong {
  font-size: 20px;
  line-height: 1.1;
}

.app-header span {
  color: var(--muted);
  font-size: 13px;
}

.chat-card {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.96);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-log {
  min-height: 420px;
  max-height: calc(100vh - 172px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 22px;
  scroll-behavior: smooth;
}

.chat-message {
  max-width: min(680px, 88%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel-strong);
}

.chat-message p,
.chat-message li {
  line-height: 1.72;
}

.chat-message p {
  margin: 0;
}

.chat-message.user {
  align-self: flex-end;
  border-color: rgba(13, 118, 111, 0.36);
  background: var(--accent-soft);
}

.chat-message.assistant {
  align-self: flex-start;
}

.chat-message.report-message {
  max-width: 100%;
  width: 100%;
  border-color: rgba(13, 118, 111, 0.26);
  background: #fff;
}

.chat-composer {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 14px;
  background: rgba(255, 255, 255, 0.72);
}

textarea {
  width: 100%;
  min-height: 92px;
  max-height: 180px;
  border: 1px solid #c9c1b4;
  border-radius: 8px;
  padding: 12px 13px;
  font: inherit;
  line-height: 1.58;
  resize: vertical;
  background: #fff;
  color: var(--ink);
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #c9c1b4;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(13, 118, 111, 0.14);
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(13, 118, 111, 0.14);
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.ghost-button,
.ghost-link,
.copy-button.ghost {
  border: 1px solid #c9c1b4;
  background: #fff;
  color: var(--accent-dark);
}

.ghost-button:hover,
.ghost-link:hover,
.copy-button.ghost:hover {
  background: var(--accent-soft);
}

.ghost-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 900;
  text-decoration: none;
}

.report-buffer {
  display: none;
}

.report-heading {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.report-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

h2,
h3 {
  margin: 0;
}

.report-heading h2 {
  margin-top: 8px;
  font-size: 22px;
}

.report-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.copy-button {
  min-height: 36px;
  padding: 7px 11px;
  font-size: 14px;
}

.priority-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.priority-item {
  border: 1px solid rgba(13, 118, 111, 0.22);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  background: var(--accent-soft);
}

.priority-item h3,
.report-section h3 {
  margin-bottom: 7px;
  font-size: 16px;
}

.priority-item p,
.report-section p {
  margin: 0;
}

.loop-panel,
.feedback-form,
.attachment-form,
.case-evidence-panel {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(13, 118, 111, 0.24);
  border-radius: 8px;
  padding: 14px;
  margin-top: 14px;
  background: #fbfffd;
}

.loop-header,
.feedback-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.loop-header span,
.feedback-form-head span,
.loop-metric span,
.feedback-form label > span {
  color: var(--muted);
  font-size: 13px;
}

.loop-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.loop-metric {
  min-width: 0;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.loop-metric strong {
  line-height: 1.3;
}

.loop-judgment,
.feedback-prompt {
  margin: 0;
  line-height: 1.65;
}

.loop-list {
  display: grid;
  gap: 6px;
}

.loop-list ul {
  margin: 0;
  padding-left: 20px;
}

.experiment-box {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.experiment-box p {
  margin: 0;
  line-height: 1.65;
}

.experiment-box dl {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px 10px;
  margin: 0;
}

.experiment-box dt {
  color: var(--muted);
  font-weight: 800;
}

.experiment-box dd {
  margin: 0;
  line-height: 1.55;
}

.feedback-form label,
.attachment-form label {
  display: grid;
  gap: 6px;
}

.attachment-status-list {
  display: grid;
  gap: 10px;
}

.attachment-status-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.attachment-status-item strong,
.attachment-status-item span {
  min-width: 0;
}

.attachment-status-item > div:first-child {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.attachment-status-item > div:first-child span {
  color: var(--muted);
  font-size: 13px;
}

.attachment-status-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill em {
  color: var(--muted);
  font-style: normal;
  font-weight: 700;
}

.status-pill.ok {
  border-color: rgba(13, 118, 111, 0.25);
  background: #eaf7f3;
  color: #075c55;
}

.status-pill.wait {
  border-color: #ded4c6;
  background: #fbf8f2;
  color: #70531f;
}

.status-pill.bad {
  border-color: rgba(174, 47, 47, 0.24);
  background: #fff0ee;
  color: #8a2424;
}

.audit-detail {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.audit-detail summary {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px;
  padding: 9px 10px;
  background: #f8f7f3;
  cursor: pointer;
  font-weight: 900;
}

.audit-detail ul {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding-left: 20px;
}

.audit-detail li span {
  display: block;
  color: var(--muted);
  line-height: 1.55;
}

.feedback-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.report-detail {
  margin-top: 14px;
}

.report-section {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.report-section ul,
.route-detail ul {
  padding-left: 20px;
  margin: 8px 0 0;
}

.asset-list {
  list-style: none;
  padding-left: 0;
}

.asset-list li {
  display: grid;
  gap: 4px;
  padding: 9px 0;
  border-top: 1px dashed var(--line);
}

.asset-list li:first-child {
  border-top: 0;
  padding-top: 0;
}

.asset-list span {
  display: block;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: #fff;
  font-weight: 800;
}

.route-detail {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.route-detail summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--warn-soft);
  color: #572719;
  font-weight: 900;
  cursor: pointer;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  width: 100%;
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.history-item span {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.5;
}

.history-item em {
  color: var(--accent-dark);
  font-size: 13px;
  font-style: normal;
  font-weight: 800;
}

.review-shell {
  width: min(980px, calc(100% - 28px));
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  margin: 0 auto;
  padding: 18px 0 22px;
}

.review-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel-strong);
}

.review-toolbar label {
  display: grid;
  gap: 6px;
}

.review-toolbar label span {
  color: var(--muted);
  font-size: 13px;
}

.review-list {
  display: grid;
  gap: 12px;
}

.ops-metrics {
  display: grid;
  gap: 12px;
}

.ops-metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.ops-distribution-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.ops-distribution {
  min-width: 0;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.ops-distribution h3 {
  font-size: 15px;
}

.ops-bar {
  min-height: 30px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border-top: 1px dashed var(--line);
  padding-top: 7px;
  font-size: 13px;
}

.ops-bar:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.ops-bar span {
  min-width: 0;
  color: var(--muted);
}

.ops-latest {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 13px;
}

.ops-health {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.ops-health-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ops-health-head div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.ops-health-head span {
  color: var(--muted);
  font-size: 13px;
}

.ops-health-badge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 900;
}

.ops-health-badge.ok {
  border-color: rgba(13, 118, 111, 0.3);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.ops-health-badge.warn {
  border-color: #e2b58e;
  background: var(--warn-soft);
  color: #6d311a;
}

.ops-alert-list {
  display: grid;
  gap: 8px;
}

.ops-alert {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.ops-alert.critical,
.ops-alert.high {
  border-left-color: #bd3b2f;
}

.ops-alert.warning {
  border-left-color: #c68124;
}

.ops-alert.info {
  border-left-color: var(--accent);
}

.ops-alert div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ops-alert span {
  color: var(--muted);
  font-size: 13px;
}

.ops-alert p {
  margin: 0;
  line-height: 1.55;
}

.ops-case-panel {
  display: grid;
  gap: 10px;
}

.ops-case-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ops-case-toolbar button {
  min-height: 36px;
  border: 1px solid #c9c1b4;
  padding: 7px 11px;
  background: #fff;
  color: var(--accent-dark);
  font-size: 14px;
}

.ops-case-toolbar button.active,
.ops-case-toolbar button:hover {
  border-color: rgba(13, 118, 111, 0.3);
  background: var(--accent-soft);
}

.ops-case-list {
  display: grid;
  gap: 10px;
}

.ops-case-item {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.ops-case-item p {
  margin: 0;
  line-height: 1.55;
}

.review-item {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.review-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.review-item-head span,
.risk-line {
  color: var(--muted);
}

.review-item p {
  margin: 0;
  line-height: 1.65;
}

.review-item summary {
  cursor: pointer;
  font-weight: 900;
}

.review-item pre {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8f7f3;
  white-space: pre-wrap;
}

.export-box {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfffd;
}

.export-box span {
  color: var(--muted);
  font-size: 13px;
}

.export-box pre {
  max-height: 360px;
  margin: 0;
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
}

.review-detail {
  display: grid;
  gap: 12px;
}

.review-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.review-detail-grid h3,
.review-action-form h3 {
  font-size: 15px;
}

.small-line {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.review-action-form {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfffd;
}

.review-action-form label {
  display: grid;
  gap: 6px;
}

.review-action-form label span {
  color: var(--muted);
  font-size: 13px;
}

.attachment-review-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.attachment-review-panel h3 {
  font-size: 15px;
}

.attachment-review-item {
  display: grid;
  gap: 7px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}

.attachment-review-item:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.attachment-review-item p {
  margin: 0;
}

.case-status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.case-status-panel div:first-child {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.case-status-panel h3 {
  font-size: 15px;
}

.case-status-panel span {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 720px) {
  .chat-shell {
    width: min(100% - 18px, 880px);
    padding-top: 10px;
  }

  .chat-log {
    min-height: 360px;
    max-height: calc(100vh - 164px);
    padding: 14px;
  }

  .chat-message {
    max-width: 94%;
  }

  .priority-list {
    grid-template-columns: 1fr;
  }

  .loop-grid,
  .feedback-row,
  .experiment-box dl {
    grid-template-columns: 1fr;
  }

  .report-topline,
  .app-header,
  .loop-header,
  .feedback-form-head {
    align-items: stretch;
    flex-direction: column;
  }

  .ghost-button,
  .ghost-link,
  .report-actions,
  .copy-button {
    width: 100%;
  }

  .report-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .review-shell {
    width: min(100% - 18px, 980px);
    padding-top: 10px;
  }

  .review-toolbar {
    grid-template-columns: 1fr;
  }

  .ops-health-head,
  .ops-alert div,
  .attachment-status-item,
  .case-status-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .attachment-status-item {
    grid-template-columns: 1fr;
  }

  .ops-metric-grid,
  .ops-distribution-grid {
    grid-template-columns: 1fr;
  }

  .review-detail-grid {
    grid-template-columns: 1fr;
  }
}
