:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --sidebar: #efebe2;
  --text: #24211b;
  --muted: #7a7366;
  --border: #e2ddd1;
  --accent: #e8a317;
  --accent-ink: #3a2a00;
  --user-bubble: #f3e3bd;
  --code-bg: #f4f1ea;
  --danger: #c0392b;
  --warn: #b7791f;
  --radius: 14px;
  --sidebar-w: 270px;
  --track: #ece7dc;
  --hot: #c05621;
  --on: #2f9e5b; --on-bg: #e3f3e8; --on-ink: #1f6b3d;
  --off: #8a8274; --off-bg: #ece7dc; --off-ink: #4f493e;
  --wake: #d97706; --wake-bg: #fdecc8; --wake-ink: #7a4a00; --wake-ring: #f8d58f;
  --down: #c05621; --down-bg: #fde2d2; --down-ink: #8a3a12;
  --chart-line: #c98500; --chart-fill: #f3e3bd;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --panel: #1f1c15;
    --sidebar: #12100c;
    --text: #ece7dc;
    --muted: #9b9384;
    --border: #2f2b22;
    --accent: #f0b429;
    --accent-ink: #2a1e00;
    --user-bubble: #3a3020;
    --code-bg: #0f0d09;
    --danger: #ef6f62;
    --warn: #e0a84a;
    --track: #2f2b22;
    --hot: #ef8a5a;
    --on: #4cc47f; --on-bg: #1d3526; --on-ink: #8fe0b0;
    --off: #8a8274; --off-bg: #2a2720; --off-ink: #b9b1a2;
    --wake: #f0a83a; --wake-bg: #3a2c12; --wake-ink: #f7cf86; --wake-ring: #6b4a12;
    --down: #ef8a5a; --down-bg: #3a2218; --down-ink: #f5b597;
    --chart-line: #f0b429; --chart-fill: #3a3020;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.error { color: var(--danger); }

/* ---------- 로그인 ---------- */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-logo { width: 64px; height: 64px; margin: 0 auto; }
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-card input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
}
.login-card button {
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.login-card button:disabled { opacity: .6; }

/* ---------- 레이아웃 ---------- */

.layout {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px 16px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { width: 24px; height: 24px; }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}
.conv-item:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.conv-item.active { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-actions { display: none; }
.conv-item:hover .conv-actions, .conv-item.active .conv-actions { display: flex; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 10px; }

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.quota.allowed_warning { color: var(--warn); }
.quota.rejected { color: var(--danger); }
.push-row { display: flex; align-items: center; gap: 6px; padding: 8px 16px; font-size: 13px; border-top: 1px solid var(--border); }
.push-row svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.push-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; font-size: 12px; }
.push-actions.muted { color: var(--muted); }
.push-on { color: var(--ok, #2f9e44); font-weight: 600; }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); font-size: 12px; text-decoration: underline; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn.small svg { width: 16px; height: 16px; }

.scrim { display: none; }

/* ---------- 채팅 ---------- */

.chat {
  min-height: 0;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--border);
}
.chat-head h2 {
  flex: 1;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu-btn { visibility: hidden; }

.messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.messages-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.welcome { text-align: center; color: var(--muted); margin-top: 18vh; }
.welcome img { width: 56px; height: 56px; opacity: .9; }

.msg { display: flex; flex-direction: column; min-width: 0; }
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  max-width: 85%;
  background: var(--user-bubble);
  padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  white-space: normal;
  overflow-wrap: anywhere;
}
.msg.assistant .bubble { max-width: 100%; overflow-wrap: anywhere; }
.msg-meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; align-items: center; min-height: 18px; }

.typing { display: inline-flex; gap: 3px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* 마크다운 */
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 .7em; }
.markdown ul, .markdown ol { margin: 0 0 .7em; padding-left: 1.4em; }
.markdown h1, .markdown h2, .markdown h3 { font-size: 1.05em; margin: 1em 0 .5em; }
.markdown a { color: var(--accent); }
.markdown blockquote { margin: 0 0 .7em; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.markdown code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; background: var(--code-bg); padding: .1em .35em; border-radius: 5px; }
.markdown pre { margin: 0 0 .8em; border-radius: 10px; overflow-x: auto; border: 1px solid var(--border); position: relative; }
.code-copy {
  position: absolute; top: 6px; right: 6px; padding: 2px 8px; font-size: 11px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg); color: var(--muted); opacity: .85;
}
.code-copy:hover { opacity: 1; color: var(--text); }
.msg-actions { display: flex; gap: 2px; margin-top: 2px; color: var(--muted); }
.msg-actions .icon-btn { color: var(--muted); }
.edit-banner { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); padding: 0 6px 6px; }
.markdown pre code.hljs { display: block; padding: 12px 14px; background: var(--code-bg); font-size: 13px; line-height: 1.5; }
.markdown table { border-collapse: collapse; margin: 0 0 .8em; display: block; overflow-x: auto; font-size: 14px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }

