/* 슬라이드 메이커 — 교정지(proof sheet) 콘셉트: 회색 종이, 먹색 글자, 형광펜 노랑 하나 */
:root {
  --paper: #ececea;
  --sheet: #fbfbfa;
  --ink: #141414;
  --ink-2: #3b3b39;
  --muted: #6b6b66;
  --rule: #d2d2cd;
  --rule-strong: #141414;
  --mark: #ffe04a;
  --on-mark: #141414;
  --btn: #141414;
  --on-btn: #fbfbfa;
  --danger: #b42318;
  --danger-soft: #fbe9e7;
  --warn-soft: #fff4c2;
  --warn-text: #5c4500;
  --ok: #17803d;
  --serif: 'Noto Serif KR', 'Apple SD Gothic Neo', serif;
  --sans: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  /* 한글은 고정폭 글꼴에 없으니 본문 글꼴로 대체 (시스템 고정폭 한글은 자간이 벌어진다) */
  --mono: 'IBM Plex Mono', 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', monospace;
  --radius: 2px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151514;
    --sheet: #1d1d1b;
    --ink: #ecece6;
    --ink-2: #c9c9c2;
    --muted: #9b9b93;
    --rule: #34342f;
    --rule-strong: #ecece6;
    --mark: #ffe04a;
    --on-mark: #141414;
    --btn: #ecece6;
    --on-btn: #151514;
    --danger: #ff8a7a;
    --danger-soft: #3a1d18;
    --warn-soft: #3a3214;
    --warn-text: #f3d77a;
    --ok: #6fd18f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }

body {
  margin: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-family: var(--serif); font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; }
p { margin: 0; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
::selection { background: var(--mark); color: var(--on-mark); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ───────── 상단 바 ───────── */
.topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 56px; padding: 0 24px;
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-name { font-family: var(--serif); font-weight: 900; font-size: 18px; letter-spacing: -0.02em; }
/* 슬라이드 한 장 모양: 먹색 판 위 노란 제목줄 */
.brand-mark { width: 24px; height: 16px; background: var(--ink); position: relative; flex: none; }
.brand-mark::after { content: ''; position: absolute; left: 4px; top: 4px; width: 10px; height: 3px; background: var(--mark); }
.account { display: flex; align-items: center; gap: 2px; font-size: 14px; flex-wrap: wrap; justify-content: flex-end; }
.account-name { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-right: 10px; }
.link-btn {
  border: 0; background: none; color: var(--ink-2); font: inherit; cursor: pointer;
  padding: 6px 8px; border-radius: var(--radius);
}
.link-btn:hover { color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }

/* ───────── 공통 ───────── */
.card { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn.primary { background: var(--btn); color: var(--on-btn); }
.btn.primary:hover:not(:disabled) { background: var(--mark); color: var(--on-mark); }
.btn.ghost { background: transparent; border-color: var(--rule-strong); color: var(--ink); }
.btn.ghost:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger); color: var(--sheet); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.small-btn { height: 32px; padding: 0 12px; font-size: 13px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius); border: 0;
  background: transparent; color: var(--ink-2); font-size: 22px; line-height: 1; cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--ink); color: var(--paper); }
.icon-btn svg { width: 20px; height: 20px; }
:is(.btn, .icon-btn, .link-btn, .send-btn, .thumb):focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, tr:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 2px;
}
input, select {
  font: inherit; color: var(--ink); background: var(--sheet);
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 9px 12px; min-width: 0; height: 42px;
}
input:hover, select:hover { border-color: var(--muted); }
.field { display: grid; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field-label { font-family: var(--mono); font-size: 12px; color: var(--muted); padding: 0; }
.form-error { color: var(--danger); font-size: 14px; }
.form-error:empty { display: none; }

/* ───────── 로그인 ───────── */
.login { flex: 1; display: grid; place-items: center; padding: 6vh 20px 12vh; overflow-y: auto; }
.login-card { width: min(360px, 100%); display: grid; gap: 8px; background: none; border: 0; }
.login-card h1 { font-size: 34px; font-weight: 900; letter-spacing: -0.03em; margin-bottom: 2px; }
.login-card > .muted { margin-bottom: 20px; font-size: 14px; }
.login-card .field-label { margin-top: 8px; }
.login-card input { height: 46px; }
.login-card .btn { margin-top: 18px; height: 46px; }

/* ───────── 대화 ───────── */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.chat-inner { max-width: 800px; margin: 0 auto; padding: 16px 24px 8px; }

/* 대본처럼: 왼쪽 열에 말한 쪽, 오른쪽에 내용 */
.messages { list-style: none; margin: 0; padding: 0; }
.msg {
  display: grid; grid-template-columns: 48px minmax(0, 1fr); column-gap: 16px; row-gap: 10px;
  padding: 20px 0; border-top: 1px solid var(--rule);
}
.msg:first-child { border-top: 0; }
.msg::before {
  grid-column: 1; grid-row: 1 / span 3;
  font-family: var(--mono); font-size: 12px; color: var(--muted); padding-top: 2px;
}
.msg > * { grid-column: 2; min-width: 0; }
.msg.user::before { content: '나'; color: var(--ink); }
.msg.assistant::before { content: 'AI'; }
.msg.error::before { content: '오류'; color: var(--danger); }
.msg.production-item::before { content: 'PPT'; }
.bubble { max-width: 68ch; }
.msg.user .bubble { white-space: pre-wrap; font-weight: 500; }
.msg.error .bubble { color: var(--danger); }

.md > * + * { margin-top: 10px; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li + li { margin-top: 4px; }
.md li::marker { color: var(--muted); }
.md strong { font-weight: 700; }
.md h3 { font-size: 16px; margin-top: 16px; }
.md code { font-family: var(--mono); background: var(--sheet); border: 1px solid var(--rule); padding: 0 4px; border-radius: var(--radius); font-size: 0.88em; }

/* 답변 작성 중: 깜빡이는 커서 */
.typing { display: inline-block; width: 9px; height: 18px; vertical-align: -3px; background: var(--ink); animation: caret 1s steps(1) infinite; }
.typing span { display: none; }
@keyframes caret { 50% { opacity: 0; } }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.att-img { width: 104px; height: 78px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--rule); background: var(--sheet); display: block; }
.att-file {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius);
  background: var(--sheet); border: 1px solid var(--rule); font-size: 13px; max-width: 260px;
}
.att-file span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-badge { flex: none; font-family: var(--mono); font-size: 10px; font-weight: 600; color: var(--sheet); background: var(--ink); padding: 1px 5px; }

