:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #1d2129; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2f6fed; --accent-text: #fff; --user: #2f6fed; --user-text: #fff;
  --assist: #ffffff; --tool: #eef2ff; --tool-text: #3b4a9e; --danger: #d9534f;
  --radius: 12px; --sidebar-w: 280px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --panel: #1a1f26; --text: #e6e8eb; --muted: #9aa3ad; --line: #2a313b;
    --accent: #5b8cff; --user: #3a63c9; --assist: #1f252e; --tool: #232b45; --tool-text: #b6c3ff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

.app { display: flex; height: 100%; }
.sidebar { width: var(--sidebar-w); background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; padding: 16px; font-weight: 700; font-size: 17px; border-bottom: 1px solid var(--line); }
.brand-icon { font-size: 22px; }
.nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; border-bottom: 1px solid var(--line); }
.nav-item { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--tool); color: var(--tool-text); font-weight: 600; }
.conv-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px 4px; font-size: 12px; color: var(--muted); }
.conv-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.conv-list li { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.conv-list li:hover { background: var(--bg); }
.conv-list li.active { background: var(--tool); color: var(--tool-text); }
.conv-list li span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-list li button { visibility: hidden; }
.conv-list li:hover button { visibility: visible; }
.sidebar-foot { padding: 10px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.sidebar-foot .warn { color: #d97706; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar h1 { font-size: 16px; margin: 0; flex: 1; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.icon-btn, .small-btn, .primary-btn, .danger-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.icon-btn { border: 0; background: none; font-size: 18px; }
.primary-btn { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.danger-btn { color: var(--danger); }
.hide-desktop { display: none; }

/* 채팅 */
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.welcome { margin: auto; max-width: 560px; text-align: center; color: var(--muted); }
.welcome h2 { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.chip:hover { border-color: var(--accent); }
.msg { max-width: 760px; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--assist); border: 1px solid var(--line); border-bottom-left-radius: 4px; white-space: normal; }
.msg.assistant p { margin: 0 0 8px; } .msg.assistant p:last-child { margin: 0; }
.msg.assistant pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.msg.assistant code { background: var(--bg); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.msg.assistant pre code { background: none; padding: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px; padding-left: 22px; }
.msg.assistant table { border-collapse: collapse; margin: 6px 0; font-size: 14px; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--line); padding: 4px 8px; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { font-size: 15px; margin: 8px 0 4px; }
.msg.error { align-self: flex-start; background: #fdecea; color: #a12622; border: 1px solid #f5c2c0; }
.tool-line { align-self: flex-start; font-size: 12px; color: var(--tool-text); background: var(--tool); border-radius: 999px; padding: 3px 10px; }
.tool-line.err { background: #fdecea; color: #a12622; }
.tool-line.running::after { content: " …"; }
.typing { color: var(--muted); font-size: 13px; align-self: flex-start; padding-left: 4px; }
.composer { display: flex; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); max-height: 180px; }
.composer button { width: 44px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; cursor: pointer; }
.composer button:disabled { opacity: .5; cursor: default; }

/* 모듈 테이블 */
.toolbar { display: flex; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.toolbar input[type=search], .toolbar input[type=text] { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.toolbar select { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); }
.table-wrap { flex: 1; overflow: auto; padding: 12px 20px; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
.table tbody tr { cursor: pointer; } .table tbody tr:hover { background: var(--bg); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--tool); color: var(--tool-text); }
.badge.ok { background: #e3f6e8; color: #1e7a3a; } .badge.no { background: #fdecea; color: #a12622; } .badge.warn { background: #fff4d6; color: #8a5a00; }
.empty { color: var(--muted); text-align: center; padding: 40px; }

/* 기억 */
.memory-list { list-style: none; margin: 0; padding: 12px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.memory-list li { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.memory-list li .cat { font-size: 12px; color: var(--muted); min-width: 44px; }
.memory-list li span.txt { flex: 1; }
.memory-list li time { font-size: 12px; color: var(--muted); }

/* 모달 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-card { background: var(--panel); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal-card h3 { margin: 0 0 12px; }
#recordForm { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#recordForm label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#recordForm label.wide { grid-column: 1 / -1; }
#recordForm input, #recordForm select, #recordForm textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); color: var(--text); }
#recordForm label.check { flex-direction: row; align-items: center; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.spacer { flex: 1; }

@media (max-width: 800px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .hide-desktop { display: inline-block; }
  .messages, .toolbar, .table-wrap, .memory-list { padding-left: 16px; padding-right: 16px; }
  .composer { padding: 10px 16px 12px; }
  #recordForm { grid-template-columns: 1fr; }
}

/* 사용자 영역 / 관리자 */
.user-box { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 13px; }
.user-box span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; align-self: center; }
.table td .small-btn { padding: 3px 8px; font-size: 12px; margin-right: 4px; }
#userTable tbody tr { cursor: default; }

/* 설정 / 일정 범위 */
.settings { padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; max-width: 720px; }
.card h3 { margin: 0 0 6px; font-size: 16px; } .muted { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-row input, .form-row select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); color: var(--text); min-width: 200px; }
.form-row label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.msg { font-size: 13px; padding: 8px 10px; border-radius: 8px; display: none; margin-top: 10px; }
.msg.err { display: block; background: #fdecea; color: #a12622; } .msg.ok { display: block; background: #e3f6e8; color: #1e7a3a; }
.range-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.range-bar .small-btn.active { background: var(--tool); color: var(--tool-text); border-color: transparent; }
.range-bar input { border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: var(--bg); color: var(--text); }
.notice { padding: 8px 20px; font-size: 13px; color: var(--muted); background: var(--panel); border-bottom: 1px solid var(--line); }

/* 달력 */
.cal-toolbar { display: flex; align-items: center; gap: 6px; flex: 1; }
.cal-title { font-weight: 700; font-size: 16px; margin-left: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 12px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent); color: #fff; }
.cal-layout { flex: 1; display: flex; min-height: 0; }
.cal-side { width: 230px; flex-shrink: 0; border-right: 1px solid var(--line); background: var(--panel); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.wide-btn { width: 100%; padding: 9px; }
.mini-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.mini-head .icon-btn { font-size: 14px; padding: 2px 6px; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font-size: 12px; }
.mini-dow { color: var(--muted); font-size: 11px; padding: 2px 0; }
.mini-day { padding: 4px 0; border-radius: 6px; cursor: pointer; position: relative; }
.mini-day:hover { background: var(--bg); } .mini-day.other { color: var(--muted); opacity: .5; }
.mini-day.today { background: var(--accent); color: #fff; } .mini-day.selected:not(.today) { box-shadow: inset 0 0 0 1px var(--accent); }
.mini-day.has::after { content: ""; position: absolute; bottom: 1px; left: 50%; transform: translateX(-50%); width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .6; }
.mini-dow.sun, .mini-day.sun { color: #d9534f; } .mini-dow.sat, .mini-day.sat { color: var(--accent); }
.mini-day.today.sun, .mini-day.today.sat { color: #fff; }
.cal-group { margin-top: 6px; } .cal-group-title { font-size: 12px; font-weight: 700; color: var(--muted); margin: 6px 0 4px; }
.cal-chk { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.cal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cal-wrap { flex: 1; overflow: auto; padding: 12px 16px; display: flex; flex-direction: column; }
.cal-day { width: 300px; flex-shrink: 0; border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; display: flex; flex-direction: column; }
.day-head { display: flex; align-items: center; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 15px; }
.day-allday { padding: 8px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.day-hours { flex: 1; }
.hour-row { display: flex; min-height: 34px; border-bottom: 1px dashed var(--line); }
.hour { width: 52px; flex-shrink: 0; font-size: 11px; color: var(--muted); padding: 4px 8px; text-align: right; }
.hour-evs { flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 3px 6px 3px 0; }
.day-ev { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 4px 8px; border-radius: 6px; background: var(--bg); cursor: pointer; font-size: 13px; }
.day-ev:hover { background: var(--tool); }
.day-ev-time { color: var(--muted); font-size: 12px; } .day-ev-title { font-weight: 600; } .day-ev-loc, .day-ev-cal { font-size: 11px; color: var(--muted); }
.day-ev-cal { margin-left: auto; }
.cal-cell.selected { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 50%, transparent); }
.ev.full { white-space: normal; }
@media (max-width: 1000px) { .cal-side { display: none; } .cal-day { position: fixed; right: 0; top: 0; bottom: 0; width: min(320px, 90vw); z-index: 15; box-shadow: -4px 0 16px rgba(0,0,0,.15); } }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; flex: 1; }
.cal-grid { grid-template-rows: auto; }
.cal-grid.month { grid-auto-rows: minmax(110px, 1fr); }
.cal-grid.week { grid-auto-rows: minmax(300px, 1fr); }
.cal-dow { padding: 8px 0; text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); border-bottom: 1px solid var(--line); }
.cal-cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6px; min-width: 0; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell:hover { background: var(--bg); }
.cal-cell.other { color: var(--muted); background: color-mix(in srgb, var(--bg) 60%, transparent); }
.cal-cell .d { font-size: 13px; font-weight: 600; line-height: 22px; width: 24px; height: 22px; text-align: center; border-radius: 50%; align-self: flex-start; }
.cal-cell.sun .d, .cal-dow.sun { color: #d9534f; } .cal-cell.sat .d, .cal-dow.sat { color: var(--accent); }
.cal-cell.other.sun .d, .cal-cell.other.sat .d { opacity: .5; }
.cal-cell.today { background: color-mix(in srgb, var(--accent) 7%, var(--panel)); box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell.today .d { color: var(--accent); }
.ev { font-size: 12px; line-height: 1.3; padding: 2px 6px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.ev.allday { background: var(--accent); color: #fff; border-left-color: transparent; }
.ev.c1 { border-left-color: #2f9e6a; background: color-mix(in srgb, #2f9e6a 14%, var(--panel)); } .ev.allday.c1 { background: #2f9e6a; }
.ev.c2 { border-left-color: #d98b21; background: color-mix(in srgb, #d98b21 14%, var(--panel)); } .ev.allday.c2 { background: #d98b21; }
.ev.c3 { border-left-color: #9b59b6; background: color-mix(in srgb, #9b59b6 14%, var(--panel)); } .ev.allday.c3 { background: #9b59b6; }
.ev .t { opacity: .75; margin-right: 3px; }
.ev.more { background: none; border: 0; color: var(--muted); padding-left: 6px; }
.cal-grid.week .ev { white-space: normal; }
.cal-grid.week .cal-cell .d { width: auto; border-radius: 12px; padding: 0 8px; }
@media (max-width: 800px) {
  .cal-grid.month { grid-auto-rows: minmax(72px, 1fr); } .cal-wrap { padding: 8px; }
  .ev { font-size: 11px; padding: 1px 4px; } .ev .t { display: none; } .cal-title { font-size: 14px; }
}
.cal-filter { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0 2px 10px; font-size: 13px; }
.cal-chk { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.cal-chk input { accent-color: var(--accent); } .cal-chk.c1 input { accent-color: #2f9e6a; } .cal-chk.c2 input { accent-color: #d98b21; } .cal-chk.c3 input { accent-color: #9b59b6; }

/* 보안 */
.steps { padding-left: 20px; font-size: 13px; margin: 6px 0 10px; } .steps li { margin: 4px 0; }
.qr svg { width: 180px; height: 180px; background: #fff; border-radius: 8px; padding: 6px; }
.codes { background: var(--bg); padding: 10px; border-radius: 8px; font-size: 14px; letter-spacing: 1px; }
.sessions { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.sessions li { padding: 4px 0; color: var(--muted); } .sessions li b { color: var(--text); }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