/* 입력창 */
.composer {
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
}
.composer-box {
  max-width: 780px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 10px 8px 14px;
  box-shadow: 0 1px 6px rgb(0 0 0 / .05);
}
.composer textarea {
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOS 자동 확대 방지 */
  max-height: 200px;
}
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.deep-toggle {
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
  user-select: none;
}
.deep-toggle input { display: none; }
.deep-toggle.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.send-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
}
.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn.stop { background: var(--text); color: var(--bg); }
.send-btn.stop svg { fill: currentColor; stroke: none; }

/* ---------- 모바일: 사이드바를 드로어로 ---------- */

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .composer { padding-bottom: 8px; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(var(--sidebar-w), 82vw);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .drawer-open .sidebar { transform: none; }
  .drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / .35); }
  .menu-btn { visibility: visible; }
  .conv-actions { display: flex; }
}

/* ---------- 내비게이션 ---------- */

.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px 8px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-size: 14px;
}
.side-nav a svg { width: 18px; height: 18px; }
.side-nav a:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.side-nav a.active { background: color-mix(in srgb, var(--accent) 30%, transparent); font-weight: 700; }
.side-label { font-size: 12px; font-weight: 700; color: var(--muted); padding: 10px 10px 4px; }

.mini-machine {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-size: 14px;
}
.mini-machine:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.mini-machine.active { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.mini-val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mini-val.waking { color: var(--wake-ink); }

.tabbar {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 4px 24px calc(6px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 6px 0; font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: color-mix(in srgb, var(--accent) 60%, var(--text)); font-weight: 700; }

/* ---------- 상태 표시 ---------- */

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--on); }
.dot.offline { background: transparent; border: 2px solid var(--off); box-sizing: border-box; }
.dot.waking { background: var(--wake); box-shadow: 0 0 0 3px var(--wake-ring); animation: pulse 1.4s infinite; }
.dot.shutting_down { background: var(--down); }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px transparent; } }

.pill {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--on-bg); color: var(--on-ink);
}
.pill.offline { background: var(--off-bg); color: var(--off-ink); }
.pill.waking { background: var(--wake-bg); color: var(--wake-ink); }
.pill.shutting_down { background: var(--down-bg); color: var(--down-ink); }

/* ---------- 페이지 (머신) ---------- */

