:root {
  color-scheme: light dark;
  --ink: #1d252c;
  --muted: #687178;
  --line: #d8d5ce;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --soft: #f3f0e8;
  --soft-2: #ece5d8;
  --reader-bg: #f8f5ef;
  --active-row: #dfece5;
  --input-bg: #ffffff;
  --composer-header-bg: #1a2229;
  --composer-header-ink: #fff8ea;
  --composer-field-label-bg: #f5efe4;
  --shadow: rgb(20 24 28 / 18%);
  --accent: #34745f;
  --accent-strong: #225745;
  --accent-soft: #d6e8df;
  --danger: #b5453c;
  --focus: #4a9279;
  font-family: "Segoe UI", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f4efe6;
  --muted: #a89f91;
  --line: #2d3336;
  --panel: #171c1f;
  --panel-strong: #1d2327;
  --soft: #0f1315;
  --soft-2: #22201b;
  --reader-bg: #121719;
  --active-row: #172b24;
  --input-bg: #101517;
  --composer-header-bg: #17231f;
  --composer-header-ink: #fff4de;
  --composer-field-label-bg: #151a1d;
  --shadow: rgb(0 0 0 / 42%);
  --accent: #63b394;
  --accent-strong: #8bd0b6;
  --accent-soft: #1d352d;
  --danger: #ff8277;
  --focus: #63b394;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.attachment-picker:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button.primary {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

[data-theme="dark"] button.primary {
  color: #07110d;
}

button.primary:hover {
  background: var(--accent-strong);
}

button.danger {
  color: var(--danger);
}

button.icon {
  width: 36px;
  padding: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--ink);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.mobile-only {
  display: none;
}

.shell {
  min-height: 100vh;
}

.login-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  overflow: hidden;
  background: #0b1114;
}

.login-backdrop {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgb(9 14 17 / 88%) 0%, rgb(9 14 17 / 70%) 46%, rgb(9 14 17 / 34%) 100%),
    url("https://www.thesquishybit.co.uk/brand-assets/industrial-mesh-green-blue.png") center / cover no-repeat;
  transform: scale(1.02);
}

.auth-panel {
  position: relative;
  z-index: 1;
  max-width: 460px;
  width: min(460px, 100%);
  margin: 0;
  padding: 32px;
  background: rgb(16 21 23 / 88%);
  color: #f4efe6;
  border: 1px solid rgb(139 208 182 / 28%);
  border-radius: 6px;
  box-shadow: 0 24px 80px rgb(0 0 0 / 42%);
  backdrop-filter: blur(12px);
}

.auth-panel h1 {
  margin: 28px 0 8px;
  font-size: 30px;
  line-height: 1.1;
}

.auth-panel p {
  color: #b9c7c2;
}

.layout {
  display: grid;
  grid-template-columns: 248px minmax(340px, 440px) minmax(0, 1fr);
  min-height: 100vh;
  background: var(--soft);
}

.sidebar,
.messages,
.reader {
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--soft);
}

.brand,
.brand-lockup,
.brand-actions,
.toolbar,
.reader-toolbar,
.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  justify-content: space-between;
  min-height: 64px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand-lockup {
  min-width: 0;
}

.brand-title {
  display: block;
  font-weight: 750;
  font-size: 17px;
  line-height: 1.1;
}

.brand-subtitle {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.brand-mark {
  flex: 0 0 auto;
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 50%;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 13px;
  font-weight: 800;
}

[data-theme="dark"] .brand-mark {
  color: var(--accent-strong);
}

.mailbox {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.mailbox strong {
  display: block;
  font-size: 13px;
}

.mailbox span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.mailbox-admin label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 750;
}

.mailbox-admin select {
  width: 100%;
  min-height: 34px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--ink);
}

.brand-actions {
  flex: 0 0 auto;
  gap: 6px;
}

.sidebar-actions {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  gap: 8px;
}

.action-button {
  width: 100%;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  justify-content: start;
  text-align: left;
  min-height: 40px;
  background: var(--input-bg);
}

.action-button svg,
.reader-toolbar button svg {
  width: 18px;
  height: 18px;
}

.compose-entry {
  padding: 12px;
  background: var(--panel);
}

.compose-entry button {
  width: 100%;
}

.folder-list {
  overflow: auto;
  padding: 4px 8px 12px;
  flex: 1 1 auto;
}

.folder {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 6px;
  margin: 2px 0;
}

.folder.active {
  background: var(--soft-2);
  color: var(--accent-strong);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--accent);
}

