/* AI 패널 — 회의록 같은 화면: 명패(자리), 발언 기록, 종이 결과물 */
:root {
  --mist: #edf0f3;
  --paper: #ffffff;
  --ink: #18202b;
  --slate: #566170;
  --line: #d3d9e0;
  --line-soft: #e4e8ed;
  --indigo: #2d3fa6;
  --indigo-deep: #222f80;
  --amber-bg: #ffefc9;
  --amber-ink: #7a4a00;
  --red: #a32626;
  --red-bg: #fbe9e7;
  --green: #17693f;
  /* 구성원 색 (자리 순서대로) */
  --c: var(--slate);
  --c0: #0b7f74; --c1: #7e3d99; --c2: #b4491f; --c3: #5e7112; --c4: #1f63c4; --c5: #b3305f;
  --sans: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  /* 결과물용 명조. 설치되어 있지 않으면 바탕체 대신 고딕으로 보인다. */
  --serif: "Noto Serif KR", "Nanum Myeongjo", "AppleMyungjo", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --mono: "D2Coding", Consolas, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--mist); color: var(--ink);
  font: 15px/1.6 var(--sans); word-break: keep-all; overflow-wrap: anywhere;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--indigo); }
:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }
.muted { color: var(--slate); }
.small { font-size: 13px; }

