:root {
  color-scheme: light dark;
  --font: "Poppins", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --speed: 180ms;
}

:root,
:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --soft: #f6f6f6;
  --soft-2: #ededed;
  --text: #070707;
  --muted: #6f6f6f;
  --line: #e7e7e7;
  --line-strong: #d5d5d5;
  --accent: #050505;
  --accent-text: #ffffff;
  --danger: #9f1d1d;
  --ok: #1f7a42;
  --shadow: 0 18px 55px rgba(0,0,0,.08);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #050505;
    --panel: #090909;
    --soft: #121212;
    --soft-2: #1c1c1c;
    --text: #f5f5f5;
    --muted: #9a9a9a;
    --line: #242424;
    --line-strong: #343434;
    --accent: #ffffff;
    --accent-text: #050505;
    --danger: #ff7b7b;
    --ok: #63d08e;
    --shadow: 0 20px 70px rgba(0,0,0,.32);
  }
}

:root[data-theme="dark"] {
  --bg: #050505;
  --panel: #090909;
  --soft: #121212;
  --soft-2: #1c1c1c;
  --text: #f5f5f5;
  --muted: #9a9a9a;
  --line: #242424;
  --line-strong: #343434;
  --accent: #ffffff;
  --accent-text: #050505;
  --danger: #ff7b7b;
  --ok: #63d08e;
  --shadow: 0 20px 70px rgba(0,0,0,.32);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }
.mobile-only { display: none !important; }

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.auth-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 30px;
  box-shadow: var(--shadow);
  animation: rise .32s ease both;
}
.auth-logo { width: 52px; height: 52px; display: block; border-radius: 16px; margin-bottom: 18px; }
.overline {
  margin: 0 0 4px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.auth-card h1, .title-wrap h2, .image-card h2 {
  margin: 0;
  font-size: clamp(26px, 4vw, 38px);
  letter-spacing: -.04em;
  line-height: 1.05;
}
.muted { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 10px 0 0; }
.auth-form { margin-top: 26px; display: grid; gap: 10px; }
label { font-size: 12px; color: var(--muted); font-weight: 600; }
.password-field, .inline-field, .web-tools-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
input, textarea {
  width: 100%;
  outline: 0;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: var(--radius-md);
  padding: 12px 13px;
  font-size: 13px;
  transition: border-color var(--speed), background var(--speed), box-shadow var(--speed);
}
textarea { resize: none; line-height: 1.65; }
input:focus, textarea:focus { border-color: var(--line-strong); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent); }
.error-text { min-height: 18px; margin: 0; color: var(--danger); font-size: 12px; }

