:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0d1118;
  color: #eef2f8;
  --bg: #0d1118;
  --panel: #1a1f28;
  --panel-strong: #202634;
  --panel-soft: #151923;
  --line: #343b49;
  --line-soft: #262d3a;
  --text: #eef2f8;
  --muted: #9ba6b8;
  --muted-strong: #c6cedc;
  --accent: #7048f7;
  --accent-strong: #805dff;
  --accent-soft: rgba(112, 72, 247, 0.18);
  --success: #46c792;
  --warn: #f0b45b;
  --danger: #ee6c7d;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 72% -12%, rgba(112, 72, 247, 0.22), transparent 28rem),
    linear-gradient(180deg, #111622 0%, #0d1118 42%, #0c1017 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  width: min(100vw - 48px, 1440px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 36px;
}

.hero-panel,
.filter-panel,
.list-panel,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(26, 31, 40, 0.94);
  box-shadow: var(--shadow);
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 122px;
  padding: 24px 30px;
  background:
    linear-gradient(90deg, rgba(26, 31, 40, 0.98), rgba(31, 36, 50, 0.96)),
    var(--panel);
}

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

.eyebrow {
  margin: 0 0 8px;
  color: #7d8799;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  color: #f3f6fb;
  font-size: 30px;
  line-height: 1.2;
  font-weight: 850;
  letter-spacing: 0;
}

.health-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.segment-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(104px, auto));
  align-items: center;
  gap: 6px;
  min-width: min(100%, 480px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171a24;
}

.segment-tabs a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 8px;
  color: #a7b0c1;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
}

.segment-tabs a:not(.is-active) {
  cursor: default;
}

.segment-tabs .is-active {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #fff;
  box-shadow: 0 14px 32px rgba(112, 72, 247, 0.34);
}

.filter-panel {
  margin-top: 26px;
  padding: 24px;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 220px) auto;
  gap: 20px;
  align-items: end;
}

.field-group {
  display: grid;
  min-width: 0;
  gap: 10px;
}

.field-group label {
  color: #aeb8ca;
  font-size: 15px;
  font-weight: 760;
  line-height: 1.2;
}

input[type="email"],
select {
  width: 100%;
  min-width: 0;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11141d;
  color: #f4f6fb;
  outline: none;
}

input[type="email"] {
  padding: 0 16px;
}

input[type="email"]::placeholder {
  color: rgba(236, 240, 247, 0.46);
}

select {
  appearance: none;
  padding: 0 42px 0 16px;
  background-image:
    linear-gradient(45deg, transparent 50%, #aeb8ca 50%),
    linear-gradient(135deg, #aeb8ca 50%, transparent 50%);
  background-position:
    calc(100% - 20px) 24px,
    calc(100% - 14px) 24px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  font-weight: 760;
}

input[type="email"]:focus,
select:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(112, 72, 247, 0.22);
}

#searchButton {
  width: 124px;
  height: 54px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #fff;
  font-size: 17px;
  font-weight: 850;
  box-shadow: 0 14px 34px rgba(112, 72, 247, 0.34);
}

#searchButton:hover {
  filter: brightness(1.04);
}

#searchButton:disabled {
  cursor: wait;
  opacity: 0.66;
}