.page {
  flex: 1; min-width: 0; min-height: 0; overflow-y: auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px 24px;
  font-variant-numeric: tabular-nums;
}
.page > * { max-width: 1100px; margin-left: auto; margin-right: auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -0.5px; }
.page-sub { font-size: 13px; color: var(--muted); }
.muted { font-size: 12px; color: var(--muted); }
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.machine-card {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; cursor: pointer;
}
.machine-card:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.machine-card.st-waking { border-color: var(--wake-ring); }
.mc-head { display: flex; align-items: center; gap: 12px; }
.mc-icon {
  width: 40px; height: 40px; flex-shrink: 0; display: grid; place-items: center;
  border-radius: 12px; background: var(--user-bubble); color: color-mix(in srgb, var(--accent) 45%, var(--text));
}
.st-offline .mc-icon { background: var(--off-bg); color: var(--off); }
.st-waking .mc-icon { background: var(--wake-bg); color: var(--wake-ink); }
.mc-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mc-name { font-size: 16px; font-weight: 700; }
.mc-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.meters { display: grid; gap: 12px; }
.meter { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.meter-label { font-size: 12px; color: var(--muted); }
.meter-value { font-size: 15px; font-weight: 700; white-space: nowrap; }
.meter-value small, .stat-value small { font-size: 12px; font-weight: 400; color: var(--muted); }
.bar-track { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar { height: 6px; border-radius: 3px; background: var(--accent); transition: width .4s ease; }
.bar.hot { background: var(--hot); }
.bar.wake { background: var(--wake); }

.disk-rows { display: flex; flex-direction: column; gap: 8px; }
.disk-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; }
.disk-text { font-size: 12px; color: var(--muted); white-space: nowrap; }

.spark-wrap { display: none; }
.chart-svg { display: block; width: 100%; height: 96px; }
.chart-svg.spark { height: 44px; }
.chart-grid { stroke: var(--track); stroke-width: 1; fill: none; }
.chart-area { fill: var(--chart-fill); stroke: none; }
.chart-line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-empty { height: 96px; display: grid; place-items: center; font-size: 13px; color: var(--muted); }
.spark-wrap .chart-empty { height: 44px; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

.wake-panel { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 12px; background: var(--wake-bg); font-size: 13px; }
.wake-panel .row { display: flex; justify-content: space-between; }
.wake-panel .bar-track { background: color-mix(in srgb, var(--wake) 20%, transparent); }

.mc-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--text);
}
.chip svg { width: 13px; height: 13px; }

.mc-actions { display: flex; gap: 8px; }
.mc-actions:empty { display: none; }
.btn {
  flex: 1; height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text);
  font-size: 15px; font-weight: 600;
}
.btn svg { width: 18px; height: 18px; stroke-width: 2.2; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.subtle { color: var(--down-ink); }
.btn:disabled { opacity: .55; cursor: default; }
.detail-actions { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.detail-actions .btn { flex: 0 0 auto; padding: 0 20px; }
.detail-head { align-items: center; }
.detail-head .icon-btn { width: 44px; height: 44px; color: var(--text); }
.detail-foot { margin: -8px auto 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--muted); min-height: 18px; }

.panel {
  display: flex; flex-direction: column; gap: 10px; padding: 14px; margin-bottom: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
}
.panel h2 { margin: 0; font-size: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.seg { display: flex; gap: 4px; }
.seg button {
  padding: 4px 12px; min-height: 32px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--border); background: transparent; color: var(--off-ink);
}
.seg button.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.specs { gap: 0; padding-top: 12px; }
.specs h2 { margin-bottom: 6px; }
.spec-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--track); font-size: 14px; }
.spec-row span:first-child { color: var(--muted); flex-shrink: 0; }
.spec-row span:last-child { text-align: right; overflow-wrap: anywhere; }

/* ---------- 채팅: 도구 사용 표시, 비서 알림 ---------- */

.tool-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 .6em; }
.tool-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--panel); font-size: 12px; color: var(--off-ink);
}
.tool-chip svg { width: 14px; height: 14px; }
.tool-chip svg.ok { stroke: var(--on); stroke-width: 2.5; }
.tool-chip svg.bad { stroke: var(--danger); stroke-width: 2.5; }
.spinner {
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--track); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.msg.notice .bubble {
  max-width: 100%; padding: 10px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel)); border: 1px solid var(--border);
}
.notice-meta { display: inline-flex; align-items: center; gap: 4px; }
.notice-meta svg { width: 13px; height: 13px; }

@media (max-width: 860px) {
  .side-nav { display: none; }
  .tabbar { display: grid; }
}

@media (min-width: 861px) {
  .page { padding: 28px 40px 32px; }
  .spark-wrap { display: block; }
}

/* ---------- 명령 실행: 승인 카드, 명령 블록, 실행 기록 ---------- */

