:root {
  --bg: #eef2f1;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #1f2b29;
  --muted: #64716d;
  --line: #d8e0dd;
  --green: #247768;
  --green-dark: #15564c;
  --blue: #315f9b;
  --gold: #b47b22;
  --rose: #b85f5a;
  --shadow: 0 18px 44px rgba(31, 43, 41, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, #fbfcfc 0%, #eef4f2 48%, #edf1ef 100%);
  font-family:
    Pretendard,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.55;
}

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(36, 119, 104, 0.25);
  outline-offset: 2px;
}

.shell {
  width: min(1360px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar,
.section-title,
.mini-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 18px;
}

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

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  flex: 0 0 auto;
  border: 1px solid rgba(36, 119, 104, 0.28);
  border-radius: var(--radius);
  background: #e1efeb;
  padding: 10px;
}

.brand-mark span {
  border-radius: 999px;
  background: var(--green);
}

.brand-mark span:nth-child(2) {
  background: var(--blue);
}

.brand-mark span:nth-child(3) {
  background: var(--gold);
}

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

h1 {
  font-size: 1.55rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.2rem;
  line-height: 1.25;
}

h3 {
  font-size: 1rem;
  line-height: 1.3;
}

.brand p,
.section-title p,
.mini-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.94rem;
}

.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--green-dark);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.workbench {
  display: grid;
  grid-template-columns: minmax(360px, 0.86fr) minmax(520px, 1.14fr);
  gap: 18px;
  align-items: start;
}

.input-panel,
.output-panel,
.lab-panel {
  min-width: 0;
  border: 1px solid rgba(216, 224, 221, 0.95);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  padding: 20px;
}

.mode-pill {
  display: inline-flex;
  min-width: 74px;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--green-dark);
  background: #e1efeb;
  font-size: 0.76rem;
  font-weight: 900;
}

.message-form {
  display: grid;
  gap: 15px;
  margin-top: 18px;
}

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

.quick-grid button,
.feedback-grid button,
.ghost-button,
.icon-button {
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: #34433f;
  background: var(--surface-soft);
  font-weight: 850;
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.quick-grid button:hover,
.feedback-grid button:hover,
.feedback-grid button.active,
.ghost-button:hover,
.icon-button:hover {
  border-color: rgba(36, 119, 104, 0.48);
  color: var(--green-dark);
  background: #e8f3ef;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field span,
.lens-picker legend {
  color: #354440;
  font-size: 0.86rem;
  font-weight: 900;
}

input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fbfcfc;
}

input[type="text"],
input[type="password"],
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 150px;
  resize: vertical;
  padding: 12px;
}

.lens-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.lens-picker legend {
  grid-column: 1 / -1;
}

.lens-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.lens-picker span {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfc;
  color: #41504c;
  font-weight: 850;
}

.lens-picker input:checked + span {
  border-color: rgba(36, 119, 104, 0.58);
  color: var(--green-dark);
  background: #e1efeb;
}

.primary-button {
  min-height: 54px;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--green);
  font-weight: 900;
  box-shadow: 0 14px 30px rgba(36, 119, 104, 0.22);
}

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

.signal-board {
  overflow: hidden;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f4f8f6;
}

.signal-board canvas {
  display: block;
  width: 100%;
  aspect-ratio: 45 / 16;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f6f9f8;
}

.tab {
  min-height: 42px;
  border-right: 1px solid var(--line);
  color: #53615d;
  background: transparent;
  font-weight: 900;
}

.tab:last-child {
  border-right: 0;
}

.tab.active {
  color: #ffffff;
  background: var(--green);
}

.result-text {
  min-height: 300px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdfa;
  padding: 18px;
  overflow-wrap: anywhere;
}

.result-text h3 {
  margin-bottom: 12px;
  font-size: 1.16rem;
}

.result-text p {
  margin-bottom: 12px;
}

.result-text p:last-child {
  margin-bottom: 0;
}

.candidate-panel,
.feedback-panel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

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

.candidate-card,
.lab-card,
.stat-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
}

.candidate-card {
  display: grid;
  gap: 7px;
}

.candidate-card strong,
.lab-card strong,
.stat-card strong {
  color: var(--ink);
  line-height: 1.3;
}

.candidate-card span,
.lab-card span,
.stat-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.candidate-card p,
.lab-card p,
.stat-card p,
#feedbackSummary {
  color: var(--muted);
  font-size: 0.88rem;
}

