:root {
  --bg: #f6f7f9;
  --bar: #1f2430;
  --bar-text: #f6f7f9;
  --accent: #4f6bed;
  --accent-text: #fff;
  --border: #e2e5ea;
  --muted: #6b7280;
  --user: #4f6bed;
  --assistant: #eef0f4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: #1f2430;
}

/* App container — owns the full viewport (no top bar). */
#app { min-height: 100vh; }

/* Drawers (chat + settings) */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 100vw);
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.drawer[hidden] { display: none; }

.drawer-head {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.iconbtn {
  background: transparent; border: none; font-size: 20px; line-height: 1;
  cursor: pointer; color: var(--muted); padding: 2px 4px;
}
.iconbtn:hover { color: #1f2430; }
.head-actions { display: flex; align-items: center; gap: 2px; }

/* Chat */
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user { align-self: flex-end; background: var(--user); color: #fff; border-bottom-right-radius: 3px; }
.bubble.assistant { align-self: flex-start; background: var(--assistant); border-bottom-left-radius: 3px; }

/* Rendered markdown inside assistant bubbles */
.bubble.assistant { white-space: normal; }
.bubble.assistant > :first-child { margin-top: 0; }
.bubble.assistant > :last-child { margin-bottom: 0; }
.bubble.assistant p { margin: 0 0 8px; }
.bubble.assistant h1, .bubble.assistant h2, .bubble.assistant h3,
.bubble.assistant h4, .bubble.assistant h5, .bubble.assistant h6 { margin: 10px 0 6px; line-height: 1.25; }
.bubble.assistant h1 { font-size: 1.25em; }
.bubble.assistant h2 { font-size: 1.15em; }
.bubble.assistant h3 { font-size: 1.05em; }
.bubble.assistant h4, .bubble.assistant h5, .bubble.assistant h6 { font-size: 1em; }
.bubble.assistant ul, .bubble.assistant ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble.assistant li { margin: 2px 0; }
.bubble.assistant li > ul, .bubble.assistant li > ol { margin: 2px 0 2px; }
.bubble.assistant strong { font-weight: 700; }
.bubble.assistant a { color: var(--accent); }
.bubble.assistant code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}
.bubble.assistant pre {
  background: #1f2430;
  color: #eef0f4;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
}
.bubble.assistant pre code { background: none; padding: 0; color: inherit; font-size: 0.85em; }
.bubble.assistant blockquote {
  margin: 6px 0;
  padding: 2px 10px;
  border-left: 3px solid var(--muted);
  color: var(--muted);
}
.bubble.assistant hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble.tool { align-self: center; background: #fff8e1; border: 1px solid #f2e2a8; color: #7a5c00; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; max-width: 95%; }

.status { padding: 0 16px 8px; color: var(--muted); font-size: 13px; min-height: 18px; }

.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }

/* Settings */
.settings-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.settings-body label { font-size: 13px; font-weight: 600; margin-top: 8px; }
#settings-anthropic, #settings-openrouter { display: flex; flex-direction: column; gap: 8px; }
#settings-anthropic[hidden], #settings-openrouter[hidden] { display: none; }
.settings-body input, .settings-body select {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.settings-sep { border: none; border-top: 1px solid var(--border); margin: 14px 0 4px; }
button.danger {
  background: #fff;
  color: #c0392b;
  border: 1px solid #e3b0a8;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
}
button.danger:hover { background: #fdecea; }

/* Shared button */
button.primary {
  background: var(--accent); color: var(--accent-text);
  border: 1px solid var(--accent); border-radius: 8px;
  padding: 9px 16px; font-size: 14px; cursor: pointer;
}
button.primary:hover { filter: brightness(1.06); }
button:disabled { opacity: 0.6; cursor: default; }

/* Clippy assistant (bottom-right) + its chat bubble */
#clippy-wrap {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}
#clippy {
  cursor: pointer;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
  transition: transform 0.15s ease;
}
#clippy:hover { transform: translateY(-2px) scale(1.03); }
#clippy:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }

.bubble-panel {
  width: min(400px, calc(100vw - 40px));
  height: min(560px, calc(100vh - 160px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: bubble-in 0.16s ease-out;
  position: relative;
}
.bubble-panel[hidden] { display: none; }
/* Tail pointing down toward Clippy */
.bubble-panel::after {
  content: "";
  position: absolute;
  bottom: -9px;
  right: 30px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: rotate(45deg);
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Master-password gate */
#login-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
#login-gate[hidden] { display: none; }
#login-form {
  width: min(340px, calc(100vw - 40px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
#login-form h1 { margin: 0; font-size: 22px; }
#login-form p { margin: 0; color: var(--muted); font-size: 14px; }
#login-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
#login-form .login-error { color: #c0392b; font-size: 13px; }
#login-form .login-error[hidden] { display: none; }
