/* dschat — 프레임워크 없음, 외부 요청 0.
   다크가 기본이고 시스템이 라이트면 라이트로 간다. */

:root {
  --bg: #0d1117; --bg2: #161b22; --bg3: #1c2128; --bg4: #22272e;
  --line: #30363d;
  --fg: #e6edf3; --fg2: #9198a1; --fg3: #6e7681;
  --accent: #4493f8; --accent2: #1f6feb;
  --ok: #3fb950; --warn: #d29922; --bad: #f85149;
  --user: #1f2937; --think: #14181f;
  --side: 268px; --opts: 330px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fff; --bg2: #f6f8fa; --bg3: #eef1f4; --bg4: #e6eaef;
    --line: #d0d7de;
    --fg: #1f2328; --fg2: #59636e; --fg3: #818b98;
    --user: #eef2f7; --think: #f3f5f8;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg); overflow: hidden;
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
        "Malgun Gothic", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--fg2); } .dim { color: var(--fg3); font-weight: 400; }
.small { font-size: 12px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ───────── 로그인 ───────── */
.login { height: 100%; display: grid; place-items: center; padding: 20px; }
.loginCard { width: 100%; max-width: 350px; display: flex; flex-direction: column; gap: 10px; }
.brand { font-size: 27px; text-align: center; }
.loginCard .sub { text-align: center; color: var(--fg2); font-size: 13px; margin: 0 0 8px; }
.loginCard input, .modalCard input {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; outline: none; width: 100%;
}
.loginCard input:focus, .modalCard input:focus { border-color: var(--accent); }
.loginCard button {
  background: var(--accent2); color: #fff; border-radius: 10px; padding: 11px;
  font-weight: 600; margin-top: 4px;
}
.loginCard button:disabled { opacity: .5; }
.fine { font-size: 12px; color: var(--fg3); text-align: center; margin-top: 6px; }

/* ───────── 모달 ───────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.62); display: grid;
         place-items: center; z-index: 60; padding: 18px; }
.modalCard {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 9px;
}
.modalCard.wide { max-width: 900px; max-height: 88vh; }
.modalCard h3 { margin: 0; }
.modalHead { display: flex; align-items: center; justify-content: space-between; }
.modalBtns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.modalBtns button { padding: 9px 16px; border-radius: 9px; background: var(--accent2); color: #fff; }
.modalBtns .ghost { background: transparent; border: 1px solid var(--line); color: var(--fg2); }

/* ───────── 관리자 ───────── */
.adminBody { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.adNow { background: var(--bg3); border: 1px solid var(--line); border-radius: 10px;
         padding: 10px 13px; font-size: 13.5px; }
.adScroll { overflow-x: auto; }
.adTable { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.adTable th { text-align: left; color: var(--fg3); font-weight: 500; font-size: 11.5px;
              padding: 6px 9px; border-bottom: 1px solid var(--line); }
.adTable td { padding: 8px 9px; border-bottom: 1px solid var(--line); }
.adTable button.small { border: 1px solid var(--line); border-radius: 7px; padding: 3px 10px; font-size: 12px; }
.tagz { color: var(--ok); border: 1px solid currentColor; border-radius: 5px; padding: 1px 6px; font-size: 11px; }
.taga { color: var(--warn); border: 1px solid currentColor; border-radius: 5px; padding: 1px 6px; font-size: 11px; }
.adNote { font-size: 12px; color: var(--fg3); line-height: 1.7; }
.adViewer { border-top: 1px solid var(--line); padding-top: 12px; }
.adViewerHead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.adViewerHead .small { border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; }
.adVBody { max-height: 44vh; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; }
.adConv { background: var(--bg3); border: 1px solid var(--line); border-radius: 9px;
          padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.adConv:hover { border-color: var(--accent); }
.adMsg { border-left: 2px solid var(--line); padding: 4px 0 4px 11px; font-size: 13.5px; white-space: pre-wrap; }
.adMsg.user { border-left-color: var(--accent); }

/* ───────── 레이아웃 ───────── */
.app { height: 100%; display: grid; grid-template-columns: var(--side) 1fr;
       min-height: 0; overflow: hidden; }
.app.optsOpen { grid-template-columns: var(--side) 1fr var(--opts); }

.side { background: var(--bg2); border-right: 1px solid var(--line);
        display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.sideTop { padding: 12px 12px 8px; display: flex; gap: 8px; }
.newBtn { flex: 1; background: var(--bg3); border: 1px solid var(--line); border-radius: 10px;
          padding: 10px; font-weight: 600; text-align: left; }
.newBtn:hover { border-color: var(--accent); }
.convSearch { margin: 0 12px 8px; background: var(--bg); border: 1px solid var(--line);
              border-radius: 9px; padding: 7px 11px; outline: none; font-size: 13px; }
.convSearch:focus { border-color: var(--accent); }
.convList { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 8px;
            overscroll-behavior: contain; }
.conv { display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 10px;
        border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--fg2); }
.conv:hover { background: var(--bg3); color: var(--fg); }
.conv.on { background: var(--bg3); color: var(--fg); font-weight: 600; }
.conv .ct { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .cn { font-size: 11px; color: var(--fg3); flex: none; }
.cmore { width: 22px; height: 22px; border-radius: 6px; color: var(--fg3); flex: none;
         opacity: 0; font-size: 14px; line-height: 1; }
.conv:hover .cmore, .conv.on .cmore { opacity: 1; }
.cmore:hover { background: var(--bg4); color: var(--fg); }
.convEmpty { padding: 12px 10px; font-size: 13px; color: var(--fg3); }
.sideBottom { border-top: 1px solid var(--line); padding: 10px 12px; font-size: 12px; }
.srv { display: flex; align-items: center; gap: 7px; color: var(--fg2); margin-bottom: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg3); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
.dot.load { background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.userRow { display: flex; align-items: center; gap: 8px; }
.who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); font-weight: 600; }
.linkBtn { color: var(--fg3); text-decoration: underline; font-size: 12px; flex: none; }
.linkBtn:hover { color: var(--fg); }
.storeNote { margin-top: 8px; font-size: 11px; color: var(--fg3); line-height: 1.6; }

/* **min-height: 0 이 없으면 스크롤이 아예 안 된다.**
   grid/flex 자식의 기본 min-height 는 auto 라, 안쪽 내용만큼 커져서
   overflow-y:auto 가 넘칠 게 없다고 판단한다. 이 한 줄이 스크롤을 만든다. */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0;
        position: relative; overflow: hidden; }
.top { height: 50px; border-bottom: 1px solid var(--line); display: flex; align-items: center;
       gap: 8px; padding: 0 12px; flex: none; }
.convTitle { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconBtn { width: 32px; height: 32px; border-radius: 8px; color: var(--fg2); font-size: 15px;
           display: grid; place-items: center; flex: none; }
.iconBtn:hover { background: var(--bg3); color: var(--fg); }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px;
        font-size: 12px; color: var(--fg3); flex: none; white-space: nowrap; }
.chip:hover { border-color: var(--accent); }
.chip.on { color: var(--accent); border-color: var(--accent); background: rgba(68,147,248,.10); }
.chip.off { opacity: .6; }

.banner { flex: none; padding: 8px 16px; font-size: 13px; text-align: center;
          background: var(--bg3); border-bottom: 1px solid var(--line); color: var(--fg2); }
.banner.warn { color: var(--warn); border-bottom-color: var(--warn); }

/* ───────── 메시지 ───────── */
.msgs { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 22px 0 8px;
        overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.empty { max-width: 620px; margin: 10vh auto; text-align: center; padding: 0 20px; }
.emptyIcon { font-size: 44px; }
.empty h2 { margin: 10px 0 6px; font-size: 20px; }
.empty p { margin: 4px 0; font-size: 13px; }

.row { max-width: 800px; margin: 0 auto 20px; padding: 0 20px; }
.row.user .bubble { background: var(--user); border-radius: 14px; padding: 11px 15px;
  margin-left: auto; max-width: 84%; width: fit-content; white-space: pre-wrap; word-break: break-word; }
.row.bot .bubble { white-space: pre-wrap; word-break: break-word; }
.row.bot .bubble h4 { margin: 14px 0 6px; font-size: 15px; }
.row.bot .bubble ul, .row.bot .bubble ol { margin: 6px 0; padding-left: 22px; white-space: normal; }
.row.bot .bubble li { margin: 2px 0; }
.row.bot .bubble blockquote { margin: 6px 0; padding: 2px 0 2px 12px;
  border-left: 3px solid var(--line); color: var(--fg2); white-space: normal; }
.row.bot .bubble hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.bubble code { background: var(--bg3); padding: 1px 5px; border-radius: 5px; font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.errbox { color: var(--bad); border: 1px solid var(--bad); border-radius: 10px; padding: 10px 13px; }

/* 코드블록 */
.cb { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 10px 0;
      white-space: normal; }
.cbHead { display: flex; justify-content: space-between; align-items: center;
  background: var(--bg3); padding: 5px 10px; font-size: 11px; color: var(--fg3); }
.cbCopy { font-size: 11px; color: var(--fg3); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 9px; background: var(--bg2); }
.cbCopy:hover { color: var(--fg); border-color: var(--accent); }
.cb pre { margin: 0; background: var(--bg2); padding: 12px 14px; overflow-x: auto;
  font-size: 13px; line-height: 1.55; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.cb pre code { background: none; padding: 0; }

.think { border-left: 2px solid var(--line); background: var(--think);
  border-radius: 0 10px 10px 0; margin-bottom: 10px; font-size: 13px; color: var(--fg2); }
.think summary { cursor: pointer; padding: 8px 12px; list-style: none; user-select: none;
  display: flex; align-items: center; gap: 6px; }
.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "▸"; font-size: 11px; }
.think[open] summary::before { content: "▾"; }
.think .thinkBody { padding: 0 12px 10px; white-space: pre-wrap; line-height: 1.65;
  max-height: 340px; overflow-y: auto; }

.acts { display: flex; align-items: center; gap: 8px; margin-top: 7px; opacity: 0; transition: .15s; }
.row:hover .acts { opacity: 1; }
.act { font-size: 11.5px; color: var(--fg3); border: 1px solid transparent; border-radius: 6px; padding: 2px 7px; }
.act:hover { color: var(--fg); border-color: var(--line); background: var(--bg3); }
.meta { font-size: 11px; color: var(--fg3); margin-left: auto; }
.sysline { font-size: 12px; color: var(--warn); margin-top: 8px; }
.cursor { display: inline-block; width: 7px; height: 15px; background: var(--accent);
  vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.stage { font-size: 12.5px; color: var(--fg3); display: flex; align-items: center; gap: 7px; }

.toBottom { position: absolute; right: 22px; bottom: 108px; width: 34px; height: 34px;
  border-radius: 50%; background: var(--bg3); border: 1px solid var(--line); color: var(--fg2);
  z-index: 5; }
.toBottom:hover { color: var(--fg); border-color: var(--accent); }

/* ───────── 입력 ───────── */
.composer { flex: none; padding: 8px 20px 16px; }
.inputWrap { max-width: 800px; margin: 0 auto; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 16px; display: flex; align-items: flex-end;
  padding: 6px 6px 6px 14px; }
.inputWrap:focus-within { border-color: var(--accent); }
#input { flex: 1; background: none; border: none; outline: none; resize: none;
  padding: 8px 0; max-height: 240px; line-height: 1.55; }
.sendBtn { width: 34px; height: 34px; border-radius: 10px; background: var(--accent2); color: #fff;
  flex: none; font-size: 15px; display: grid; place-items: center; }
.sendBtn:disabled { opacity: .35; }
.sendBtn.stop { background: var(--bad); }
.hint { max-width: 800px; margin: 6px auto 0; font-size: 11px; color: var(--fg3); text-align: center; }
.queueNote { max-width: 800px; margin: 0 auto 8px; font-size: 12.5px; color: var(--warn);
  background: var(--bg2); border: 1px solid var(--warn); border-radius: 10px; padding: 8px 12px;
  text-align: center; }

/* ───────── 옵션 ───────── */
.opts { background: var(--bg2); border-left: 1px solid var(--line); display: flex;
        flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.optsTop { height: 50px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; justify-content: space-between; padding: 0 12px; }
.optsBody { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex;
            flex-direction: column; gap: 16px; overscroll-behavior: contain; }
.opt { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.opt > span { display: flex; justify-content: space-between; align-items: center; color: var(--fg2); }
.opt em { font-style: normal; color: var(--fg); font-weight: 600; }
.opt small { color: var(--fg3); font-size: 11px; line-height: 1.55; }
.opt small.warn { color: var(--warn); }
.opt input[type=range] { width: 100%; accent-color: var(--accent); }
.opt input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.opt textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; outline: none; resize: vertical; font-size: 13px; }
.optsBody > button { background: var(--bg3); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px; font-size: 13px; }
.optsBody > button:hover { border-color: var(--accent); }
.optsBody > button.danger { color: var(--bad); }
.optsBody > button.danger:hover { border-color: var(--bad); }
.optsInfo { border-top: 1px solid var(--line); padding-top: 12px; font-size: 12px; }
.kv { display: flex; justify-content: space-between; padding: 3px 0; color: var(--fg2); }
.kv b { color: var(--fg); font-weight: 600; }

/* ───────── 컨텍스트 메뉴 ───────── */
.ctxMenu { position: fixed; z-index: 70; background: var(--bg3); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px; display: flex; flex-direction: column; min-width: 140px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.ctxMenu button { text-align: left; padding: 8px 11px; border-radius: 7px; font-size: 13px; }
.ctxMenu button:hover { background: var(--bg4); }
.ctxMenu button.danger { color: var(--bad); }

/* ───────── 토스트 ───────── */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--bg3); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 17px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 80; max-width: 90vw; text-align: center; }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { border-color: var(--bad); color: var(--bad); }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.only-mobile { display: none; }

/* ───────── 모바일 ───────── */
@media (max-width: 860px) {
  .only-mobile { display: grid; }
  .app, .app.optsOpen { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 80vw; max-width: 310px; z-index: 50;
    transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .opts { position: fixed; inset: 0 0 0 auto; width: 88vw; max-width: 350px; z-index: 50; }
  .row { padding: 0 14px; }
  .composer { padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); }
  .cmore { opacity: 1; }
  .acts { opacity: 1; }
  .toBottom { right: 14px; bottom: 116px; }
  .modalCard.wide { max-height: 92vh; }
}

/* 관리자: 지워진 대화 표시 */
.adConv.gone { opacity: .72; border-style: dashed; }
.delTag { color: var(--bad); }
.del { color: var(--bad); font-size: 11px; font-weight: 400; }
.tagi { color: var(--accent); border: 1px solid currentColor; border-radius: 5px; padding: 1px 6px; font-size: 11px; }
