@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --bg: #0b0b0b;
  --panel: #171717;
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f5f5f5;
  --muted: #a3a3a3;
  --accent: #a3a3a3;
  --accent-bright: #f5f5f5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 8%, #202020 0, var(--bg) 50%);
  font-family: 'DM Sans', sans-serif;
}

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 76px;
  padding: 0 clamp(20px, 6vw, 88px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(169, 184, 214, 0.09);
}
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; font: 700 17px 'Manrope', sans-serif; letter-spacing: -0.4px; }
.brand strong { color: var(--accent-bright); }
.brand-mark, .avatar { display: grid; place-items: center; flex: 0 0 auto; font-family: 'Manrope', sans-serif; font-weight: 800; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; color: #111; background: #f5f5f5; }
.status { display: flex; align-items: center; gap: 8px; color: #b6bfd1; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #68dba3; box-shadow: 0 0 12px #68dba377; }

.workspace { min-height: 0; flex: 1; display: flex; position: relative; }
.chat-layout { width: min(1000px, 100%); min-width: 0; flex: 1; display: flex; flex-direction: column; margin: auto; padding: 28px clamp(18px, 4vw, 50px); }
.chat-card { min-height: min(68vh, 680px); flex: 1; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--panel-border); border-radius: 20px; background: rgba(17, 24, 39, 0.82); box-shadow: 0 22px 70px #0003; }
.messages { min-height: 0; flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.message { display: flex; align-items: flex-start; gap: 11px; }
.avatar { width: 29px; height: 29px; border-radius: 9px; color: #111; background: #f5f5f5; font-size: 13px; }
.bubble { max-width: min(85%, 570px); padding: 11px 14px; color: #f1f1f1; background: #202020; border: 1px solid #ffffff0c; border-radius: 4px 14px 14px; font-size: 14px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.user-message { justify-content: flex-end; }
.user-message .bubble { color: #111; background: #f5f5f5; border: 0; border-radius: 14px 4px 14px 14px; }
.composer { margin: 0 14px; padding: 10px 10px 10px 15px; display: flex; align-items: flex-end; gap: 12px; border: 1px solid #ffffff1a; border-radius: 15px; background: #111; }
textarea { width: 100%; min-height: 26px; max-height: 130px; resize: none; border: 0; outline: 0; color: var(--text); background: transparent; font: 14px/1.6 'DM Sans', sans-serif; }
textarea::placeholder { color: #7f899e; }
#send-button { min-width: 80px; height: 38px; display: flex; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 10px; color: #111; background: #f5f5f5; font: 700 13px 'DM Sans', sans-serif; cursor: pointer; transition: opacity .2s, transform .2s; }
#send-button:hover { transform: translateY(-1px); }
#send-button:disabled { opacity: .55; cursor: wait; transform: none; }
.hint { margin: 12px 18px 15px; color: #778197; text-align: center; font-size: 11px; line-height: 1.5; }
.site-footer { padding: 18px 20px 21px; display: flex; flex-wrap: wrap; justify-content: center; gap: 7px 18px; border-top: 1px solid rgba(169, 184, 214, 0.09); color: #8993a8; text-align: center; font-size: 12px; }
.site-footer a { color: #c4b5fd; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

#topbar-actions { display: flex; align-items: center; gap: 10px; }
.toolbar-button { min-height: 36px; padding: 0 12px; border: 1px solid var(--panel-border); border-radius: 10px; color: var(--text); background: rgba(17, 24, 39, 0.75); font: 600 12px 'DM Sans', sans-serif; cursor: pointer; }
.toolbar-button:hover { border-color: var(--accent); }
.history-panel { width: 260px; min-width: 220px; min-height: 0; flex: 0 0 260px; overflow-y: auto; padding: 24px 14px; border-right: 1px solid var(--panel-border); background: rgba(10, 14, 25, 0.55); }
.history-panel[hidden] { display: none; }
.history-panel h2 { margin: 0 0 16px 8px; font: 700 16px 'Manrope', sans-serif; }
.new-chat-button { width: 100%; min-height: 40px; margin: 0 0 18px; padding: 0 12px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--panel-border); border-radius: 10px; color: var(--text); background: transparent; text-align: left; font: 600 13px 'DM Sans', sans-serif; cursor: pointer; }
.new-chat-button:hover { background: rgba(255, 255, 255, 0.08); }
.history-list { display: flex; flex-direction: column; gap: 5px; }
.history-entry { width: 100%; padding: 10px 11px; border: 1px solid transparent; border-radius: 9px; color: var(--text); background: transparent; text-align: left; font: 13px/1.45 'DM Sans', sans-serif; cursor: pointer; }
.history-entry:hover { border-color: var(--panel-border); background: rgba(255, 255, 255, 0.06); }
.history-entry.active { border-color: var(--panel-border); background: rgba(255, 255, 255, 0.1); }
.history-entry strong { display: block; margin-bottom: 3px; color: var(--accent-bright); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.history-empty { padding: 0 8px; color: var(--muted); font-size: 13px; }

body[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-border: rgba(0, 0, 0, 0.12);
  --text: #171717;
  --muted: #737373;
  --accent: #525252;
  --accent-bright: #262626;
  background: #fff;
}
body[data-theme="light"] .topbar,
body[data-theme="light"] .site-footer { border-color: rgba(48, 58, 82, 0.12); }
body[data-theme="light"] .status { color: #586278; }
body[data-theme="light"] .chat-card { background: rgba(255, 255, 255, 0.9); box-shadow: 0 22px 70px #29365a1a; }
body[data-theme="light"] .history-panel { background: rgba(255, 255, 255, 0.7); }
body[data-theme="light"] .history-entry:hover { background: #eef1f8; }
body[data-theme="light"] .bubble { color: #30384b; background: #eef1f8; border-color: #27314a12; }
body[data-theme="light"] .user-message .bubble { color: #fff; background: #171717; }
body[data-theme="light"] .brand-mark,
body[data-theme="light"] .avatar { color: #fff; background: #171717; }
body[data-theme="light"] .composer,
body[data-theme="light"] .toolbar-button { color: var(--text); background: #fff; border-color: rgba(0, 0, 0, 0.16); }
body[data-theme="light"] #send-button { color: #fff; background: #171717; }
body[data-theme="light"] textarea { color: var(--text); }
body[data-theme="light"] textarea::placeholder { color: #818ba0; }
body[data-theme="light"] .site-footer { color: #69738a; }
body[data-theme="light"] .history-entry { color: var(--text); background: #f2f4fa; }
body[data-theme="light"] .history-entry.active { background: #e5e5e5; }
body[data-theme="light"] .new-chat-button:hover { background: #f2f2f2; }

@media (max-width: 520px) {
  .topbar-actions { gap: 6px; }
  .status { font-size: 0; gap: 0; }
  .toolbar-button { min-height: 34px; padding: 0 9px; font-size: 11px; }
  .history-panel { position: absolute; z-index: 3; top: 0; bottom: 0; width: min(280px, 82vw); min-width: 0; box-shadow: 12px 0 32px #0004; }
  .topbar { height: 66px; padding: 0 18px; }
  .chat-layout { padding: 18px 12px; }
  .chat-card { min-height: 70vh; }
  .messages { padding: 16px; }
  .composer { margin: 0 9px; padding-left: 11px; }
  #send-button { min-width: 68px; }
  .site-footer { flex-direction: column; gap: 6px; }
}
