/* ===== Design Tokens ===== */
:root {
  --bg: #f2f5f9;
  --card: #ffffff;
  --line: #d8e0ea;
  --text: #132339;
  --sub: #50647e;
  --brand: #0e76d9;
  --brand-hover: #0a60b2;
  --brand-light: #e8f2fc;
  --brand-glow: rgba(14, 118, 217, 0.12);

  /* Semantic status colors */
  --success: #0d9f6e;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --info: #1d3f68;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;

  /* Elevation */
  --shadow-sm: 0 1px 3px rgba(15, 47, 80, 0.06);
  --shadow-md: 0 8px 28px rgba(15, 47, 80, 0.07);
  --shadow-lg: 0 12px 40px rgba(15, 47, 80, 0.10);

  /* Agent accent colors */
  --agent-coordinator: #7c3aed;
  --agent-technical: #0891b2;
  --agent-commercial: #d97706;
  --agent-reviewer: #059669;

  /* Spacing */
  --section-gap: 20px;
  --card-padding: 24px;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
}

/* ===== Reset ===== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, #eef4fb 0%, #f7fafd 50%, #e9f1fb 100%);
  min-height: 100vh;
}

/* ===== Page Hero ===== */
.page-hero {
  background: linear-gradient(135deg, #0e76d9 0%, #1a56a8 60%, #0f3d6e 100%);
  color: #fff;
  padding: 36px 0 32px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(14, 60, 120, 0.18);
}

.page-hero-inner {
  width: min(1100px, 94vw);
  margin: 0 auto;
}

.page-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 1px;
}

.page-subtitle {
  margin: 8px 0 0;
  font-size: 15px;
  opacity: 0.85;
  font-weight: 400;
  line-height: 1.6;
}

/* ===== Layout ===== */
.container {
  width: min(1100px, 94vw);
  margin: 32px auto;
  display: grid;
  gap: var(--section-gap);
  grid-template-columns: 1fr;
}

/* ===== Card ===== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--card-padding);
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

/* ===== Section Header ===== */
.section-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
}

.section-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  color: var(--brand);
  margin-top: 2px;
  padding: 5px;
  background: var(--brand-light);
  border-radius: 8px;
}

h1, h2 {
  margin: 0;
  line-height: 1.3;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 18px;
}

.sub {
  margin: 4px 0 0;
  color: var(--sub);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== Form ===== */
form {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.label {
  font-weight: 600;
  font-size: 14px;
}

input[type="file"],
select,
button,
textarea {
  font: inherit;
}

input[type="file"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="file"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.2s, box-shadow 0.2s, opacity 0.2s, transform 0.1s;
}

.btn:active:enabled {
  transform: scale(0.97);
}

.btn-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary .btn-icon {
  filter: brightness(0) invert(1);
}

.btn-primary:hover:enabled {
  background: var(--brand-hover);
  box-shadow: 0 4px 12px var(--brand-glow);
}

.btn-primary:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--brand-light);
  color: var(--brand);
  border: 1px solid transparent;
}

.btn-secondary .btn-icon {
  filter: none;
  color: var(--brand);
}

.btn-secondary:hover:enabled {
  background: #dbeafe;
  border-color: var(--brand);
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Button loading state */
.btn.is-loading {
  pointer-events: none;
  opacity: 0.75;
}

.btn.is-loading .btn-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Status ===== */
.status {
  margin: 12px 0 0;
  min-height: 28px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-line;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.25s, color 0.25s, border-color 0.25s;
}

.status:empty {
  padding: 0;
  min-height: 0;
}

.status-idle {
  color: var(--info);
  background: transparent;
}

.status-working {
  color: var(--brand);
  background: var(--brand-light);
  border: 1px solid #bfdbfe;
}

.status-done {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
}

.status-error {
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
}

/* ===== Result Section ===== */
.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex: 1;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-size: 13px;
}

#result {
  min-height: 420px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 13px;
  background: #fafbfc;
}

