:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #0f151d;
  --border: #1e2936;
  --border-strong: #2b3a4c;
  --text: #e7eef6;
  --muted: #8b9bb0;
  --subtle: #65758a;
  --human: #5eead4;
  --agent: #a78bfa;
  --danger: #fb7185;
  --warning: #fbbf24;
  --success: #34d399;
  --shadow: 0 18px 52px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --gap: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(94, 234, 212, 0.03) 1px, transparent 1px),
    linear-gradient(0deg, rgba(167, 139, 250, 0.03) 1px, transparent 1px),
    var(--bg);
  background-size: 40px 40px;
  color: var(--text);
}

button,
textarea,
select {
  font: inherit;
}

button,
select {
  min-height: 34px;
}

button {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #17202b;
  color: var(--text);
  cursor: pointer;
  transition:
    border-color 120ms ease,
    background 120ms ease,
    transform 120ms ease;
}

button:hover {
  border-color: #486176;
  background: #1b2633;
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--human);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: 132px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.94);
  backdrop-filter: blur(16px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  grid-template-columns: 12px 36px 12px;
  align-items: center;
  width: 72px;
  height: 38px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f151d;
}

.mark-node {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.human-node {
  background: var(--human);
  box-shadow: 0 0 18px rgba(94, 234, 212, 0.55);
}

.agent-node {
  background: var(--agent);
  box-shadow: 0 0 18px rgba(167, 139, 250, 0.55);
}

.mark-line {
  height: 2px;
  background: linear-gradient(90deg, var(--human), var(--agent));
}

.brand-lockup h1,
.brand-lockup p,
.panel-heading h2,
.panel-heading p {
  margin: 0;
}

.brand-lockup h1 {
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0;
}

.brand-lockup p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.webmcp-banner,
.agent-pulse,
.status-pill,
.severity-pill,
.tool-pill,
.filter-chip,
.agent-asks button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  border-radius: 999px;
  white-space: nowrap;
}

.webmcp-banner {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: #0f151d;
  font-size: 13px;
}

.webmcp-banner.is-ready {
  border-color: rgba(52, 211, 153, 0.5);
  color: var(--success);
}

.webmcp-banner.is-unavailable {
  border-color: rgba(251, 191, 36, 0.5);
  color: var(--warning);
  white-space: normal;
  justify-content: flex-start;
  max-width: 640px;
}

.agent-pulse {
  padding: 7px 10px;
  border: 1px solid rgba(167, 139, 250, 0.55);
  color: var(--agent);
  background: rgba(167, 139, 250, 0.1);
  font-size: 12px;
  font-weight: 800;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--agent);
  animation: pulse 900ms ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.4;
    transform: scale(0.82);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

.icon-button,
.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  font-weight: 750;
}

.icon-button {
  min-width: 38px;
}

.primary-button {
  border-color: rgba(94, 234, 212, 0.55);
  background: #123832;
  color: #cffff7;
}

.primary-button:hover {
  border-color: var(--human);
  background: #16483f;
}

.secondary-button.danger {
  border-color: rgba(251, 113, 133, 0.45);
  background: #351820;
  color: #ffd0d8;
}

.ops-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 340px;
  gap: 12px;
  padding: 12px;
  align-items: start;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(18, 24, 33, 0.96);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-heading.compact {
  padding: 12px 14px;
}

.panel-heading h2 {
  font-size: 14px;
  line-height: 1.15;
}

.panel-heading p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.case-rail,
.right-stack {
  position: sticky;
  top: 84px;
}

.right-stack {
  display: grid;
  gap: 12px;
}

.filter-row {
  display: flex;
  gap: 6px;
  padding: 10px 10px 2px;
  overflow-x: auto;
}

.filter-chip {
  padding: 6px 10px;
  color: var(--muted);
  border-color: var(--border);
  background: #0f151d;
  font-size: 12px;
}

.filter-chip.is-active {
  color: #071311;
  border-color: var(--human);
  background: var(--human);
}