.cmd-block { margin: 0 0 .7em; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--panel); }
.cmd-head { display: flex; align-items: center; gap: 6px; padding: 7px 12px; font-size: 12px; color: var(--off-ink); }
.cmd-head svg { width: 14px; height: 14px; }
.cmd-head svg.ok { stroke: var(--on); stroke-width: 2.5; }
.cmd-head svg.bad { stroke: var(--danger); stroke-width: 2.5; }
.markdown pre.cmd, pre.cmd { margin: 0; border: 0; border-radius: 0; border-top: 1px solid var(--border); }
pre.cmd code { display: block; padding: 10px 12px; background: var(--code-bg); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.cmd-out { border-top: 1px solid var(--border); }
.cmd-out summary { padding: 6px 12px; font-size: 12px; color: var(--muted); cursor: pointer; }
.cmd-out pre { margin: 0; padding: 10px 12px; max-height: 320px; overflow: auto; font-size: 12px; background: var(--code-bg); white-space: pre-wrap; }

.approval-card {
  display: flex; flex-direction: column; gap: 10px; padding: 14px;
  border: 1px solid var(--wake-ring); border-radius: 14px; background: var(--wake-bg);
}
.approval-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--wake-ink); }
.approval-head svg { width: 18px; height: 18px; }
.approval-left { margin-left: auto; font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.approval-shell { font-size: 12px; color: var(--muted); margin-bottom: -4px; }
.approval-card pre.cmd { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.approval-card pre.cmd code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.approval-actions { display: flex; gap: 8px; }

.runs { gap: 0; }
.runs h2 { margin-bottom: 6px; }
.run-row { border-top: 1px solid var(--track); }
.run-row summary { display: flex; flex-direction: column; gap: 2px; padding: 9px 0; cursor: pointer; list-style: none; }
.run-row summary::-webkit-details-marker { display: none; }
.run-row code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.run-meta { font-size: 12px; color: var(--muted); }
.run-st.ok { color: var(--on-ink); }
.run-st.bad { color: var(--danger); }
.run-row pre { margin: 0 0 10px; padding: 10px; max-height: 260px; overflow: auto; font-size: 12px; background: var(--code-bg); border-radius: 8px; white-space: pre-wrap; }

/* ---------------------------------------------------------------- 검색·고정 */
.search-box { display: flex; align-items: center; gap: 6px; margin: 4px 12px 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.search-box svg { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; }
.search-hit { flex-direction: column; align-items: stretch; gap: 2px; }
.hit-snippet { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hit-snippet mark { background: rgb(232 163 23 / .35); color: inherit; border-radius: 3px; }
.hit-meta { font-size: 11px; color: var(--muted); }
.pin-mark { display: inline-flex; color: var(--muted); }
.pin-mark svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.conv-item.pin-end { margin-bottom: 8px; position: relative; }
.conv-item.pin-end::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -5px; border-bottom: 1px solid var(--border); }
.msg.flash .bubble { animation: flash 2s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px rgb(232 163 23 / .55); } 100% { box-shadow: 0 0 0 3px transparent; } }

/* ---------------------------------------------------------------- 첨부 */
.head-actions { display: flex; align-items: center; gap: 2px; }
.chat.dragging .composer-box { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(232 163 23 / .25); }

.file-grid { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 8px; }
.file-thumb {
  padding: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--code-bg);
  width: 132px; height: 132px; cursor: zoom-in;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-grid:has(.file-thumb:only-child) .file-thumb { width: auto; height: auto; max-width: min(320px, 100%); }
.file-grid:has(.file-thumb:only-child) .file-thumb img { max-height: 320px; object-fit: contain; }
.file-cards { display: flex; flex-direction: column; gap: 6px; margin: 2px 0 8px; }
.file-card {
  display: flex; align-items: center; gap: 10px; text-align: left; max-width: 360px;
  padding: 8px 12px 8px 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); cursor: pointer;
}
.file-card:hover { border-color: var(--accent); }
.file-ext {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; letter-spacing: .02em;
}
.file-text { display: flex; flex-direction: column; min-width: 0; }
.file-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; color: var(--muted); }
.msg.user .file-card { background: transparent; }

