/* Vesta 웹 UI (PROJECT.md 6.3). 휴대폰 폭(390px)을 먼저 맞추고 넓은 화면에서는 대화 목록을 옆에 둔다 */
:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --line: #e2e0db;
  --accent: #b4532a;
  --accent-text: #ffffff;
  --user: #ece7df;
  --code-bg: #f0eeea;
  --good: #2f7d4f;
  --bad: #b3261e;
  --warn-bg: #fff4e0;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --panel: #1f2125;
    --text: #e8e6e1;
    --muted: #9a9ea6;
    --line: #33363c;
    --accent: #e07a4a;
    --accent-text: #16171a;
    --user: #2b2e33;
    --code-bg: #26282d;
    --good: #6cc48f;
    --bad: #f2867d;
    --warn-bg: #3a2f1c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  -webkit-text-size-adjust: 100%;
}
#root { height: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; min-height: 40px; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.stop { color: var(--bad); border-color: var(--bad); }
button.link { border: none; background: none; color: var(--muted); padding: 4px 8px; min-height: 32px; }
button.icon { border: none; background: none; font-size: 20px; padding: 4px 10px; }
button.wide { width: 100%; }
input, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.mono, code, pre { font-family: var(--mono); font-size: 14px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.error { color: var(--bad); margin: 6px 0; }
.center { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 10px 0; }
.card.clickable { cursor: pointer; }
.card .mono { overflow-wrap: anywhere; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 3px 0; flex-wrap: wrap; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login h2 { margin: 0; }
.login p { margin: 0; }

.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 4px; padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; margin-right: 6px; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tab { border: none; background: none; color: var(--muted); padding: 6px 10px; min-height: 36px; }
.tab.active { color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }

.chat { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 280px; flex-shrink: 0; border-right: 1px solid var(--line); background: var(--panel);
  padding: 10px; overflow-y: auto;
}
.sessions { list-style: none; margin: 10px 0 0; padding: 0; }
.session { padding: 8px 10px; border-radius: 10px; cursor: pointer; overflow: hidden; }
.session-head { display: flex; align-items: center; gap: 4px; }
.session-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session .remove { opacity: 0.35; padding: 2px 4px; }
.session:hover .remove, .session.active .remove { opacity: 1; }
@media (hover: none) { .session .remove { opacity: 0.7; } }
button.danger { color: #c0392b; margin-top: 8px; }
.gallery .card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.session.active, .session:hover { background: var(--user); }
.scrim { display: none; }
.conversation { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 12px 16px 24px; -webkit-overflow-scrolling: touch; }
.messages > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.empty { text-align: center; margin-top: 18vh; }
.bubble { margin: 10px auto; overflow-wrap: anywhere; }
.bubble.user { background: var(--user); border-radius: 16px; padding: 10px 14px; white-space: pre-wrap; width: fit-content; max-width: min(85%, 820px); margin-right: 0; }
.bubble.assistant { padding: 2px 0; }
.meta { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.answer p { margin: 8px 0; }
.answer h3, .answer h4 { margin: 14px 0 6px; }
.answer ul, .answer ol { padding-left: 22px; margin: 6px 0; }
.answer blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.answer code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.code { background: var(--code-bg); border-radius: 10px; margin: 10px 0; overflow: hidden; }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 2px 6px 2px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.code pre { margin: 0; padding: 10px 12px; overflow-x: auto; }
.code pre code { background: none; padding: 0; }
.table-wrap { overflow-x: auto; margin: 8px 0; }
.answer table { border-collapse: collapse; font-size: 14px; }
.answer th, .answer td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; min-width: 5.5em; word-break: keep-all; overflow-wrap: break-word; }
.cite { color: var(--accent); font-size: 12px; vertical-align: super; margin: 0 1px; }
.sources { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; font-size: 13px; }
.source { padding: 2px 0; overflow-wrap: anywhere; }
.source .cite { vertical-align: baseline; font-size: 13px; }
.tool { font-size: 14px; padding: 2px 0; }
.warn { background: var(--warn-bg); border-radius: 10px; padding: 8px 12px; margin: 8px 0; font-size: 14px; cursor: pointer; }
.warn ul { margin: 6px 0 0; padding-left: 20px; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.approval { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: 10px 12px; margin: 10px 0; background: var(--panel); }
.approval.risk-exec { border-left-color: var(--bad); }
.approval-head { display: flex; gap: 8px; align-items: center; font-weight: 600; margin-bottom: 6px; }
.approval pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--code-bg); border-radius: 8px; padding: 8px 10px; margin: 6px 0; max-height: 280px; overflow-y: auto; }
.approval textarea { margin: 6px 0; }
.actions { display: flex; gap: 8px; margin-top: 6px; }
.actions button { flex: 1; }

.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--panel);
}
.composer textarea { resize: none; max-height: 200px; line-height: 1.4; }
.composer button { flex-shrink: 0; }
.composer button.icon { min-width: 40px; padding: 8px; font-size: 18px; line-height: 1; }
.composer button.recording { background: var(--bad); color: #fff; border-color: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
/* 음성 대화 모드 (M18) */
.voicebar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); }
.voicebar .bar.level { flex: 1 1 80px; max-width: 160px; margin: 0; }
.attachments { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px 0; background: var(--panel); border-top: 1px solid var(--line); }
.thumb { position: relative; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumb .remove { position: absolute; top: -6px; right: -6px; min-height: 22px; width: 22px; padding: 0; border-radius: 999px; font-size: 14px; line-height: 1; }
.bubble-images { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.bubble-images img { max-width: min(240px, 100%); max-height: 240px; border-radius: 10px; display: block; }

.page { flex: 1; overflow-y: auto; padding: 8px 16px 32px; }
.page > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.bar { height: 8px; background: var(--code-bg); border-radius: 999px; overflow: hidden; margin: 6px 0; }
.bar .fill { height: 100%; background: var(--good); }
.bar .fill.over { background: var(--bad); }

@media (max-width: 760px) {
  .sidebar {
    position: absolute; z-index: 20; top: 0; bottom: 0; left: 0; width: min(300px, 82vw);
    transform: translateX(-102%); transition: transform .18s ease; box-shadow: 0 0 24px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: absolute; inset: 0; z-index: 10; background: rgba(0,0,0,.3); }
  .messages { padding: 10px 12px 20px; }
  /* iOS는 16px 미만 입력란을 확대한다 */
  input, textarea { font-size: 16px; }
}
@media (min-width: 761px) {
  .topbar .icon { display: none; }
}

.generated { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.generated img { width: min(420px, 100%); border-radius: 12px; display: block; border: 1px solid var(--line); }
.generated video, .gallery video { width: min(560px, 100%); max-height: 70vh; border-radius: 12px; display: block; border: 1px solid var(--line); background: #000; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.gallery .card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.gallery .card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.gallery .card p { margin: 6px 2px 0; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.turn-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.turn-actions button.on { background: var(--user); border-radius: 8px; }
.turn-actions select { min-height: 32px; padding: 2px 6px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); }

.run { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }
/* 사용자 관리·비밀번호 (M15) */
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.stack select, .run select { background: var(--panel); color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.run.selected { background: var(--panel); border-radius: 6px; }
.run { cursor: pointer; }
