:root {
  color-scheme: light dark;
  --bg: #f3f3f4;
  --surface: #ffffff;
  --fg: #1a1a1a;
  --muted: #7c7c85;
  --border: #e6e6e9;
  --yellow: #ffdb4d;
  --yellow-strong: #ffcc00;
  --bubble-user: var(--yellow);
  --bubble-user-fg: #1a1a1a;
  --bubble-assistant: var(--surface);
  --accent: #1a1a1a;
  --shadow: 0 1px 2px rgba(20,20,20,0.06), 0 4px 16px rgba(20,20,20,0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --surface: #212227;
    --fg: #f0f0f1;
    --muted: #9a9aa3;
    --border: #303136;
    --bubble-assistant: var(--surface);
    --bubble-user-fg: #1a1a1a;
    --accent: #ffdb4d;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.35);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Golos Text", -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

/* login */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-box {
  display: flex; flex-direction: column; gap: 12px; width: 300px; padding: 28px;
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
}
.login-box h1 { margin: 0 0 8px; font-size: 1.5rem; font-weight: 700; text-align: center; }
.login-box input {
  padding: 12px 16px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font-size: 1rem; font-family: inherit;
}
.login-box button {
  padding: 12px 16px; border-radius: 14px; border: none;
  background: var(--yellow); color: #1a1a1a; font-size: 1rem; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: background .15s ease;
}
.login-box button:hover { background: var(--yellow-strong); }
.login-error { color: #dc2626; font-size: 0.85rem; text-align: center; margin: 0; }

/* layout */
.layout { display: flex; height: 100vh; overflow: hidden; }
.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; background: var(--surface); box-shadow: var(--shadow); z-index: 1;
}
.chat-header .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.chat-header .brand .dot {
  width: 22px; height: 22px; border-radius: 50%; background: var(--yellow);
  display: flex; align-items: center; justify-content: center; font-size: 0.75rem;
}
.chat-header button {
  background: var(--bg); border: none; color: var(--fg); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; margin-left: 6px; font-family: inherit;
  font-size: 0.85rem; font-weight: 500; transition: background .15s ease;
}
.chat-header button:hover { background: var(--yellow); }
.chat-header .icon-btn {
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: transparent; font-size: 1rem; color: var(--muted);
}
.chat-header .icon-btn:hover { background: var(--bg); color: var(--fg); }
.chat-header .icon-btn.open { transform: rotate(180deg); }

#modelSelect {
  background: var(--bg); border: none; color: var(--fg); border-radius: 999px;
  padding: 8px 12px; cursor: pointer; font-family: inherit; font-size: 0.85rem;
  font-weight: 500;
}

.usage-note { margin-top: 6px; font-size: 0.72rem; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }

.msg-row { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.avatar {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  background: var(--yellow); color: #1a1a1a;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; box-shadow: var(--shadow);
}

.bubble {
  max-width: 74%; padding: 12px 16px; border-radius: 20px; line-height: 1.5;
  overflow-wrap: break-word; box-shadow: var(--shadow);
}
.bubble pre { overflow-x: auto; background: rgba(127,127,127,0.14); padding: 10px; border-radius: 12px; }
.bubble code { font-size: 0.85em; }
.bubble.user { background: var(--bubble-user); color: var(--bubble-user-fg); border-bottom-right-radius: 6px; }
.bubble.assistant { background: var(--bubble-assistant); border-bottom-left-radius: 6px; }
.bubble .badge { display: block; font-size: 0.68rem; opacity: 0.55; margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.composer {
  display: flex; align-items: center; gap: 8px; margin: 12px 16px 16px;
  padding: 8px; background: var(--surface); border-radius: 26px; box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 10px 8px; border-radius: 16px;
  border: none; background: transparent; color: var(--fg); font-size: 1rem;
  font-family: inherit; outline: none;
}
.composer button[type="submit"] {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--yellow); color: #1a1a1a; cursor: pointer; font-size: 0;
  display: flex; align-items: center; justify-content: center; transition: background .15s ease;
}
.composer button[type="submit"]::after { content: "➤"; font-size: 1.05rem; }
.composer button[type="submit"]:hover { background: var(--yellow-strong); }
.composer button:disabled { opacity: 0.5; cursor: default; }
#micBtn {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--bg); cursor: pointer; font-size: 1.1rem; transition: background .15s ease;
}
#micBtn:hover { background: var(--border); }
#micBtn.active { background: #dc2626; color: #fff; }

.system-message { align-self: center; text-align: center; font-size: 0.76rem; color: var(--muted); margin: 4px 0; }
.retry-row { margin-top: 8px; }
.retry-row button {
  padding: 6px 14px; border-radius: 999px; border: none; background: rgba(127,127,127,0.15);
  color: inherit; cursor: pointer; font-size: 0.82rem; font-family: inherit;
}

/* files panel */
.files-panel { width: 300px; background: var(--surface); display: none; flex-direction: column; overflow: hidden; }
.files-panel.open { display: flex; }
.files-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; font-weight: 700; }
.files-header button { border: none; background: var(--bg); border-radius: 50%; width: 30px; height: 30px; color: var(--fg); cursor: pointer; font-size: 1rem; }
.files-path { padding: 4px 16px 10px; font-size: 0.78rem; color: var(--muted); word-break: break-all; }
.files-list { overflow-y: auto; flex: 0 1 auto; padding: 0 8px; }
.files-list div { padding: 8px 10px; border-radius: 12px; cursor: pointer; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.files-list div:hover { background: var(--bg); }
.file-content { flex: 1; margin: 8px; padding: 12px; overflow: auto; font-size: 0.8rem; background: var(--bg); border-radius: 14px; white-space: pre-wrap; }

@media (max-width: 720px) {
  .files-panel.open { position: fixed; inset: 0; width: 100%; z-index: 10; }
}