.folder span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count {
  min-width: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.messages {
  display: flex;
  flex-direction: column;
}

.toolbar {
  min-height: 64px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.search {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 12px;
  background: var(--input-bg);
  color: var(--ink);
}

.message-list {
  overflow: auto;
}

.message-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-height: 92px;
  padding: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  text-align: left;
}

.message-row.active {
  background: var(--active-row);
  box-shadow: inset 3px 0 0 var(--accent);
}

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

.unread-dot {
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: transparent;
}

.message-row.unread .unread-dot {
  background: var(--accent);
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

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

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

.subject {
  margin-top: 4px;
}

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

.reader {
  display: flex;
  flex-direction: column;
  background: var(--reader-bg);
}

.reader-toolbar {
  min-height: 64px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.reader-toolbar button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.reader-toolbar select {
  height: 36px;
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--ink);
}

.reader-content {
  overflow: auto;
  padding: 24px;
}

.empty {
  margin: 72px auto 0;
  max-width: 420px;
  color: var(--muted);
  text-align: center;
}

.message h2 {
  margin: 0 0 12px;
  font-size: 24px;
}

.headers {
  display: grid;
  gap: 5px;
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 13px;
}

.headers strong {
  color: var(--ink);
}

.body {
  max-width: 900px;
  line-height: 1.55;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 20px;
  overflow-wrap: anywhere;
  color: var(--ink);
}

.body-plain {
  white-space: pre-wrap;
}

.body-html {
  color: var(--ink);
}

.body-html p,
.body-html div,
.body-html span,
.body-html td,
.body-html th,
.body-html li {
  color: inherit;
}

[data-theme="dark"] .body-html,
[data-theme="dark"] .body-html p,
[data-theme="dark"] .body-html div,
[data-theme="dark"] .body-html span,
[data-theme="dark"] .body-html td,
[data-theme="dark"] .body-html th,
[data-theme="dark"] .body-html li {
  color: var(--ink) !important;
}

[data-theme="dark"] .body-html table,
[data-theme="dark"] .body-html tbody,
[data-theme="dark"] .body-html tr,
[data-theme="dark"] .body-html td,
[data-theme="dark"] .body-html th,
[data-theme="dark"] .body-html div,
[data-theme="dark"] .body-html p {
  background-color: transparent !important;
}

.body a {
  color: var(--accent-strong);
}

.translation-note {
  max-width: 900px;
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.attachments {
  margin: 16px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 13px;
}

.composer {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(720px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto auto minmax(220px, 1fr) auto auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 18px 60px var(--shadow);
  overflow: hidden;
}

.composer.hidden {
  display: none;
}

.composer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  background: var(--composer-header-bg);
  color: var(--composer-header-ink);
  border-bottom: 1px solid var(--accent);
}

.composer-header button {
  color: var(--composer-header-ink);
  border-color: transparent;
  background: transparent;
}

.composer-fields {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
}

.composer-fields label {
  padding: 10px 12px;
  color: var(--muted);
  background: var(--composer-field-label-bg);
  border-top: 1px solid var(--line);
}

.composer-fields input {
  min-width: 0;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  background: var(--input-bg);
  color: var(--ink);
  outline-offset: -2px;
}

.composer textarea {
  width: 100%;
  min-height: 300px;
  resize: vertical;
  border: 0;
  padding: 14px;
  line-height: 1.5;
  background: var(--input-bg);
  color: var(--ink);
  outline-offset: -2px;
}

.composer-attachments {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.attachment-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--ink);
  cursor: pointer;
}

.attachment-picker:hover {
  border-color: var(--accent);
}

.attachment-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

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

.compose-attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

.compose-attachment span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-remove {
  width: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
}

.attachment-remove svg {
  width: 14px;
  height: 14px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand strong,
.login-brand small {
  display: block;
}

.login-brand strong {
  font-size: 18px;
}

.login-brand small {
  margin-top: 3px;
  color: #b9c7c2;
  font-size: 13px;
}

.auth-panel .brand-mark {
  color: var(--accent-strong);
  background: rgb(29 53 45 / 88%);
}

.composer-actions {
  justify-content: space-between;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.status {
  color: var(--muted);
  font-size: 13px;
}

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

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 220px minmax(300px, 380px);
  }

  .reader {
    grid-column: 1 / -1;
    min-height: 55vh;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  .mobile-only {
    display: inline-grid;
  }

  .layout {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 100vh;
  }

  .sidebar,
  .messages,
  .reader {
    min-height: 100vh;
    border-right: 0;
  }

  .layout[data-mobile-view="folders"] .messages,
  .layout[data-mobile-view="folders"] .reader,
  .layout[data-mobile-view="messages"] .sidebar,
  .layout[data-mobile-view="messages"] .reader,
  .layout[data-mobile-view="reader"] .sidebar,
  .layout[data-mobile-view="reader"] .messages {
    display: none;
  }

  .brand {
    position: sticky;
    top: 0;
    z-index: 3;
  }

  .brand-title {
    font-size: 16px;
  }

  .brand-subtitle {
    font-size: 10px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 12px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .folder-list {
    display: block;
    padding: 8px;
    flex: 1 1 auto;
  }

  .folder {
    min-width: 0;
    min-height: 42px;
  }

  .toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 56px;
    padding: 8px;
  }

  .message-row {
    min-height: 84px;
  }

  .reader-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: auto;
    padding: 8px;
    overflow-x: auto;
    align-items: stretch;
  }

  .reader-toolbar button,
  .reader-toolbar select {
    flex: 0 0 auto;
  }

  .reader-toolbar select {
    min-width: 140px;
  }

  .reader-content {
    padding: 16px;
  }

  .message h2 {
    font-size: 21px;
  }

  .body {
    padding: 14px;
  }

  .composer {
    inset: 0;
    width: 100vw;
    max-height: none;
    height: 100vh;
    border-radius: 0;
  }

  .composer-fields {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .composer textarea {
    min-height: 220px;
  }

  .login-shell {
    padding: 18px;
  }

  .auth-panel {
    padding: 24px;
  }

  .sidebar-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
  }
}
