:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #152026;
  --muted: #687782;
  --line: #d7dde2;
  --line-strong: #9aa7b0;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e0f2ef;
  --info: #255ea8;
  --info-soft: #eef5ff;
  --warn: #a15c07;
  --warn-soft: #fff7e8;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(21, 32, 38, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  min-height: calc(100vh - 48px);
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 2.7rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.actions,
.entry-row,
.section-title,
.chart-head,
.toggle-row,
.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.content-grid {
  display: grid;
  grid-template-columns: minmax(460px, 1fr) 370px 390px;
  gap: 18px;
  align-items: start;
}

.chart-panel,
.input-panel,
.ai-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chart-panel {
  padding: 20px;
}

.chart-head {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.chart-head p,
.hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.chart-head p {
  max-width: 620px;
  margin-bottom: 0;
}

.toggle-row {
  min-height: 38px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.settings-group {
  display: grid;
  gap: 13px;
}

.settings-group h2 {
  margin-bottom: 0;
}

.full-row {
  display: block;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.95fr) minmax(130px, 1fr);
  align-items: end;
}

.setting-row .toggle-row {
  min-height: 44px;
  align-items: center;
}

.mode-row {
  display: grid;
  gap: 7px;
}

.mode-row > span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9f9;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  display: grid;
  place-items: center;
  min-height: 34px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
}

.segmented input:checked + label {
  background: var(--accent);
  color: #ffffff;
}

.canvas-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.stats-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.stats-grid strong {
  font-size: 1.05rem;
}

.input-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.ai-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.tool-group {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.tool-group:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.entry-row {
  display: grid;
  grid-template-columns: 1fr 1fr 44px;
  align-items: end;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

input,
select {
  height: 44px;
  padding: 0 11px;
}

select {
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 18px) 19px / 6px 6px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 12px) 19px / 6px 6px no-repeat,
    #ffffff;
}

input[type="range"] {
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 0;
  accent-color: var(--accent);
  background: transparent;
}

textarea {
  min-height: 116px;
  resize: vertical;
  padding: 11px;
  line-height: 1.45;
}

.hint {
  margin: 9px 0 0;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title h2 {
  margin: 0;
}

.table-wrap {
  max-height: 430px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf4f3;
  color: #23413d;
  font-size: 0.78rem;
  text-transform: uppercase;
}

td {
  background: #ffffff;
}

td:first-child {
  width: 42%;
}

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

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

td input {
  height: 36px;
  border-radius: 6px;
}

.delete-button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--danger);
  font-size: 1.2rem;
  line-height: 1;
}

.ghost-button,
.solid-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.solid-button {
  background: var(--accent);
  color: #ffffff;
}

.ghost-button:hover {
  border-color: var(--line-strong);
  background: #f8fbfb;
}

.solid-button:hover {
  background: var(--accent-strong);
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.icon-action {
  width: 44px;
  padding: 0;
  font-size: 1.45rem;
  line-height: 1;
}

.paste-group {
  display: grid;
  gap: 10px;
}

.hidden {
  display: none !important;
}

.status-pill {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  background: #f8fbfb;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill[data-state="ready"] {
  border-color: #a7d7ce;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-pill[data-state="loading"] {
  border-color: #b8cff0;
  background: var(--info-soft);
  color: var(--info);
}

.status-pill[data-state="error"] {
  border-color: #f0b5ad;
  background: #fff1f0;
  color: var(--danger);
}

.ai-model-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.ai-actions-group {
  display: grid;
  gap: 10px;
}

.ai-button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ai-button-grid button {
  padding-inline: 10px;
}

.preset-row,
.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-preview p {
  margin: 0 0 10px;
  white-space: pre-line;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.ai-preview-table {
  max-height: 210px;
  margin-top: 10px;
}

.chat-group {
  display: grid;
  gap: 10px;
}

.chat-log {
  display: grid;
  gap: 9px;
  max-height: 360px;
  min-height: 210px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfc;
}

.chat-message {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.chat-message strong {
  color: var(--accent-strong);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.chat-message p {
  margin: 0;
  white-space: pre-line;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
}

.chat-message.user {
  border-color: #bfd5ed;
  background: var(--info-soft);
}

.chat-message.user strong {
  color: var(--info);
}

.chat-message.error {
  border-color: #f0b5ad;
  background: #fff7f6;
}

.chat-message.error strong {
  color: var(--danger);
}

.chat-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 8px;
  align-items: stretch;
}

.chat-input-row textarea {
  min-height: 82px;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

@media (max-width: 1280px) {
  .content-grid {
    grid-template-columns: minmax(0, 1fr) 390px;
  }

  .ai-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-group {
    grid-column: 1 / -1;
  }
}

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

  .input-panel,
  .ai-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tool-group {
    border-bottom: 0;
    padding-bottom: 0;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .workspace {
    min-height: calc(100vh - 28px);
  }

  .topbar,
  .chart-head {
    display: grid;
    align-items: start;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1 1 120px;
  }

  .chart-panel,
  .input-panel {
    padding: 12px;
  }

  .input-panel {
    grid-template-columns: 1fr;
  }

  .ai-panel {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 430px) {
  .entry-row {
    grid-template-columns: 1fr;
  }

  .setting-row {
    grid-template-columns: 1fr;
  }

  .ai-model-row,
  .ai-button-grid,
  .chat-input-row {
    grid-template-columns: 1fr;
  }

  .icon-action {
    width: 100%;
  }
}