/* ---------- 위쪽 띠 ---------- */
.top {
  display: flex; align-items: center; gap: 28px;
  padding: 0 24px; height: 56px; background: var(--ink); color: #fff;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a {
  color: #c5ccd6; text-decoration: none; padding: 6px 12px; border-radius: 4px; font-weight: 500;
}
.top nav a:hover { color: #fff; }
.top nav a.on { color: #fff; background: rgba(255, 255, 255, 0.14); }
.top .btn.quiet { color: #c5ccd6; }
.top .btn.quiet:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.top :focus-visible { outline-color: #fff; }

main { max-width: 1320px; margin: 0 auto; padding: 28px 24px 64px; }

/* ---------- 단추와 입력 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-weight: 600; line-height: 1.2; cursor: pointer; text-decoration: none;
  padding: 9px 14px; border-radius: 4px; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
}
.btn:hover { border-color: var(--slate); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn.primary:hover { background: var(--indigo-deep); border-color: var(--indigo-deep); }
.btn.quiet { border-color: transparent; background: transparent; padding: 6px 8px; font-weight: 500; color: var(--indigo); }
.btn.quiet:hover { background: rgba(45, 63, 166, 0.08); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-bg); }
.btn.danger.armed { background: var(--red); color: #fff; }

label, .label { display: block; font-weight: 600; margin: 18px 0 6px; }
input:not([type="radio"]):not([type="checkbox"]), textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid #aab3be; border-radius: 4px; padding: 9px 10px;
}
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #7b8592; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--indigo); }
label + .muted.small, input + .muted.small, textarea + .muted.small { margin-top: 5px; }
.form-error { color: var(--red); font-weight: 600; margin-top: 14px; }
.form-error:empty { display: none; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-row.three { grid-template-columns: repeat(3, 1fr); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 17px; height: 17px; accent-color: var(--indigo); }

.segmented { display: inline-flex; border: 1px solid #aab3be; border-radius: 4px; overflow: hidden; background: var(--paper); flex-wrap: wrap; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { margin: 0; padding: 8px 15px; font-weight: 500; cursor: pointer; border-right: 1px solid var(--line); }
.segmented span:last-child label { border-right: 0; }
.segmented input:checked + label { background: var(--ink); color: #fff; }
.segmented input:focus-visible + label { outline: 3px solid var(--indigo); outline-offset: -3px; }

/* ---------- 로그인 ---------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-box { width: 100%; max-width: 380px; background: var(--paper); border-top: 6px solid var(--ink); padding: 32px 30px 30px; }
.login-box h1 { font-size: 26px; letter-spacing: -0.02em; }
.login-box h1 + p { margin-top: 6px; }
.login-box .btn { width: 100%; margin-top: 22px; padding: 12px; }

.login-box.wide { max-width: 460px; }
.login-box .notice { margin: 14px 0 0; background: var(--mist); }
.otp-form .btn { margin-top: 16px; }
.otp-input { font-family: var(--mono) !important; font-size: 26px !important; letter-spacing: 0.32em; text-align: center; padding: 10px !important; }
.back-login { width: auto !important; margin: 12px 0 4px -8px !important; padding: 6px 8px !important; }
.enroll-steps { margin: 18px 0 14px; padding-left: 1.3em; }
.enroll-steps li { margin-bottom: 14px; padding-left: 2px; }
.enroll-steps label { margin-top: 12px; }
.qr { margin: 12px 0 8px; }
.qr img { display: block; background: #fff; border: 1px solid var(--line); }
.enroll-steps details summary { cursor: pointer; color: var(--indigo); font-weight: 600; font-size: 13px; }
.enroll-steps details p { margin-top: 6px; }
.secret { font-family: var(--mono); font-size: 14px; background: var(--mist); padding: 3px 7px; border-radius: 3px; user-select: all; overflow-wrap: anywhere; }

/* ---------- 두 단 배치 ---------- */
.cols { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 40px; align-items: start; }
.cols.session { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 32px; }
.cols.settings { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); gap: 32px; }
@media (max-width: 1240px) { .cols.settings { grid-template-columns: minmax(0, 1fr); } }
h1 { font-size: 24px; letter-spacing: -0.02em; line-height: 1.3; }
h2 { font-size: 17px; letter-spacing: -0.01em; }

/* ---------- 새 토론 ---------- */
.compose-form #topic { font-size: 17px; }
.members-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 18px; }
.members-head .label { margin: 0 0 6px; }
.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; cursor: pointer; display: inline-flex; align-items: baseline; gap: 7px;
  padding: 7px 12px 7px 9px; background: var(--paper); border: 1px dashed #8a95a3; border-radius: 4px; color: var(--ink); font-weight: 600;
}
.chip:hover { border-style: solid; border-color: var(--ink); }
.chip-plus { font-weight: 700; color: var(--indigo); }
.seat-rows { margin-top: 12px; display: grid; gap: 6px; }
.seat-row {
  display: grid; grid-template-columns: 6px minmax(90px, 0.8fr) minmax(0, 1.5fr) minmax(0, 1.1fr) auto; gap: 10px; align-items: center;
  background: var(--paper); padding: 8px 8px 8px 0; border: 1px solid var(--line);
}
.seat-row .swatch { align-self: stretch; margin: -8px 0; }
.seat-row .seat-ai { font-weight: 600; padding-left: 4px; }
.seat-row .role-prompt { grid-column: 2 / -1; }
.compose-form .segmented + .muted { margin-top: 8px; max-width: 62ch; }
.compose-form > .btn.primary { margin-top: 22px; padding: 12px 26px; font-size: 16px; }

.past h2 { margin-bottom: 12px; padding-top: 6px; }
.past-list { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--ink); }
.past-list a { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.past-list a:hover { background: var(--paper); }
.past-topic { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.past-list .muted { grid-column: 1 / -1; }

.status { font-size: 13px; font-weight: 700; white-space: nowrap; }
.status.running { color: var(--indigo); }
.status.done { color: var(--green); }
.status.stopped { color: var(--slate); }
.status.error { color: var(--red); }

.empty { background: var(--paper); border: 1px solid var(--line); padding: 28px; margin-top: 18px; }
.empty p + p { margin-top: 4px; }
.empty .btn { margin-top: 18px; }
.empty-line { margin-top: 20px; padding: 18px; background: var(--paper); border: 1px dashed #8a95a3; }

/* ---------- 토론 화면 ---------- */
.session-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.back { font-size: 13px; text-decoration: none; }
.back::before { content: "‹ "; }
.topic { font-size: 26px; margin: 2px 0 6px; max-width: 34em; white-space: pre-wrap; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; flex-shrink: 0; }

/* 명패: 회의 탁자에 놓인 이름표. 위쪽 띠 색이 발언 기록의 색과 이어진다. */
.seats { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 30px; }
.plate {
  min-width: 148px; max-width: 230px; flex: 1 1 148px;
  background: var(--paper); border-top: 6px solid var(--c); padding: 10px 12px 10px;
  display: grid; gap: 1px; box-shadow: 0 1px 0 var(--line), 0 6px 0 -3px #dfe4ea;
}
.plate-name { font-weight: 700; line-height: 1.35; }
.plate-sub { font-size: 12.5px; color: var(--slate); }
.plate-state { font-size: 12.5px; font-weight: 700; margin-top: 6px; color: var(--slate); }
.plate.spoke .plate-state { color: var(--c); }
.plate.failed .plate-state { color: var(--red); }
.plate.idle { opacity: 0.72; }
.plate.speaking { background: color-mix(in srgb, var(--c) 9%, var(--paper)); }
.plate.speaking .plate-state { color: var(--c); }
.plate.speaking .plate-state::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 7px; border-radius: 50%; background: var(--c); animation: pulse 1.1s ease-in-out infinite; }
.plate.synth { --c: var(--ink); margin-left: auto; }
.c0 { --c: var(--c0); } .c1 { --c: var(--c1); } .c2 { --c: var(--c2); }
.c3 { --c: var(--c3); } .c4 { --c: var(--c4); } .c5 { --c: var(--c5); }
.swatch { background: var(--c); }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.log-col > h2, .doc-col > h2 { padding-bottom: 8px; border-bottom: 2px solid var(--ink); }
.round { font-size: 14px; margin: 22px 0 8px; display: flex; gap: 10px; align-items: baseline; }
.round span { font-weight: 500; color: var(--slate); }
.entry { border-left: 4px solid var(--c); padding: 2px 0 2px 14px; margin-bottom: 18px; position: relative; }
.entry .who { font-weight: 700; color: var(--c); display: flex; gap: 10px; align-items: baseline; margin-bottom: 2px; }
.entry .who .muted { font-weight: 400; }
.entry.mine { --c: var(--ink); background: var(--paper); padding: 10px 14px; }
.entry.mine .said { white-space: pre-wrap; }
.entry.synth { --c: var(--ink); }
.entry.failed .said { color: var(--red); }
.entry.folded .said { max-height: 11.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 62%, transparent); mask-image: linear-gradient(#000 62%, transparent); }
.fold { margin-top: 2px; margin-left: -8px; }
.waiting { color: var(--slate); margin: 6px 0 18px; display: flex; align-items: center; gap: 9px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--indigo); animation: pulse 1.1s ease-in-out infinite; }

.more { margin-top: 26px; }
.more-form { background: var(--paper); border: 1px solid var(--line); padding: 4px 18px 18px; }
.more-form .btn { margin-top: 12px; }
.notice { padding: 12px 14px; background: var(--paper); border-left: 4px solid var(--slate); margin-bottom: 14px; }
.notice.bad { border-left-color: var(--red); background: var(--red-bg); color: #6f1717; }

/* 결과물: 인쇄한 문서처럼 */
.doc-col { position: sticky; top: 16px; }
.doc {
  background: var(--paper); padding: 34px 38px 40px; margin-top: 14px;
  font-family: var(--serif); font-size: 16px; line-height: 1.85;
  box-shadow: 0 1px 0 var(--line), 0 14px 28px -22px rgba(24, 32, 43, 0.55);
  max-height: calc(100vh - 90px); overflow: auto;
}
.doc.blank { font-family: var(--sans); color: var(--slate); font-size: 15px; }
.md > :first-child, .doc > :first-child { margin-top: 0; }
.md p, .md ul, .md ol, .doc p, .doc ul, .doc ol, .doc blockquote, .md blockquote { margin: 0 0 0.8em; }
.md ul, .md ol, .doc ul, .doc ol { padding-left: 1.4em; }
.md li.sub, .doc li.sub { margin-left: 1.3em; list-style-type: circle; }
.doc h1 { font-size: 25px; line-height: 1.4; margin: 0 0 0.7em; padding-bottom: 0.5em; border-bottom: 1px solid var(--ink); }
.doc h2 { font-size: 19px; margin: 1.7em 0 0.5em; }
.doc h3, .doc h4 { font-size: 16.5px; margin: 1.3em 0 0.4em; }
.md h1, .md h2, .md h3, .md h4 { font-size: 15px; margin: 0.9em 0 0.3em; }
.md code, .doc code { font-family: var(--mono); font-size: 0.88em; background: var(--mist); padding: 1px 5px; border-radius: 3px; }
.md pre, .doc pre { background: var(--mist); padding: 12px 14px; overflow: auto; margin: 0 0 0.9em; line-height: 1.5; }
.md pre code, .doc pre code { background: none; padding: 0; }
.md blockquote, .doc blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--slate); }
.doc hr, .md hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
mark.flag { background: var(--amber-bg); color: var(--amber-ink); font-family: var(--sans); font-size: 0.8em; font-weight: 700; padding: 2px 6px; border-radius: 3px; white-space: nowrap; }

.table-wrap { overflow-x: auto; margin: 0 0 1em; }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 14px; line-height: 1.5; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { border-bottom: 2px solid var(--ink); font-weight: 700; white-space: nowrap; }

/* ---------- AI 연결 ---------- */
.prov-list h1 + p { margin: 6px 0 20px; max-width: 60ch; }
table.prov { background: var(--paper); }
table.prov th, table.prov td { overflow-wrap: normal; }
table.prov tbody th { font-weight: 700; white-space: nowrap; }
table.prov td:nth-child(2), table.prov td:nth-child(3) { white-space: nowrap; }
table.prov td:nth-child(5) { overflow-wrap: anywhere; min-width: 10em; }
table.prov tr.off { color: var(--slate); }
table.prov .addr { display: block; font-family: var(--mono); font-size: 13px; white-space: nowrap; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }
.row-actions { white-space: nowrap; text-align: right; }
.test { font-size: 13px; color: var(--slate); }
.test.ok { color: var(--green); font-weight: 600; }
.test.bad { color: var(--red); }
.prov-form { background: var(--paper); border-top: 6px solid var(--ink); padding: 22px 24px 26px; }
.prov-form .segmented + .muted { margin-top: 8px; }
.prov-form textarea, #purl, #pmodel, #pah, #ppath { font-family: var(--mono); font-size: 13.5px; }
.adv { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
.adv summary { cursor: pointer; font-weight: 600; color: var(--indigo); }
.adv > .muted.small:last-child { margin-top: 10px; }
.prov-form .check { margin-top: 20px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

.via { display: inline-block; font-size: 12px; font-weight: 700; line-height: 1.5; padding: 0 6px; border: 1px solid currentColor; border-radius: 3px; white-space: nowrap; color: var(--slate); }
.via.cli { color: var(--ink); background: var(--ink); border-color: var(--ink); color: #fff; }
.plate-sub .via, .chip .via { margin-left: 6px; font-size: 11px; }
.segmented input:disabled + label { color: #9aa3ae; background: var(--mist); cursor: not-allowed; text-decoration: line-through; }
.btn.inline { margin-top: 2px; margin-left: -8px; font-size: 13px; }
.prov-form .segmented + .label { margin-top: 14px; }

/* ---------- 계정 ---------- */
table.users th .via { margin-left: 8px; }
.side-forms { display: grid; gap: 24px; }
.confirm-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.confirm-form input { width: 11.5em !important; padding: 6px 8px !important; }
.confirm-form .btn { padding: 7px 10px; }
.btn.danger:not(.quiet) { border-color: var(--red); }
.prov-form .stack > .btn.primary { margin-top: 18px; }

/* ---------- 알림 ---------- */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 4px; max-width: min(90vw, 560px);
  transition: opacity 0.18s, transform 0.18s; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--red); }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 980px) {
  .cols, .cols.session, .cols.settings { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .doc-col { position: static; }
  .cols.session .doc-col { order: -1; } /* 좁은 화면에서는 결과물을 먼저 */
  .doc { max-height: none; }
}
@media (max-width: 640px) {
  main { padding: 20px 16px 48px; }
  .top { padding: 0 12px; gap: 10px; }
  .top nav a { padding: 6px 9px; }
  .session-head { flex-direction: column; }
  .actions { justify-content: flex-start; }
  .topic { font-size: 22px; }
  .field-row, .field-row.three { grid-template-columns: 1fr; gap: 0; }
  .seat-row { grid-template-columns: 6px 1fr auto; }
  .seat-row select, .seat-row .seat-name, .seat-row .role-prompt { grid-column: 2 / -1; }
  .seat-row .btn { grid-row: 1; grid-column: 3; }
  .plate { min-width: 0; flex-basis: 44%; }
  .plate.synth { margin-left: 0; }
  .doc { padding: 24px 20px 28px; }
  .row-actions { text-align: left; white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse, .plate.speaking .plate-state::after { animation: none; }
  #toast { transition: none; }
}
