:root {
  color-scheme: light;
  --ink: #101828;
  --muted: #667085;
  --line: #d9e2ea;
  --panel: #ffffff;
  --soft: #f4f8fb;
  --blue: #0365ac;
  --blue-dark: #07486f;
  --teal: #0b947f;
  --gold: #d6a429;
  --danger: #a33a1d;
  --shadow: 0 20px 45px rgba(12, 38, 59, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: clip;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: linear-gradient(135deg, #eef7fb 0%, #ffffff 50%, #eef5f0 100%);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

svg {
  width: 1.2em;
  height: 1.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mail-shell {
  min-height: 100vh;
  padding: 18px;
}

.mail-topbar {
  display: grid;
  grid-template-columns: minmax(160px, 250px) minmax(240px, 1fr) minmax(180px, auto);
  gap: 16px;
  align-items: center;
  max-width: 1440px;
  margin: 0 auto 18px;
  padding: 12px;
  border: 1px solid rgba(217, 226, 234, 0.88);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 12px 30px rgba(17, 57, 84, 0.08);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.brand img {
  width: min(230px, 100%);
  height: auto;
  display: block;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.top-actions a,
.button,
.compose-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--blue-dark);
  background: #fff;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 760;
  white-space: nowrap;
}

.top-actions a:hover,
.button:hover,
.compose-button:hover {
  border-color: rgba(3, 101, 172, 0.45);
  box-shadow: 0 10px 22px rgba(3, 101, 172, 0.12);
}

.identity-chip {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  color: #fff;
  background: #064f85;
}

.identity-chip .avatar {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  color: var(--blue);
  font-weight: 900;
}

.identity-chip small,
.identity-chip strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity-chip small {
  color: rgba(255, 255, 255, 0.72);
  font-weight: 700;
}

.status-panel,
.mail-app {
  max-width: 1440px;
  margin: 0 auto;
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 340px;
  padding: clamp(24px, 5vw, 56px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.status-panel h1,
.panel-heading h1,
.panel-heading h2 {
  margin: 0;
  color: var(--ink);
  line-height: 1.05;
  letter-spacing: 0;
}

.status-panel h1 {
  max-width: 740px;
  font-size: clamp(1.65rem, 4.2vw, 3rem);
}

.status-panel p {
  max-width: 660px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.mail-app {
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(260px, 390px) minmax(360px, 1fr);
  gap: 14px;
  align-items: start;
}

.folder-panel,
.message-column,
.reader-panel,
.compose-panel {
  border: 1px solid rgba(217, 226, 234, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 16px 34px rgba(12, 38, 59, 0.1);
}

.folder-panel {
  position: sticky;
  top: 18px;
  padding: 16px;
}

.panel-heading {
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-heading h1 {
  font-size: 1.85rem;
}

.panel-heading h2 {
  font-size: 1.25rem;
}

.compose-button {
  width: 100%;
  margin-bottom: 14px;
  color: #fff;
  border-color: transparent;
  background: var(--blue);
}

.folder-list {
  display: grid;
  gap: 8px;
}

.folder-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.folder-button strong,
.folder-button small {
  overflow-wrap: anywhere;
}

.folder-button small {
  color: var(--muted);
  font-weight: 800;
}

.folder-button.is-active,
.folder-button:hover {
  border-color: #b9dff7;
  background: #ecf8ff;
}

.message-column {
  min-height: calc(100vh - 130px);
  overflow: hidden;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.search-row input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
}

.connection-badge,
.ai-label,
.attachment-chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 5px 9px;
  color: var(--blue-dark);
  background: #e9f6ff;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.connection-badge.is-offline {
  color: var(--danger);
  background: #fff3ed;
}

.message-list {
  display: grid;
  max-height: calc(100vh - 200px);
  overflow: auto;
}

.message-card {
  display: grid;
  gap: 7px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 13px 14px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.message-card:hover,
.message-card.is-active {
  background: #f3fbff;
}

.message-card.is-unread strong {
  color: var(--blue-dark);
}

.message-card-header,
.message-meta,
.reader-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.message-card strong,
.message-card span,
.message-card p {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-card strong {
  font-size: 0.95rem;
}

.message-card span,
.message-card p {
  font-size: 0.88rem;
}

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

.reader-panel {
  min-height: calc(100vh - 130px);
  padding: clamp(16px, 2.5vw, 24px);
}

.empty-reader {
  display: grid;
  min-height: 360px;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.reader-icon {
  display: grid;
  width: 60px;
  height: 60px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  box-shadow: 0 18px 32px rgba(3, 101, 172, 0.24);
}

.reader-header {
  display: grid;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.reader-header h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.05rem);
  line-height: 1.14;
  letter-spacing: 0;
}

.reader-meta {
  color: var(--muted);
  flex-wrap: wrap;
}

.ai-row,
.attachment-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.reader-body {
  color: #344054;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.reader-tools {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.tool-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.tool-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.tool-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.attachment-chip {
  border: 1px solid #bdebdc;
  color: #045f4d;
  background: #effbf6;
  cursor: pointer;
}

.compose-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(520px, calc(100vw - 36px));
  padding: 18px;
}

.compose-panel form {
  display: grid;
  gap: 12px;
}

.compose-panel label {
  display: grid;
  gap: 6px;
  color: #475467;
  font-weight: 800;
}

.compose-panel input,
.compose-panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
}

.compose-panel textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button.primary {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.button.ghost {
  color: var(--blue-dark);
}

.form-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(430px, calc(100vw - 36px));
  transform: translateY(130%);
  border-radius: 8px;
  padding: 14px 16px;
  color: #fff;
  background: #101828;
  box-shadow: var(--shadow);
  transition: transform 180ms ease;
}

.toast.is-visible {
  transform: translateY(0);
}

.is-hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1120px) {
  .mail-topbar {
    grid-template-columns: minmax(160px, 1fr) minmax(170px, auto);
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    order: 3;
  }

  .mail-app {
    grid-template-columns: 210px minmax(280px, 1fr);
  }

  .reader-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }
}

@media (max-width: 760px) {
  .mail-shell {
    padding: 10px;
  }

  .mail-topbar,
  .status-panel,
  .mail-app {
    border-radius: 8px;
  }

  .mail-topbar,
  .status-panel,
  .mail-app {
    grid-template-columns: 1fr;
  }

  .identity-chip {
    width: 100%;
  }

  .status-panel {
    display: grid;
    min-height: auto;
  }

  .status-actions {
    justify-content: flex-start;
  }

  .folder-panel {
    position: static;
  }

  .folder-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .folder-button {
    min-width: 148px;
  }

  .message-column,
  .reader-panel {
    min-height: auto;
  }

  .message-list {
    max-height: none;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .message-card-header,
  .message-meta,
  .reader-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .compose-panel {
    inset: auto 10px 10px;
    width: auto;
  }
}
