:root {
  --app-bg: #eef2f3;
  --surface: #ffffff;
  --surface-soft: #f7f9f8;
  --ink: #14201f;
  --muted: #63716f;
  --line: #d9e1df;
  --brand: #1f6b63;
  --brand-dark: #164c48;
  --accent: #c86d4b;
  --blue: #2f5f93;
  --shadow: 0 20px 55px rgba(23, 34, 34, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--app-bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "YuGothic", "Noto Sans JP", system-ui, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1,
.panel h2,
.preview-toolbar h2,
.output-panel h2 {
  margin: 0;
  line-height: 1.15;
}

.topbar h1 {
  font-size: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.control-rail {
  display: grid;
  gap: 14px;
  align-content: start;
  max-height: calc(100vh - 116px);
  overflow: auto;
  padding-right: 2px;
}

.panel,
.output-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(20, 32, 31, 0.05);
}

.panel {
  padding: 16px;
}

.panel-header,
.output-header,
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel h2,
.preview-toolbar h2,
.output-panel h2 {
  font-size: 18px;
}

.status-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef6f2;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.field select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 107, 99, 0.14);
}

.primary-button,
.ghost-button,
.consult-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-button {
  background: var(--brand);
  color: white;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.ghost-button {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button:hover {
  border-color: var(--brand);
}

.consult-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #10231f;
  color: white;
  text-decoration: none;
}

.consult-button:hover {
  background: #1b3632;
}

.text-link-button {
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.text-link-button:hover {
  text-decoration: underline;
}

.wide {
  width: 100%;
  margin-top: 14px;
}

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

.source-grid div {
  min-height: 78px;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.source-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.source-grid strong {
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pipeline {
  list-style: none;
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
}

.pipeline li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  font-weight: 800;
}

.pipeline span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b8c6c2;
}

.pipeline li.active {
  color: var(--brand-dark);
  border-color: rgba(31, 107, 99, 0.34);
  background: #eff8f5;
}

.pipeline li.active span {
  background: var(--brand);
}

.pipeline li.done span {
  background: var(--accent);
}

.design-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.design-card {
  width: 100%;
  display: grid;
  gap: 9px;
  text-align: left;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
}

.design-card:hover,
.design-card.selected {
  border-color: var(--brand);
  background: #f1f8f5;
}

.design-card.selected {
  box-shadow: inset 0 0 0 1px var(--brand);
}

.design-card-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.design-card strong {
  font-size: 15px;
}

.score {
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 900;
}

.design-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.design-card .reason {
  color: #31413e;
  font-weight: 700;
}

.design-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.design-meta span {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border: 1px solid rgba(31, 107, 99, .22);
  border-radius: 999px;
  background: white;
  color: var(--brand-dark);
  font-size: 11px;
  font-weight: 900;
}

.swatches {
  display: flex;
  gap: 6px;
}

.swatches i {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(20, 32, 31, 0.16);
}

.preview-column {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(420px, 1fr) minmax(240px, 31vh) auto;
  gap: 14px;
}

.preview-toolbar {
  min-height: 72px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, 62px);
  gap: 4px;
  padding: 4px;
  background: #e5ecea;
  border-radius: 8px;
}

.segmented button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
}

.segmented button.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(20, 32, 31, 0.11);
}

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

.edit-toggle.active {
  background: #eef8f5;
  border-color: rgba(31, 107, 99, .42);
  color: var(--brand-dark);
}

.chat-panel {
  display: grid;
  gap: 12px;
}

.structure-list,
.version-list {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.structure-item {
  display: grid;
  gap: 5px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.structure-item strong {
  font-size: 13px;
}

.structure-item p,
.empty-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.version-list button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  text-align: left;
}

.version-list button:hover {
  border-color: var(--brand);
  background: #eef8f5;
}

.version-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #31413e;
  font-size: 12px;
  font-weight: 800;
}

.version-list small {
  color: var(--muted);
  font-size: 11px;
}

.selection-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(20, 32, 31, 0.05);
}

.selection-panel strong {
  display: block;
  font-size: 15px;
}

.selection-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.selection-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.selection-actions button {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 900;
}

.selection-actions button:hover {
  border-color: var(--brand);
  background: #eef8f5;
}

.chat-messages {
  min-height: 172px;
  max-height: 260px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

.message {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.65;
}

.message.assistant {
  justify-self: start;
  background: white;
  border: 1px solid var(--line);
  color: #31413e;
}

.message.user {
  justify-self: end;
  background: var(--brand);
  color: white;
}

.quick-prompts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-prompts button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--brand-dark);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.quick-prompts button:hover {
  border-color: var(--brand);
  background: #eef8f5;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.chat-composer textarea {
  width: 100%;
  height: auto;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  resize: vertical;
  background: white;
  color: var(--ink);
  font: inherit;
  line-height: 1.55;
}

.chat-composer button {
  align-self: end;
  min-width: 70px;
}

.preview-stage {
  display: grid;
  place-items: center;
  min-height: 420px;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(20, 32, 31, .04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(20, 32, 31, .04) 25%, transparent 25%),
    #dfe7e5;
  background-size: 24px 24px;
}

.preview-stage iframe {
  width: 100%;
  height: 100%;
  min-height: 680px;
  border: 0;
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}

.preview-stage.mobile iframe {
  width: 390px;
  max-width: 100%;
  height: 740px;
  min-height: 740px;
}

.output-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 230px;
  overflow: hidden;
}

.quality-panel {
  min-height: 0;
}

.quality-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 12px 14px 14px;
}

.quality-list li {
  display: grid;
  gap: 4px;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.quality-list li.ok {
  border-color: rgba(31, 107, 99, .28);
  background: #f0f8f5;
}

.quality-list li.warn {
  border-color: rgba(200, 109, 75, .38);
  background: #fff7f1;
}

.quality-list strong {
  font-size: 12px;
}

.quality-list span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.output-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.output-header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 190px;
  resize: none;
  border: 0;
  outline: none;
  padding: 14px;
  background: #111b1a;
  color: #d8efea;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  min-height: 38px;
  max-width: min(520px, calc(100% - 32px));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 999px;
  background: #14201f;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  font-size: 13px;
  font-weight: 800;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

  .control-rail {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: none;
    overflow: visible;
  }

  .source-panel,
  .chat-panel {
    grid-column: span 3;
  }

  .preview-column {
    grid-template-rows: auto auto minmax(420px, 68vh) minmax(220px, 30vh) auto;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .topbar-actions button {
    min-width: 0;
    max-width: 100%;
    width: 100%;
    padding: 0 8px;
  }

  .workspace {
    padding: 12px;
  }

  .control-rail {
    grid-template-columns: 1fr;
  }

  .source-panel,
  .process-panel,
  .design-panel,
  .chat-panel {
    grid-column: auto;
  }

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

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

  .selection-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    justify-content: stretch;
  }

  .selection-actions button {
    padding: 0 6px;
  }

  .preview-actions,
  .segmented,
  .edit-toggle {
    width: 100%;
  }

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

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

  .chat-composer {
    grid-template-columns: 1fr;
  }

  .chat-composer button {
    width: 100%;
  }

  .quality-list {
    grid-template-columns: 1fr;
  }
}
