:root {
  color-scheme: light;
  --bg: #eaecef;
  --panel: #ffffff;
  --panel-soft: #eaecef;
  --ink: #000000;
  --muted: #233d4d;
  --line: #eaecef;
  --line-strong: #233d4d;
  --green: #233d4d;
  --green-soft: #eaecef;
  --amber: #fe7f2d;
  --amber-soft: #eaecef;
  --red: #000000;
  --red-soft: #eaecef;
  --steel: #233d4d;
  --steel-soft: #eaecef;
  --shadow: none;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: min(1480px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow,
.summary-label {
  margin: 0 0 6px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 4vw, 54px);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(520px, 1.35fr);
  gap: 18px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 78px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line);
}

.input-panel {
  position: sticky;
  top: 18px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  color: var(--steel);
  background: var(--panel-soft);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: #ffffff;
  transform: translateY(-1px);
}

.field-label {
  display: block;
  padding: 16px 18px 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea {
  display: block;
  width: calc(100% - 36px);
  min-height: 550px;
  margin: 0 18px;
  padding: 16px;
  resize: vertical;
  border: 1px solid var(--line);
  outline: none;
  color: var(--ink);
  background: #ffffff;
  font-size: 15px;
  line-height: 1.75;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

textarea:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px #eaecef;
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 18px;
}

.text-stats {
  color: var(--muted);
  font-size: 13px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 136px;
  min-height: 44px;
  padding: 0 18px;
  color: var(--panel-soft);
  background: var(--ink);
  cursor: pointer;
  font-weight: 750;
  transition:
    background 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.primary-button:hover {
  background: var(--muted);
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
}

.overall-badge,
.rating-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.overall-badge.is-idle {
  color: var(--steel);
  background: var(--steel-soft);
}

.overall-badge.is-running {
  color: var(--amber);
  background: var(--amber-soft);
}

.overall-badge.is-done {
  color: var(--amber);
  background: var(--amber-soft);
}

.analysis-stage {
  position: relative;
  min-height: 0;
  margin: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

#signalCanvas {
  display: block;
  width: 100%;
  height: 200px;
}

.stage-overlay {
  position: static;
  padding: 18px 28px 22px;
  border-top: 1px solid var(--line-strong);
  background: #ffffff;
}

.progress-shell {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 3;
  height: 8px;
  overflow: hidden;
  background: var(--panel-soft);
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--amber);
  transition: none;
}

.stage-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 800;
}

.stage-copy {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.thinking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 18px 18px;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.thinking-header span:last-child {
  color: var(--muted);
  font-weight: 700;
}

.thinking-log {
  display: grid;
  gap: 12px;
  min-height: 180px;
  max-height: 260px;
  margin: -8px 18px 18px;
  padding: 16px;
  overflow-y: auto;
  border: 1px solid var(--line);
  background: #ffffff;
}

.chat-message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.chat-role {
  display: grid;
  place-items: center;
  width: 36px;
  height: 28px;
  border: 1px solid var(--line-strong);
  color: var(--panel);
  background: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.chat-bubble {
  min-height: 42px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--panel-soft);
}

.chat-message.is-muted .chat-role {
  color: var(--muted);
  background: #ffffff;
}

.chat-message.is-muted .chat-bubble {
  color: var(--muted);
  background: #ffffff;
}

.chat-message.is-active .chat-role {
  border-color: var(--amber);
  background: var(--amber);
}

.chat-message.is-active .chat-bubble {
  border-color: var(--amber);
  background: #ffffff;
}

.typing-caret {
  display: inline-block;
  width: 8px;
  height: 14px;
  margin-left: 4px;
  vertical-align: -2px;
  background: var(--amber);
  animation: pulse 1100ms ease-in-out infinite;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  margin-left: 8px;
  vertical-align: 1px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  background: var(--amber);
  animation: pulse 1200ms ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 160ms;
}

.typing-dots span:nth-child(3) {
  animation-delay: 320ms;
}

.summary {
  display: grid;
  grid-template-columns: minmax(180px, 0.42fr) 1fr;
  gap: 16px;
  margin: 0 18px 18px;
  padding: 16px;
  border: 1px solid var(--amber);
  background: var(--amber-soft);
}

.summary.is-hidden {
  display: none;
}

.summary-title {
  margin: 0;
  color: var(--amber);
  font-size: 18px;
  font-weight: 850;
  line-height: 1.35;
}

.summary-copy {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.table-wrap {
  margin: 0 18px 18px;
  overflow-x: auto;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.6;
}

th {
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 13px;
  font-weight: 850;
}

td {
  font-size: 14px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

td:first-child {
  width: 24%;
  font-weight: 760;
}

td:nth-child(2) {
  width: 18%;
}

.empty-row td {
  height: 120px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.rating-badge.is-present {
  color: var(--steel);
  background: var(--steel-soft);
}

.rating-badge.is-concern {
  color: var(--amber);
  background: var(--amber-soft);
}

.rating-badge.is-gap {
  color: var(--red);
  background: var(--red-soft);
}

.rating-badge.is-clear {
  color: var(--green);
  background: var(--green-soft);
}

.rating-badge.is-illegal {
  color: var(--panel-soft);
  background: var(--red);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.7;
  }

  50% {
    transform: scale(1.55);
    opacity: 1;
  }
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
  }

  textarea {
    min-height: 420px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100vw - 24px, 1480px);
    padding-top: 18px;
  }

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

  h1 {
    font-size: 34px;
  }

  .panel-header,
  .input-footer,
  .summary {
    align-items: stretch;
    flex-direction: column;
  }

  .summary {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 360px;
    font-size: 14px;
  }

  .primary-button {
    width: 100%;
  }

  .analysis-stage {
    min-height: 220px;
  }

  #signalCanvas {
    height: 220px;
  }
}