/* 제작 카드 */
.production { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 20px; display: grid; gap: 14px; }
.prod-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.prod-title { font-family: var(--serif); font-weight: 700; font-size: 17px; }
.prod-count { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-left: 10px; font-weight: 400; }
.prod-status { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 14px; }
.prod-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.prod-note { font-size: 13px; color: var(--muted); }
.prod-warning { background: var(--warn-soft); color: var(--warn-text); padding: 8px 12px; border-radius: var(--radius); font-size: 13px; }
.prod-error { color: var(--danger); }

/* 제작 단계: 지난 단계는 먹색, 지금 단계는 노랑, 남은 단계는 선 */
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.steps li { border-top: 3px solid var(--rule); padding-top: 6px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.steps li.done { border-top-color: var(--ink); color: var(--ink-2); }
.steps li.now { border-top-color: var(--mark); color: var(--ink); font-weight: 500; }
.steps li.now::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 6px; background: var(--ink); vertical-align: 2px; animation: caret 1s steps(1) infinite; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px 12px; }
.thumb { padding: 0; border: 0; background: none; cursor: zoom-in; display: grid; gap: 5px; color: var(--muted); font-family: var(--mono); font-size: 11px; text-align: left; }
.thumb img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border: 1px solid var(--rule); display: block; background: var(--paper); }
.thumb:hover img { border-color: var(--ink); }
.thumb:hover span { color: var(--ink); }

@media (prefers-reduced-motion: reduce) { .typing, .steps li.now::after { animation: none; } }

/* 입력창 */
.composer { flex: none; padding: 8px 24px 20px; }
.composer-inner {
  max-width: 752px; margin: 0 auto; background: var(--sheet); border: 1px solid var(--rule-strong);
  border-radius: var(--radius); padding: 8px; transition: box-shadow 0.12s;
}
.composer-inner:focus-within { box-shadow: 4px 4px 0 var(--ink); }
.composer-inner.drag { box-shadow: 4px 4px 0 var(--mark); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.attach { position: relative; overflow: hidden; }
.attach input { position: absolute; inset: 0; opacity: 0; cursor: pointer; height: auto; }
.attach:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
#input {
  flex: 1; min-width: 0; border: 0; background: transparent; resize: none; font: inherit; color: var(--ink);
  padding: 7px 4px; max-height: 200px; line-height: 1.55;
}
#input::placeholder { color: var(--muted); }
#input:focus-visible { outline: none; }
.send-btn {
  flex: none; width: 36px; height: 36px; border-radius: var(--radius); border: 0; cursor: pointer;
  background: var(--btn); color: var(--on-btn); display: grid; place-items: center;
}
.send-btn:hover:not(:disabled) { background: var(--mark); color: var(--on-mark); }
.send-btn svg { width: 20px; height: 20px; }
.send-btn:disabled { background: var(--rule); color: var(--muted); cursor: not-allowed; }
.composer-hint { font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 4px 8px 0; }
.composer-hint:empty { display: none; }
.pending { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 4px 10px; }
.pending-item { position: relative; }
.pending-item .att-img { width: 64px; height: 48px; }
.pending-item .remove {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: var(--radius); border: 0;
  background: var(--ink); color: var(--paper); font-size: 13px; line-height: 20px; cursor: pointer; padding: 0;
}

