:root {
  --bg: #faf9f6;
  --sidebar-bg: #f3f1ec;
  --surface: #ffffff;
  --surface-muted: #ece9e2;
  --border: #e5e2da;
  --border-strong: #d4d0c7;
  --text: #161618;
  --text-muted: #6c6c73;
  --accent: #0f766e;
  --accent-dot: #10b981;
  --accent-fg: #ffffff;
  --user-bubble: #eceae3;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #b91c1c;
  --scrim: rgba(22, 22, 24, 0.34);
  --shadow: 0 8px 30px rgba(22, 22, 24, 0.05);
  --shadow-focus: 0 10px 32px rgba(15, 118, 110, 0.08);
  --shadow-modal: 0 24px 60px rgba(22, 22, 24, 0.16);
  --radius-lg: 22px;
  --radius-md: 14px;
  --max-width: 740px;
  --sidebar-width: 268px;
}

:root[data-theme="dark"] {
  --bg: #111113;
  --sidebar-bg: #161619;
  --surface: #1b1b20;
  --surface-muted: #24242b;
  --border: #2a2a31;
  --border-strong: #3a3a44;
  --text: #f4f4f6;
  --text-muted: #9898a3;
  --accent: #10b981;
  --accent-dot: #34d399;
  --accent-fg: #081c15;
  --user-bubble: #232329;
  --error-bg: #2a1416;
  --error-border: #5c2227;
  --error-text: #fca5a5;
  --scrim: rgba(0, 0, 0, 0.56);
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.32);
  --shadow-focus: 0 10px 36px rgba(16, 185, 129, 0.12);
  --shadow-modal: 0 28px 70px rgba(0, 0, 0, 0.52);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* App Shell */
.app {
  display: flex;
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  flex: 0 0 auto;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width 0.22s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.22s ease;
}

.app.sidebar-collapsed .sidebar {
  width: 0;
  border-right-color: transparent;
}

.sidebar-inner {
  width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  flex: 0 0 auto;
  height: 58px;
  padding: 0 14px 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-action {
  flex: 0 0 auto;
  padding: 4px 12px 12px;
}

.new-chat-btn {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.new-chat-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.new-chat-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* History list */
.history-section {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 12px;
}

.history-label {
  padding: 6px 10px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  user-select: none;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 10px;
  transition: background 0.14s ease;
}

.history-item:hover {
  background: var(--surface-muted);
}

.history-item.is-active {
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.history-select-btn {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.865rem;
  text-align: left;
  padding: 9px 34px 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-select-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.history-delete-btn {
  position: absolute;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.14s ease, background 0.14s ease, color 0.14s ease;
}

.history-item:hover .history-delete-btn,
.history-item:focus-within .history-delete-btn,
.history-item.is-active .history-delete-btn {
  opacity: 1;
}

.history-delete-btn:hover {
  background: var(--border);
  color: var(--text);
}

.history-empty {
  margin: 8px 10px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* Sidebar Footer (Hesap + Ayarlar) */
.sidebar-footer {
  flex: 0 0 auto;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.account-cta-btn {
  width: 100%;
  height: 40px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.855rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.account-cta-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.account-cta-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.account-cta-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

.account-card {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}

.account-info-btn {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 5px 6px;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s ease;
}

.account-info-btn:hover {
  background: var(--surface-muted);
}

.account-avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.account-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.account-name {
  font-size: 0.835rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-icon-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  min-width: 32px;
}

.settings-btn {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.89rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.settings-btn svg {
  color: var(--text-muted);
  transition: color 0.15s ease;
}

.settings-btn:hover {
  background: var(--surface-muted);
}

.settings-btn:hover svg {
  color: var(--text);
}

.settings-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 20;
  animation: fadeIn 0.18s ease;
}

/* Workspace */
.workspace {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Header */
.topbar {
  flex: 0 0 auto;
  height: 58px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Hide topbar open-button & brand when desktop sidebar is already visible */
.app:not(.sidebar-collapsed) .sidebar-open-btn,
.app:not(.sidebar-collapsed) .topbar-brand {
  display: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 650;
  font-size: 1.125rem;
  letter-spacing: -0.03em;
  padding: 6px 8px;
  margin-left: -8px;
  border-radius: 10px;
  transition: opacity 0.16s ease;
}

.brand:hover {
  opacity: 0.78;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent-dot);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-dot) 18%, transparent);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  min-width: 36px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Main stage */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  position: relative;
}

.app.is-empty .stage {
  justify-content: center;
  padding-bottom: 10vh;
}

.app.is-empty .messages {
  display: none;
}

.app:not(.is-empty) .welcome {
  display: none;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 28px;
  padding: 0 20px;
  animation: fadeUp 0.35s ease;
}

.welcome-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.welcome-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--accent-dot);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent-dot) 18%, transparent);
}

.welcome-word {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.welcome-title {
  margin: 0;
  font-size: clamp(1.25rem, 2.5vw, 1.55rem);
  font-weight: 500;
  letter-spacing: -0.025em;
  color: var(--text-muted);
}

/* Messages */
.messages {
  flex: 1 1 auto;
  width: 100%;
  overflow-y: auto;
  padding: 16px 20px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  scroll-behavior: smooth;
}

.message {
  width: 100%;
  max-width: var(--max-width);
  display: flex;
  flex-direction: column;
  animation: fadeUp 0.2s ease;
}

.message-user {
  align-items: flex-end;
}

.message-user .message-body {
  max-width: min(82%, 580px);
  background: var(--user-bubble);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 18px 18px 4px 18px;
  font-size: 0.965rem;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-assistant {
  align-items: flex-start;
}

.assistant-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
}

.assistant-avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-top: 2px;
  position: relative;
}

.assistant-avatar::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: var(--accent-dot);
}

.assistant-content {
  flex: 1 1 auto;
  min-width: 0;
}

.message-assistant .message-body {
  font-size: 0.975rem;
  line-height: 1.68;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  padding-top: 2px;
}

.message-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.message-assistant:hover .message-actions,
.message-assistant:focus-within .message-actions {
  opacity: 1;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  padding: 4px 8px;
  margin-left: -8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.copy-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 10px 2px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--text-muted);
  animation: pulse 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.18s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.36s;
}

