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

:root {
  --bg: #000000;
  --surface: #060709;
  --surface-2: #0b0d11;
  --border: #161b24;
  --text: #e8edf5;
  --muted: #6f7b8e;
  --accent: #2f81f7;
  --accent-hover: #4a92ff;
  --accent-dim: #0f2a4d;
  --danger: #e5534b;
  --radius: 12px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

/* Instant-save toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  z-index: 200; padding: 10px 18px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: 0.88rem;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55);
  display: flex; align-items: center; gap: 8px;
  opacity: 0; transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #4caf7d; }
.toast.err::before { background: var(--danger); }

.brand { font-weight: 600; font-size: 1.05rem; letter-spacing: -0.01em; display: inline-flex; align-items: center; gap: 9px; }
.brand-accent { color: var(--accent); }
.logo-mark { width: 22px; height: 22px; color: var(--accent); flex-shrink: 0; }

/* ---------- Landing (single screen, no scroll) ---------- */
#landingView {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.landing-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px 48px;
}
.landing-bar .right { display: flex; gap: 10px; }

.hero {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 24px;
}
.hero-glow {
  display: none;
}
.hero > *:not(.hero-glow) { position: relative; z-index: 1; }

.eyebrow {
  color: var(--accent);
  font-size: 0.85rem;
  letter-spacing: 2px;
  margin-bottom: 18px;
}
.hero-title {
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin-bottom: 20px;
}
.hero-sub {
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 540px;
  margin-bottom: 32px;
}
.hero-features { display: flex; gap: 28px; flex-wrap: wrap; justify-content: center; }
.feat { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
.feat-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* ---------- Buttons ---------- */
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 10px 16px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; width: 100%; margin-top: 18px; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary-sm { background: var(--accent); color: #fff; }
.btn-primary-sm:hover { background: var(--accent-hover); }
.btn-sm { padding: 7px 15px; font-size: 0.85rem; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid transparent; }
.btn-danger:hover { color: #fff; background: var(--danger); }
.link { color: var(--accent); cursor: pointer; background: none; padding: 0; font-weight: 400; }

/* ---------- Auth modal ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal {
  position: relative;
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.modal h2 { font-size: 1.2rem; margin-bottom: 18px; font-weight: 600; letter-spacing: -0.01em; }
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: none; color: var(--muted);
  font-size: 1.4rem; line-height: 1; padding: 4px;
}
.modal-close:hover { color: var(--text); }

/* ---------- Forms ---------- */
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 12px 0 6px; }
input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.switch-line { text-align: center; margin-top: 16px; font-size: 0.88rem; color: var(--muted); }
.msg { font-size: 0.85rem; margin-top: 12px; min-height: 18px; }
.msg.error { color: var(--danger); }
.msg.ok { color: #4caf7d; }

/* ---------- App shell: sidebar layout ---------- */
#appView { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { font-weight: 600; font-size: 1.05rem; padding: 8px 12px 28px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 9px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.side-nav .tab {
  position: relative;
  width: 100%; text-align: left;
  background: transparent; color: var(--muted);
  border: none; border-radius: 6px;
  padding: 9px 13px; font-size: 0.9rem;
  transition: color 0.12s, background 0.12s;
}
.side-nav .tab:hover { color: var(--text); }
.side-nav .tab.active { color: var(--text); background: var(--surface-2); }
.side-nav .tab.active::before {
  content: "";
  position: absolute; left: 0; top: 50%;
  width: 2px; height: 16px;
  background: var(--accent);
  border-radius: 1px;
  transform: translateY(-50%);
}

/* Saved conversations */
.conv-section { flex: 1; display: flex; flex-direction: column; min-height: 0; margin-top: 16px; }
.conv-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 12px 8px; font-size: 0.75rem; color: var(--muted); letter-spacing: 0.04em; }
.conv-new { background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; width: 22px; height: 22px; padding: 0; font-size: 1rem; line-height: 1; display: flex; align-items: center; justify-content: center; }
.conv-new:hover { color: var(--text); border-color: var(--accent); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 6px; cursor: pointer;
  color: var(--muted); font-size: 0.85rem;
}
.conv-item:hover { background: var(--surface-2); color: var(--text); }
.conv-item.active { background: var(--surface-2); color: var(--text); }
.conv-item .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .conv-del { opacity: 0; background: transparent; border: none; color: var(--muted); padding: 2px 4px; font-size: 0.8rem; flex-shrink: 0; }
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-del:hover { color: var(--danger); }
.conv-empty { padding: 8px 12px; font-size: 0.8rem; color: var(--muted); }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; flex-shrink: 0; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; }
.avatar {
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 600; flex-shrink: 0;
  background-size: cover; background-position: center;
}
/* Account-page avatar editor */
.avatar-edit { display: flex; align-items: center; gap: 14px; }
.avatar-lg {
  width: 56px; height: 56px; border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 600; flex-shrink: 0;
  background-size: cover; background-position: center;
}
.avatar-actions { display: flex; flex-direction: column; gap: 6px; }
.user-chip .who { color: var(--text); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.gear-btn {
  flex-shrink: 0;
  width: 30px; height: 30px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 7px;
  transition: color 0.12s, background 0.12s;
}
.gear-btn:hover { color: var(--text); background: var(--surface-2); }
.gear-btn svg { width: 17px; height: 17px; }
.sidebar-foot .btn-ghost { width: 100%; }

/* ---------- Content area ---------- */
.content { flex: 1; padding: 48px 56px; }
.panel { max-width: 940px; margin: 0 auto; }
.panel-head { margin-bottom: 28px; }
.panel-head h2 { font-size: 1.4rem; margin-bottom: 5px; font-weight: 600; letter-spacing: -0.02em; }
.panel-desc { color: var(--muted); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card-narrow { max-width: 440px; }
.card-title { font-size: 0.95rem; margin-bottom: 10px; font-weight: 600; }

/* Account info rows */
.account-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.account-col { min-width: 0; }
.info-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.info-row:last-child { border-bottom: none; }
.info-row-top { align-items: flex-start; }
.info-label { color: var(--muted); }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; transition: background 0.15s, border-color 0.15s;
}
.slider::before {
  content: ""; position: absolute; left: 3px; top: 50%;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transform: translateY(-50%);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translate(16px, -50%); background: #fff; }

/* API key UI */
.api-base { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.api-base code, .key-reveal code, .key-row code {
  font-family: ui-monospace, monospace; font-size: 0.82rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; color: var(--text);
  word-break: break-all;
}
.key-gen { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.key-gen select { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.85rem; cursor: pointer; }
.key-gen input { flex: 1; min-width: 140px; width: auto; padding: 8px 10px; font-size: 0.85rem; }

.key-reveal { margin-top: 14px; padding: 12px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent-dim); }
.key-reveal-warn { font-size: 0.8rem; color: #8cb8f5; margin-bottom: 8px; }
.key-reveal-row { display: flex; gap: 8px; align-items: stretch; }
.key-reveal-row code { flex: 1; }

.key-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.key-row {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
}
.key-row-top { display: flex; align-items: center; gap: 10px; }
.key-row .k-prefix {
  font-family: ui-monospace, monospace; font-size: 0.85rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; color: var(--text);
  word-break: break-all;
}
.key-row .k-name { font-size: 0.85rem; color: var(--muted); }
.key-row .k-used { font-size: 0.75rem; color: var(--muted); }
.key-row .spacer { flex: 1; }

h2 { font-size: 1.1rem; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; }
/* Fixed column widths so headers line up with cells */
table th:nth-child(1), table td:nth-child(1) { width: 56px; }
table th:nth-child(2), table td:nth-child(2) { width: 140px; }
table th:nth-child(4), table td:nth-child(4) { width: 96px; }
.badge { display: inline-flex; align-items: center; font-size: 0.72rem; padding: 3px 9px; border-radius: 5px; background: var(--accent-dim); color: #8cb8f5; border: 1px solid rgba(47,129,247,0.25); }
.row-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Chat (Claude-style) ---------- */
.chat-panel { display: flex; flex-direction: column; height: calc(100vh - 96px); padding: 0; max-width: 760px; margin: 0 auto; }
.chat-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; padding: 8px 0; }

.chat-greeting {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  font-family: Georgia, "Times New Roman", "Songti TC", serif;
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--text);
  min-height: 200px;
}
.greet-mark { width: 0.92em; height: 0.92em; color: var(--accent); flex-shrink: 0; }

.chat-box { padding: 8px 4px 20px; }
.bubble { max-width: 88%; padding: 12px 16px; border-radius: 14px; margin-bottom: 14px; white-space: pre-wrap; font-size: 0.95rem; line-height: 1.65; }
.bubble.user { background: var(--accent-dim); color: var(--text); margin-left: auto; }
.bubble.assistant { background: var(--surface); border: 1px solid var(--border); }

.composer-wrap { padding: 8px 0 24px; }
.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px 10px;
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  width: 100%; border: none; background: transparent;
  color: var(--text); font-size: 0.98rem; line-height: 1.6;
  resize: none; outline: none; font-family: inherit;
  max-height: 200px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.composer-model { font-size: 0.78rem; color: var(--muted); }

/* Model picker (Claude / ChatGPT style) */
.model-picker { position: relative; }
.model-trigger {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 0.82rem; font-weight: 500;
}
.model-trigger:hover { background: var(--surface-2); }
.model-trigger:disabled { color: var(--muted); cursor: not-allowed; opacity: 0.6; }
.model-trigger .chev { width: 13px; height: 13px; color: var(--muted); transition: transform 0.15s; }
.model-trigger[aria-expanded="true"] .chev { transform: rotate(180deg); }
.model-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }

.model-menu {
  position: absolute; bottom: calc(100% + 8px); left: 0;
  min-width: 240px; max-height: 320px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  z-index: 50;
}
.model-menu-group { padding: 8px 10px 4px; font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; display: flex; align-items: center; gap: 6px; }
.model-menu-group .dot { width: 7px; height: 7px; border-radius: 50%; }
.model-option {
  display: flex; align-items: center; gap: 8px; width: 100%;
  text-align: left; background: transparent; color: var(--text);
  border: none; border-radius: 8px; padding: 9px 10px; font-size: 0.88rem;
}
.model-option:hover { background: var(--surface-2); }
.model-option .check { margin-left: auto; color: var(--accent); opacity: 0; }
.model-option.selected .check { opacity: 1; }

.send-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff;
  font-size: 1.1rem; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--surface-2); color: var(--muted); cursor: default; }

