:root {
  --bg: #0d0f12;
  --bg-2: #111418;
  --panel: #151a20;
  --panel-2: #1b2129;
  --panel-3: #222933;
  --border: #252c35;
  --border-2: #303845;
  --text: #e7eaef;
  --text-2: #b4bcc7;
  --muted: #7d8794;
  --accent: #7c8cff;
  --accent-2: #6273f5;
  --accent-soft: rgba(124, 140, 255, 0.14);
  --green: #3fb950;
  --green-soft: rgba(63, 185, 80, 0.14);
  --red: #f8665e;
  --red-soft: rgba(248, 102, 94, 0.13);
  --amber: #e3b341;
  --amber-soft: rgba(227, 179, 65, 0.13);
  --blue: #58a6ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "D2Coding", Menlo, Consolas, monospace;
  --sans: "Preon Sans", -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  --sidebar-w: 272px;
  --files-w: 380px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--blue);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12.5px;
}

.pre-line {
  white-space: pre-line;
}

.ic {
  flex: none;
  display: block;
}

/* ------------------------------------------------------------ 기본 컨트롤 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--panel-3);
}

.btn.primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent);
}

.btn.danger {
  background: var(--red-soft);
  border-color: rgba(248, 102, 94, 0.45);
  color: #ffb4ae;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.small {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn.block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  flex: none;
}

.icon-btn:hover:not(:disabled) {
  background: var(--panel-3);
  color: var(--text);
}

.icon-btn.tiny {
  width: 24px;
  height: 24px;
  border-radius: 6px;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  color: var(--accent);
  padding: 2px 4px;
  font-size: 12.5px;
}

.link-btn:hover {
  text-decoration: underline;
}

.input,
.select,
textarea.input {
  background: var(--bg);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  outline: none;
  min-width: 0;
}

.input:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input.block {
  width: 100%;
}

.select {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237d8794' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.field-label {
  display: block;
  margin: 10px 0 6px;
  color: var(--text-2);
  font-size: 13px;
}

.error {
  color: var(--red);
  font-size: 13px;
  margin: 8px 0 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--panel-3);
  color: var(--text-2);
  white-space: nowrap;
}

.badge.ok {
  background: var(--green-soft);
  color: #7ee08c;
}

.badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.bad {
  background: var(--red-soft);
  color: #ff9d96;
}

.badge.run {
  background: var(--accent-soft);
  color: #b4bdff;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  flex: none;
}

.dot.ok {
  background: var(--green);
}

.dot.warn {
  background: var(--amber);
}

.dot.bad {
  background: var(--red);
}

.dot.run {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--border-2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

.spinner.small {
  width: 13px;
  height: 13px;
  border-width: 2px;
  display: inline-block;
  vertical-align: -2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-3);
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.25s;
}

.progress.good > span {
  background: var(--green);
}

.progress.mid > span {
  background: var(--amber);
}

.progress.low > span {
  background: var(--red);
}

/* ------------------------------------------------------------ 시작 화면 */
.screen {
  min-height: 100dvh;
  padding: 24px;
}

.screen.center {
  display: grid;
  place-items: center;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.gate {
  width: min(400px, 100%);
  padding: 32px 28px 28px;
  text-align: center;
}

.gate h1 {
  font-size: 20px;
  margin: 14px 0 8px;
}

.gate p {
  color: var(--text-2);
  margin: 0 0 14px;
}

.gate .input {
  margin-top: 6px;
  text-align: center;
  font-size: 16px;
}

.gate .btn {
  margin-top: 14px;
}

.gate-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ------------------------------------------------------------ 레이아웃 */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
}

#app.files-open {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--files-w);
}

#sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 10px calc(10px + env(safe-area-inset-bottom));
  gap: 8px;
}

#main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

#filepanel {
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  display: none;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

#app.files-open #filepanel {
  display: flex;
}

#backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

.only-narrow {
  display: none;
}

