:root {
  --bg: #0d0f14;
  --bg-1: #12151c;
  --bg-2: #171b24;
  --bg-3: #1e2430;
  --line: #262c39;
  --fg: #dbe0ea;
  --fg-dim: #8d96a8;
  --fg-faint: #5f6878;
  --accent: #6d8cff;
  --accent-soft: #6d8cff22;
  --good: #4ec9a0;
  --warn: #e0a458;
  --bad: #e06c75;
  --radius: 10px;
  --rail: 56px;
  --side: 400px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  overflow: hidden;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}
button { cursor: pointer; }

/* ── 로그인 ───────────────────────────────────────── */
#gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2233, var(--bg));
}
#gate .card {
  width: 360px; padding: 32px;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 16px;
  text-align: center;
}
#gate h1 { font-size: 22px; letter-spacing: .04em; margin-bottom: 6px; }
#gate p { color: var(--fg-dim); font-size: 13px; margin-bottom: 20px; }
#gate input {
  width: 100%; padding: 11px 14px; margin-bottom: 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  text-align: center; letter-spacing: .2em;
}
#gate input:focus { border-color: var(--accent); }
#gate button {
  width: 100%; padding: 11px; border-radius: var(--radius);
  background: var(--accent); color: #0b0e15; font-weight: 700;
}
#gate .msg { margin-top: 12px; font-size: 12px; color: var(--bad); min-height: 16px; }

/* ── 레이아웃 ─────────────────────────────────────── */
#app { display: none; height: 100%; }
#app.on { display: flex; }

#rail {
  width: var(--rail); flex: none;
  background: var(--bg-1); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0;
}
#rail .logo {
  width: 34px; height: 34px; border-radius: 10px; margin-bottom: 8px;
  background: linear-gradient(140deg, var(--accent), #9d6dff);
  display: grid; place-items: center; font-weight: 800; color: #0b0e15; font-size: 15px;
}
.railbtn {
  width: 38px; height: 38px; border-radius: 10px; color: var(--fg-dim);
  display: grid; place-items: center; font-size: 16px;
}
.railbtn:hover { background: var(--bg-3); color: var(--fg); }
.railbtn.on { background: var(--accent-soft); color: var(--accent); }
#rail .spacer { flex: 1; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ── 탭 / 주소창 ──────────────────────────────────── */
#tabs {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 10px 0; background: var(--bg-1);
  overflow-x: auto; scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }
.tab {
  display: flex; align-items: center; gap: 8px;
  max-width: 210px; min-width: 110px; padding: 7px 10px;
  background: var(--bg-2); border: 1px solid transparent; border-bottom: none;
  border-radius: 9px 9px 0 0; color: var(--fg-dim); font-size: 13px;
  white-space: nowrap; flex: none;
}
.tab.on { background: var(--bg); border-color: var(--line); color: var(--fg); }
.tab span { overflow: hidden; text-overflow: ellipsis; }
.tab .x { color: var(--fg-faint); font-size: 15px; line-height: 1; }
.tab .x:hover { color: var(--bad); }
#newtab { flex: none; width: 30px; height: 30px; border-radius: 8px; color: var(--fg-dim); font-size: 17px; }
#newtab:hover { background: var(--bg-3); color: var(--fg); }

#nav {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.navbtn {
  width: 30px; height: 30px; border-radius: 8px; color: var(--fg-dim); flex: none; font-size: 14px;
}
.navbtn:hover { background: var(--bg-3); color: var(--fg); }
#omni {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
}
#omni:focus-within { border-color: var(--accent); }
#omni .hint { color: var(--fg-faint); font-size: 11px; flex: none; }
#omni input { flex: 1; min-width: 0; }
#omni input::placeholder { color: var(--fg-faint); }

/* ── 화면 ─────────────────────────────────────────── */
#stage { flex: 1; position: relative; background: var(--bg); }
#stage iframe {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: none; background: #fff; display: none;
}
#stage iframe.on { display: block; }

#home {
  position: absolute; inset: 0; overflow-y: auto; padding: 28px 32px 60px; display: none;
}
#home.on { display: block; }
#home h2 { font-size: 20px; margin-bottom: 4px; }
#home .sub { color: var(--fg-dim); font-size: 13px; margin-bottom: 24px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px;
}
.card h3 {
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--fg-faint); margin-bottom: 12px; display: flex; justify-content: space-between;
}
.card h3 button { font-size: 11px; color: var(--accent); letter-spacing: 0; text-transform: none; }
.row {
  display: flex; align-items: center; gap: 9px; padding: 5px 0;
  font-size: 13px; border-bottom: 1px solid transparent;
}
.row + .row { border-top: 1px solid var(--bg-3); }
.row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--fg-faint); font-size: 11px; flex: none; }
.row.link { cursor: pointer; }
.row.link:hover .grow { color: var(--accent); }
.row .del { color: var(--fg-faint); opacity: 0; }
.row:hover .del { opacity: 1; }
.row .del:hover { color: var(--bad); }
.done .grow { color: var(--fg-faint); text-decoration: line-through; }
.empty { color: var(--fg-faint); font-size: 12px; padding: 6px 0; }
.addrow { display: flex; gap: 6px; margin-top: 10px; }
.addrow input {
  flex: 1; min-width: 0; padding: 6px 10px; font-size: 12.5px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
}
.addrow button { padding: 0 12px; border-radius: 8px; background: var(--bg-3); font-size: 12.5px; color: var(--fg-dim); }
.addrow button:hover { color: var(--fg); }