.notice { color: var(--muted); font-size: 0.85rem; padding: 8px 0; text-align: center; }

/* ---------- Group badges (Discord-style) ---------- */
.group-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.gbadge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.72rem; padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; user-select: none;
  background: var(--surface-2); color: var(--muted);
  transition: opacity 0.12s;
}
.gbadge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.gbadge.on { color: #fff; }
.gbadge.off { opacity: 0.45; }
.gbadge.off:hover { opacity: 0.7; }

/* ---------- Model management ---------- */
.model-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.model-add select, .model-add input {
  width: auto; padding: 8px 10px; font-size: 0.85rem;
}
.model-add #newModelId { flex: 1; min-width: 180px; }
.model-add #newModelLabel { flex: 1; min-width: 160px; }
.model-add select { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }

.model-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.model-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
}
.model-row .gbadge { cursor: default; }
.model-row .m-label { font-size: 0.9rem; }
.model-row .m-id { font-size: 0.78rem; color: var(--muted); font-family: ui-monospace, monospace; }
.model-row .spacer { flex: 1; }

/* ---------- Docs ---------- */
.doc-body { line-height: 1.7; }
.doc-body h3 { font-size: 1rem; margin: 18px 0 8px; font-weight: 600; }
.doc-body h3:first-child { margin-top: 0; }
.doc-body p { color: var(--text); margin-bottom: 12px; }
.doc-body ul, .doc-body ol { margin: 0 0 12px 20px; color: var(--text); }
.doc-body li { margin-bottom: 6px; }
.doc-body code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; font-family: ui-monospace, monospace; font-size: 0.85em; }
.doc-body pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; overflow-x: auto; margin-bottom: 14px; }
.doc-body pre code { background: none; border: none; padding: 0; }
.doc-body a { color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  #appView { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar-brand { padding: 6px 12px; }
  .side-nav { flex-direction: row; flex: 1 1 100%; }
  .sidebar-foot { border-top: none; padding-top: 0; display: flex; align-items: center; gap: 12px; }
  .user-chip { padding: 0; }
  .content { padding: 24px; }
  .account-grid { grid-template-columns: 1fr; }
}
