:root {
  --bg: #0f1216; --panel: #161b22; --panel2: #1c232d; --border: #2a3441; --text: #e6edf3; --muted: #8b98a8;
  --accent: #4f8cff; --ok: #3fb950; --fail: #f85149; --warn: #d29922; --user: #23405f; --add: #1f3b2a; --del: #4a1f22;
  --mono: ui-monospace, "Cascadia Code", "D2Coding", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: transparent; border-color: var(--fail); color: var(--fail); }
button.small { padding: 3px 9px; font-size: 12px; }
input, select, textarea { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; font-family: inherit; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.err { color: var(--fail); }
.row-end { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 10px; }
.spacer { flex: 1; }

.layout { display: grid; grid-template-columns: 220px 1fr auto; height: 100vh; }
.sidebar, .audit { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.audit { border-left: 1px solid var(--border); border-right: 0; width: 340px; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.side-foot { padding: 8px 14px; border-top: 1px solid var(--border); font-size: 11px; }
.list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.list li { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.list li:hover { background: var(--panel2); }
.list li.active { background: var(--panel2); outline: 1px solid var(--accent); }
.audit .list li { cursor: default; border-bottom: 1px solid var(--border); border-radius: 0; }
.audit .list li code { display: block; color: var(--muted); word-break: break-all; }
.audit-actions { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.audit-actions button.mini { margin-left: auto; color: var(--fail); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--panel); }
.title { font-weight: 600; font-size: 16px; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.top-actions select { width: 260px; padding: 4px 6px; font-size: 12px; }

.chat { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; text-align: center; }
.msg { max-width: 900px; padding: 10px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border); }
.msg.user { align-self: flex-end; background: var(--user); border-color: #2f5a88; }
/* 직원별 지정 색상: 글씨는 흰색 */
.msg.user.tinted, .msg.user.tinted .who { color: #fff; }
.msg.user.tinted code, .msg.user.tinted pre { background: rgba(0, 0, 0, .25); color: #fff; }
.msg.user.tinted a { color: #fff; text-decoration: underline; }
.msg.assistant p:first-child { margin-top: 0; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant pre { background: var(--bg); padding: 8px 10px; border-radius: 6px; overflow-x: auto; }
.msg.assistant code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.msg.assistant pre code { padding: 0; background: none; }
.msg.error { border-color: var(--fail); color: var(--fail); }
.msg.status { background: transparent; border: 0; color: var(--muted); padding: 2px 6px; }
.msg.tool { padding: 6px 10px; background: var(--panel2); }
.msg.tool summary { cursor: pointer; color: var(--muted); }
.msg.tool .tool-in { color: var(--muted); margin: 6px 0; max-height: 160px; overflow: auto; }
.msg.tool .tool-out { background: var(--bg); padding: 8px; border-radius: 6px; max-height: 320px; overflow: auto; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: var(--border); color: var(--text); }
.badge.write { background: var(--warn); color: #000; }
.badge.fail { background: var(--fail); color: #fff; }
.ok { color: var(--ok); }
.fail { color: var(--fail); }
.spin { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.msg.approval { border-color: var(--warn); width: 100%; max-width: 900px; }
.msg.approval.approved { border-color: var(--ok); }
.msg.approval.rejected { border-color: var(--fail); opacity: .8; }
.msg.approval-all { background: transparent; border: 0; padding: 0; width: 100%; max-width: 900px; }
.appr-head { font-weight: 600; margin-bottom: 8px; }
.target { font-family: var(--mono); font-size: 12.5px; margin-bottom: 6px; }
.diff, .cmd { background: var(--bg); padding: 8px 10px; border-radius: 6px; max-height: 420px; overflow: auto; }
.diff .dl { display: block; }
.diff .add { background: var(--add); color: #7ee787; }
.diff .del { background: var(--del); color: #ffa198; }
.diff .hunk { color: var(--accent); }
.diff .hdr { color: var(--muted); }
.warn { color: var(--warn); margin-top: 6px; font-size: 13px; }
.appr-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.appr-actions .note { flex: 1; }
.appr-actions.all { justify-content: flex-end; }
.decision { margin-top: 8px; font-size: 13px; }
.decision.pending { color: var(--muted); }

.composer { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--panel); }
.composer textarea { flex: 1; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px; width: 380px; max-height: 92vh; overflow-y: auto; }
.modal-box.wide { width: 760px; }
.modal-box h2 { margin: 0 0 10px; font-size: 18px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.grid label.check { flex-direction: row; align-items: center; color: var(--text); }
.grid label.check input { width: auto; }
.span2 { grid-column: span 2; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 12px; }
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.test-out { grid-column: span 2; background: var(--bg); padding: 10px; border-radius: 6px; max-height: 200px; overflow: auto; }

/* 상단 로고 줄: 흰 배경 (로고 이미지가 흰 바탕이라 줄 전체를 흰색으로) */
.sidebar .side-head { background: #fff; }
.logo { display: inline-flex; align-items: center; line-height: 0; }
.logo img { height: 22px; width: auto; max-width: 130px; display: block; }
.sidebar .side-head button { background: #f0f2f5; border-color: #d0d7de; color: #24292f; }
.sidebar .side-head button:hover { border-color: var(--accent); background: #e6ebf1; }

/* 왼쪽 패널: 크기 조절/닫기, 업체 검색, 대화 목록 */
.layout { --sw: 220px; grid-template-columns: var(--sw) 1fr auto; }
/* 닫으면 사이드바가 그리드에서 빠지므로 컬럼도 2개로 줄여야 본문이 제자리에 온다 */
.layout.side-closed { grid-template-columns: 1fr auto; }
.layout.side-closed .sidebar { display: none; }
.sidebar { position: relative; min-width: 0; }
.splitter { position: absolute; top: 0; right: -3px; width: 6px; height: 100%; cursor: col-resize; z-index: 5; }
.splitter:hover { background: var(--accent); opacity: .5; }
body.resizing { cursor: col-resize; user-select: none; }
button.icon { padding: 3px 7px; font-size: 13px; }
.side-head { gap: 6px; }
.side-search { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.side-search input { padding: 5px 8px; font-size: 13px; }
/* 우클릭 메뉴 */
.ctx { position: fixed; z-index: 100; list-style: none; margin: 0; padding: 4px; min-width: 180px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.ctx li { padding: 6px 12px; border-radius: 5px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.ctx li:hover { background: var(--panel2); }
.ctx li.danger { color: var(--fail); }
.ctx li.sep { height: 1px; padding: 0; margin: 4px 6px; background: var(--border); cursor: default; }
.ctx li.sep:hover { background: var(--border); }

/* 그룹(폴더) */
.list > li.grp { padding: 0; margin-bottom: 2px; background: none; }
.list > li.grp:hover { background: none; }
.grp-head { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 6px; cursor: pointer; user-select: none; }
.grp-head:hover { background: var(--panel2); }
.grp-head .tw { width: 10px; color: var(--muted); font-size: 10px; }
.grp-name { font-weight: 600; font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp-actions { display: none; gap: 2px; }
.grp-head:hover .grp-actions { display: flex; }
button.mini { padding: 0 5px; font-size: 11px; line-height: 18px; background: transparent; border-color: transparent; color: var(--muted); }
button.mini:hover { border-color: var(--accent); color: var(--text); }
.grp-body { list-style: none; margin: 0; padding: 0 0 0 16px; }
.grp-body > li.co { padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.grp-body > li.co:hover { background: var(--panel2); }
.grp-body > li.co.active { background: var(--panel2); outline: 1px solid var(--accent); }
.co-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
li.co.dragging { opacity: .4; }
.drop-hint { padding: 5px 8px; font-style: italic; }

.convs { list-style: none; margin: 6px 0 0; padding: 0 0 0 8px; border-left: 2px solid var(--border); }
.convs li { display: flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 4px; font-size: 12.5px; }
.convs .cv-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convs li button.mini { display: none; }
.convs li:hover button.mini { display: block; }
.convs li:hover { background: var(--bg); }
.convs li.active { background: var(--bg); color: var(--accent); outline: none; }
.top-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.top-actions #global-search { width: 280px; padding: 5px 9px; font-size: 13px; }

/* 통합검색 결과 */
.search-view { display: block; }
.search-head { display: flex; align-items: center; gap: 8px; padding: 4px 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.results-list { list-style: none; margin: 0; padding: 0; max-width: 900px; }
.results-list li { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; cursor: pointer; background: var(--panel); }
.results-list li:hover { border-color: var(--accent); }
.hit-head { margin-bottom: 4px; }
.snippet { color: var(--muted); font-size: 13px; }
mark { background: var(--warn); color: #000; border-radius: 2px; padding: 0 2px; }
.msg.hit { outline: 2px solid var(--warn); }

/* v0.2 추가 */
.row { display: flex; gap: 6px; align-items: center; }
.row input { flex: 1; }
.side-foot { display: flex; flex-direction: column; gap: 6px; }
.foot-row { display: flex; gap: 6px; align-items: center; }
.model-select { flex: 1; padding: 3px 6px; font-size: 12px; }
.usage { display: flex; flex-direction: column; gap: 3px; }
.usage-head { display: flex; align-items: center; }
.bar { height: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--ok); transition: width .3s; }
.bar .fill.warn { background: var(--warn); }
.bar .fill.danger { background: var(--fail); }
/* #login a 보다 우선하도록 id 를 함께 지정 (파란 배경에 파란 글씨로 보이던 문제) */
#login a.primary-link, .primary-link { display: inline-block; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 6px; text-decoration: none; font-weight: 600; }
#login a.primary-link:hover { filter: brightness(1.1); }
.who { font-size: 12px; font-weight: 600; color: #9fc2ff; margin-bottom: 3px; }
.who.agent { color: #7ee787; }
.msg.assistant .body > p:first-child { margin-top: 0; }
.msg.assistant .body > p:last-child { margin-bottom: 0; }
.results { list-style: none; margin: 4px 0 0; padding: 0; border: 1px solid var(--border); border-radius: 6px; max-height: 200px; overflow-y: auto; background: var(--bg); }
.results li { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.results li:hover { background: var(--panel2); }
.results li:last-child { border-bottom: 0; }
.hint { display: block; margin-top: 4px; color: var(--warn); font-size: 12px; }
#settings-form fieldset { margin-bottom: 12px; }
select.guessed { border-color: var(--warn); }
#settings-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
#settings-form label.check { flex-direction: row; align-items: center; color: var(--text); margin-bottom: 8px; }
#settings-form label.check input { width: auto; }
#settings-form .row { margin-top: 8px; }
#login form label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
#login a { color: var(--accent); }
.login-logo { background: #fff; border-radius: 8px; padding: 10px 14px; display: inline-block; margin-bottom: 10px; line-height: 0; }
.login-logo img { height: 28px; display: block; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); max-height: 28vh; }
  .splitter { display: none; }
  .top-actions #global-search { width: 160px; }
  .sidebar .list { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar .list li { border: 1px solid var(--border); }
  .audit { width: 100%; max-height: 40vh; }
  .grid { grid-template-columns: 1fr; }
  .span2, .test-out { grid-column: span 1; }
}