/* 입력창의 첨부 */
.composer-left { display: flex; align-items: center; gap: 6px; }
.attach-btn { color: var(--muted); }
.pending-files { display: flex; gap: 6px; overflow-x: auto; padding: 0 0 8px; }
.pending-file {
  position: relative; flex: none; display: flex; align-items: center; gap: 6px; max-width: 180px;
  padding: 4px 26px 4px 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 12px;
}
.pending-file img, .pending-file .file-ext { width: 36px; height: 36px; border-radius: 7px; object-fit: cover; }
.pending-file.error { border-color: var(--danger); color: var(--danger); }
.pending-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-progress { position: absolute; left: 4px; right: 4px; bottom: 2px; height: 3px; border-radius: 2px; background: var(--border); overflow: hidden; }
.pending-progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.pending-x {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer;
}

/* 미리보기 */
.viewer {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  background: var(--bg); padding-top: env(safe-area-inset-top);
}
.viewer-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--border); }
.viewer-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.viewer-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-meta { font-size: 12px; color: var(--muted); }
.viewer-versions { font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); }
.viewer-head a.icon-btn { color: inherit; }
.viewer-body { position: relative; flex: 1; min-height: 0; overflow: auto; display: flex; padding-bottom: env(safe-area-inset-bottom); }
.viewer-img { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; touch-action: pinch-zoom; }
.viewer-frame { flex: 1; border: 0; width: 100%; background: #fff; }
.viewer-doc { width: 100%; max-width: 780px; margin: 0 auto; padding: 20px 18px 40px; align-self: flex-start; }
.viewer-text { margin: 0; width: 100%; align-self: flex-start; }
.viewer-text code.hljs { display: block; padding: 16px 18px; font-size: 13px; line-height: 1.55; background: var(--code-bg); min-height: 100%; }
.viewer-none { margin: auto; color: var(--muted); padding: 20px; text-align: center; }
.viewer-nav {
  position: fixed; top: 50%; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); display: grid; place-items: center; opacity: .85; cursor: pointer;
}
.viewer-nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viewer-nav.prev { left: 12px; }

/* 사진 보기: 검은 배경, 상단 바는 사진 위에 겹쳐 띄우고 탭하면 숨김 */
.viewer.photo { background: #000; color: #fff; padding-top: 0; }
.viewer.photo .viewer-head {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2; border: 0;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: linear-gradient(rgb(0 0 0 / .65), rgb(0 0 0 / 0)); transition: opacity .2s;
}
.viewer.photo .viewer-meta { color: rgb(255 255 255 / .7); }
.viewer.photo .icon-btn, .viewer.photo .viewer-head a.icon-btn { color: #fff; }
.viewer.photo .viewer-nav { background: rgb(0 0 0 / .45); border-color: rgb(255 255 255 / .2); color: #fff; transition: opacity .2s; }
.viewer.ui-hidden .viewer-head, .viewer.ui-hidden .viewer-nav { opacity: 0; pointer-events: none; }
.viewer.photo .viewer-body { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.viewer.photo .viewer-img { cursor: zoom-in; -webkit-touch-callout: none; }
.viewer-body.zoomed { display: grid; } /* 작으면 가운데, 크면 오른쪽·아래로 넘쳐 스크롤 */
.viewer-body.zoomed .viewer-img { max-width: none; max-height: none; width: 250%; margin: auto; cursor: zoom-out; }
.viewer-nav.next { right: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; padding: 16px; width: 100%; align-self: flex-start; }
.gallery-item {
  display: flex; flex-direction: column; gap: 6px; padding: 0; border: 0; background: none; color: var(--text); cursor: pointer; text-align: left;
}
.gallery-item img, .gallery-item .file-ext { width: 100%; aspect-ratio: 1; border-radius: 12px; object-fit: cover; border: 1px solid var(--border); }
.gallery-item .file-ext { font-size: 16px; height: auto; }
.gallery-name { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 860px) {
  .viewer-nav { display: none; } /* 모바일은 좌우로 밀어서 넘김 */
  .file-thumb { width: 104px; height: 104px; }
}
