:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --surface: #f9fafb;
  --text: #18212f;
  --muted: #667085;
  --line: #d6dde7;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d9f3ef;
  --blue: #1d4ed8;
  --blue-soft: #e8f0ff;
  --danger: #b42318;
  --warn: #a16207;
  --warn-soft: #fff7df;
  --shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(260px, 420px) auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

.brand h1 {
  font-size: 21px;
  line-height: 1.2;
}

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

.base-url {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.base-url input,
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.base-url input,
input,
select {
  min-height: 38px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
  padding: 10px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.primary-button,
.secondary-button,
.ghost-button,
.tab {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

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

.secondary-button {
  color: var(--accent-strong);
  border-color: #9ad8cf;
  background: #f4fffd;
}

.ghost-button {
  color: #344054;
  border-color: var(--line);
  background: #fff;
}

.status-badge {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
}

.status-badge.ok {
  color: var(--accent-strong);
  border-color: #9ad8cf;
  background: var(--accent-soft);
}

.status-badge.error {
  color: var(--danger);
  border-color: #f3b1a8;
  background: #fff1f0;
}

.template-view {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.template-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.template-head h2 {
  font-size: 24px;
}

.template-head p {
  margin-top: 6px;
  color: var(--muted);
}

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

.template-card {
  min-height: 280px;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.template-card:hover {
  border-color: var(--accent);
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  color: var(--blue);
  background: var(--blue-soft);
}

.chip.ready {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.template-card h3 {
  font-size: 20px;
}

.template-card p {
  color: var(--muted);
  line-height: 1.55;
}

.mini-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: #344054;
  font-size: 13px;
}

.mini-list li {
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.workspace {
  min-height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 360px;
  gap: 14px;
  padding: 14px;
}

.sidebar,
.work-panel,
.debug-panel {
  min-width: 0;
}

.sidebar,
.debug-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.template-summary,
.panel-section,
.work-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.template-summary {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.template-summary > span {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

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

.template-summary p {
  color: var(--muted);
  line-height: 1.55;
}

.hint-list,
.compact-list,
.reply-list {
  display: grid;
  gap: 8px;
}

.hint-list span,
.compact-list .item,
.reply-card {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.hint-list span {
  color: #344054;
  font-size: 13px;
  line-height: 1.45;
}

.panel-section {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title span {
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.tab {
  color: #344054;
  border-color: var(--line);
  background: #fff;
}

.tab.active {
  color: var(--accent-strong);
  border-color: #9ad8cf;
  background: var(--accent-soft);
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.option-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.option-list.empty {
  min-height: 72px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
}

.option-item {
  min-height: 74px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.option-item input {
  width: 16px;
  min-height: 16px;
  margin: 3px 0 0;
  accent-color: var(--accent);
}

.option-item span {
  min-width: 0;
}

.option-item strong {
  display: block;
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
}

.option-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.wide {
  grid-column: 1 / -1;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.conversation-box {
  display: grid;
  gap: 8px;
}

.reply-list.empty,
.compact-list.empty,
.template-grid.empty {
  min-height: 92px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
}

.reply-card {
  display: grid;
  gap: 8px;
}

.reply-card strong {
  font-size: 14px;
}

.reply-card p {
  color: var(--text);
  line-height: 1.55;
}

.reply-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

pre {
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #0f172a;
  background: #f8fafc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.hidden {
  display: none !important;
}

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

  .base-url {
    grid-template-columns: 72px 1fr;
  }

  .template-grid,
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .template-grid,
  .form-grid,
  .option-list {
    grid-template-columns: 1fr;
  }

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

  .workspace {
    padding: 10px;
  }
}