.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.quick button {
  padding: 7px 13px; border-radius: 999px; font-size: 12.5px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--fg-dim);
}
.quick button:hover { border-color: var(--accent); color: var(--accent); }

/* ── 사이드바 ─────────────────────────────────────── */
#side {
  width: var(--side); flex: none; display: flex; flex-direction: column;
  background: var(--bg-1); border-left: 1px solid var(--line);
}
#side.off { display: none; }
#side header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
#side header .t { font-weight: 700; font-size: 13px; letter-spacing: .04em; flex: 1; }
#side header .who { font-size: 11px; color: var(--fg-faint); }
#side header button { font-size: 11px; color: var(--fg-faint); padding: 3px 7px; border-radius: 6px; }
#side header button:hover { background: var(--bg-3); color: var(--fg); }

#log { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 14px; }
.msg { font-size: 13.5px; }
.msg.user { align-self: flex-end; max-width: 88%; background: var(--accent-soft); border: 1px solid #6d8cff44;
  padding: 8px 12px; border-radius: 12px 12px 3px 12px; white-space: pre-wrap; }
.msg.bot { max-width: 100%; }
.msg.bot p { margin: 0 0 8px; }
.msg.bot ul, .msg.bot ol { margin: 0 0 8px 18px; }
.msg.bot li { margin-bottom: 3px; }
.msg.bot code { background: var(--bg-3); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.msg.bot pre { background: var(--bg-3); padding: 10px 12px; border-radius: 9px; overflow-x: auto; margin-bottom: 8px; }
.msg.bot pre code { background: none; padding: 0; }
.msg.bot a { color: var(--accent); }
.msg.bot strong { color: #fff; }
.msg.bot h3, .msg.bot h4 { font-size: 13.5px; margin: 10px 0 5px; }
.msg.bot table { border-collapse: collapse; margin-bottom: 8px; font-size: 12.5px; }
.msg.bot td, .msg.bot th { border: 1px solid var(--line); padding: 4px 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; margin: 0 4px 4px 0;
  padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--fg-dim);
}
.chip.mem { border-color: #4ec9a055; color: var(--good); }
.chip.err { border-color: #e06c7555; color: var(--bad); }
.thinking { color: var(--fg-faint); font-size: 12px; }
.thinking i { font-style: normal; animation: blink 1.2s infinite; }
@keyframes blink { 0%, 100% { opacity: .3 } 50% { opacity: 1 } }

#ask { border-top: 1px solid var(--line); padding: 10px 12px; }
#ask .box {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
}
#ask .box:focus-within { border-color: var(--accent); }
#ask textarea { flex: 1; resize: none; max-height: 140px; line-height: 1.5; }
#ask button {
  flex: none; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #0b0e15; font-weight: 700;
}
#ask button:disabled { opacity: .4; cursor: default; }
#ask .ctx { font-size: 11px; color: var(--fg-faint); padding: 0 4px 6px; display: flex; gap: 6px; }
#ask .ctx b { color: var(--fg-dim); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 모달 ─────────────────────────────────────────── */
#modal {
  position: fixed; inset: 0; z-index: 60; display: none;
  background: #000a; align-items: center; justify-content: center; padding: 30px;
}
#modal.on { display: flex; }
#modal .sheet {
  width: 620px; max-height: 86vh; overflow-y: auto;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 16px; padding: 24px 26px;
}
#modal h2 { font-size: 17px; margin-bottom: 18px; display: flex; justify-content: space-between; }
#modal h2 button { font-size: 18px; color: var(--fg-faint); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 11px; font-size: 13px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .note { font-size: 11px; color: var(--fg-faint); margin-top: 4px; }
.field .note a { color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.actions button { padding: 8px 16px; border-radius: 9px; font-size: 13px; background: var(--bg-3); color: var(--fg-dim); }
.actions button.primary { background: var(--accent); color: #0b0e15; font-weight: 700; }
.actions button:hover { color: var(--fg); }
.actions button.primary:hover { color: #0b0e15; }
#modal pre {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; line-height: 1.7;
}
#modal .status { font-size: 12px; color: var(--fg-dim); margin-top: 10px; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2b3242; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  :root { --side: 100%; }
  #side { position: fixed; inset: 0; z-index: 40; }
}
