:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #1f1d1a;
  --muted: #6b675f;
  --border: #e3e0d9;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --warn: #b35c00;
  --claude: #d97757;
  --codex: #10a37f;
  --gemini: #4f7ef7;
  --bubble: #e8e5de;
  --code-bg: #f0eee9;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --panel: #1e1c19;
    --text: #ece9e2;
    --muted: #a19c92;
    --border: #34312c;
    --accent: #7b93fd;
    --accent-text: #0f1220;
    --bubble: #2a2824;
    --code-bg: #25231f;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
button.secondary { background: var(--bg); }
button.danger { background: var(--danger); color: #fff; border-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
.icon-btn { border: none; background: transparent; font-size: 18px; padding: 4px 8px; }
.small-btn { padding: 4px 10px; font-size: 13px; }
code { font-family: var(--mono); font-size: .9em; background: var(--code-bg); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; }

/* 로그인 */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 24px; display: grid; gap: 10px; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 0; }
.login-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }

/* 레이아웃 */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; }
.brand { font-size: 18px; }
.conversation-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-row { position: relative; display: flex; align-items: center; margin-bottom: 2px; }
.conv-row.removing { pointer-events: none; overflow: hidden; max-height: 0; margin-bottom: 0; opacity: 0; transform: translateX(18px); transition: max-height .26s ease, margin-bottom .26s ease, opacity .2s ease, transform .26s ease; }
.conv-item { display: block; flex: 1; min-width: 0; width: 100%; text-align: left; border: none; background: transparent; padding: 8px 30px 8px 10px; border-radius: 8px; margin-bottom: 0; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--bubble); }
.conv-item .t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .s { display: block; font-size: 12px; color: var(--muted); }
.conv-del { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; padding: 0; border: none; border-radius: 6px; background: transparent; color: var(--muted); font-size: 12px; line-height: 1; display: grid; place-items: center; opacity: 0; transition: opacity .15s, background .15s, color .15s; }
.conv-row:hover .conv-del, .conv-row:focus-within .conv-del, .conv-item.active + .conv-del { opacity: .75; }
.conv-del:hover { opacity: 1 !important; background: rgba(201, 42, 42, .15); color: var(--danger); }
@media (prefers-reduced-motion: reduce) { .conv-row.removing { transition-duration: .01ms; } }
@media (hover: none), (max-width: 900px) { .conv-del { opacity: .7; } }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.agent-status { display: grid; gap: 4px; font-size: 13px; }
.foot-actions { display: flex; gap: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.claude { background: var(--claude); }
.dot.codex { background: var(--codex); }
.dot.gemini { background: var(--gemini); }
.dot.off { background: var(--muted); opacity: .4; }
.scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
#menu { display: none; }
.conv-title { flex: 1; margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; flex-shrink: 0; }
.segmented button { border: none; border-radius: 0; padding: 5px 10px; font-size: 13px; background: transparent; white-space: nowrap; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-text); }
.segmented .default-mark { font-size: 10px; opacity: .8; }