/* ------------------------------------------------------------ 사이드바 */
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand .ic {
  color: var(--accent);
}

.project-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.project-row .select {
  flex: 1;
  padding: 7px 30px 7px 10px;
  font-size: 13.5px;
  background-color: var(--panel);
}

.new-chat {
  justify-content: flex-start;
  background: var(--panel);
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 6px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

#thread-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  margin: 0 -4px;
  padding: 0 4px;
}

.thread {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 6px 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text-2);
}

.thread:hover {
  background: var(--panel);
}

.thread.active {
  background: var(--panel-2);
  color: var(--text);
}

.thread .t-main {
  flex: 1;
  min-width: 0;
}

.thread .t-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13.5px;
}

.thread .t-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11.5px;
}

.thread .t-menu {
  opacity: 0;
  width: 26px;
  height: 26px;
}

.thread:hover .t-menu,
.thread.active .t-menu {
  opacity: 1;
}

.empty-list {
  color: var(--muted);
  font-size: 12.5px;
  padding: 10px;
}

.side-foot {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-left: 6px;
  min-width: 0;
}

.account-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.usage-mini {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.usage-mini:hover {
  border-color: var(--border-2);
}

.usage-line {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
}

.usage-line b {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ 상단 바 */
#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  min-height: 54px;
}

.title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

#thread-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-2);
  background: var(--panel);
  color: var(--text-2);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.pill:hover {
  color: var(--text);
}

.pill .sep {
  color: var(--border-2);
}

/* ------------------------------------------------------------ 배너 */
#banners {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px;
}

#banners:not(:empty) {
  padding-top: 10px;
}

.banner {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-2);
  background: var(--panel);
  color: var(--text-2);
  font-size: 13.5px;
}

.banner.warn {
  border-color: rgba(227, 179, 65, 0.4);
  background: var(--amber-soft);
  color: #f0d080;
}

.banner.bad {
  border-color: rgba(248, 102, 94, 0.4);
  background: var(--red-soft);
  color: #ffb4ae;
}

.banner .grow {
  flex: 1;
}

/* ------------------------------------------------------------ 대화 */
#scroller {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}

#transcript {
  max-width: 860px;
  margin: 0 auto;
  padding: 22px 20px 30px;
}

.jump {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 150px;
  z-index: 5;
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
}

.welcome {
  text-align: center;
  padding: 12vh 10px 20px;
  color: var(--text-2);
}

.welcome .gate-icon {
  margin-bottom: 14px;
}

.welcome h2 {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--text);
}

.welcome .hints {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  max-width: 640px;
  margin: 26px auto 0;
  text-align: left;
}

.hint {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
}

.hint:hover {
  border-color: var(--border-2);
  color: var(--text);
}

.older-btn {
  display: block;
  margin: 0 auto 18px;
}

.turn {
  margin-bottom: 26px;
}

.turn-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg.user {
  display: flex;
  justify-content: flex-end;
  margin: 4px 0 6px;
}

.msg.user .bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  padding: 9px 14px;
  max-width: min(85%, 640px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.thumb {
  max-width: 220px;
  max-height: 180px;
  border-radius: 10px;
  border: 1px solid var(--border-2);
  object-fit: cover;
  cursor: zoom-in;
}

.msg.agent {
  padding: 2px 2px;
}

.msg.agent.commentary {
  color: var(--text-2);
  font-size: 13.5px;
}

.msg-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}

/* 마크다운 */
.md {
  word-break: break-word;
}

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 10px;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 18px 0 8px;
  line-height: 1.3;
}

.md h1 {
  font-size: 20px;
}

.md h2 {
  font-size: 17px;
}

.md h3 {
  font-size: 15px;
}

.md ul,
.md ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.md li {
  margin: 3px 0;
}

.md blockquote {
  margin: 0 0 10px;
  padding: 4px 12px;
  border-left: 3px solid var(--border-2);
  color: var(--text-2);
}

.md code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.md pre {
  position: relative;
  background: #0a0c0f;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 12px;
}

