:root {
  color-scheme: dark;
  --bg: #101114;
  --surface: #17191f;
  --surface-2: #20242d;
  --surface-3: #2a303b;
  --text: #f5f7fb;
  --muted: #aab2c0;
  --line: #323947;
  --brand: #3bc7b8;
  --brand-2: #f2c94c;
  --danger: #ff6978;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="daylight"] {
  color-scheme: light;
  --bg: #f2f5f8;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --surface-3: #dfe7ec;
  --text: #15191f;
  --muted: #596673;
  --line: #d3dce3;
  --brand: #0969da;
  --brand-2: #24a148;
}

body[data-theme="forest"] {
  --bg: #101613;
  --surface: #18211d;
  --surface-2: #213129;
  --surface-3: #2e4338;
  --brand: #70e1a1;
  --brand-2: #f8d66d;
}

body[data-theme="orchid"] {
  --bg: #151217;
  --surface: #201923;
  --surface-2: #2d2331;
  --surface-3: #3d3043;
  --brand: #ff8cc6;
  --brand-2: #7bdff2;
}

body[data-theme="copper"] {
  --bg: #151312;
  --surface: #211c19;
  --surface-2: #302823;
  --surface-3: #46382f;
  --brand: #ffb36b;
  --brand-2: #7bd3c2;
}

body[data-theme="graphite"] {
  --bg: #0f1113;
  --surface: #191c20;
  --surface-2: #22262c;
  --surface-3: #313741;
  --brand: #d7dee8;
  --brand-2: #69d2e7;
}

body[data-theme="ruby"] {
  --bg: #171113;
  --surface: #22181b;
  --surface-2: #322126;
  --surface-3: #432c33;
  --brand: #ff6f91;
  --brand-2: #ffd166;
}

body[data-theme="lagoon"] {
  --bg: #0f1416;
  --surface: #172124;
  --surface-2: #213237;
  --surface-3: #2a444a;
  --brand: #4dd0e1;
  --brand-2: #c5e86c;
}

body[data-theme="paper"] {
  color-scheme: light;
  --bg: #f7f3ed;
  --surface: #fffdf8;
  --surface-2: #eee8df;
  --surface-3: #e2d8cb;
  --text: #1b1917;
  --muted: #68615a;
  --line: #d7cec3;
  --brand: #b65d2f;
  --brand-2: #386a56;
}

body[data-theme="contrast"] {
  --bg: #050505;
  --surface: #111111;
  --surface-2: #1f1f1f;
  --surface-3: #2e2e2e;
  --text: #ffffff;
  --muted: #d0d0d0;
  --line: #555555;
  --brand: #00e5ff;
  --brand-2: #ffff00;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #07100f;
  font-weight: 800;
}

.brand-name {
  font-weight: 800;
  line-height: 1.1;
}

.brand-domain,
.section-title,
.provider-pill span,
.list-toolbar p,
.empty-reader p,
.dialog-card p,
.reader-meta,
.thread-time,
.message-preview,
#attachmentSummary {
  color: var(--muted);
}

.brand-domain {
  font-size: 12px;
  margin-top: 2px;
}

.compose-main,
.primary-button {
  border: 0;
  color: #07100f;
  background: var(--brand);
  font-weight: 800;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 18px;
  box-shadow: var(--shadow);
}

.folder-nav,
.sidebar-section {
  display: grid;
  gap: 6px;
}

.section-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  padding: 0 8px;
}

.nav-item,
.label-chip,
.provider-pill,
.ghost-button,
.mini-button,
.icon-button,
.filter-pill,
.attach-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
}

.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
}

.nav-item:hover,
.nav-item.active,
.label-chip:hover,
.filter-pill.active {
  background: var(--surface-2);
  border-color: var(--line);
}

.nav-item b {
  color: var(--brand-2);
  font-size: 12px;
}

.label-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  text-align: left;
}