/* Composer */
.composer-shell {
  flex: 0 0 auto;
  width: 100%;
  max-width: calc(var(--max-width) + 40px);
  padding: 0 20px 20px;
}

.error-banner {
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  font-size: 0.875rem;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 14px 10px 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-focus);
}

.composer-input {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.985rem;
  line-height: 1.55;
  min-height: 28px;
  max-height: 180px;
  overflow-y: auto;
}

.composer-input::placeholder {
  color: var(--text-muted);
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.composer-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.picker-wrap {
  position: relative;
}

.picker-pill {
  height: 32px;
  max-width: 240px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.picker-pill:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.picker-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.picker-pill:disabled {
  opacity: 0.62;
  cursor: default;
}

.picker-pill[aria-expanded="true"] {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.picker-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-chevron {
  flex: 0 0 auto;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.picker-pill[aria-expanded="true"] .picker-chevron {
  transform: rotate(180deg);
}

.thinking-pill .thinking-icon {
  flex: 0 0 auto;
  color: var(--text-muted);
}

.thinking-pill.is-active-thinking .thinking-icon {
  color: var(--accent);
}

.thinking-pill:disabled .thinking-chevron-pill {
  display: none;
}

/* Popovers */
.popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 35;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: fadeUp 0.14s ease;
}

.model-popover {
  width: min(330px, calc(100vw - 40px));
}

.thinking-popover {
  width: 210px;
}

.popover-heading {
  padding: 10px 12px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.popover-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.popover-search {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
}

.popover-search::placeholder {
  color: var(--text-muted);
}

.popover-list {
  max-height: 310px;
  overflow-y: auto;
  padding: 6px;
}

.popover-group-label {
  padding: 8px 8px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.popover-option {
  width: 100%;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.popover-option:hover {
  background: var(--surface-muted);
}

.popover-option[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 11%, transparent);
}

.popover-option-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.popover-option-title {
  font-size: 0.84rem;
  font-weight: 550;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.popover-option-meta {
  font-size: 0.73rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.popover-option-right {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.popover-badge {
  font-size: 0.68rem;
  font-weight: 550;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
}

.popover-check {
  color: var(--accent);
}

.popover-empty {
  padding: 18px 12px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.message-model-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 6px;
}

/* Guest Quota & Member Lock */
.quota-badge {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.77rem;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.14s ease, color 0.14s ease;
}

.quota-badge:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.quota-badge.is-low {
  border-color: color-mix(in srgb, #d97706 42%, var(--border));
  color: #b45309;
}

:root[data-theme="dark"] .quota-badge.is-low {
  color: #fbbf24;
}

.quota-badge.is-empty {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--error-text);
}

.topbar-link-btn {
  height: 32px;
  padding: 0 11px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.topbar-link-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.topbar-primary-btn {
  height: 32px;
  padding: 0 13px;
  border: none;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 550;
  cursor: pointer;
  transition: opacity 0.14s ease;
}

.topbar-primary-btn:hover {
  opacity: 0.9;
}

.credit-pill {
  height: 32px;
  padding: 0 6px 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.credit-pill svg {
  color: var(--accent);
}

.credit-pill:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.credit-pill-plus {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
}

.credit-pill.is-low {
  border-color: color-mix(in srgb, #d97706 48%, var(--border));
}

.credit-pill.is-empty {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--error-text);
}

.quota-banner {
  margin-bottom: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.855rem;
  line-height: 1.48;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.banner-action-btn {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 12px;
  border: none;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.14s ease;
}

.banner-action-btn:hover {
  opacity: 0.9;
}

.popover-option.is-locked {
  opacity: 0.72;
}

.popover-badge-member {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.67rem;
  font-weight: 550;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
}

/* Auth & Billing Modals */
.segmented-2 {
  grid-template-columns: repeat(2, 1fr);
}

.segmented-btn[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.auth-bonus-note {
  padding: 10px 12px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.48;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.form-input:focus {
  border-color: var(--accent);
}

.primary-full-btn {
  width: 100%;
  height: 42px;
  margin-top: 4px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.primary-full-btn:hover:not(:disabled) {
  opacity: 0.92;
}

.primary-full-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.modal-card-wide {
  max-width: 640px;
  max-height: min(88dvh, 760px);
  display: flex;
  flex-direction: column;
}

.billing-body {
  overflow-y: auto;
  gap: 16px;
}

.billing-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.billing-summary-label {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.billing-balance {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.billing-summary-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.plan-pill {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

.billing-notice {
  padding: 11px 13px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--text);
  font-size: 0.83rem;
  line-height: 1.48;
}

.packages-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.package-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.package-card.is-featured {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--border));
}

.package-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.package-name {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 650;
}

.package-price {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.package-badge {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

.package-desc {
  margin: 4px 0 0;
  font-size: 0.78rem;
  line-height: 1.42;
  color: var(--text-muted);
}

.package-list {
  margin: 8px 0 0;
  padding-left: 16px;
  font-size: 0.77rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.package-btn {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

.package-btn:hover:not(:disabled) {
  background: var(--surface-muted);
}

.package-card.is-featured .package-btn {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-fg);
}

.package-card.is-featured .package-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.ledger-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.ledger-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ledger-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.ledger-left {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ledger-title {
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.ledger-delta {
  font-weight: 650;
  white-space: nowrap;
}

.ledger-delta.is-plus {
  color: var(--accent);
}

.ledger-delta.is-minus {
  color: var(--text-muted);
}

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

  .billing-summary-right {
    align-items: flex-start;
  }
}

.send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease;
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  opacity: 0.92;
}

.send-btn:active:not(:disabled) {
  transform: translateY(0);
}

.send-btn:disabled {
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: not-allowed;
}

.send-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.send-btn .icon-stop {
  display: none;
}

.send-btn.is-streaming {
  background: var(--text);
  color: var(--bg);
}

.send-btn.is-streaming .icon-send {
  display: none;
}

.send-btn.is-streaming .icon-stop {
  display: block;
}

/* Thinking / Reasoning block */
.thinking-block {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-muted) 55%, transparent);
  overflow: hidden;
}

.thinking-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color 0.14s ease;
}

.thinking-summary::-webkit-details-marker {
  display: none;
}

.thinking-summary:hover {
  color: var(--text);
}

.thinking-chevron {
  transition: transform 0.16s ease;
  flex: 0 0 auto;
}

.thinking-block[open] .thinking-chevron {
  transform: rotate(90deg);
}

.thinking-block.is-thinking .thinking-label {
  animation: fadePulse 1.4s infinite ease-in-out;
}

.thinking-body {
  padding: 0 12px 10px 30px;
  font-size: 0.84rem;
  line-height: 1.58;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  padding-top: 8px;
}

.segmented-4 {
  grid-template-columns: repeat(4, 1fr);
}

@keyframes fadePulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

/* Settings Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.16s ease;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: fadeUp 0.2s ease;
}

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

.modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.modal-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--text);
}

.setting-help {
  display: block;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
}

.segmented-btn {
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented-btn[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.setting-textarea {
  width: 100%;
  resize: vertical;
  min-height: 76px;
  max-height: 180px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s ease;
}

.setting-textarea:focus {
  border-color: var(--accent);
}

.setting-danger {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.danger-btn {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--error-border);
  border-radius: 10px;
  background: var(--error-bg);
  color: var(--error-text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 550;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.danger-btn:hover:not(:disabled) {
  opacity: 0.88;
}

.danger-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: scale(0.85);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: var(--sidebar-width);
    transform: translateX(0);
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-modal);
  }

  .app.sidebar-collapsed .sidebar {
    width: var(--sidebar-width);
    transform: translateX(-100%);
    box-shadow: none;
  }

  .app:not(.sidebar-collapsed) .sidebar-open-btn,
  .app:not(.sidebar-collapsed) .topbar-brand {
    display: inline-flex;
  }

  .topbar {
    padding: 0 14px;
  }

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

  .composer-shell {
    padding: 0 12px 14px;
  }

  .picker-pill {
    max-width: 175px;
  }

  .message-actions,
  .history-delete-btn {
    opacity: 1;
  }
}
