* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:#0f1117; --panel:#171a23; --panel2:#1e222e; --border:#2a2f3d;
  --text:#e6e8ee; --muted:#8b92a5; --accent:#6366f1; --accent2:#4f46e5;
  --green:#22c55e; --red:#ef4444; --yellow:#eab308;
}
html,body { height:100%; }
body { font-family:'Apple SD Gothic Neo','Malgun Gothic',-apple-system,sans-serif;
  background:var(--bg); color:var(--text); font-size:14px; }
#app { height:100vh; display:flex; flex-direction:column; }
button { cursor:pointer; font-family:inherit; }
input,select,textarea { font-family:inherit; }

/* ---- 인증 화면 ---- */
.auth-wrap { display:flex; align-items:center; justify-content:center; height:100vh; }
.auth-card { background:var(--panel); border:1px solid var(--border); border-radius:16px;
  padding:36px; width:380px; }
.auth-card h1 { font-size:26px; margin-bottom:6px; letter-spacing:-1px; }
.auth-card .sub { color:var(--muted); margin-bottom:24px; font-size:13px; }
.field { margin-bottom:14px; }
.field label { display:block; font-size:12px; color:var(--muted); margin-bottom:5px; }
.field input { width:100%; padding:11px 12px; background:var(--panel2); border:1px solid var(--border);
  border-radius:9px; color:var(--text); font-size:14px; }
.field input:focus { outline:none; border-color:var(--accent); }
.btn { width:100%; padding:12px; background:var(--accent2); color:#fff; border:none;
  border-radius:9px; font-size:15px; font-weight:600; }
