:root {
  color-scheme: dark;
  --bg: #09090b;
  --bg-sidebar: #18181b;
  --surface: #27272a;
  --surface-hover: #3f3f46;
  --border: #27272a;
  --border-strong: #3f3f46;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #52525b;
  --accent: #f4f4f5;
  --accent-hover: #ffffff;
  --danger: #ef4444;
  --code-bg: #000000;
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--surface-hover);
  border-radius: 4px;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 14px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.1s ease, color 0.1s ease, border-color 0.1s ease;
}

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

button:disabled {
  cursor: wait;
  opacity: 0.5;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 14px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--muted);
}

textarea {
  line-height: 1.5;
  resize: none;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

h3 {
  margin-bottom: 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

h4 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.muted,
.message {
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.message.error {
  color: var(--danger);
}

.legal-links {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
  font-size: 12px;
}

.legal-links a,
.legal-page a {
  color: var(--muted);
}

.legal-page {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0;
  line-height: 1.7;
}

.legal-page h2 {
  margin-top: 28px;
  margin-bottom: 8px;
  font-size: 17px;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(360px, 100%);
}

.auth-panel .eyebrow {
  color: var(--muted);
  text-align: center;
}

.auth-panel h1,
.auth-panel .muted {
  text-align: center;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 26px 0 24px;
}

.tab {
  flex: 1;
  padding: 8px 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
}

.tab.active {
  border-bottom-color: var(--text);
  color: var(--text);
}

.form,
.compact-form {
  display: grid;
  gap: 12px;
}

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

.form button,
.primary-action,
.feedback-form button,
.compact-form button {
  min-height: 40px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
}

.form button:hover,
.primary-action:hover,
.feedback-form button:hover,
.compact-form button:hover {
  background: #d4d4d8;
}

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

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--bg-sidebar);
}

.brand {
  min-height: 64px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--surface-hover);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.brand .eyebrow {
  display: none;
}

.icon-button {
  width: 32px;
  height: 32px;
  margin-left: auto;
  color: var(--muted);
}

.icon-button:hover {
  color: var(--text);
}

.primary-action {
  width: calc(100% - 32px);
  margin: 0 16px 14px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
}

.primary-action:hover {
  background: var(--surface);
}

.search {
  padding: 0 16px 14px;
}

.search input,
.feedback-form select,
.feedback-form textarea {
  border-color: transparent;
  background: var(--bg-sidebar);
}

.search input:hover,
.feedback-form select:hover,
.feedback-form textarea:hover {
  border-color: var(--border);
}

.conversation-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: auto;
  padding: 0 12px;
}

.conversation-item {
  width: 100%;
  justify-content: flex-start;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--muted);
  text-align: left;
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--surface);
  color: var(--text);
}

.conversation-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.conversation-meta,
.audit-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.feedback-form {
  display: grid;
  gap: 8px;
  margin: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: relative;
}

.topbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  min-width: 0;
}

.topbar-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
}

.model-control {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.model-control select {
  width: 220px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 7px 24px 7px 8px;
  font-size: 13px;
  font-weight: 500;
}

.reasoning-control select {
  width: 96px;
}

.model-control select:hover {
  background: var(--surface);
}

.model-description {
  max-width: 360px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-strip {
  display: flex;
  gap: 6px;
}

.status-strip span,
#creditBalance {
  display: inline-grid;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
}

.account {
  min-width: 0;
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

#userEmail {
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-toggle {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  color: var(--muted);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 32px;
  overflow: auto;
  padding: 28px 24px 0;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.message-bubble {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
  color: var(--text);
  line-height: 1.65;
  white-space: pre-wrap;
  font-size: 15px;
}

.message-bubble.user {
  font-weight: 500;
}

.message-bubble.assistant {
  color: var(--text);
}

.message-bubble pre {
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

.message-bubble code {
  border-radius: 4px;
  background: var(--surface);
  padding: 2px 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.message-bubble pre code {
  background: transparent;
  padding: 0;
}

.composer {
  width: min(1200px, calc(100% - 48px));
  min-width: 0;
  margin: 0 auto 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--bg-sidebar);
}

.composer:focus-within {
  border-color: var(--muted);
}

.composer textarea {
  min-width: 0;
  min-height: 34px;
  max-height: 220px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 5px 0;
  font-size: 15px;
}

.composer textarea:focus {
  outline: none;
}

.composer textarea::placeholder {
  color: var(--faint);
}

.composer button {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  min-height: 32px;
  align-self: end;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 18px;
  font-weight: 700;
}

.composer button:hover {
  background: var(--muted);
}

.inspector {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(420px, 100vw);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: auto;
  border-left: 1px solid var(--border);
  background: var(--bg-sidebar);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

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

.drawer-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
}

.panel {
  margin: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.audit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.billing-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.billing-package {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-sidebar);
}

.billing-package strong {
  display: block;
  color: var(--text);
  font-size: 13px;
}

.audit-item {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-sidebar);
  color: var(--muted);
  font-size: 12px;
}

.audit-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 13px;
}

.user-detail-card {
  border-color: var(--border-strong);
  background: var(--surface);
}

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

.stat-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-sidebar);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-list {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.action-item {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
}

.subsection {
  margin-top: 14px;
}

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

.export-actions .small-action,
.export-actions .audit-meta {
  grid-column: 1 / -1;
}

.export-actions .link-button {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  text-decoration: none;
}

.split-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.split-item > div {
  min-width: 0;
}

.pill {
  flex: 0 0 auto;
  display: inline-grid;
  min-height: 22px;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.small-action {
  width: 100%;
  min-height: 32px;
  margin-top: 8px;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  font-size: 12px;
}

.link-button {
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
}

.link-button:hover {
  color: var(--text);
}

.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

@media (max-width: 1120px) {
  .app {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .topbar-main,
  .account,
  .status-strip {
    width: 100%;
    flex-wrap: wrap;
  }

  .account {
    justify-content: flex-start;
  }

  .model-description {
    max-width: min(420px, 100%);
  }

  #userEmail {
    max-width: 180px;
  }
}

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

  .sidebar {
    display: none;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-main,
  .account,
  .status-strip {
    flex-wrap: wrap;
  }

  .model-control select {
    width: min(100%, 280px);
  }

  .reasoning-control select {
    width: 120px;
  }

  .model-description {
    max-width: calc(100vw - 36px);
  }

  .message-bubble,
  .composer {
    width: calc(100% - 24px);
    max-width: calc(100% - 24px);
  }

  .messages {
    padding-inline: 12px;
  }
}
