:root {
  --bg: #07111f;
  --bg-2: #0b1730;
  --panel: rgba(10, 22, 44, 0.86);
  --panel-strong: rgba(10, 20, 40, 0.96);
  --panel-soft: rgba(255, 255, 255, 0.04);
  --text: #eef4ff;
  --muted: #9fb0d0;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --primary: #6c7cff;
  --primary-2: #8b6dff;
  --danger: #ff5c7a;
  --success: #2dcc8c;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  --sidebar-w: 320px;
  --topbar-h: 78px;
}

html[data-theme="light"] {
  --bg: #eef4ff;
  --bg-2: #dfe9ff;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --panel-soft: rgba(15, 23, 42, 0.04);
  --text: #0f172a;
  --muted: #5f6f8f;
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(15, 23, 42, 0.16);
  --shadow: 0 20px 60px rgba(42, 72, 120, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Inter", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(108, 124, 255, 0.2), transparent 28%),
    radial-gradient(circle at bottom left, rgba(45, 204, 140, 0.14), transparent 26%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100%;
}

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: rgba(4, 11, 23, 0.74);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
  min-width: 0;
  z-index: 20;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  box-shadow: 0 10px 24px rgba(108, 124, 255, 0.34);
  flex: 0 0 auto;
}

.brand-title {
  font-weight: 800;
  font-size: 18px;
  line-height: 1.15;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.btn {
  border-radius: 14px;
  padding: 12px 16px;
  transition: 0.2s ease;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}

.btn-primary {
  color: #fff;
  border: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 14px 30px rgba(108, 124, 255, 0.28);
}

.btn-block {
  width: 100%;
}

.sidebar-search input {
  width: 100%;
  height: 46px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--line);
  outline: none;
  padding: 0 14px;
}

.sidebar-search input::placeholder,
#messageInput::placeholder {
  color: var(--muted);
}

.sidebar-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.sidebar-section-title {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  min-height: 0;
  padding-right: 4px;
}

.chat-item {
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.chat-item.active {
  border-color: rgba(108, 124, 255, 0.35);
  background: rgba(108, 124, 255, 0.14);
}

.chat-item-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
  word-break: break-word;
}

.chat-item-meta {
  font-size: 12px;
  color: var(--muted);
}

.sidebar-bottom {
  display: grid;
  gap: 10px;
}

.sidebar-link-btn {
  height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--line);
}

.sidebar-link-btn.danger {
  color: #fff;
  background: rgba(255, 92, 122, 0.18);
  border-color: rgba(255, 92, 122, 0.3);
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr auto;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 17, 31, 0.46);
  backdrop-filter: blur(16px);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.topbar-title {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
}

.topbar-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.mobile-only {
  display: none;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 10px 6px 6px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.user-chip img {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.08);
}

.user-chip-meta > div:first-child {
  font-size: 14px;
  font-weight: 700;
}

