:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef3ee;
  --ink: #1f2923;
  --muted: #67736b;
  --line: #d8ded7;
  --accent: #116a5b;
  --accent-dark: #0c4f44;
  --warn: #965b12;
  --danger: #9d3131;
  --shadow: 0 18px 60px rgba(29, 42, 35, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.chat-panel,
.plan-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  border-radius: 8px;
  overflow: hidden;
}

.plan-panel {
  border-radius: 8px;
  padding: 18px;
  overflow: auto;
}

.top-bar,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

h3 {
  font-size: 13px;
  line-height: 1.2;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}

.top-bar p,
.panel-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-dark);
  font-size: 24px;
  line-height: 1;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
}

.message {
  max-width: min(760px, 88%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.message.system {
  align-self: flex-start;
  background: var(--surface-soft);
}

.message.error {
  border-color: rgba(157, 49, 49, 0.35);
  background: #fff4f2;
  color: var(--danger);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

textarea {
  width: 100%;
  min-height: 48px;
  max-height: 160px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 106, 91, 0.14);
}

.composer button,
.quick-actions button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 650;
}

.composer button {
  min-width: 90px;
  padding: 0 18px;
}

.composer button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-pill.needs_clarification,
.status-pill.awaiting_confirmation {
  background: #fff4dc;
  color: var(--warn);
}

.status-pill.executed {
  background: #e6f4ef;
  color: var(--accent-dark);
}

.status-pill.failed,
.status-pill.cancelled,
.status-pill.unsupported {
  background: #fff4f2;
  color: var(--danger);
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 20px;
}

.detail-section {
  margin-top: 20px;
}

.empty-state,
.scope-card,
.row-card {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.scope-card strong,
.row-card strong {
  color: var(--ink);
}

.row-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.row-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.quick-actions button {
  min-height: 38px;
  padding: 8px;
  background: var(--accent-dark);
  font-size: 13px;
}

.approval-actions .quick-actions {
  grid-template-columns: repeat(3, 1fr);
}

.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: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 10px;
    min-height: 100dvh;
    padding: 10px;
  }

  .chat-panel {
    min-height: 66dvh;
  }

  .plan-panel {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 0;
  }

  .chat-panel,
  .plan-panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  .top-bar,
  .panel-heading {
    padding: 14px;
  }

  .message-list {
    padding: 14px;
  }

  .message {
    max-width: 94%;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer button {
    min-height: 44px;
  }
}
