:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1a1f26;
  --text: #e6e8eb;
  --muted: #8a93a0;
  --accent: #3b82f6;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --border: #262c35;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "SF Pro Text", "Pretendard", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }
button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
button:hover { background: var(--border); }
button.primary { background: var(--accent); border-color: var(--accent); }
input, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 6px;
}
.hidden { display: none !important; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-card h1 { margin: 0 0 4px; font-size: 28px; }
.login-card .tagline { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login-card form { display: grid; gap: 12px; }
.login-card label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.login-card button { padding: 10px; margin-top: 4px; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.err { color: var(--err); min-height: 18px; font-size: 12px; }

/* top */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.top h1 { font-size: 16px; margin: 0; }
.top-right { display: flex; gap: 8px; align-items: center; }
.top-right #user { color: var(--muted); font-size: 12px; }
.back { color: var(--muted); }

/* card grid */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  padding: 24px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: transform .08s, border-color .08s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card h2 { font-size: 18px; margin: 0 0 4px; }
.card .tagline { color: var(--muted); font-size: 12px; min-height: 32px; }
.card .meta { display: flex; justify-content: space-between; margin-top: 12px; font-size: 11px; color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.badge.alive { background: rgba(16,185,129,.2); color: var(--ok); }
.badge.dead { background: rgba(239,68,68,.2); color: var(--err); }
.stack { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.stack span { font-size: 10px; background: var(--panel-2); padding: 2px 6px; border-radius: 4px; color: var(--muted); }

/* chat layout */
.chat-body { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.chat-body main { flex: 1; overflow: hidden; min-height: 0; }
.chat-layout { display: grid; grid-template-columns: 320px 1fr; height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.doc-tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 8px; border-bottom: 1px solid var(--border); }
.doc-tabs button { padding: 4px 8px; font-size: 11px; }
.doc-tabs button.active { background: var(--accent); border-color: var(--accent); }
.doc-view { flex: 1; overflow: auto; padding: 16px; font-size: 13px; line-height: 1.6; }
.doc-view pre { background: var(--panel-2); padding: 8px; border-radius: 4px; overflow: auto; font-size: 11px; }
.doc-view code { background: var(--panel-2); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.doc-view h1, .doc-view h2, .doc-view h3 { border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.doc-view table { border-collapse: collapse; width: 100%; font-size: 12px; }
.doc-view th, .doc-view td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }

/* chat mode */
.chat-main { display: flex; flex-direction: column; height: 100%; overflow: hidden; min-width: 0; }
.log-pane { flex: 0 0 30%; display: flex; flex-direction: column; background: var(--panel); border-bottom: 1px solid var(--border); overflow: hidden; min-height: 120px; }
.log-head { padding: 6px 12px; font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--panel-2); }
.log-body { flex: 1; overflow: auto; padding: 6px 12px; font-family: Menlo, Monaco, monospace; font-size: 11px; line-height: 1.6; }
.log-line { display: flex; gap: 8px; align-items: baseline; padding: 1px 0; }
.log-line .ts { color: var(--muted); font-size: 10px; min-width: 62px; }
.log-line .tool { font-weight: 600; min-width: 90px; color: var(--accent); }
.log-line .tool.err { color: var(--err); }
.log-line .detail { color: var(--text); opacity: .7; word-break: break-all; }

.chat-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.chat-body-scroll { flex: 1; overflow: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; max-width: 88%; }
.msg-user { align-self: flex-end; justify-content: flex-end; }
.msg-assistant { align-self: flex-start; }
.msg .bubble { padding: 10px 14px; border-radius: 14px; line-height: 1.55; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.msg-user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-assistant .bubble { background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-assistant .bubble p { margin: 0 0 8px; }
.msg-assistant .bubble p:last-child { margin-bottom: 0; }
.msg-assistant .bubble pre { background: var(--bg); padding: 8px; border-radius: 6px; overflow: auto; font-size: 12px; }
.msg-assistant .bubble code { background: var(--bg); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.msg .meta { font-size: 10px; color: var(--muted); margin-top: 2px; }

.chat-input { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--panel); }
.chat-input textarea { flex: 1; resize: none; font-family: inherit; font-size: 13.5px; line-height: 1.4; padding: 8px 10px; }
.chat-input button { padding: 0 20px; background: var(--accent); border-color: var(--accent); font-weight: 600; }

.panes { display: flex; flex-direction: row; overflow: hidden; height: 100%; }
.pane { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; position: relative; border-left: 1px solid var(--border); }
.pane:first-child { border-left: none; }
.pane-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px; background: var(--panel); border-bottom: 1px solid var(--border); }
.pane-product { font-size: 12px; padding: 2px 6px; }
.pane .term { flex: 1; overflow: hidden; padding: 4px; }
.inline-approval {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--warn); color: #1a1200; padding: 12px;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600;
}
.inline-approval button { background: #1a1200; color: var(--warn); border: none; }

/* dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 12px; max-width: 800px; width: 90vw; padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dlg-head { display: flex; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 15px; }
dialog ul { list-style: none; margin: 0; padding: 12px 16px; max-height: 200px; overflow: auto; }
dialog li { padding: 8px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; cursor: pointer; font-size: 12px; }
dialog li.active { border-color: var(--accent); background: var(--panel-2); }
dialog pre { background: var(--panel-2); padding: 12px; margin: 0 16px; border-radius: 6px; max-height: 300px; overflow: auto; font-size: 11px; }
.dlg-actions { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); justify-content: flex-end; align-items: center; }
.dlg-actions label { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--warn); color: #1a1200;
  padding: 12px 16px; border-radius: 8px;
  font-weight: 600; z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