.messages { flex: 1; overflow-y: auto; padding: 16px; overscroll-behavior: contain; }
.thread { max-width: 980px; margin: 0 auto; display: grid; gap: 14px; }
.empty { color: var(--muted); text-align: center; margin-top: 18vh; }
.user-msg { justify-self: end; max-width: min(720px, 92%); background: var(--bubble); border-radius: 14px 14px 4px 14px; padding: 9px 13px; white-space: pre-wrap; word-break: break-word; }
.user-msg .to { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.responses { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--muted); border-radius: var(--radius); padding: 10px 14px; min-width: 0; }
.card.claude { border-left-color: var(--claude); }
.card.codex { border-left-color: var(--codex); }
.card.gemini { border-left-color: var(--gemini); }
.card-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.card-head .name { font-weight: 600; }
.card-head .meta { color: var(--muted); margin-left: auto; display: flex; gap: 8px; align-items: center; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); }
.badge.running { color: var(--accent); border-color: var(--accent); }
.badge.failed, .badge.interrupted { color: var(--danger); border-color: var(--danger); }
.badge.completed { color: var(--ok); border-color: var(--ok); }
.spinner { width: 10px; height: 10px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.todos { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.todos li.done { text-decoration: line-through; opacity: .7; }
.todos li.active { color: var(--text, inherit); font-weight: 700; }
.todos-wrap { margin-top: 8px; }
.todos-wrap .todos { margin-top: 4px; }
.todos-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.todos-bar { flex: 1; max-width: 160px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.12); overflow: hidden; }
.todos-bar i { display: block; height: 100%; background: var(--accent, #c9a2ff); transition: width .4s ease; }
.body { margin-top: 8px; word-break: break-word; }
.body.placeholder { color: var(--muted); font-style: italic; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 .7em; }
.body pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.body pre code { background: none; padding: 0; }
.body h3, .body h4, .body h5, .body h6 { margin: .9em 0 .4em; }
.body ul, .body ol { padding-left: 1.3em; margin: 0 0 .7em; }
.body blockquote { margin: 0 0 .7em; padding-left: 10px; border-left: 3px solid var(--border); color: var(--muted); }
.body a { color: var(--accent); }
.table-wrap { overflow-x: auto; margin-bottom: .7em; }
.body table { border-collapse: collapse; font-size: 13px; }
.body th, .body td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.card.failed .body { color: var(--danger); }

.composer { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--panel); }
.picker { flex: 1 0 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-width: 0; }
.pick-group { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.picker .pick-name { flex-shrink: 0; min-width: 0; font-size: 12px; font-weight: 600; }
.pick-dropdown { position: relative; display: inline-flex; min-width: 0; max-width: 100%; }
.pick-select {
  appearance: none; -webkit-appearance: none; min-width: 0; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: left; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--text); padding: 5px 26px 5px 11px; border: 1px solid var(--border); border-radius: 99px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
}
.pick-dropdown.open .pick-select, .pick-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pick-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 50;
  min-width: 100%; width: max-content; max-width: min(340px, calc(100vw - 32px));
  padding: 5px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); box-shadow: 0 10px 28px rgba(0, 0, 0, .2);
  display: grid; gap: 2px;
}
.pick-option {
  display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px 10px;
  border: none; border-radius: 8px; background: transparent; color: var(--text);
  font-size: 13px; text-align: left; white-space: nowrap; cursor: pointer;
}
.pick-option:hover, .pick-option:focus-visible { background: var(--bubble); border-color: transparent; outline: none; }
.pick-option.selected, .pick-option.selected:hover { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.pick-check { width: 14px; flex-shrink: 0; text-align: center; font-size: 12px; }
.pick-option-label { overflow: hidden; text-overflow: ellipsis; }
.pick-fixed { font-size: 13px; padding: 5px 11px; border-radius: 99px; background: var(--bg); border: 1px solid var(--border); }
.picker:empty { display: none; }
.pick-row { display: flex; gap: 6px; align-items: center; overflow-x: auto; scrollbar-width: none; padding-bottom: 1px; }
.pick-row::-webkit-scrollbar { display: none; }
.pick-name { font-size: 11px; color: var(--muted); white-space: nowrap; min-width: 64px; }
.pick { flex-shrink: 0; font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--bg); white-space: nowrap; }
.pick.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.pick-hint { flex: 1 1 160px; min-width: 0; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.profile-head { display: flex; gap: 6px; align-items: center; }
.profile-head .profile-label { flex: 1; font-weight: 600; }
.profile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.profile input[type="text"], .profile select, .profile textarea { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
@media (max-width: 600px) { .profile-grid { grid-template-columns: 1fr; } }
.composer-main { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.attach { align-self: flex-end; padding-bottom: 8px; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; padding: 2px 4px 2px 8px; border: 1px solid var(--border); border-radius: 99px; background: var(--bg); max-width: 100%; }
.chip.error { border-color: var(--danger); color: var(--danger); }
.chip-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; margin-right: 6px; }
.chip.has-thumb { padding-left: 4px; }
.msg-thumb { display: block; max-width: min(260px, 100%); max-height: 200px; border-radius: 8px; border: 1px solid var(--border); }
.body .msg-thumb { max-width: min(640px, 100%); max-height: 480px; margin: 8px 0; }
.chip-x { border: none; background: transparent; padding: 0 4px; font-size: 11px; }
.files { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 12px; }
.tag { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.delegation { justify-self: start; max-width: min(720px, 92%); font-size: 13px; padding: 6px 12px; border: 1px dashed var(--border); border-radius: 10px; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.schedule-list { display: grid; gap: 10px; }
.schedule { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; }
.schedule.off { opacity: .6; }
.schedule-title { font-weight: 600; }
.schedule .detail { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; background: var(--bg); padding: 6px 8px; border-radius: 6px; }
.schedule-actions { display: flex; gap: 12px; align-items: center; justify-content: flex-end; font-size: 13px; }
.composer textarea { width: 100%; resize: none; border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; background: var(--bg); max-height: 40vh; line-height: 1.45; }
.composer-actions { display: flex; gap: 6px; }
@media (max-width: 600px) { .composer-actions { width: 100%; justify-content: flex-end; } .composer-actions button { flex: 1; } }

/* 설정 */
.settings { width: min(780px, 100vw); max-height: min(92vh, 100%); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); }
.settings::backdrop { background: rgba(0, 0, 0, .45); }
.settings form { display: flex; flex-direction: column; max-height: min(92vh, 100dvh); }
.settings-head, .tabs, .settings-foot { flex-shrink: 0; }
.settings-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.settings-head h2 { margin: 0; font-size: 17px; }
.tabs { display: flex; gap: 4px; padding: 8px 12px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.tabs button { border: none; background: transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--bubble); }
.settings-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; display: grid; gap: 14px; align-content: start; }
.field { display: grid; gap: 4px; }
.field > label { font-weight: 600; font-size: 13px; }
.field .help { font-size: 12px; color: var(--muted); }
.field input[type="text"], .field input[type="number"], .field select, .field textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.field textarea { font-family: var(--mono); font-size: 13px; min-height: 70px; }
.field.check { grid-template-columns: auto 1fr; align-items: start; column-gap: 8px; }
.field.check input { margin-top: 4px; }
.field.check .help { grid-column: 2; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.callout { font-size: 13px; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); }
.callout.warn { border-color: var(--warn); }
.diag { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 8px; }
.settings-foot { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--border); }
.settings-msg { flex: 1; margin: 0; font-size: 13px; white-space: pre-wrap; }
.settings-msg.err { color: var(--danger); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; transform: translateX(-100%); transition: transform .2s ease; }
  .app.drawer-open .sidebar { transform: none; }
  .app.drawer-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 10; }
  #menu { display: inline-block; }
  .topbar { padding: 8px 10px; flex-wrap: wrap; }
  .conv-title { font-size: 15px; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .messages { padding: 12px 10px; }
  .responses { grid-template-columns: 1fr; }
  .settings { width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; }
}
.field > .label { font-weight: 600; font-size: 13px; }
.field input[type="time"] { width: max-content; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: inherit; font-size: 15px; }
.section-title { margin: 0 0 4px; font-size: 15px; }
.pick-sep { width: 1px; align-self: stretch; background: var(--border); margin: 2px 6px; }
.settings-body .pick-row { flex-wrap: wrap; overflow: visible; }
.trans-card { border: 1px solid var(--border); border-radius: 10px; background: var(--code-bg); margin: 0 0 .75em; overflow: hidden; }
.trans-card:last-child { margin-bottom: 0; }
.trans-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: rgba(255, 255, 255, .03); }
.trans-lang { font-size: 12px; font-weight: 600; color: var(--muted); }
.copy-btn { padding: 3px 10px; font-size: 12px; border-radius: 6px; font-weight: 500; }
.copy-btn.copied { border-color: var(--ok); color: var(--ok); }
.trans-text { padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.6; }