.md pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.5;
}

.copy-code {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  background: var(--panel-2) !important;
}

.md pre:hover .copy-code {
  opacity: 1;
}

.md table {
  border-collapse: collapse;
  margin: 0 0 12px;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

.md th,
.md td {
  border: 1px solid var(--border-2);
  padding: 6px 10px;
  text-align: left;
}

.md th {
  background: var(--panel-2);
}

.md hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.md a.local-link {
  color: #a9b4ff;
  text-decoration: none;
  border-bottom: 1px dashed rgba(169, 180, 255, 0.5);
}

.md img {
  max-width: 100%;
}

/* 도구 카드 */
.tool {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  overflow: hidden;
}

.tool > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  color: var(--text-2);
  font-size: 13px;
  min-width: 0;
}

.tool > summary::-webkit-details-marker {
  display: none;
}

.tool > summary:hover {
  color: var(--text);
}

.tool > summary .t-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
  font-size: 12.5px;
}

.tool.plain > summary .t-text {
  font-family: var(--sans);
  font-size: 13px;
}

.tool.running {
  border-color: rgba(124, 140, 255, 0.45);
}

.tool.failed {
  border-color: rgba(248, 102, 94, 0.35);
}

.tool-body {
  border-top: 1px solid var(--border);
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool pre,
pre.code {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  background: #0a0c0f;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  overflow: auto;
  max-height: 360px;
  white-space: pre-wrap;
  word-break: break-all;
}

.cmd-line {
  color: #c9d1ff;
}

.status {
  flex: none;
}

.note {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 2px;
  min-width: 0;
}

.note span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin: 6px 0;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border);
}

.reasoning {
  color: var(--muted);
  font-size: 13px;
}

.reasoning > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.reasoning > summary::-webkit-details-marker {
  display: none;
}

.reasoning > summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reasoning .reason-text {
  margin: 6px 0 2px 22px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}

/* 파일 변경 */
.fc-list {
  border-top: 1px solid var(--border);
}

.fc-row {
  border-bottom: 1px solid var(--border);
}

.fc-row:last-child {
  border-bottom: 0;
}

.fc-row > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12.5px;
}

.fc-row > summary::-webkit-details-marker {
  display: none;
}

.fc-row .path {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kind {
  font-size: 11px;
  font-weight: 700;
  padding: 0 6px;
  border-radius: 5px;
  background: var(--panel-3);
  color: var(--text-2);
}

.kind.add {
  background: var(--green-soft);
  color: #7ee08c;
}

.kind.delete {
  background: var(--red-soft);
  color: #ff9d96;
}

.kind.update {
  background: var(--accent-soft);
  color: #b4bdff;
}

.counts {
  display: flex;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11.5px;
}

.plus {
  color: var(--green);
}

.minus {
  color: var(--red);
}

.diff {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  background: #0a0c0f;
  overflow: auto;
  max-height: 460px;
  padding: 6px 0;
}

.diff .ln {
  display: block;
  padding: 0 12px;
  white-space: pre;
  min-height: 1.5em;
}

.diff .ln.add {
  background: rgba(63, 185, 80, 0.12);
  color: #aff5b4;
}

.diff .ln.del {
  background: rgba(248, 102, 94, 0.12);
  color: #ffc1bd;
}

.diff .ln.hunk {
  color: #a5b4fc;
  background: rgba(124, 140, 255, 0.07);
}

.diff .ln.meta {
  color: var(--muted);
}

.diff-file {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}

.diff-file-head {
  padding: 7px 12px;
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
}

/* 턴 하단 */
.turn-plan {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 8px;
}

.plan-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.plan-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.plan-steps li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  color: var(--text-2);
}

.plan-steps li.completed {
  color: var(--muted);
  text-decoration: line-through;
}

.plan-steps li.inProgress {
  color: var(--text);
  font-weight: 600;
}