.btn:hover { background:var(--accent); }
.btn.sm { width:auto; padding:7px 14px; font-size:13px; border-radius:7px; }
.btn.ghost { background:transparent; border:1px solid var(--border); color:var(--text); }
.btn.ghost:hover { background:var(--panel2); }
.link { color:var(--accent); cursor:pointer; }
.msg { padding:10px 12px; border-radius:8px; font-size:13px; margin-bottom:14px; }
.msg.err { background:rgba(239,68,68,.12); color:#fca5a5; border:1px solid rgba(239,68,68,.3); }
.msg.ok { background:rgba(34,197,94,.12); color:#86efac; border:1px solid rgba(34,197,94,.3); }
.tabs { display:flex; gap:8px; margin-bottom:20px; }
.tabs button { flex:1; padding:9px; background:transparent; border:1px solid var(--border);
  border-radius:8px; color:var(--muted); }
.tabs button.active { background:var(--accent2); color:#fff; border-color:var(--accent2); }

/* ---- 메인 레이아웃 ---- */
.top { display:flex; align-items:center; gap:14px; padding:10px 16px; background:var(--panel);
  border-bottom:1px solid var(--border); }
.top .logo { font-weight:800; font-size:18px; letter-spacing:-1px; }
.top .spacer { flex:1; }
.top .who { color:var(--muted); font-size:13px; }
.main { flex:1; display:flex; min-height:0; }
.sidebar { width:260px; background:var(--panel); border-right:1px solid var(--border);
  display:flex; flex-direction:column; }
.sidebar .new { margin:12px; width:calc(100% - 24px); box-sizing:border-box;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sess-list { flex:1; overflow:auto; padding:0 8px; }
.sess { padding:10px 12px; border-radius:8px; cursor:pointer; margin-bottom:4px; color:var(--muted); }
.sess:hover { background:var(--panel2); }
.sess.active { background:var(--panel2); color:var(--text); }
.sess .t { font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sess .meta { font-size:11px; color:var(--muted); margin-top:3px; }

.chat { flex:1; display:flex; flex-direction:column; min-width:0; }
.chat-head { padding:10px 16px; border-bottom:1px solid var(--border); display:flex;
  align-items:center; gap:10px; flex-wrap:wrap; }
.chat-head select { padding:7px 10px; background:var(--panel2); border:1px solid var(--border);
  border-radius:7px; color:var(--text); max-width:300px; }
.pill { padding:4px 10px; border-radius:20px; font-size:12px; background:var(--panel2);
  border:1px solid var(--border); }
.pill.plan { color:var(--yellow); border-color:rgba(234,179,8,.4); }
.pill.auto { color:var(--green); border-color:rgba(34,197,94,.4); }
.ctx-bar { width:120px; height:7px; background:var(--panel2); border-radius:4px; overflow:hidden; }
.ctx-bar > div { height:100%; background:var(--accent); }

.messages { flex:1; overflow:auto; padding:20px; }
.bubble { max-width:860px; margin:0 auto 18px; }
.bubble .role { font-size:12px; color:var(--muted); margin-bottom:6px; }
.bubble.user .body { background:var(--accent2); color:#fff; display:inline-block;
  padding:10px 14px; border-radius:12px; white-space:pre-wrap; }
.bubble.assistant .body { background:var(--panel); border:1px solid var(--border);
  padding:14px 16px; border-radius:12px; white-space:pre-wrap; line-height:1.6; }
.step { font-size:12px; color:var(--muted); padding:5px 10px; margin:4px 0; border-left:2px solid var(--border);
  background:var(--panel2); border-radius:0 6px 6px 0; }
.step.tool { color:#a5b4fc; }
.diff { background:#0b0d13; border:1px solid var(--border); border-radius:8px; margin:8px 0;
  font-family:'SF Mono',Consolas,monospace; font-size:12.5px; overflow:auto; }
.diff .fname { padding:6px 12px; background:var(--panel2); color:var(--muted); border-bottom:1px solid var(--border); }
.diff pre { padding:8px 12px; }
.diff .add { color:#86efac; } .diff .del { color:#fca5a5; }
.diff .applied { color:var(--green); } .diff .plan { color:var(--yellow); }
pre code, .code { font-family:'SF Mono',Consolas,monospace; }
.mono { font-family:'SF Mono',Consolas,monospace; }

.composer { border-top:1px solid var(--border); padding:12px 16px; }
.composer .row { max-width:860px; margin:0 auto; display:flex; gap:10px; align-items:flex-end; }
.composer textarea { flex:1; resize:none; padding:12px; background:var(--panel2);
  border:1px solid var(--border); border-radius:10px; color:var(--text); font-size:14px;
  max-height:180px; min-height:48px; }
.composer textarea:focus { outline:none; border-color:var(--accent); }
.timer { font-size:12px; color:var(--accent); margin-bottom:6px; text-align:center; }

.empty { color:var(--muted); text-align:center; margin-top:80px; }
.admin-table { width:100%; border-collapse:collapse; margin-top:12px; }
.admin-table th,.admin-table td { padding:9px 10px; border-bottom:1px solid var(--border);
  text-align:left; font-size:13px; }
.admin-table th { color:var(--muted); font-weight:500; }
.badge { padding:2px 8px; border-radius:12px; font-size:11px; }
.badge.pending { background:rgba(234,179,8,.15); color:var(--yellow); }
.badge.approved { background:rgba(34,197,94,.15); color:var(--green); }
.badge.suspended { background:rgba(239,68,68,.15); color:#fca5a5; }
.modal-bg { position:fixed; inset:0; background:rgba(0,0,0,.6); display:flex; align-items:center;
  justify-content:center; z-index:50; }
.modal { background:var(--panel); border:1px solid var(--border); border-radius:14px; padding:24px;
  width:520px; max-height:80vh; overflow:auto; }
.modal h2 { margin-bottom:16px; }
.model-opt { padding:10px 12px; border:1px solid var(--border); border-radius:9px; margin-bottom:8px;
  cursor:pointer; display:flex; justify-content:space-between; align-items:center; }
.model-opt:hover,.model-opt.sel { border-color:var(--accent); background:var(--panel2); }
.model-opt .nm { font-weight:600; }
.model-opt .cap { font-size:11px; color:var(--muted); }
.tag { font-size:10px; padding:1px 6px; border-radius:8px; margin-left:4px; }
.tag.tools { background:rgba(99,102,241,.2); color:#a5b4fc; }
.tag.vision { background:rgba(34,197,94,.18); color:#86efac; }
.tag.think { background:rgba(234,179,8,.18); color:#fde68a; }
.hint { color:var(--muted); font-size:12px; margin-top:4px; }

/* ============================================================
   반응형 (모바일/태블릿) — 데스크톱(>=1024px)은 위 기본 스타일 유지
   ============================================================ */

/* 전역 기초 */
html, body { overflow-x: hidden; }
#app { height: 100vh; height: 100dvh; height: var(--app-h, 100dvh); }
.bubble .body { overflow-wrap: anywhere; word-break: break-word; }
.diff, pre { overflow-x: auto; }          /* 코드/diff 는 내부에서만 가로 스크롤 */
.bubble img, .messages img { max-width: 100%; height: auto; }

/* 아이콘 버튼(햄버거/설정) — 기본(데스크톱)은 숨김 */
.iconbtn {
  display: none; align-items: center; justify-content: center;
  width: 44px; height: 44px; min-width: 44px; padding: 0;
  background: transparent; border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-size: 20px; line-height: 1;
}
.iconbtn:hover { background: var(--panel2); }
.overlay { display: none; }
.show-mobile { display: none; }           /* 모바일 전용 요소: 데스크톱 숨김 */

/* 상단 safe-area (노치) */
.top { padding-top: calc(10px + env(safe-area-inset-top)); position: sticky; top: 0; z-index: 30; }

/* ---------- 태블릿/모바일 공통 (<1024px): 드로어 모드 ---------- */
@media (max-width: 1023px) {
  .iconbtn { display: inline-flex; }
  .hide-mobile { display: none !important; }
  .show-mobile { display: block; }

  .top { gap: 8px; }
  .top .logo { font-size: 17px; flex: 1; text-align: center; }
  .top .spacer { display: none; }

  /* 오버레이 */
  .overlay { display: none; position: fixed; inset: 0; z-index: 38;
    background: rgba(0,0,0,.5); -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px); }
  .overlay.show { display: block; }
  body.drawer-open { overflow: hidden; }

  /* 좌측 목록 → 좌측 오프캔버스 드로어 */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 284px; max-width: 85vw; z-index: 40;
    transform: translateX(-101%); transition: transform .25s ease, visibility .25s; visibility: hidden;
    box-shadow: 2px 0 16px rgba(0,0,0,.4);
    padding-top: env(safe-area-inset-top);
    display: flex; flex-direction: column;
  }
  .sidebar.open { transform: none; visibility: visible; }
  .sidebar-foot { border-top: 1px solid var(--border); padding: 10px 8px;
    display: flex; flex-direction: column; gap: 6px; }
  .sidebar-foot .btn { width: 100%; }

  /* 우측 컨트롤(.chat-head) → 우측 오프캔버스 드로어 */
  .chat-head {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 300px; max-width: 88vw; z-index: 40;
    transform: translateX(101%); transition: transform .25s ease, visibility .25s; visibility: hidden;
    box-shadow: -2px 0 16px rgba(0,0,0,.4);
    flex-direction: column; align-items: stretch; gap: 12px;
    overflow-y: auto; background: var(--panel);
    padding: calc(16px + env(safe-area-inset-top)) 14px 16px;
  }
  .chat-head.open { transform: none; visibility: visible; }
  .chat-head::before { content: "설정 · 모델"; font-weight: 700; color: var(--muted); font-size: 13px; }
  .chat-head select { max-width: none; width: 100%; min-height: 44px; }
  .chat-head .btn.sm { width: 100%; min-height: 44px; font-size: 14px; }
  .chat-head .spacer { display: none; }
  .chat-head .ctx-bar { width: 100%; }

  /* 채팅 전체 폭 */
  .chat { width: 100%; }
  .messages { padding: 14px 12px; }
  .bubble { max-width: 100%; }
  .bubble.user .body { max-width: 100%; }

  /* 입력창 하단 safe-area + 터치 */
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .composer .row { gap: 8px; }
  .composer #send { min-height: 44px; min-width: 64px; }
  .composer textarea { min-height: 46px; font-size: 16px; } /* 16px: iOS 자동확대 방지 */
}

/* ---------- 작은 모바일 (<420px) 미세 조정 ---------- */
@media (max-width: 420px) {
  .top { padding-left: 10px; padding-right: 10px; }
  .top .logo { font-size: 16px; }
  .messages { padding: 12px 10px; }
}

/* 세션 목록 항목 액션(이름변경/삭제) */
.sess { display: flex; align-items: center; gap: 4px; }
.sess-main { flex: 1; min-width: 0; }
.sess-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.sess:hover .sess-actions, .sess.active .sess-actions { opacity: 1; }
.sess-act { background: transparent; border: none; color: var(--muted); font-size: 13px;
  padding: 4px 6px; border-radius: 6px; line-height: 1; }
.sess-act:hover { background: var(--bg); }

/* 선택한 로컬 폴더 표시줄 */
.folderbar { padding: 7px 16px; font-size: 12px; color: var(--muted);
  background: var(--panel); border-bottom: 1px solid var(--border);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folderbar b { color: var(--accent); }

/* 모바일: 액션 항상 표시 + 터치 크기 */
@media (max-width: 1023px) {
  .sess-actions { opacity: 1; }
  .sess-act { padding: 8px; font-size: 15px; }
}
