:root {
  --bg: #f3f0ea;
  --panel: #fffdf8;
  --panel-soft: #e8e3da;
  --text: #111111;
  --muted: #75716a;
  --line: #d9d2c7;
  --accent: #111111;
  --accent-text: #f8f4ec;
  --bubble: #e7e1d7;
  --shadow: 0 18px 48px rgba(20, 16, 11, .12);
}

body.dark {
  --bg: #141923;
  --panel: #1e2531;
  --panel-soft: #2a3342;
  --text: #f5f2eb;
  --muted: #a7adba;
  --line: #344052;
  --accent: #f5f2eb;
  --accent-text: #141923;
  --bubble: #252e3c;
  --shadow: 0 18px 48px rgba(0, 0, 0, .36);
}

* { box-sizing: border-box; }

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

button,
textarea { font: inherit; }

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

.app-shell {
  display: flex;
  flex-direction: column;
  max-width: 860px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 68px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(14px);
}

.icon-button,
.plain-button {
  background: transparent;
}

.menu-button {
  display: grid;
  align-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 0 8px;
}

.menu-button span {
  display: block;
  width: 24px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  font-size: 20px;
  font-weight: 850;
}

.brand b { color: var(--muted); }

.drawer-logo,
.welcome-logo {
  display: grid;
  place-items: center;
  background: var(--text);
  color: var(--bg);
  font-weight: 900;
}

.model-current {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(56vw, 360px);
  margin-left: auto;
  padding: 6px 9px 6px 6px;
  border-radius: 13px;
  background: var(--panel-soft);
  font-size: 12px;
  font-weight: 700;
}

#selectedModelName {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tiny-logo,
.logo {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--text);
  color: var(--bg);
  font-size: 10px;
  font-weight: 900;
}

.chevron {
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 16px;
}

.welcome {
  margin: auto;
  text-align: center;
}

.welcome-logo {
  width: 76px;
  height: 76px;
  margin: 0 auto 16px;
  border-radius: 25px;
  font-size: 36px;
}

.welcome h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.05;
}

.welcome p {
  margin: 0;
  color: var(--muted);
}

.bubble {
  max-width: min(86%, 680px);
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.message-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: min(86%, 680px);
}

.message-wrap.user { align-self: flex-end; align-items: flex-end; }
.message-wrap.assistant { align-self: flex-start; align-items: flex-start; }

.message-wrap .bubble {
  max-width: 100%;
}