.step-mark {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-2);
  flex: none;
  margin-top: 2px;
  display: grid;
  place-items: center;
}

li.completed .step-mark {
  background: var(--green);
  border-color: var(--green);
  color: #0d0f12;
}

li.inProgress .step-mark {
  border-color: var(--accent);
  border-right-color: transparent;
  animation: spin 1s linear infinite;
}

.turn-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.turn-foot .working {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
}

.turn-error {
  width: 100%;
  border: 1px solid rgba(248, 102, 94, 0.4);
  background: var(--red-soft);
  color: #ffb4ae;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  white-space: pre-wrap;
}

.warn-text {
  color: var(--amber);
}

.danger-text {
  color: var(--red);
}

/* ------------------------------------------------------------ 승인 요청 */
#composer-area {
  padding: 0 16px calc(12px + env(safe-area-inset-bottom));
}

#approvals {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#approvals:not(:empty) {
  margin-bottom: 10px;
  max-height: 55vh;
  overflow-y: auto;
}

.approval {
  border: 1px solid rgba(227, 179, 65, 0.5);
  background: #17150f;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.approval h4 {
  margin: 0 0 6px;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--amber);
  font-size: 14px;
}

.approval p {
  margin: 0 0 8px;
  color: var(--text-2);
  font-size: 13px;
}

.approval .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.approval .q {
  margin: 10px 0;
}

.approval .q-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.option {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.option:hover {
  background: var(--panel-2);
}

/* ------------------------------------------------------------ 입력창 */
#composer {
  max-width: 860px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border-2);
  border-radius: 18px;
  padding: 10px 10px 8px 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

#composer:focus-within {
  border-color: rgba(124, 140, 255, 0.7);
}

#composer.disabled {
  opacity: 0.6;
}

#prompt {
  width: 100%;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  max-height: 40vh;
  min-height: 24px;
  padding: 2px 0;
}

#prompt::placeholder {
  color: var(--muted);
}

.composer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.composer-left {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  min-width: 0;
}

.composer-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: none;
}

.mini-select {
  appearance: none;
  background: var(--panel-2)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%237d8794' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 9px center;
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: 999px;
  padding: 4px 24px 4px 10px;
  font-size: 12.5px;
  max-width: 170px;
  outline: none;
}

.mini-select:hover,
.mini-select:focus {
  border-color: var(--border-2);
  color: var(--text);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-2);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px;
}

.toggle.on {
  background: rgba(227, 179, 65, 0.15);
  border-color: rgba(227, 179, 65, 0.55);
  color: var(--amber);
}

.send-btn,
.stop-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  flex: none;
}

.send-btn {
  background: var(--accent-2);
  color: #fff;
}

.send-btn:disabled {
  background: var(--panel-3);
  color: var(--muted);
}

.stop-btn {
  background: var(--text);
  color: var(--bg);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 3px 4px 3px 6px;
  font-size: 12.5px;
}

.chip img {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  object-fit: cover;
}

.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------ 파일 패널 */
.fp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 6px 14px;
}

.fp-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  min-width: 0;
}

.fp-title .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fp-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 0 12px 6px;
  font-size: 12.5px;
  color: var(--text-2);
}

.fp-crumbs button {
  border: 0;
  background: none;
  color: var(--text-2);
  padding: 2px 4px;
  border-radius: 5px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fp-crumbs button:hover {
  background: var(--panel-2);
  color: var(--text);
}

.fp-crumbs .ic {
  color: var(--muted);
}

.fp-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}

.fp-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 6px;
}

.frow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  min-width: 0;
}

.frow:hover {
  background: var(--panel);
}

.frow .ic.dir {
  color: #8fa2ff;
}

.frow .ic.filei {
  color: var(--muted);
}