.status-text {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status-text.is-error {
  color: #ff9aa8;
}

.mail-workspace {
  display: grid;
  grid-template-columns: minmax(280px, 400px) minmax(0, 1fr);
  gap: 24px;
  margin-top: 24px;
  min-height: 560px;
}

.list-panel,
.detail-panel {
  min-width: 0;
  overflow: hidden;
}

.list-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 560px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  color: #aeb8ca;
  font-size: 18px;
  font-weight: 820;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel-header span {
  flex: 0 0 auto;
  color: #aeb8ca;
  font-size: 18px;
  font-weight: 820;
}

.message-list {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  margin: 0;
  padding: 14px;
  overflow: auto;
  list-style: none;
}

.message-item {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #151a24;
  color: inherit;
  text-align: left;
}

.message-item:hover {
  border-color: #515a6b;
  background: #1b2130;
}

.message-item.is-active {
  border-color: var(--accent-strong);
  background: linear-gradient(180deg, rgba(112, 72, 247, 0.2), rgba(27, 33, 48, 0.96));
  box-shadow: inset 0 0 0 1px rgba(128, 93, 255, 0.28);
}

.item-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.item-subject,
.item-from,
.item-codes {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-subject {
  color: #f2f5fb;
  font-size: 15px;
  font-weight: 800;
}

.item-date {
  flex: 0 0 auto;
  color: #8d98aa;
  font-size: 12px;
}

.item-from {
  color: #9da8ba;
  font-size: 13px;
}

.item-codes {
  color: var(--success);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  font-weight: 800;
}

.list-empty,
.detail-empty {
  display: grid;
  place-items: center;
  color: #9ba6b8;
  font-size: 17px;
  font-weight: 740;
  text-align: center;
}

.list-empty {
  min-height: 260px;
  padding: 24px;
  border-top: 1px solid var(--line-soft);
}

.detail-panel {
  min-height: 560px;
}

.detail-empty {
  min-height: 560px;
  padding: 32px;
}

.message-detail {
  display: grid;
  gap: 26px;
  padding: 28px;
}

.detail-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 14px;
}

.seen-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 760;
}

.seen-badge.is-unread {
  border-color: rgba(70, 199, 146, 0.48);
  background: rgba(70, 199, 146, 0.12);
  color: #79e0b5;
}

#detailSubject {
  margin: 0;
  color: #f5f7fb;
  font-size: 28px;
  line-height: 1.28;
  font-weight: 850;
  letter-spacing: 0;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
}

.detail-meta div,
.detail-section {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(17, 20, 29, 0.64);
}

.detail-meta div {
  padding: 16px;
}

.detail-meta dt,
.detail-section h3 {
  margin: 0;
  color: #8f9bad;
  font-size: 13px;
  font-weight: 780;
  line-height: 1.2;
}

.detail-meta dd {
  margin: 8px 0 0;
  color: #edf1f7;
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.detail-section {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.codes {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  background: rgba(70, 199, 146, 0.14);
  color: #78dfb4;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 18px;
  font-weight: 850;
  letter-spacing: 0;
}

.code.is-empty {
  min-width: 0;
  background: rgba(240, 180, 91, 0.12);
  color: #f0c37c;
  font-family: inherit;
  font-size: 14px;
  font-weight: 760;
}

.snippet {
  max-height: 360px;
  margin: 0;
  overflow: auto;
  color: #d8dee9;
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-wrap;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .hero-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .segment-tabs {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-form {
    grid-template-columns: 1fr 180px;
  }

  #searchButton {
    width: 100%;
    grid-column: 1 / -1;
  }

  .mail-workspace {
    grid-template-columns: 1fr;
  }

  .list-panel,
  .detail-panel,
  .detail-empty {
    min-height: 420px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100vw - 24px, 1440px);
    padding-top: 12px;
  }

  .hero-panel,
  .filter-panel {
    padding: 18px;
  }

  h1 {
    font-size: 26px;
  }

  .segment-tabs {
    grid-template-columns: 1fr;
  }

  .segment-tabs a {
    min-height: 42px;
    font-size: 15px;
  }

  .search-form {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .mail-workspace {
    gap: 16px;
    min-height: 0;
  }

  .panel-header {
    min-height: 64px;
    padding: 0 16px;
  }

  .message-list {
    padding: 10px;
  }

  .message-detail {
    padding: 20px;
  }

  #detailSubject {
    font-size: 22px;
  }

  .detail-meta {
    grid-template-columns: 1fr;
  }

  .detail-topline,
  .item-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .item-date {
    flex: auto;
  }
}
