:root {
  color-scheme: dark;
  --bg: #080c16;
  --panel: #0e1422;
  --panel-2: #131b2c;
  --ink: #edf3ff;
  --muted: #94a3b8;
  --line: #263248;
  --accent: #6da8ff;
  --accent-2: #8b5cf6;
  --danger: #ff6b7a;
  --shadow: 0 20px 60px rgba(0, 0, 0, .42);
  --text-scale: 100%;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-2: #edf2f8;
  --ink: #172033;
  --muted: #5b687c;
  --line: #d5deea;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --danger: #c92a3a;
  --shadow: 0 20px 55px rgba(24, 39, 75, .16);
}

* { box-sizing: border-box; }
html { font-size: var(--text-scale); }
html, body { height: 100%; margin: 0; }
body { overflow: hidden; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif; }
button, select, textarea, input { font: inherit; }
button, select { color: inherit; }
button { cursor: pointer; }

.app { display: flex; height: 100dvh; }
.sidebar { width: 285px; flex: 0 0 285px; display: flex; flex-direction: column; gap: 14px; padding: 16px; background: var(--panel); border-right: 1px solid var(--line); transition: margin-left .24s ease; z-index: 30; }
.sidebar-collapsed .sidebar { margin-left: -285px; }
.sidebar-head, .modal-head, .topbar, .mode-row, .composer, .attachment-tray, .check-row { display: flex; align-items: center; }
.sidebar-head, .modal-head { justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.brand-mark, .welcome-mark { display: inline-grid; place-items: center; color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 24px rgba(83, 114, 255, .32); }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; }
.sidebar-label { margin-top: 8px; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.session-list { flex: 1; min-height: 0; overflow-y: auto; }
.session-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: center; margin-bottom: 5px; padding: 10px 8px 10px 12px; border-radius: 10px; color: var(--muted); }
.session-item:hover, .session-item.active { background: var(--panel-2); color: var(--ink); }
.session-item.active { box-shadow: inset 3px 0 var(--accent); }
.session-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; }
.session-delete { border: 0; background: transparent; color: inherit; opacity: .55; }
.session-delete:hover { color: var(--danger); opacity: 1; }
.sidebar-foot { display: grid; gap: 8px; }