/* 파일함 */
/* 높이를 정해 두어야 Safari 에서도 목록 칸이 내용 높이 0으로 접히지 않는다. 닫혀 있을 때는 보이지 않게 [open] 일 때만 flex. */
.files-dialog[open] { display: flex; flex-direction: column; height: min(860px, 92vh); height: min(860px, 92dvh); }
@media (max-width: 900px) { .files-dialog[open] { height: 100dvh; } }
.files-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; align-content: start; }
.files-empty { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 30px 0; }
.file-tile { display: flex; flex-direction: column; gap: 4px; padding: 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: inherit; text-decoration: none; font-size: 12px; min-width: 0; }
.file-tile:hover { border-color: var(--accent, #c9a96a); }
/* 답변 속 로컬 파일 링크: 파일 이름은 바로 열기, 📂 는 파일함 폴더 보기 */
.local-path { overflow-wrap: anywhere; }
.local-folder { display: inline-block; margin-left: 4px; padding: 0 4px; border-radius: 6px; text-decoration: none; font-size: .95em; line-height: 1.4; vertical-align: baseline; }
.local-folder:hover, .local-folder:focus-visible { background: color-mix(in srgb, var(--accent, #c9a96a) 22%, transparent); }
.folder-bar { display: flex; align-items: center; gap: 8px; min-width: 0; width: 100%; }
.folder-bar .folder-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.folder-bar .small-btn { flex: none; }
.file-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: rgba(255, 255, 255, .04); display: grid; place-items: center; font-size: 30px; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { color: var(--muted); font-size: 11px; }

.task-waiting { color:#e8be77; font-size:12px; line-height:1.5; }
.status.waiting, .office-status.waiting { color:#e8be77; }