.label-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.work { background: #4dd0e1; }
.finance { background: #f2c94c; }
.travel { background: #ff8cc6; }
.personal { background: #70e1a1; }

.provider-pill {
  display: flex;
  justify-content: space-between;
  background: var(--surface-2);
  padding: 9px 10px;
  font-size: 13px;
}

.main-panel {
  min-width: 0;
  background: var(--bg);
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.06);
}

.search-box {
  flex: 1;
  min-width: 180px;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0 14px;
}

.search-box span {
  color: var(--muted);
  font-size: 13px;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.ghost-button,
.mini-button,
.icon-button,
.filter-pill,
.attach-button {
  background: var(--surface);
  border-color: var(--line);
  min-height: 36px;
  padding: 0 12px;
}

.ghost-button:hover,
.mini-button:hover,
.icon-button:hover,
.attach-button:hover {
  background: var(--surface-2);
}

.mail-layout {
  display: grid;
  grid-template-columns: minmax(330px, 42%) minmax(0, 1fr);
  height: calc(100vh - 68px);
}

.message-list-panel {
  border-right: 1px solid var(--line);
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.list-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  align-items: center;
}

.list-toolbar h1 {
  margin: 0;
  font-size: 28px;
}

.list-toolbar p {
  margin: 4px 0 0;
  font-size: 13px;
}

.toolbar-actions,
.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-pill {
  min-height: 32px;
}

.advanced-filters {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 18px;
  display: grid;
  gap: 10px;
}

.filter-menu-title {
  font-weight: 800;
}

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

.filter-fields label,
.filter-toggles label {
  color: var(--muted);
  font-size: 12px;
}

.filter-fields input,
.filter-fields select {
  width: 100%;
  min-height: 34px;
  margin-top: 4px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  outline: 0;
  padding: 0 10px;
}

.filter-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filter-toggles label {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0 9px;
}

.message-list {
  overflow: auto;
  padding: 0 10px 18px;
}

.message-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  width: 100%;
  text-align: left;
}

.message-row:hover,
.message-row.active {
  background: var(--surface);
  border-color: var(--line);
}

.message-row.unread .message-subject,
.message-row.unread .sender-name {
  font-weight: 850;
}

.star {
  color: var(--brand-2);
  font-size: 17px;
}

.sender-line,
.message-subject,
.message-preview {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sender-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.message-subject {
  margin-top: 4px;
}

.message-preview {
  margin-top: 3px;
  font-size: 13px;
}

.row-labels {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.row-labels span {
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.thread-time {
  font-size: 12px;
}

.reader-panel {
  overflow: auto;
  background: var(--surface);
}

.empty-reader {
  min-height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  padding: 28px;
}

.empty-icon {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 14px 18px;
  color: var(--brand);
  font-weight: 800;
}

.reader-content {
  padding: 28px;
}

.reader-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.reader-top h2 {
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.08;
  margin: 0 0 12px;
}

.reader-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: start;
  justify-content: flex-end;
}

.reader-body {
  padding: 24px 0;
  line-height: 1.6;
  white-space: pre-wrap;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-list span {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.ai-box {
  border-left: 3px solid var(--brand);
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 0 8px 8px 0;
  margin-top: 16px;
}

.compose-window {
  position: fixed;
  right: 24px;
  bottom: 0;
  width: min(560px, calc(100vw - 32px));
  height: min(680px, calc(100vh - 48px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 20;
}

.hidden {
  display: none !important;
}

.compose-window header,
.dialog-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.compose-fields {
  display: grid;
  border-bottom: 1px solid var(--line);
}

.compose-fields input,
.compose-fields select,
.settings-grid input,
.settings-grid textarea {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  outline: 0;
  padding: 13px 16px;
}

.compose-from-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.compose-from-row span {
  padding-left: 16px;
}

.compose-fields select {
  appearance: none;
  color: var(--text);
  background: transparent;
}

.compose-window textarea {
  flex: 1;
  min-height: 150px;
  border: 0;
  resize: none;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 16px;
}

.writing-assistant {
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  padding: 10px 12px;
}

.assistant-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.assistant-result {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 8px;
  max-height: 88px;
  overflow: auto;
}

.suggestion-list {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.suggestion-list li {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
}

.suggestion-list b {
  color: var(--text);
}

.signature-preview {
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  color: var(--muted);
  font-size: 13px;
  max-height: 130px;
  overflow: auto;
}

.signature-preview img {
  display: block;
  max-width: 220px;
  max-height: 70px;
  margin-top: 8px;
}

.compose-window footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.attach-button input {
  display: none;
}

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

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

.dialog-card {
  width: min(780px, calc(100vw - 28px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dialog-card.wide {
  width: min(980px, calc(100vw - 28px));
}

.dialog-card h2,
.dialog-card h3 {
  margin: 0;
}

.dialog-card p {
  margin: 4px 0 0;
  font-size: 13px;
}

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

.settings-grid section,
.provider-config {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-2);
}

.settings-grid label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 12px;
}

.settings-grid textarea {
  min-height: 104px;
  resize: vertical;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 8px;
}

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

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

.theme-swatch,
.connect-card {
  min-height: 62px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
  text-align: left;
}

.theme-swatch.active {
  outline: 2px solid var(--brand);
}

.connect-grid {
  padding: 16px;
}

.connect-card {
  display: grid;
  gap: 4px;
}

.connect-card span {
  color: var(--muted);
  font-size: 13px;
}

.provider-config {
  margin: 0 16px 16px;
}

.provider-config code {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  margin-top: 8px;
  color: var(--brand);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
  z-index: 40;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.mobile-only {
  display: none;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    transform: translateX(-110%);
    transition: transform 0.18s ease;
    z-index: 30;
    box-shadow: var(--shadow);
  }

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

  .mobile-only {
    display: inline-flex;
  }

  .mail-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .message-list-panel {
    border-right: 0;
    min-height: 46vh;
  }

  .reader-panel {
    min-height: 54vh;
    border-top: 1px solid var(--line);
  }

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

@media (max-width: 680px) {
  .topbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .top-actions,
  .toolbar-actions,
  .reader-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions > *,
  .toolbar-actions > *,
  .reader-actions > * {
    flex: 1;
  }

  .list-toolbar,
  .reader-top {
    display: grid;
  }

  .theme-grid,
  .connect-grid,
  .filter-fields {
    grid-template-columns: 1fr;
  }
}