.main { position: relative; min-width: 0; flex: 1; display: flex; flex-direction: column; }
.topbar { position: relative; min-height: 62px; padding: 10px 18px; gap: 12px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(18px); z-index: 20; }
.top-title { min-width: 0; display: flex; flex-direction: column; }
.top-title strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.top-title span { color: var(--muted); font-size: .72rem; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.icon-button, .top-button, .composer-button, .quiet, .primary, .send-button { border: 1px solid var(--line); border-radius: 10px; background: transparent; }
.icon-button { width: 38px; height: 38px; font-size: 1.25rem; }
.top-button { min-height: 40px; padding: 0 13px; }
.top-button:hover, .icon-button:hover, .quiet:hover, .composer-button:hover { background: var(--panel-2); }
.primary, .send-button { border-color: transparent; color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 750; }
.primary, .quiet { display: inline-flex; justify-content: center; align-items: center; min-height: 42px; padding: 0 14px; text-decoration: none; }
.wide { width: 100%; }
.danger { color: var(--danger); }

.popover { position: absolute; right: 16px; top: 57px; width: min(320px, calc(100vw - 32px)); padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); }
.popover label, .modal-card > label { display: block; margin: 5px 0 7px; color: var(--muted); font-size: .8rem; font-weight: 750; }
select, .modal-card input[type="range"] { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.check-row { gap: 9px; margin: 14px 0 !important; color: var(--ink) !important; font-weight: 500 !important; }
.check-row input { width: 18px; height: 18px; }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 28px max(18px, calc((100% - 920px) / 2)); scroll-behavior: smooth; }
.welcome { max-width: 650px; margin: 13vh auto 0; text-align: center; color: var(--muted); }
.welcome-mark { width: 70px; height: 70px; border-radius: 24px; margin-bottom: 18px; font-size: 2rem; font-weight: 900; }
.welcome h1 { margin: 0 0 10px; color: var(--ink); font-size: clamp(1.9rem, 5vw, 3rem); }
.welcome p { line-height: 1.7; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; max-width: 900px; margin: 0 auto 22px; }
.message.user { grid-template-columns: minmax(0, 1fr); }
.avatar { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); font-size: .8rem; font-weight: 900; }
.message-body { min-width: 0; }
.message.user .message-body { justify-self: end; max-width: min(760px, 88%); padding: 12px 15px; border-radius: 16px 16px 4px 16px; background: #234781; color: white; }
.message-text { line-height: 1.68; overflow-wrap: anywhere; }
.message-text > :first-child { margin-top: 0; }
.message-text > :last-child { margin-bottom: 0; }
.message-text pre { position: relative; overflow-x: auto; padding: 38px 14px 14px; border: 1px solid var(--line); border-radius: 11px; background: #070b13; color: #e6edf7; }
.copy-code { position: absolute; right: 8px; top: 7px; padding: 5px 8px; border: 1px solid #2b374c; border-radius: 7px; color: #bdc9da; background: #111928; }
.message-text code:not(pre code) { padding: .14em .35em; border-radius: 5px; background: var(--panel-2); }
.message-text table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.message-text th, .message-text td { padding: 8px 10px; border: 1px solid var(--line); }
.message-image { display: block; max-width: min(100%, 680px); max-height: 680px; margin: 8px 0; border: 1px solid var(--line); border-radius: 14px; object-fit: contain; background: var(--panel-2); cursor: zoom-in; }
.message-tools { display: flex; gap: 8px; margin-top: 8px; }
.message-tools button { border: 0; background: transparent; color: var(--muted); padding: 4px; }
.message-tools button:hover { color: var(--accent); }
.thinking { color: var(--muted); }
.thinking::after { content: ''; animation: dots 1.2s infinite; }
@keyframes dots { 0% { content: ''; } 33% { content: '.'; } 66% { content: '..'; } 100% { content: '...'; } }

.attachment-tray { width: min(920px, calc(100% - 32px)); margin: 0 auto 8px; gap: 12px; padding: 9px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.attachment-tray[hidden] { display: none !important; }
.attachment-tray img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; }
.attachment-tray div { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.attachment-tray strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.attachment-tray span { color: var(--muted); font-size: .75rem; }
.composer-wrap { position: relative; padding: 10px max(16px, calc((100% - 920px) / 2)) max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.mode-row { gap: 9px; margin-bottom: 8px; color: var(--muted); font-size: .78rem; }
.mode-row label { font-weight: 800; }
.mode-row select { width: auto; min-height: 34px; padding: 4px 8px; }
.mode-row span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.composer { gap: 9px; padding: 8px; border: 1px solid var(--line); border-radius: 16px; background: var(--bg); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.composer-button { flex: 0 0 42px; height: 42px; font-size: 1.15rem; }
.composer-button.recording { color: white; border-color: var(--danger); background: var(--danger); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
.composer textarea { min-height: 42px; max-height: 180px; flex: 1; resize: none; padding: 9px 4px; border: 0; outline: 0; color: var(--ink); background: transparent; line-height: 1.45; }
.send-button { align-self: flex-end; min-width: 76px; height: 42px; }
.send-button:disabled, button:disabled { cursor: not-allowed; opacity: .55; }
.fine-print { margin-top: 6px; color: var(--muted); text-align: center; font-size: .68rem; }
.drop-hint { position: absolute; inset: -130px 16px 8px; display: none; place-items: center; border: 2px dashed var(--accent); border-radius: 16px; color: var(--accent); background: color-mix(in srgb, var(--panel) 92%, transparent); font-size: 1.2rem; font-weight: 800; z-index: 10; }
body.dragging .drop-hint { display: grid; }

.modal, .lightbox { position: fixed; inset: 0; z-index: 100; place-items: center; padding: 18px; background: rgba(2, 6, 14, .78); backdrop-filter: blur(8px); }
.modal:not([hidden]), .lightbox:not([hidden]) { display: grid; }
.modal-card { width: min(460px, 100%); padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.modal-card h2 { margin: 0; }
.modal-card select, .modal-card input[type="range"] { margin-bottom: 14px; }
.settings-note { color: var(--muted); font-size: .78rem; line-height: 1.5; }
.lightbox img { max-width: 94vw; max-height: 82vh; object-fit: contain; }
.lightbox-actions { display: flex; justify-content: center; gap: 10px; margin-top: 14px; }

@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 315px); flex-basis: min(86vw, 315px); margin-left: 0; transform: translateX(0); box-shadow: var(--shadow); }
  .sidebar-collapsed .sidebar { margin-left: 0; transform: translateX(-105%); }
  .top-button span { display: none; }
  .messages { padding-top: 20px; }
  .mode-row span { display: none; }
  .fine-print { display: none; }
  .composer-wrap { padding-top: 8px; }
  .send-button { min-width: 62px; }
}

@media print {
  .sidebar, .topbar, .composer-wrap, .attachment-tray, .message-tools { display: none !important; }
  body, .main, .messages { overflow: visible; height: auto; background: white; color: black; }
}


.welcome-logo {
  display: block;
  width: min(160px, 42vw);
  height: auto;
  margin: 0 auto 18px;
  border-radius: 28px;
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
}
.welcome-logo[style*="none"] + .welcome-mark { display: inline-flex; }
.welcome:has(.welcome-logo:not([style*="none"])) .welcome-mark { display: none; }
