:root {
  color-scheme: dark;
  /* codex-theme-v1 / Ayu */
  --bg: #0b0f14;
  --surface: #10141c;
  --surface-soft: #1c2430;
  --surface-raised: #151b24;
  --border: #303744;
  --text: #bfbdb6;
  --muted: #7d8490;
  --accent: #e6b450;
  --accent-strong: #f0c36a;
  --danger: #f26d78;
  --success: #70bf56;
  --skill: #d0a1ff;
  --inbound: #1b222d;
  --outbound: #e6b450;
  --outbound-ink: #10141c;
  --disabled: #242b35;
  --disabled-text: #69717f;
  --accent-wash: rgba(230, 180, 80, 0.14);
  --accent-focus: rgba(230, 180, 80, 0.26);
  --danger-wash: rgba(242, 109, 120, 0.15);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.48);
  --font-ui: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-code: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --sidebar-expanded-width: 300px;
  --sidebar-width: var(--sidebar-expanded-width);
  --list-width: 320px;
  font-family: var(--font-ui);
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  max-width: 100%;
  background:
    radial-gradient(circle at 82% -10%, rgba(230, 180, 80, 0.07), transparent 34%),
    var(--bg);
  color: var(--text);
}

body:not(.sidebar-expanded) {
  --sidebar-width: 72px;
}

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

code,
kbd,
pre,
samp {
  font-family: var(--font-code);
}

button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--outbound-ink);
  font-weight: 650;
  cursor: pointer;
  padding: 0 14px;
}

button:hover:not(:disabled) {
  background: var(--accent-strong);
}

button:disabled {
  border-color: var(--border);
  background: var(--disabled);
  color: var(--disabled-text);
  cursor: not-allowed;
}

.secondary-button {
  border-color: var(--border);
  background: transparent;
  color: var(--text);
}

.secondary-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 5px var(--list-width) 5px minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.message-list-panel,
.reader {
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overflow: hidden;
  padding: 14px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sidebar-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(230, 180, 80, 0.36);
  background: #0a0e13;
  color: var(--accent);
  font-weight: 700;
}

.brand-text,
.sidebar-content {
  min-width: 0;
}

body:not(.sidebar-expanded) .brand-text,
body:not(.sidebar-expanded) .sidebar-content,
body:not(.sidebar-expanded) .sidebar-footer {
  display: none;
}

.sidebar-content {
  display: grid;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.pane-resizer {
  position: relative;
  z-index: 3;
  background: var(--border);
  cursor: col-resize;
}

.pane-resizer::after {
  content: "";
  position: absolute;
  inset: 0 -4px;
}

.pane-resizer:hover,
body.resizing .pane-resizer {
  background: var(--accent);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

h2 {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
}

p,
.field span,
.check-row {
  color: var(--muted);
  font-size: 13px;
}

.logout-button {
  width: 100%;
  border-color: var(--border);
  background: transparent;
  color: var(--muted);
}

.logout-button:hover {
  border-color: var(--border);
  background: rgba(191, 189, 182, 0.07);
  color: var(--text);
}

.field {
  display: grid;
  gap: 7px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d1219;
  color: var(--text);
  padding: 10px 11px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-focus);
}

textarea {
  resize: vertical;
  min-height: 92px;
}

.mailbox-form {
  display: grid;
  gap: 10px;
}

.mailbox-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
}

.mailbox-section {
  display: grid;
  gap: 8px;
}