.user-chip-meta > div:last-child {
  font-size: 12px;
  color: var(--muted);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.welcome-screen,
.chat-screen {
  min-height: 0;
  overflow: auto;
}

.welcome-screen {
  padding: 26px;
}

.welcome-card {
  max-width: 1000px;
  background: linear-gradient(180deg, rgba(13, 28, 56, 0.78), rgba(9, 20, 41, 0.7));
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.welcome-badge {
  display: inline-flex;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: #d7deff;
  background: rgba(108, 124, 255, 0.18);
  border: 1px solid rgba(108, 124, 255, 0.24);
  margin-bottom: 12px;
}

.welcome-card h1 {
  margin: 0 0 12px;
  font-size: clamp(30px, 5vw, 54px);
  line-height: 1.08;
}

.welcome-card p {
  margin: 0;
  color: var(--muted);
  max-width: 900px;
  line-height: 1.7;
  font-size: 17px;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.quick-prompt {
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
}

.chat-screen {
  padding: 18px 22px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 1100px;
  margin: 0 auto;
  padding-bottom: 10px;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.message-row.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(108, 124, 255, 0.92), rgba(139, 109, 255, 0.92));
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.message-row.assistant .message-avatar {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--line);
}

.message-bubble-wrap {
  min-width: 0;
  max-width: min(900px, calc(100% - 56px));
}

.message-author {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  padding: 0 4px;
}

.message-row.user .message-author {
  text-align: right;
}

.message-bubble {
  border-radius: 20px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  line-height: 1.65;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow);
}

.message-row.user .message-bubble {
  background: linear-gradient(135deg, rgba(108, 124, 255, 0.9), rgba(139, 109, 255, 0.88));
  border: 0;
  color: #fff;
  border-bottom-right-radius: 8px;
}

.message-row.assistant .message-bubble {
  border-bottom-left-radius: 8px;
}

.message-bubble img,
.message-image {
  display: block;
  width: 100%;
  max-width: 420px;
  max-height: 420px;
  object-fit: cover;
  border-radius: 16px;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.message-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 8px;
}

.message-bubble pre {
  margin: 12px 0 0;
  overflow: auto;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.attachments-preview {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 22px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
}

.attachment-chip img {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 10px;
  flex: 0 0 auto;
}

.attachment-chip-name {
  font-size: 13px;
  font-weight: 600;
  word-break: break-word;
}

.attachment-chip-size {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.attachment-remove {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: rgba(255, 92, 122, 0.16);
  color: #fff;
  border: 1px solid rgba(255, 92, 122, 0.26);
  flex: 0 0 auto;
}

.composer-wrap {
  border-top: 1px solid var(--line);
  background: rgba(7, 17, 31, 0.6);
  backdrop-filter: blur(18px);
  padding: 12px 0 16px;
}

.composer {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: end;
  padding: 0 22px;
}

.attach-btn,
.send-btn {
  height: 52px;
  min-width: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
}

.attach-btn {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  font-size: 22px;
}

.send-btn {
  min-width: 122px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 14px 30px rgba(108, 124, 255, 0.28);
  font-weight: 700;
}

#messageInput {
  width: 100%;
  min-height: 56px;
  max-height: 220px;
  resize: none;
  border-radius: 18px;
  border: 1px solid var(--line);
  outline: none;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  line-height: 1.5;
}

.composer-hint {
  max-width: 1100px;
  margin: 8px auto 0;
  padding: 0 22px;
  color: var(--muted);
  font-size: 12px;
}

.settings-drawer {
  position: fixed;
  inset: 0;
  z-index: 80;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(4px);
}

.settings-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(520px, 100%);
  height: 100%;
  background: var(--panel-strong);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.28);
  display: grid;
  grid-template-rows: auto 1fr;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.settings-header h2 {
  margin: 0;
  font-size: 22px;
}

.settings-body {
  overflow: auto;
  padding: 18px 20px 28px;
}

.settings-group {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.settings-label {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.settings-input {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  outline: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 12px 14px;
}

.settings-input.textarea {
  min-height: 140px;
  resize: vertical;
}

.settings-actions {
  display: flex;
  gap: 12px;
  margin-top: 10px;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

html[data-theme="light"] body {
  background:
    radial-gradient(circle at top right, rgba(108, 124, 255, 0.12), transparent 28%),
    radial-gradient(circle at bottom left, rgba(45, 204, 140, 0.1), transparent 26%),
    linear-gradient(135deg, #eef4ff, #dfe9ff);
}

html[data-theme="light"] .sidebar {
  background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] .topbar,
html[data-theme="light"] .composer-wrap {
  background: rgba(255, 255, 255, 0.76);
}

html[data-theme="light"] .welcome-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(245,248,255,0.92));
}

html[data-theme="light"] .message-row.assistant .message-bubble {
  background: rgba(15, 23, 42, 0.04);
}

html[data-theme="light"] .message-bubble pre {
  background: rgba(15, 23, 42, 0.06);
}

html[data-theme="light"] .chat-item,
html[data-theme="light"] .quick-prompt,
html[data-theme="light"] .user-chip,
html[data-theme="light"] .sidebar-link-btn,
html[data-theme="light"] .sidebar-search input,
html[data-theme="light"] #messageInput,
html[data-theme="light"] .attach-btn,
html[data-theme="light"] .settings-input,
html[data-theme="light"] .attachment-chip,
html[data-theme="light"] .icon-btn {
  background: rgba(15, 23, 42, 0.04);
}

html[data-theme="light"] .settings-panel {
  background: rgba(255, 255, 255, 0.98);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.32);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: grid;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 12px 14px;
  }

  .welcome-screen,
  .chat-screen {
    padding: 14px;
  }

  .welcome-card {
    padding: 18px;
    border-radius: 22px;
  }

  .composer {
    grid-template-columns: auto 1fr;
    padding: 0 14px;
  }

  .send-btn {
    grid-column: 1 / -1;
    width: 100%;
    height: 50px;
  }

  .composer-hint {
    padding: 0 14px;
  }

  .attachments-preview {
    padding: 0 14px 10px;
  }

  .message-bubble-wrap {
    max-width: calc(100% - 46px);
  }

  .message-bubble {
    padding: 14px;
  }

  .user-chip-meta {
    display: none;
  }
}