.app {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  background: var(--bg);
}
.sidebar {
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}
.side-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand img { width: 40px; height: 40px; border-radius: 13px; flex: 0 0 auto; }
.brand strong { display: block; font-size: 16px; letter-spacing: -.03em; }
.brand span { display: block; max-width: 185px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; margin-top: 1px; }
.status {
  display: flex;
  gap: 11px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: var(--radius-lg);
  padding: 12px;
}
.status-dot { width: 9px; height: 9px; border-radius: 99px; background: var(--muted); box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 14%, transparent); flex: 0 0 auto; }
.status-dot.online { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 14%, transparent); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 14%, transparent); }
.status strong { display: block; font-size: 12px; }
.status small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; line-height: 1.35; }
.clean-btn, .ghost-btn, .primary-btn, .send-btn, .small-btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-md);
  min-height: 40px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  transition: transform var(--speed), background var(--speed), border-color var(--speed), opacity var(--speed);
}
.clean-btn, .ghost-btn, .small-btn {
  border: 1px solid var(--line);
  background: var(--soft);
}
.clean-btn:hover, .ghost-btn:hover, .small-btn:hover, .icon-btn:hover, .tiny-btn:hover, .model-item:hover, .history-item:hover { background: var(--soft-2); }
.primary-btn, .send-btn { background: var(--accent); color: var(--accent-text); }
.primary-btn:disabled, .send-btn:disabled, .icon-btn:disabled, .tiny-btn:disabled { opacity: .45; cursor: not-allowed; }
.new-chat { width: 100%; }
.ghost-btn { width: 100%; justify-content: flex-start; }
.ghost-btn.danger { color: var(--danger); }
.small-btn { min-height: 38px; padding: 0 11px; flex: 0 0 auto; }
.icon-btn, .tiny-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--soft);
  font-size: 17px;
  transition: background var(--speed), transform var(--speed), border-color var(--speed), opacity var(--speed);
  flex: 0 0 auto;
}
.tiny-btn { width: 30px; height: 30px; font-size: 14px; border-radius: 10px; }
button:active { transform: translateY(1px); }
.side-block { min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.models-block { flex: 0 0 246px; }
.history-block { flex: 1 1 auto; }
.block-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.block-title span { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 10px; font-weight: 700; }
.model-list, .history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 2px;
}
.model-item, .history-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-md);
  padding: 10px;
  transition: background var(--speed), border-color var(--speed), transform var(--speed);
}
.model-item.active, .history-item.active { border-color: var(--text); background: var(--soft); }
.model-icon, .history-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--soft);
  color: var(--muted);
  flex: 0 0 auto;
}
.model-item strong, .history-item strong { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-item span, .history-item span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-copy { min-width: 0; flex: 1; }
.empty-box {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.advanced {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
  background: var(--panel);
}
.advanced summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced[open] { padding-bottom: 12px; overflow-y: auto; max-height: 62vh; }
.advanced[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.advanced label, .advanced .segments, .advanced .inline-field, .advanced .web-tools-row, .advanced .ghost-btn { width: calc(100% - 24px); margin-left: 12px; margin-right: 12px; }
.advanced label { display: block; margin-top: 10px; margin-bottom: 7px; }
.advanced input { padding: 10px 11px; font-size: 12px; }
.web-tools-row { align-items: stretch; }
.segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.segments button {
  min-height: 36px;
  font-size: 11px;
  color: var(--muted);
  border-right: 1px solid var(--line);
}
.segments button:last-child { border-right: 0; }
.segments button.active { background: var(--accent); color: var(--accent-text); }

.main {
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 76px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}
.title-wrap { min-width: 0; }
.title-wrap h2 { font-size: clamp(22px, 3vw, 34px); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.chat-screen, .image-screen {
  position: relative;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px min(5vw, 72px) 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
}
.welcome {
  margin: auto;
  max-width: 560px;
  text-align: center;
  padding: 40px 16px;
}
.welcome img { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 16px; }
.welcome h3 { margin: 0; font-size: clamp(28px, 5vw, 48px); letter-spacing: -.05em; }
.welcome p { margin: 10px auto 0; color: var(--muted); line-height: 1.7; font-size: 14px; max-width: 460px; }
.message-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 760px);
  gap: 12px;
  animation: rise .2s ease both;
}
.message-row.user { grid-template-columns: minmax(0, 760px) 34px; justify-content: end; }
.message-row.user .avatar { grid-column: 2; grid-row: 1; }
.message-row.user .bubble-wrap { grid-column: 1; grid-row: 1; }
.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
}
.bubble {
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 18px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-row.user .bubble { margin-left: auto; background: var(--text); color: var(--bg); border-color: var(--text); }
.bubble pre {
  overflow: auto;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.thinking {
  margin-bottom: 8px;
  max-width: 760px;
  border: 1px dashed var(--line-strong);
  background: var(--soft);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
}
.thinking.hidden-after-answer { display: none; }
.thinking-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.file-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}
.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 10px;
  color: var(--muted);
}
.composer {
  flex: 0 0 auto;
  padding: 12px min(5vw, 72px) 20px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.attachment-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 8px;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 999px;
  padding: 6px 8px 6px 10px;
  font-size: 11px;
  color: var(--muted);
  max-width: 230px;
}
.attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 999px; color: var(--muted); }
.attachment-chip button:hover { background: var(--soft-2); }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 18px;
  padding: 8px;
  box-shadow: var(--shadow);
}
.composer-box textarea {
  min-height: 38px;
  max-height: 180px;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 8px 4px;
}
.composer-box textarea:focus { box-shadow: none; }
.send-btn { min-height: 38px; flex: 0 0 auto; }
.drop-overlay {
  pointer-events: none;
  position: absolute;
  inset: 88px min(5vw, 72px) 96px;
  display: none;
  place-items: center;
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: 26px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  z-index: 20;
}
.drop-overlay.show { display: grid; }
.drop-overlay i { font-size: 40px; color: var(--muted); }
.drop-overlay strong { display: block; margin-top: 8px; font-size: 18px; }
.drop-overlay span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }

