:root {
  color-scheme: dark;
  --bg: #191919;
  --panel: #111111;
  --panel-soft: #171717;
  --hover: #242424;
  --active: #2f2f2f;
  --line: #303030;
  --line-soft: #262626;
  --text: #f4f4f4;
  --muted: #a6a6a6;
  --subtle: #747474;
  --accent: #f4f4f4;
  --accent-text: #171717;
  --danger: #ff6b6b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line-soft);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 14px 0 18px;
}

.brand {
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 0 12px 12px;
}

#newFolderBtn {
  display: grid;
}

.new-chat-button,
.primary-button,
.ghost-button,
.danger-button,
.icon-button,
.send-button,
.branch-arrow,
.message-edit {
  border: 0;
  border-radius: 8px;
  min-height: 38px;
  color: var(--text);
  background: transparent;
  transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

.new-chat-button {
  padding: 0 13px;
  text-align: left;
  background: var(--hover);
  font-weight: 650;
}

.primary-button {
  padding: 0 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 760;
}

.ghost-button {
  padding: 0 13px;
  color: var(--muted);
}

.danger-button {
  padding: 0 13px;
  background: rgba(255, 107, 107, 0.15);
  color: #ffb7b7;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  color: var(--muted);
}

.feather-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.new-chat-button:hover,
.ghost-button:hover,
.icon-button:hover,
.message-edit:hover,
.branch-arrow:hover {
  background: var(--hover);
  color: var(--text);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.folders {
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 4px 8px 18px;
}

.folders::-webkit-scrollbar,
.messages::-webkit-scrollbar {
  width: 10px;
}

.folders::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track {
  background: transparent;
}

.folders::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  background: #3a3a3a;
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

.folders::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover {
  background-color: #525252;
}

.folder {
  margin-bottom: 12px;
}

.section-title {
  margin: 10px 10px 6px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.folder-head {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 38px;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.folder-head:hover,
.folder-head.active {
  background: var(--hover);
  color: var(--text);
}

.folder-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: transparent;
}

.folder-name,
.chat-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-name {
  font-weight: 720;
}

.folder-tools {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--subtle);
}

.folder-tools:hover {
  background: var(--active);
  color: var(--text);
}

.chat-list {
  display: grid;
  gap: 2px;
  margin: 2px 0 0;
}

.chat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  border-radius: 8px;
  color: var(--muted);
}

.chat-row:hover,
.chat-row.active {
  background: var(--hover);
  color: var(--text);
}

.chat-row.archived {
  opacity: 0.62;
}

.chat-pick {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 38px;
  padding: 0 8px 0 12px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.chat-icon {
  display: grid;
  place-items: center;
  width: 22px;
  color: var(--subtle);
}

.chat-row.active .chat-icon,
.chat-row:hover .chat-icon {
  color: var(--text);
}

.chat-kebab {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--subtle);
  opacity: 0;
}

.chat-row:hover .chat-kebab,
.chat-row.active .chat-kebab {
  opacity: 1;
}

.chat-kebab:hover {
  background: var(--active);
  color: var(--text);
}

.archive-title {
  margin: 16px 10px 6px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.chat-menu {
  position: fixed;
  z-index: 30;
  width: 180px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #222;
  box-shadow: var(--shadow);
}

.chat-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.chat-menu button:hover {
  background: #333;
}

.danger-text {
  color: #ff9b9b !important;
}

.chat-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 18px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-select {
  width: auto;
  min-width: 150px;
  min-height: 36px;
  border-radius: 8px;
  background: #202020;
  color: var(--text);
  padding: 0 34px 0 12px;
}

.title-stack {
  min-width: 0;
}

.chat-title {
  overflow: hidden;
  color: #f7f7f7;
  font-size: 18px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  margin-top: 2px;
  color: var(--subtle);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-icon {
  display: inline-grid;
  place-items: center;
}

.meta-icon .feather-icon {
  width: 13px;
  height: 13px;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  padding: 28px max(22px, calc((100vw - 292px - 790px) / 2)) 22px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 100%;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 30px;
  font-weight: 760;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 14px;
  max-width: 790px;
  margin: 0 auto 22px;
}

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

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-top: 4px;
  border-radius: 8px;
  background: #2c2c2c;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

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

.bubble {
  min-width: 0;
}

.message.user .bubble {
  justify-self: end;
  max-width: min(620px, 86%);
  padding: 12px 16px;
  border-radius: 20px;
  background: #2f2f2f;
}

.bubble-text {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.65;
}

.message-tools {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  margin-top: -12px;
  padding-right: 12px;
  color: var(--subtle);
}

.inline-editor {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.inline-editor-input {
  min-height: 96px;
  padding: 12px;
  border: 1px solid #4a4a4a;
  border-radius: 12px;
  background: #262626;
}

.inline-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.message-edit {
  display: grid;
  place-items: center;
  width: 32px;
  min-height: 32px;
  color: var(--subtle);
}

.branch-switcher {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 30px;
  padding: 0 4px;
  color: var(--subtle);
  font-size: 13px;
}

.branch-arrow {
  display: grid;
  place-items: center;
  width: 28px;
  min-height: 28px;
  color: var(--muted);
}

.branch-count {
  min-width: 38px;
  text-align: center;
}

.composer {
  padding: 12px max(18px, calc((100vw - 292px - 790px) / 2)) 24px;
}

.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: end;
  gap: 8px;
  max-width: 790px;
  min-height: 58px;
  margin: 0 auto;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: #262626;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

textarea {
  width: 100%;
  max-height: 190px;
  min-height: 36px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.45;
  transform: translateY(-3px);
  padding: 8px 0 5px;
}

textarea::placeholder {
  color: #8f8f8f;
}

.send-button {
  display: grid;
  place-items: center;
  width: 38px;
  min-height: 38px;
  border-radius: 50%;
  background: #f1f1f1;
  color: #111;
  font-size: 22px;
  font-weight: 800;
}

.send-button .feather-icon {
  transform: translate(-2px, 2px);
}

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.64);
}

.dialog-card {
  display: grid;
  gap: 14px;
  width: min(430px, calc(100vw - 28px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #212121;
  box-shadow: var(--shadow);
}

.dialog-title {
  font-size: 18px;
  font-weight: 760;
}

.dialog-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.field-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.icon-picker-section {
  display: grid;
  gap: 0;
}

.icon-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.icon-choice {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #292929;
  color: var(--muted);
}

.icon-choice:hover {
  background: #333;
  color: var(--text);
}

.icon-choice.active {
  border-color: currentColor;
  background: #191919;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #2a2a2a;
  color: var(--text);
  padding: 0 12px;
}

input:focus,
select:focus {
  border-color: #6b6b6b;
}

input[type="color"] {
  padding: 4px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dialog-spacer {
  flex: 1;
}

.cooldown {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
}

.mobile-only {
  display: none;
}

.sidebar-collapsed {
  grid-template-columns: 72px minmax(0, 1fr);
}

.sidebar-collapsed .brand-row {
  justify-content: center;
  padding: 0;
}

.sidebar-collapsed .brand,
.sidebar-collapsed .sidebar-actions,
.sidebar-collapsed .section-title,
.sidebar-collapsed .folder-name,
.sidebar-collapsed .folder-tools,
.sidebar-collapsed .archive-title {
  display: none;
}

.sidebar-collapsed .folders {
  padding: 4px 14px 18px 15px;
  scrollbar-gutter: auto;
}

.sidebar-collapsed .folder {
  margin-bottom: 4px;
}

.sidebar-collapsed .folder-head {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  width: 42px;
  height: 42px;
  margin: 0 auto;
  padding: 0;
}

.sidebar-collapsed .folder-icon {
  width: 42px;
  height: 42px;
}

.sidebar-collapsed .chat-row {
  display: flex;
  justify-content: center;
  width: 42px;
  min-height: 42px;
  margin: 0 auto 4px;
}

.sidebar-collapsed .chat-pick {
  display: grid;
  place-items: center;
  width: 42px;
  min-height: 42px;
  padding: 0;
}

.sidebar-collapsed .chat-name,
.sidebar-collapsed .chat-kebab {
  display: none;
}

.sidebar-collapsed .chat-icon {
  width: 22px;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(318px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }

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

  .mobile-only {
    display: grid;
  }

  .topbar {
    padding: 0 12px;
  }

  .topbar .ghost-button {
    display: none;
  }

  .model-select {
    min-width: 118px;
    max-width: 138px;
  }

  .icon-picker {
    grid-template-columns: repeat(6, 1fr);
  }

  .messages,
  .composer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .message {
    grid-template-columns: 1fr;
  }

  .avatar {
    display: none;
  }

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