.frow .f-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.frow .f-meta {
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.frow .f-menu {
  width: 26px;
  height: 26px;
}

.fp-empty {
  color: var(--muted);
  text-align: center;
  padding: 30px 12px;
  font-size: 13px;
}

.fp-empty .ic {
  margin: 0 auto 10px;
  color: var(--border-2);
}

.fp-uploads {
  border-top: 1px solid var(--border);
  max-height: 40%;
  overflow-y: auto;
}

.fp-uploads:empty {
  display: none;
}

.up-row {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.up-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  min-width: 0;
}

.up-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.up-sub {
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.up-row.done .up-sub {
  color: var(--green);
}

.up-row.failed .up-sub {
  color: var(--red);
}

.fp-foot {
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

#drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(13, 15, 18, 0.72);
  display: grid;
  place-items: center;
  pointer-events: none;
}

.drop-card {
  border: 2px dashed var(--accent);
  border-radius: 20px;
  padding: 40px 50px;
  background: var(--panel);
  font-size: 16px;
  color: var(--text);
  max-width: 80vw;
  text-align: center;
}

/* ------------------------------------------------------------ 모달, 메뉴, 알림 */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal {
  width: min(460px, 100%);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.modal.wide {
  width: min(980px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px 18px;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-body {
  padding: 4px 18px 16px;
  overflow: auto;
  min-height: 0;
}

.modal-body p {
  margin: 0 0 10px;
  color: var(--text-2);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border);
}

.preview-text {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
  overflow: auto;
  max-height: 70vh;
  background: #0a0c0f;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.preview-img {
  max-width: 100%;
  max-height: 72vh;
  display: block;
  margin: 0 auto;
  border-radius: 10px;
}

.menu {
  position: fixed;
  z-index: 95;
  min-width: 180px;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 5px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
  font-size: 13.5px;
  color: var(--text);
}

.menu-item:hover {
  background: var(--panel-3);
}

.menu-item.danger {
  color: #ff9d96;
}

.menu-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

#toasts {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  padding: 10px 10px 10px 14px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: toast-in 0.18s ease-out;
}

.toast.out {
  opacity: 0;
  transition: opacity 0.2s;
}

.toast-text {
  flex: 1;
}

.toast.error {
  border-color: rgba(248, 102, 94, 0.5);
}

.toast.error .ic {
  color: var(--red);
}

.toast.success .ic {
  color: var(--green);
}

@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}

/* 사용량 상세 */
.usage-detail {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.usage-bucket h4 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-2);
}

.usage-window {
  margin-bottom: 12px;
}

.usage-window .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.usage-window .big {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.usage-window .progress {
  height: 8px;
}

.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 12px;
  font-size: 13px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  word-break: break-all;
}

.section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 14px;
}

.section:first-child {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.section h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.connect {
  max-width: 560px;
  margin: 10vh auto 0;
  padding: 24px;
}

.connect h2 {
  margin: 12px 0 6px;
  font-size: 19px;
}

.connect p {
  color: var(--text-2);
}

.device-code {
  font-family: var(--mono);
  font-size: 26px;
  letter-spacing: 0.12em;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px dashed var(--border-2);
  display: inline-block;
  margin: 6px 0;
}

.steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 14px 0;
  text-align: left;
}

.steps .stepn {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
}

/* ------------------------------------------------------------ 반응형 */
@media (max-width: 1180px) {
  #app.files-open {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  #filepanel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(420px, 100vw);
    z-index: 50;
    box-shadow: var(--shadow);
  }
}

@media (max-width: 820px) {
  #app,
  #app.files-open {
    grid-template-columns: minmax(0, 1fr);
  }

  .only-narrow {
    display: inline-grid;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    z-index: 50;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  #sidebar.open {
    transform: none;
  }

  #usage-pill .pill-label {
    display: none;
  }

  #transcript {
    padding: 16px 12px 24px;
  }

  #composer-area {
    padding: 0 8px calc(8px + env(safe-area-inset-bottom));
  }

  #composer {
    border-radius: 16px;
    padding: 8px 8px 6px 12px;
  }

  .mini-select {
    max-width: 120px;
  }

  #context-left {
    display: none;
  }

  .thread .t-menu {
    opacity: 1;
  }

  .msg.user .bubble {
    max-width: 92%;
  }
}