/* ───────── 관리자 ───────── */
.admin { flex: 1; overflow-y: auto; padding: 32px 24px 64px; display: grid; gap: 40px; align-content: start; }
.admin > * { width: 100%; max-width: 1080px; margin: 0 auto; }
.admin-card { background: none; border: 0; padding: 0; display: grid; gap: 18px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; padding-bottom: 10px; border-bottom: 2px solid var(--ink); }
.admin-head h2 { font-size: 22px; font-weight: 900; letter-spacing: -0.02em; }
#admin-jobs { font-family: var(--mono); font-size: 12px; }
.settings { display: grid; gap: 20px; }
.model-list { display: flex; flex-wrap: wrap; gap: 10px; }
.model-option { position: relative; cursor: pointer; }
.model-option input { position: absolute; opacity: 0; pointer-events: none; }
.model-option .box {
  display: grid; gap: 2px; min-width: 220px; padding: 12px 14px; background: var(--sheet);
  border: 1px solid var(--rule); border-radius: var(--radius);
}
.model-option .name { font-weight: 600; }
.model-option .desc { color: var(--muted); font-size: 12px; }
.model-option:hover .box { border-color: var(--muted); }
.model-option input:checked + .box { border-color: var(--ink); box-shadow: inset 0 3px 0 var(--mark), 0 0 0 1px var(--ink); }
.model-option input:focus-visible + .box { outline: 2px solid var(--ink); outline-offset: 2px; }
.model-option input:disabled + .box { opacity: 0.5; cursor: not-allowed; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.settings-actions { display: flex; align-items: center; gap: 12px; }

.add-user { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px; background: var(--sheet); border: 1px solid var(--rule); }
.add-user input { flex: 1 1 150px; }
.add-user .form-error { flex-basis: 100%; }
.table-wrap { overflow-x: auto; }
.users { width: 100%; border-collapse: collapse; font-size: 14px; }
.users th { text-align: left; font-family: var(--mono); font-weight: 400; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.users td { padding: 12px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; font-variant-numeric: tabular-nums; }
.users td:nth-child(n+3) { font-family: var(--mono); font-size: 13px; }
.users tbody tr { cursor: pointer; }
.users tbody tr:hover { background: var(--sheet); }
.users tbody tr.selected { background: var(--sheet); box-shadow: inset 3px 0 0 var(--ink); }
.badge { display: inline-block; font-family: var(--mono); font-size: 11px; padding: 0 6px; margin-left: 8px; vertical-align: 1px; border: 1px solid currentColor; border-radius: var(--radius); }
.badge.admin { background: var(--mark); color: var(--on-mark); border-color: var(--mark); }
.badge.off { color: var(--danger); }
.badge.on { color: var(--ok); }
.detail-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#detail-meta { font-family: var(--mono); font-size: 12px; }
.sessions { display: grid; gap: 14px; }
.session { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 10px; }
.session-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.session-usage { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: pre-wrap; }
.prod-log { border-left: 3px solid var(--ink); padding: 4px 0 4px 12px; display: grid; gap: 4px; font-size: 14px; }
.prod-log.fail { border-left-color: var(--danger); }
.prod-log .summary { color: var(--ink); white-space: pre-wrap; }
.prod-log .meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* ───────── 크게 보기 ───────── */
.viewer {
  width: min(1120px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--sheet); color: var(--ink);
}
.viewer::backdrop { background: rgba(10, 10, 9, 0.78); }
.viewer-inner { display: grid; gap: 14px; padding: 14px 18px 20px; }
.viewer-top { display: flex; justify-content: space-between; align-items: center; }
#viewer-count { font-family: var(--mono); font-size: 12px; }
.viewer img { width: 100%; aspect-ratio: 16 / 9; border: 1px solid var(--rule); display: block; background: var(--paper); }
.viewer-nav { display: flex; justify-content: space-between; gap: 8px; }
.viewer-notes { border-top: 1px solid var(--rule); padding-top: 12px; display: grid; gap: 6px; }
.viewer-notes p { white-space: pre-wrap; font-size: 14px; color: var(--ink-2); }

@media (max-width: 640px) {
  .topbar { padding: 0 14px; }
  .account-name { display: none; }
  .chat-inner { padding: 8px 16px 8px; }
  .msg { grid-template-columns: 30px minmax(0, 1fr); column-gap: 10px; padding: 16px 0; }
  .composer { padding: 6px 12px 12px; }
  .composer-inner:focus-within { box-shadow: 3px 3px 0 var(--ink); }
  .admin { padding: 20px 16px 40px; gap: 32px; }
  .steps { gap: 3px; }
}