.message-meta {
  max-width: 100%;
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.message-wrap.user .message-meta {
  text-align: right;
}

.bubble.user {
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  background: var(--text);
  color: var(--bg);
}

.bubble.assistant {
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  background: var(--bubble);
}

.bubble code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, .08);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.composer {
  flex: none;
  margin: 0 12px max(14px, env(safe-area-inset-bottom));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.composer-tools {
  display: flex;
  align-items: center;
  min-height: 26px;
  padding-bottom: 2px;
}

.reasoning-current {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.reasoning-current:not(:disabled):hover {
  background: var(--panel-soft);
  color: var(--text);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.input-row textarea {
  flex: 1;
  display: block;
  min-height: 30px;
  max-height: 168px;
  padding: 6px 7px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  line-height: 1.45;
}

.send {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  margin-bottom: 1px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 21px;
  font-weight: 800;
}

.send:disabled { opacity: .45; }

.drawer {
  position: fixed;
  z-index: 5;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: min(88vw, 356px);
  padding: 16px;
  background: var(--panel);
  box-shadow: 16px 0 42px rgba(0, 0, 0, .28);
  transform: translateX(-105%);
  transition: transform .22s ease;
}

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

.drawer-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-bottom: 18px;
}

.drawer-head strong {
  font-size: 18px;
}

.drawer-logo {
  width: 34px;
  height: 34px;
  border-radius: 11px;
}

.drawer-head button {
  margin-left: auto;
  color: var(--muted);
  font-size: 28px;
}

.new-chat {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  text-align: left;
  font-weight: 750;
}

.history-title {
  padding: 26px 8px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .6px;
  text-transform: uppercase;
}

.history-list {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 6px;
  overflow: auto;
  padding: 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.history-list p { margin: 4px 0; }

.history-item {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: stretch;
  overflow: hidden;
  border-radius: 10px;
}

.history-item.active {
  background: var(--panel-soft);
}

.history-open {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 9px 8px;
  background: transparent;
  text-align: left;
}

.history-open strong,
.history-open small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history-open strong {
  font-size: 13px;
}

.history-open small {
  color: var(--muted);
  font-size: 11px;
}

.history-delete {
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

.drawer-bottom {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.theme-toggle,
.account-preview {
  display: flex;
  align-items: center;
  width: 100%;
  background: transparent;
  text-align: left;
}

.theme-toggle {
  gap: 10px;
  padding: 10px 7px;
  color: var(--muted);
  font-size: 13px;
}

.account-preview {
  gap: 10px;
  padding: 10px 4px;
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 43px;
  height: 43px;
  border-radius: 50%;
  background-position: center;
  background-size: cover;
}

.placeholder {
  background: var(--text);
  color: var(--bg);
  font-weight: 800;
}

.account-text {
  display: grid;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.account-text strong,
.account-text small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

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

.backdrop,
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .46);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}

.backdrop.show {
  z-index: 4;
  opacity: 1;
  visibility: visible;
}

.sheet-backdrop.show {
  z-index: 6;
  opacity: 1;
  visibility: visible;
}

.sheet {
  position: fixed;
  z-index: 7;
  inset: auto 0 0;
  display: flex;
  flex-direction: column;
  max-width: 860px;
  max-height: 78dvh;
  margin: auto;
  border-radius: 24px 24px 0 0;
  background: var(--panel);
  box-shadow: 0 -16px 42px rgba(0, 0, 0, .2);
  transform: translateY(105%);
  transition: transform .22s ease;
}

.sheet.show { transform: translateY(0); }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
}

.sheet-head strong {
  flex: 1;
  font-size: 16px;
}

.sheet-head button {
  width: 30px;
  color: var(--muted);
  font-size: 28px;
}

.sheet-head .back {
  background: transparent;
  font-size: 35px;
  line-height: 12px;
}

.model-list {
  overflow: auto;
  padding: 9px 13px 22px;
}

.company-row,
.model-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 12px 8px;
  border-radius: 12px;
  background: transparent;
  text-align: left;
}

.company-row:hover,
.model-row:not(:disabled):hover {
  background: var(--panel-soft);
}

.company-row span:nth-child(2) {
  flex: 1;
  font-weight: 750;
}

.company-row b,
.model-row > b {
  margin-left: auto;
  color: var(--muted);
  font-size: 21px;
  font-weight: 400;
}

.model-row > span:nth-child(2) {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.model-row strong {
  font-size: 14px;
}

.model-row em {
  color: var(--muted);
  font-style: normal;
  font-weight: 650;
}

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

.model-row.locked {
  opacity: .38;
  cursor: not-allowed;
}

.profile-full {
  overflow: auto;
  padding: 22px;
  text-align: center;
}

.profile-full > .avatar {
  width: 76px;
  height: 76px;
  margin: 0 auto;
  font-size: 28px;
}

.profile-full h2 {
  margin: 12px 0 3px;
  font-size: 21px;
}

.profile-full > p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.profile-data {
  display: grid;
  gap: 1px;
  overflow: hidden;
  margin: 23px 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  text-align: left;
}

.profile-data span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  background: var(--panel-soft);
  font-size: 13px;
}

.profile-data b {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-weight: 750;
}

.admin-reset {
  width: 100%;
  padding: 11px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 750;
}

.admin-secondary {
  margin-top: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

.admin-panel {
  display: grid;
  gap: 12px;
  overflow: auto;
  padding: 18px;
}

.admin-field {
  display: grid;
  gap: 7px;
  text-align: left;
}

.admin-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.admin-field input,
.admin-field select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
}

.admin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.admin-result {
  min-height: 44px;
  color: var(--muted);
  font-size: 13px;
}

.admin-user-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  color: var(--text);
  text-align: left;
}

.admin-user-card strong {
  display: block;
  font-size: 15px;
}

.admin-user-card small {
  display: block;
  color: var(--muted);
  line-height: 1.5;
}

.auth-lock {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 28px;
  background: var(--bg);
  text-align: center;
}

.auth-lock.hidden { display: none; }

.auth-icon {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 23px;
  background: var(--text);
  font-size: 29px;
}

.auth-lock h1 {
  margin: 14px 0 8px;
  font-size: 27px;
}

.auth-lock p {
  max-width: 330px;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 430px) {
  .brand span:last-child { display: none; }
  .model-current { max-width: calc(100vw - 116px); }
  .bubble { max-width: 92%; }
}
