:root {
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --surface: #ffffff;
  --surface-2: #f4f4f4;
  --surface-3: #ececec;
  --text: #0d0d0d;
  --muted: #6f6f6f;
  --border: #e3e3e3;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.18);
  --danger: #d92d20;
  --accent: #0d0d0d;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

[data-theme="dark"] {
  --bg: #212121;
  --sidebar: #171717;
  --surface: #2f2f2f;
  --surface-2: #3a3a3a;
  --surface-3: #454545;
  --text: #ececec;
  --muted: #b4b4b4;
  --border: #3f3f3f;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.44);
  --danger: #ff6b63;
  --accent: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--sidebar);
  padding: 8px;
}

.sidebar-top,
.sidebar-bottom {
  flex: 0 0 auto;
}

.sidebar-action,
.account-button,
.chat-item {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  text-align: left;
}

.sidebar-action:hover,
.account-button:hover,
.chat-item:hover,
.chat-item.active {
  background: var(--surface-3);
}

.action-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  font-size: 22px;
}

.chat-list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  padding: 10px 0;
}

.chat-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 6px;
  min-height: 38px;
  padding: 8px 8px 8px 10px;
}

.chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.delete-chat {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
}

.chat-item:hover .delete-chat,
.chat-item.active .delete-chat {
  opacity: 1;
}

.delete-chat:hover {
  background: var(--surface-2);
  color: var(--danger);
}

.avatar-mini {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 12px;
  font-weight: 700;
}

.account-button span:last-child {
  min-width: 0;
  display: grid;
}

.account-button small {
  color: var(--muted);
  font-size: 12px;
}

.main {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr) auto;
}

.topbar {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  padding: 8px 12px;
}

.title-button {
  justify-self: start;
  min-width: 0;
  max-width: 100%;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  font-weight: 600;
  color: var(--muted);
}

.title-button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.chevron {
  font-size: 15px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
}

.icon-button:hover {
  background: var(--surface-2);
}

.menu-toggle {
  display: none;
}

.ghost-space {
  visibility: hidden;
}

.messages {
  overflow-y: auto;
  padding: 18px 18px 28px;
}

.empty {
  min-height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
}

.empty h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0;
}

.empty p {
  margin: 12px 0 0;
  color: var(--muted);
}

.message {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 0;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 16px;
}

.message.user {
  grid-template-columns: minmax(0, 1fr);
  justify-items: end;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--bg);
  font-size: 12px;
  font-weight: 700;
}

.message.user .avatar {
  display: none;
}

.bubble {
  min-width: 0;
  max-width: 100%;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  max-width: min(74%, 620px);
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.composer-wrap {
  padding: 0 18px 18px;
}

.attachments,
.composer,
.composer-meta {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.attachment img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 8px;
}

.attachment span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.attachment button {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

.attachment button:hover {
  background: var(--surface-2);
}

.composer {
  min-height: 58px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  align-items: end;
  gap: 8px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 26px;
}

.tool-button,
.send-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.tool-button {
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.tool-button:hover {
  background: var(--surface-3);
}

#promptInput {
  min-height: 36px;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 8px 0;
  line-height: 1.5;
}

.send-button {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  font-size: 18px;
}

.send-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 6px 0;
  color: var(--muted);
  font-size: 12px;
}

.scrim {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.settings-modal {
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head,
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-foot {
  border-top: 1px solid var(--border);
  border-bottom: 0;
  justify-content: flex-end;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}

.settings-grid {
  overflow-y: auto;
  padding: 8px 18px 18px;
}

.setting-row,
.setting-block {
  display: grid;
  gap: 10px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row {
  grid-template-columns: minmax(0, 1fr) minmax(190px, 260px);
  align-items: center;
}

.setting-row span:first-child,
.setting-block > span {
  min-width: 0;
}

.setting-row strong,
.setting-block strong {
  display: block;
  font-weight: 600;
}

.setting-row small,
.setting-block small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.setting-row input,
.setting-row select,
.setting-block textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
  outline: 0;
}

.setting-block textarea {
  resize: vertical;
  line-height: 1.5;
}

.range-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: center;
}

.range-line output {
  text-align: right;
  color: var(--muted);
}

.danger-button {
  min-height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--danger);
  padding: 0 12px;
}

.danger-button:hover {
  background: var(--surface-2);
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(84vw, 310px);
    transform: translateX(-102%);
    transition: transform 160ms ease;
  }

  .app[data-sidebar="open"] .sidebar {
    transform: translateX(0);
  }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 15;
    display: none;
    background: rgba(0, 0, 0, 0.38);
  }

  .app[data-sidebar="open"] .scrim {
    display: block;
  }

  .menu-toggle {
    display: grid;
  }

  .messages {
    padding: 12px 14px 22px;
  }

  .message {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 12px;
  }

  .message.user .bubble {
    max-width: 88%;
  }

  .composer-wrap {
    padding: 0 10px 12px;
  }

  .composer-meta {
    flex-direction: column;
    gap: 3px;
  }

  .modal-backdrop {
    padding: 0;
    align-items: end;
  }

  .settings-modal {
    width: 100%;
    max-height: 88vh;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
  }

  .setting-row {
    grid-template-columns: 1fr;
  }
}