.case-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.case-button {
  width: 100%;
  display: grid;
  gap: 7px;
  padding: 10px;
  text-align: left;
  background: var(--panel-2);
}

.case-button.is-active {
  border-color: var(--human);
  background: #10201f;
}

.case-button-header,
.case-meta,
.case-finance-row,
.case-title-row,
.timeline-meta,
.tool-call-head,
.draft-meta,
.approval-title-row,
.modal-actions,
.summary-toolbar,
.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.case-button-header,
.case-title-row,
.tool-call-head,
.approval-title-row,
.summary-toolbar {
  justify-content: space-between;
}

.case-id,
.money,
.tool-name,
.approval-kind {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.case-id {
  color: var(--muted);
  font-size: 12px;
}

.case-title {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
}

.case-customer,
.case-meta,
.case-finance-row {
  color: var(--muted);
  font-size: 12px;
}

.case-meta {
  flex-wrap: wrap;
}

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.55);
}

.case-stage {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.case-summary {
  padding: 16px;
}

.summary-header {
  display: grid;
  gap: 12px;
}

.summary-toolbar {
  align-items: flex-start;
}

.summary-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.case-summary h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: 0;
}

.summary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-actions label {
  color: var(--muted);
  font-size: 12px;
}

.summary-actions select,
.composer-form select {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: #0f151d;
  padding: 7px 10px;
}

.description {
  margin: 6px 0 0;
  max-width: 860px;
  color: #c9d6e3;
  line-height: 1.5;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.info-tile {
  min-height: 82px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f151d;
}

.info-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.info-value {
  color: var(--text);
  font-size: 14px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.info-subvalue {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.policy-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.policy-strip div {
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f151d;
}

.policy-strip strong {
  display: block;
  margin-bottom: 4px;
  color: var(--warning);
  font-size: 12px;
  text-transform: uppercase;
}

.policy-strip span {
  color: #c9d6e3;
  font-size: 13px;
  line-height: 1.4;
}

.status-pill,
.severity-pill,
.tool-pill {
  min-height: 24px;
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  background: #0f151d;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.severity-p1 {
  border-color: rgba(251, 113, 133, 0.65);
  color: var(--danger);
}

.severity-p2 {
  border-color: rgba(251, 191, 36, 0.6);
  color: var(--warning);
}

.severity-p3 {
  border-color: rgba(52, 211, 153, 0.55);
  color: var(--success);
}

.status-refunded,
.status-resolved {
  border-color: rgba(52, 211, 153, 0.55);
  color: var(--success);
}

.status-refund-pending,
.status-open {
  border-color: rgba(251, 191, 36, 0.6);
  color: var(--warning);
}

.status-waiting-on-customer {
  border-color: rgba(139, 155, 176, 0.65);
  color: #bfd0e1;
}

.status-in-progress {
  border-color: rgba(167, 139, 250, 0.65);
  color: var(--agent);
}

.approval-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.approval-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: var(--radius);
  background: #1d1a10;
}

.approval-card p {
  margin: 0;
  color: #e8d9a3;
  line-height: 1.45;
}

.approval-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.approval-kind {
  color: var(--warning);
  font-size: 12px;
  text-transform: uppercase;
}

.empty-state {
  padding: 16px;
  color: var(--muted);
  line-height: 1.45;
}

.draft-panel {
  overflow: hidden;
}

.draft-textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #0f151d;
  color: var(--text);
  padding: 14px;
  line-height: 1.5;
}

.draft-meta {
  justify-content: space-between;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
}

.timeline {
  list-style: none;
  display: grid;
  gap: 10px;
  max-height: 48vh;
  min-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px;
}

.timeline-event {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-weight: 900;
}

.avatar.human {
  color: #062522;
  background: var(--human);
}

.avatar.agent {
  color: #151025;
  background: var(--agent);
}

.event-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f151d;
}

.timeline-meta {
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
}

.timeline-meta strong {
  color: var(--text);
  font-size: 12px;
}