#dispatchObjective {
  min-height: 96px;
}

/* ===== Dispatch Section ===== */
.dispatch-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.dispatch-head .status {
  margin: 0;
  flex: 1;
  min-width: 200px;
}

/* ===== Agent Grid ===== */
.agent-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.agent-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  background: #fbfdff;
  transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
  position: relative;
  overflow: hidden;
}

/* Top accent bar per agent */
.agent-panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 12px 12px 0 0;
  background: var(--line);
  transition: background 0.3s;
}

.agent-panel[data-agent="coordinator"]::before { background: var(--agent-coordinator); }
.agent-panel[data-agent="technical"]::before { background: var(--agent-technical); }
.agent-panel[data-agent="commercial"]::before { background: var(--agent-commercial); }
.agent-panel[data-agent="reviewer"]::before { background: var(--agent-reviewer); }

/* Agent panel states */
.agent-panel.is-working {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-glow), var(--shadow-sm);
  background: #f8fbff;
}

.agent-panel.is-done {
  border-color: var(--success-border);
  background: #fafffe;
}

.agent-panel.is-error {
  border-color: var(--error-border);
  background: #fffafa;
}

/* Agent Header */
.agent-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.agent-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  padding: 4px;
  border-radius: 8px;
  background: var(--brand-light);
}

.agent-panel[data-agent="coordinator"] .agent-icon {
  background: #ede9fe;
  color: var(--agent-coordinator);
}
.agent-panel[data-agent="technical"] .agent-icon {
  background: #ecfeff;
  color: var(--agent-technical);
}
.agent-panel[data-agent="commercial"] .agent-icon {
  background: #fffbeb;
  color: var(--agent-commercial);
}
.agent-panel[data-agent="reviewer"] .agent-icon {
  background: #ecfdf5;
  color: var(--agent-reviewer);
}

.agent-panel h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.agent-state {
  margin: 0;
  color: var(--sub);
  font-size: 12px;
  line-height: 1.3;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Agent state badge */
.agent-state::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sub);
  flex-shrink: 0;
  transition: background 0.3s;
}

.agent-state[data-status="idle"]::before {
  background: #94a3b8;
}

.agent-state[data-status="working"]::before {
  background: var(--brand);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.agent-state[data-status="done"]::before {
  background: var(--success);
}

.agent-state[data-status="error"]::before {
  background: var(--error);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.4); }
}

.agent-output {
  margin: 0;
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: #fff;
  padding: 10px 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12.5px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .container {
    width: 96vw;
    margin: 16px auto;
    gap: 14px;
  }

  :root {
    --card-padding: 16px;
  }

  .page-hero {
    padding: 24px 0 20px;
  }

  .page-title {
    font-size: 22px;
  }

  .page-subtitle {
    font-size: 13px;
  }

  h2 { font-size: 16px; }

  .section-icon {
    width: 28px;
    height: 28px;
    padding: 4px;
  }

  .btn {
    padding: 9px 14px;
    font-size: 13px;
  }

  #result {
    min-height: 300px;
  }

  .agent-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .agent-output {
    min-height: 100px;
    max-height: 240px;
  }

  .dispatch-head {
    flex-direction: column;
    align-items: stretch;
  }

  .dispatch-head .status {
    min-width: 0;
  }
}

@media (max-width: 390px) {
  .container {
    width: 98vw;
    margin: 10px auto;
  }

  :root {
    --card-padding: 12px;
  }

  .page-hero {
    padding: 18px 0 14px;
  }

  .page-title {
    font-size: 19px;
    letter-spacing: 0.5px;
  }

  .page-subtitle {
    font-size: 12px;
  }

  .section-header {
    gap: 10px;
  }

  .section-icon {
    width: 24px;
    height: 24px;
    padding: 3px;
  }

  .agent-panel {
    padding: 12px;
  }

  .agent-icon {
    width: 24px;
    height: 24px;
  }
}