@media (pointer: coarse) {
  .copy-code {
    opacity: 1;
  }
}

/* ------------------------------------------------------------ 수능 D-day (preon.kr 수능 탭과 같은 글꼴·구성) */
.sn-dday {
  font-family: "Noto Serif KR", "AppleMyungjo", "Batang", serif;
  font-weight: 900;
  letter-spacing: -0.025em;
}

.home {
  padding-top: 4vh;
}

.dday {
  max-width: 600px;
  margin: 0 auto 8px;
  padding: 4px 4px 0;
  color: #f1f5f9;
}

.dd-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: #94a3b8;
}

.dd-label {
  font-weight: 500;
  letter-spacing: 0.04em;
}

.dd-name {
  text-align: right;
}

.dd-num {
  margin: 12px 0 0;
  font-size: 88px;
  line-height: 0.9;
  color: #818cf8;
}

.dd-live {
  margin: 16px 0 0;
  font-size: 18px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.dd-remain {
  margin-left: 8px;
  font-size: 14px;
  font-weight: 400;
  color: #94a3b8;
}

.dd-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 28px 0 0;
  border-top: 1px solid #1e293b;
  border-bottom: 1px solid #1e293b;
  font-size: 14px;
}

.dd-grid > div {
  padding: 12px 12px 12px 0;
}

.dd-grid > div + div {
  border-left: 1px solid #1e293b;
  padding-left: 12px;
}

.dd-grid dt {
  font-size: 11px;
  color: #64748b;
}

.dd-grid dd {
  margin: 4px 0 0;
  font-weight: 500;
  line-height: 1.4;
}

.dd-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  font-size: 12px;
  color: #94a3b8;
}

.dd-bar {
  position: relative;
  flex: 1;
  height: 1px;
  background: #1e293b;
}

.dd-bar-fill {
  position: absolute;
  top: -1px;
  bottom: -1px;
  left: 0;
  background: #f1f5f9;
}

.dd-bar-dot {
  position: absolute;
  top: -3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #818cf8;
  transform: translateX(-50%);
}

.dd-pct {
  color: #f1f5f9;
  font-variant-numeric: tabular-nums;
}

.dd-motto {
  margin: 30px 0 0;
  font-family: "Noto Serif KR", "AppleMyungjo", "Batang", serif;
  font-weight: 500;
  font-size: 18px;
  line-height: 1.65;
  color: #e2e8f0;
}

.welcome-intro {
  max-width: 600px;
  margin: 40px auto 0;
  padding-top: 26px;
  border-top: 1px solid var(--border);
}

.welcome-intro h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.welcome-intro .hints {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.welcome-intro .hint {
  text-align: left;
  font: inherit;
  font-size: 13px;
}

.home .connect {
  margin-top: 36px;
  text-align: left;
}

.dd-mini {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border: 1px solid var(--border-2);
  background: var(--panel);
  border-radius: 999px;
  padding: 3px 11px;
  color: var(--text-2);
  font-size: 12px;
}

.dd-mini b {
  color: #818cf8;
  font-size: 15px;
  line-height: 1;
}

.dd-mini:hover {
  border-color: rgba(129, 140, 248, 0.6);
}

.gate-dday {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  margin: -8px 0 16px !important;
  color: var(--muted) !important;
  font-size: 12.5px;
}

.gate-dday b {
  color: #818cf8;
  font-size: 22px;
  line-height: 1;
}

.modal .dday {
  margin: 0;
}

@media (min-width: 640px) {
  .dd-num {
    font-size: 128px;
  }

  .dd-live {
    font-size: 20px;
  }

  .dd-motto {
    font-size: 20px;
  }
}

@media (max-width: 820px) {
  .dd-mini .dd-mini-label {
    display: none;
  }

  .dd-grid {
    font-size: 13px;
  }
}


.usage-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
}