.event-card p {
  margin: 0;
  color: #d6e2ee;
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.state-change {
  display: block;
  margin-top: 6px;
  color: var(--success);
  font-size: 11px;
}

.tool-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 12px 4px;
}

.tool-pill {
  border-color: rgba(167, 139, 250, 0.45);
  color: var(--agent);
  text-transform: none;
}

.tool-log {
  display: grid;
  gap: 8px;
  max-height: 32vh;
  overflow: auto;
  padding: 8px 12px 12px;
}

.tool-call {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f151d;
}

.tool-call-head {
  color: var(--muted);
  font-size: 11px;
}

.tool-call pre {
  max-width: 100%;
  overflow: auto;
  margin: 0;
  color: #c9d6e3;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.judge-console {
  margin: 0 12px 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

.judge-console summary {
  min-height: 28px;
  cursor: pointer;
  color: #bfd0e1;
}

.judge-console dl {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 6px 8px;
  margin: 4px 0 0;
}

.judge-console dt {
  color: var(--subtle);
}

.judge-console dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.composer-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.96);
  backdrop-filter: blur(18px);
}

.composer-form {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 142px 72px;
  gap: 8px;
  align-items: center;
}

.composer-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.composer-identity strong,
.composer-identity span {
  display: block;
  white-space: nowrap;
}

.composer-identity strong {
  font-size: 13px;
}

.composer-identity span {
  color: var(--muted);
  font-size: 12px;
}

.composer-form textarea {
  width: 100%;
  min-height: 44px;
  max-height: 112px;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #0f151d;
  color: var(--text);
  padding: 10px;
  line-height: 1.35;
}

.agent-asks {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  color: var(--muted);
  font-size: 12px;
}

.agent-asks button {
  min-height: 28px;
  padding: 5px 9px;
  border-color: rgba(167, 139, 250, 0.42);
  background: #161527;
  color: #d9cdfd;
  font-size: 12px;
}

.agent-asks output {
  color: var(--human);
  min-width: fit-content;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.72);
}

.modal-backdrop[hidden] {
  display: none;
}

.approval-modal {
  position: relative;
  display: grid;
  gap: 12px;
  width: min(520px, 100%);
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(251, 191, 36, 0.55);
  border-radius: var(--radius);
  background: #121821;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.modal-accent {
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--warning);
}

.approval-modal h2,
.approval-modal p {
  margin: 0;
}

.approval-modal h2 {
  font-size: 18px;
}

.approval-modal p {
  color: #d6e2ee;
  line-height: 1.45;
}

.modal-details {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f151d;
}

.modal-details dt {
  color: var(--muted);
}

.modal-details dd {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.modal-actions {
  justify-content: flex-end;
}

@media (max-width: 1180px) {
  .ops-grid {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .right-stack {
    grid-column: 1 / -1;
    position: static;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .timeline,
  .tool-log {
    max-height: 360px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding-bottom: 240px;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .ops-grid,
  .right-stack {
    grid-template-columns: 1fr;
  }

  .case-rail {
    position: static;
  }

  .info-grid,
  .policy-strip,
  .composer-form {
    grid-template-columns: 1fr;
  }

  .case-summary h2 {
    font-size: 22px;
  }

  .summary-toolbar {
    display: grid;
  }

  .composer-bar {
    max-height: 60vh;
    overflow: auto;
  }

  .agent-asks {
    flex-wrap: wrap;
    overflow: visible;
  }
}

@media (max-width: 520px) {
  .brand-mark {
    width: 58px;
    grid-template-columns: 10px 26px 10px;
  }

  .brand-lockup h1 {
    font-size: 20px;
  }

  .brand-lockup p {
    font-size: 12px;
  }

  .topbar-actions,
  .summary-actions,
  .approval-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions > *,
  .summary-actions > *,
  .approval-actions > * {
    width: 100%;
  }

  .modal-details {
    grid-template-columns: 1fr;
  }
}