.image-screen {
  padding: 24px min(5vw, 72px);
  overflow-y: auto;
  gap: 18px;
}
.image-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 22px;
  padding: 22px;
}
.image-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.image-form { margin-top: 20px; display: grid; gap: 12px; }
.image-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.image-grid label { display: grid; gap: 7px; }
.image-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.image-result {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 18px;
  overflow: hidden;
}
.image-result img { width: 100%; display: block; aspect-ratio: 1 / 1; object-fit: cover; background: var(--soft); }
.image-result div { padding: 12px; display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.image-result p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.55;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--speed), transform var(--speed);
}
.toast.show { opacity: 1; transform: translateY(0); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-grid !important; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 88vw);
    z-index: 50;
    transform: translateX(-105%);
    transition: transform var(--speed);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { min-height: 68px; padding: 12px 14px; }
  .messages { padding: 18px 14px 14px; }
  .composer { padding: 10px 14px 14px; }
  .message-row { grid-template-columns: 30px minmax(0, 1fr); gap: 9px; }
  .message-row.user { grid-template-columns: minmax(0, 1fr) 30px; }
  .avatar { width: 30px; height: 30px; border-radius: 10px; }
  .bubble { font-size: 13px; padding: 12px 13px; }
  .send-btn span { display: none; }
  .image-screen { padding: 18px 14px; }
  .image-grid { grid-template-columns: 1fr; }
  .drop-overlay { inset: 78px 14px 90px; }
}

@media (max-width: 520px) {
  .top-actions { gap: 6px; }
  .icon-btn { width: 36px; height: 36px; }
  .composer-box { border-radius: 16px; }
  .auth-card { padding: 24px; }
  .welcome h3 { font-size: 34px; }
}

.prompt-box {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--soft);
  padding: 0;
}
.prompt-box summary {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.prompt-box textarea {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  min-height: 160px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}
.dual-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
}
.setup-screen {
  height: 100%;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}
.setup-card {
  max-width: 980px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  padding: 20px;
  box-shadow: var(--shadow);
}
.setup-grid {
  display: grid;
  grid-template-columns: minmax(220px, .75fr) minmax(0, 1.25fr);
  gap: 12px;
  margin-top: 18px;
}
.setup-panel {
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-width: 0;
}
.setup-panel strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(22px, 4vw, 34px);
  letter-spacing: -.05em;
}
.setup-panel small,
.setup-note {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  margin-top: 8px;
}
.setup-kicker {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 10px;
  font-weight: 700;
}
.setup-panel pre {
  margin: 10px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-md);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.6;
}
.setup-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.setup-actions .ghost-btn {
  justify-content: center;
}
.chat-image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 260px));
  gap: 10px;
  margin-top: 12px;
}
.chat-image-card {
  display: block;
  color: inherit;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--soft);
}
.chat-image-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--soft-2);
}
.chat-image-card span {
  display: block;
  padding: 9px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
@media (max-width: 860px) {
  .setup-grid,
  .setup-actions {
    grid-template-columns: 1fr;
  }
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  height: 0;
  overflow: visible;
  transition: opacity .16s ease;
}
.message-row:hover .message-actions,
.message-row:focus-within .message-actions { opacity: 1; }
.message-actions .tiny-btn {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
}
.chat-image-card { position: relative; }
.chat-image-card a { display: block; color: inherit; text-decoration: none; }
.image-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: .92;
}
.image-delete:hover { background: var(--text); color: var(--bg); }
.image-actions-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.setup-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 900px) {
  .setup-actions { grid-template-columns: 1fr; }
  .message-actions { opacity: 1; }
}