.mailbox-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mailbox-section-heading h2 {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mailbox-section-heading span {
  color: var(--muted);
  font-size: 12px;
}

.mailbox-search-results {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  padding: 8px;
}

.mailbox-search-results[hidden] {
  display: none;
}

.mailbox-search-result {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 54px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
}

.mailbox-search-result:hover {
  border-color: var(--border);
  background: var(--surface-soft);
}

.mailbox-search-result strong,
.mailbox-display-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-search-result span,
.mailbox-email,
.mailbox-tenant {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-email,
.mailbox-tenant {
  font-family: var(--font-code);
}

.mailbox-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px 34px;
  align-items: stretch;
  min-height: 66px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

.mailbox-chip.favorite-only {
  grid-template-columns: minmax(0, 1fr) 34px;
}

.mailbox-open,
.mailbox-favorite,
.mailbox-remove {
  min-height: 64px;
  border: 0;
  border-radius: 0;
}

.mailbox-open {
  display: grid;
  align-content: center;
  gap: 2px;
  min-width: 0;
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  text-align: left;
}

.mailbox-display-name {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.mailbox-favorite,
.mailbox-remove {
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.mailbox-favorite {
  font-size: 18px;
}

.mailbox-favorite.active {
  color: var(--accent);
}

.mailbox-favorite:hover {
  background: var(--accent-wash);
  color: var(--accent-strong);
}

.mailbox-remove:hover {
  background: var(--danger-wash);
  color: var(--danger);
}

.mailbox-chip.active {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.mailbox-chip.active .mailbox-open {
  background: var(--accent-wash);
}

.mailbox-chip.loading {
  border-color: var(--skill);
}

.mailbox-chip.error {
  border-color: var(--danger);
}

.sidebar-footer {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

.message-list-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(16, 20, 28, 0.92);
}

.toolbar,
.reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  background: rgba(15, 20, 28, 0.94);
  backdrop-filter: blur(16px);
}

.toolbar > div,
.reader-header > div {
  min-width: 0;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.nav-back {
  display: none;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  border-bottom: 1px solid var(--border);
  background: #0d1219;
  padding: 8px 14px;
  color: var(--muted);
  font-size: 13px;
}

.message-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.message-item {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 12px 14px;
  text-align: left;
}

.message-item:hover,
.message-item.active {
  background: var(--surface-soft);
}

.message-item.unread .message-from {
  color: var(--accent-strong);
  font-weight: 800;
}

.message-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.message-from,
.message-date {
  color: var(--muted);
  font-size: 13px;
}

.message-from {
  color: var(--text);
  font-weight: 750;
}

.message-subject {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.unread-pill {
  display: inline-grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--outbound-ink);
  font-size: 12px;
  font-weight: 700;
  padding: 0 6px;
}

.message-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.sent-check {
  display: inline-block;
  margin-right: 5px;
  color: var(--success);
  font-size: 12px;
  letter-spacing: 0;
}

.preview-sender {
  color: var(--text);
  font-weight: 700;
}

.preview-text {
  color: var(--muted);
}

.reader {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  border-right: 0;
  background: var(--bg);
}

.bulk-bar[hidden],
.selection-bar[hidden],
.reply-form[hidden] {
  display: none;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 28px max(28px, calc((100% - 1120px) / 2));
  background:
    linear-gradient(rgba(11, 15, 20, 0.82), rgba(11, 15, 20, 0.96)),
    radial-gradient(circle at 70% 0%, rgba(208, 161, 255, 0.05), transparent 34%);
}

.chat-message-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.chat-message-row.inbound {
  justify-content: flex-start;
}

.chat-message-row.outbound {
  justify-content: flex-end;
}

.message-select-toggle {
  display: none;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  min-height: 22px;
  border: 1px solid var(--muted);
  border-radius: 999px;
  background: transparent;
  color: var(--outbound-ink);
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

.chat-message-row.selecting .message-select-toggle {
  display: grid;
}

.message-select-toggle.selected {
  border-color: var(--accent-strong);
  background: var(--accent);
}

.chat-bubble {
  width: fit-content;
  max-width: min(680px, 68%);
  min-width: 0;
  overflow: hidden;
  border: 0;
  border-radius: 18px;
  background: var(--inbound);
  box-shadow: none;
  padding: 9px 12px;
}

.chat-bubble.outbound {
  align-self: flex-end;
  background: var(--outbound);
  border-color: transparent;
}

.chat-bubble.inbound {
  align-self: flex-start;
}

.chat-bubble.selected {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.bubble-body {
  margin-top: 6px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 100%;
  white-space: pre-wrap;
}

.bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.bubble-select-row,
.bubble-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bubble-copy,
.bubble-menu-button {
  min-height: 26px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  padding: 0 7px;
}

.bubble-menu-button {
  min-width: 28px;
  font-weight: 700;
  letter-spacing: 0;
}

.bubble-copy:hover,
.bubble-menu-button:hover {
  border-color: var(--border);
  background: rgba(191, 189, 182, 0.08);
  color: var(--text);
}

.bubble-menu-wrap {
  position: relative;
}

.bubble-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 10;
  min-width: 120px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  padding: 5px;
}

.bubble-select-option {
  width: 100%;
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.bubble-select-option:hover {
  background: var(--surface-soft);
}

.selection-bar {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  border-top: 1px solid var(--border);
  background: var(--surface-raised);
  padding: 10px 14px;
  color: var(--text);
}

.selection-cancel {
  display: grid;
  place-items: center;
  width: 36px;
  min-height: 36px;
  border-color: var(--border);
  background: transparent;
  color: var(--text);
  padding: 0;
}

.selection-secondary,
.selection-copy {
  min-width: 92px;
}

.selection-secondary {
  border-color: var(--border);
  background: transparent;
  color: var(--text);
}

.selection-secondary:hover {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.reply-form {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 12px max(16px, calc((100% - 1120px) / 2));
  background: rgba(15, 20, 28, 0.94);
  backdrop-filter: blur(16px);
}

.reply-compose {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.reply-identity {
  color: var(--muted);
  font-size: 12px;
}

.reply-identity strong {
  color: var(--text);
}

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

.reply-form textarea {
  min-height: 44px;
  max-height: 140px;
  border-radius: 16px;
  background: var(--surface-soft);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  color: var(--text);
}

.empty-state,
.error-state {
  padding: 24px 16px;
  color: var(--muted);
}

.empty-state.compact {
  padding: 8px 4px;
  font-size: 12px;
}

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

.login-page {
  display: grid;
  place-items: center;
}

.login-shell {
  display: grid;
  place-items: center;
  width: min(420px, calc(100vw - 32px));
}

.login-panel {
  display: grid;
  gap: 22px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-error {
  min-height: 18px;
  color: var(--danger);
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .pane-resizer {
    display: none;
  }

  .reader {
    grid-column: 2;
    grid-row: 1;
  }

  body.pane-chats .reader,
  body.pane-mailboxes .reader {
    display: none;
  }

  body.pane-conversation .message-list-panel {
    display: none;
  }

  .nav-back {
    display: inline-flex;
    align-items: center;
  }
}

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

  body:not(.sidebar-expanded),
  body.sidebar-expanded {
    --sidebar-width: 1fr;
  }

  .sidebar,
  .message-list-panel,
  .reader {
    grid-column: 1;
    grid-row: 1;
    min-height: 100dvh;
  }

  body.pane-mailboxes .message-list-panel,
  body.pane-mailboxes .reader,
  body.pane-chats .sidebar,
  body.pane-chats .reader,
  body.pane-conversation .sidebar,
  body.pane-conversation .message-list-panel {
    display: none;
  }

  .toolbar,
  .reader-header {
    min-height: 64px;
    padding: 10px 12px;
  }

  .toolbar {
    align-items: flex-start;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .reader-header {
    align-items: flex-start;
  }

  .reader-header #readButton {
    display: none;
  }

  .chat-thread {
    padding: 12px;
  }

  .chat-bubble {
    width: 88%;
  }

  .reply-form {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .reply-form textarea {
    min-height: 74px;
  }
}

.bubble-body.rich {
  white-space: normal;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.bubble-body.rich > :first-child {
  margin-top: 0;
}

.bubble-body.rich > :last-child {
  margin-bottom: 0;
}

.bubble-body.rich p,
.bubble-body.rich div,
.bubble-body.rich blockquote,
.bubble-body.rich ul,
.bubble-body.rich ol,
.bubble-body.rich pre,
.bubble-body.rich table {
  max-width: 100%;
}

.bubble-body.rich p {
  margin: 0 0 0.75em;
}

.bubble-body.rich a {
  color: inherit;
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.bubble-body.rich table {
  border-collapse: collapse;
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
}

.bubble-body.rich td,
.bubble-body.rich th {
  padding: 3px 5px;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble-body.rich pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble-body.rich code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble-body.rich img {
  max-width: 100%;
  height: auto;
}

.conversation-limit-notice {
  align-self: center;
  max-width: min(680px, 100%);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.email-inline-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 70vh;
  margin: 9px 0;
  border-radius: 8px;
  object-fit: contain;
}

.email-attachment-image {
  margin-top: 10px;
}

.chat-bubble.outbound .bubble-body,
.chat-bubble.outbound .bubble-body * {
  color: var(--outbound-ink) !important;
}

.chat-bubble.outbound .bubble-meta,
.chat-bubble.outbound .bubble-footer,
.chat-bubble.outbound .bubble-copy,
.chat-bubble.outbound .bubble-menu-button {
  color: rgba(16, 20, 28, 0.9);
}