.lab-panel {
  margin-top: 18px;
}

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

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100% - 40px));
  border-radius: var(--radius);
  color: #ffffff;
  background: #1f2b29;
  box-shadow: 0 14px 32px rgba(31, 43, 41, 0.22);
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .candidate-list,
  .lab-list {
    grid-template-columns: 1fr;
  }

  .lab-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1360px);
    padding-top: 14px;
  }

  .topbar,
  .section-title,
  .mini-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .input-panel,
  .output-panel,
  .lab-panel {
    padding: 14px;
  }

  .top-actions,
  .quick-grid,
  .form-grid.two,
  .lens-picker,
  .feedback-grid,
  .lab-stats {
    grid-template-columns: 1fr;
  }

  .top-actions {
    display: grid;
  }

  .tabs {
    grid-template-columns: repeat(5, minmax(64px, 1fr));
    overflow-x: auto;
  }
}

/* ---------- AI 버전 (index.html + ai-app.js) ---------- */

.settings-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 18px;
}

.settings-help {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 10px 0 14px;
}

.settings-help a {
  color: var(--blue);
}

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

.settings-status {
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
}

.gen-status {
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
  min-height: 1em;
}

.ai-empty {
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 24px;
  color: var(--muted);
  line-height: 1.7;
}

.ai-empty ul {
  margin: 12px 0 0 18px;
  padding: 0;
}

.ai-loading {
  text-align: center;
  padding: 48px 20px;
  color: var(--green-dark);
}

.loading-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.loading-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  animation: dotPulse 1.2s infinite ease-in-out;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.ai-results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.understand-card,
.closing-card {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.understand-card h3,
.closing-card h3 {
  margin: 0 0 10px;
  color: var(--green-dark);
  font-size: 16px;
}

.understand-card p,
.closing-card p,
.closing-card li {
  font-size: 14px;
  line-height: 1.7;
  margin: 6px 0;
}

.closing-card ul {
  margin: 0 0 10px 18px;
  padding: 0;
}

.labeled-line strong {
  color: var(--green-dark);
}

.ai-results .candidate-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.candidate-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.candidate-head h3 {
  margin: 0;
  font-size: 17px;
}

.candidate-no {
  background: var(--green);
  color: #fff;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.candidate-approach {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 12px;
}

.candidate-message {
  background: var(--surface-soft);
  border-left: 3px solid var(--green);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 18px;
  margin-bottom: 12px;
}

.candidate-message p {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 1.8;
}

.candidate-message p:last-child {
  margin-bottom: 0;
}

.copy-btn {
  margin-bottom: 10px;
}

.coach-note {
  border-top: 1px solid var(--line);
  padding: 8px 0;
}

.coach-note summary {
  cursor: pointer;
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
}

.coach-note p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  margin: 8px 0 4px;
}

.refine-panel {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.refine-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.refine-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}

.provider-choice {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.provider-option {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface-soft);
}

.provider-option:has(input:checked) {
  border-color: var(--green);
  background: #eef7f4;
}

.provider-option input {
  grid-row: 1 / 3;
  accent-color: var(--green);
}

.provider-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
}

.provider-desc {
  grid-column: 2;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.candidate-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.candidate-actions .copy-btn {
  margin-bottom: 0;
}

.like-btn.liked {
  border-color: var(--rose);
  color: var(--rose);
  background: #fdf1f0;
}

.outcome-wrap {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 12px;
}

.outcome-label {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 8px;
}

.outcome-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.outcome-chips button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
}

.outcome-chips button.on {
  border-color: var(--green);
  background: #eef7f4;
  color: var(--green-dark);
  font-weight: 700;
}

.archive-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.archive-row {
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.consent-box {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.consent-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  cursor: pointer;
}

.consent-label input {
  margin-top: 4px;
  flex-shrink: 0;
}

/* AI 화면 모바일 보정 — 인스타그램 등 인앱 브라우저 유입 대비 */
@media (max-width: 720px) {
  .refine-row {
    flex-direction: column;
  }

  .refine-row .ghost-button {
    min-height: 44px;
  }

  .candidate-actions .ghost-button,
  .outcome-chips button {
    flex: 1 1 auto;
    min-height: 44px;
    text-align: center;
  }

  .ai-results .candidate-card,
  .understand-card,
  .closing-card {
    padding: 14px;
  }
}
