:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --surface-tint: #f1f6ff;
  --line: #dfe3ea;
  --line-strong: #ccd2dc;
  --text: #151922;
  --muted: #697386;
  --muted-2: #8a93a3;
  --accent: #0a84ff;
  --accent-strong: #0067d6;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(18, 24, 40, 0.10);
  --radius: 8px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100vh;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
  line-height: 1.25;
}

label {
  display: grid;
  gap: 7px;
  color: #303744;
  font-size: 13px;
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
}

input {
  height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 108px;
  resize: vertical;
  padding: 11px 12px;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.14);
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 36px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

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

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

.secondary-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(10, 132, 255, 0.12), transparent 32%),
    linear-gradient(180deg, #ffffff 0%, #f4f6fa 100%);
}

.login-panel {
  display: grid;
  width: min(420px, 100%);
  gap: 18px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

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

.login-brand p,
.sidebar-brand span,
.view-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: var(--radius);
  background: #111827;
  color: #fff;
  font-weight: 850;
}

.form-error,
.form-status {
  min-height: 18px;
  margin: 0;
  font-size: 13px;
}

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

.form-status {
  color: var(--muted);
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  height: 100vh;
  grid-template-rows: auto 1fr;
  gap: 20px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  padding: 18px 14px;
  backdrop-filter: blur(18px);
}

.sidebar-brand {
  padding: 4px 6px 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar-brand strong {
  display: block;
  font-size: 14px;
}

.sidebar-nav {
  display: grid;
  align-content: start;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
}

.nav-item svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.nav-item:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface-tint);
  color: var(--accent-strong);
}

.main-area {
  display: grid;
  min-width: 0;
  min-height: 100vh;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 251, 253, 0.88);
  padding: 14px 22px;
  backdrop-filter: blur(18px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.session-label {
  max-width: 280px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  min-width: 0;
  min-height: 0;
  padding: 18px;
}

.dashboard-view,
.settings-view {
  display: grid;
  gap: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card,
.quiet-panel,
.placeholder-view {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(18, 24, 40, 0.05);
}

.kpi-card {
  display: grid;
  gap: 8px;
  min-height: 128px;
  padding: 18px;
}

.kpi-card span,
.kpi-card p,
.account-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi-card strong {
  font-size: 30px;
  line-height: 1;
}

.kpi-card p {
  margin: 0;
}

.quiet-panel {
  padding: 20px;
}

.quiet-panel p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

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

.placeholder-view h2 {
  color: var(--text);
  font-size: 22px;
}

.placeholder-view p {
  margin: 0;
}

.placeholder-icon {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.account-list {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
}

.account-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.account-list dd {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.mail-module {
  display: grid;
  overflow: hidden;
  height: calc(100vh - 108px);
  min-height: 560px;
  grid-template-rows: auto auto auto 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(18, 24, 40, 0.06);
}

.mail-toolbar {
  display: grid;
  grid-template-columns: auto minmax(240px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 12px;
  background: #fff;
}

.mail-search-wrap {
  display: block;
}

.mail-search {
  height: 38px;
  border-color: transparent;
  background: #f1f3f6;
}

.mail-mobile-switcher {
  display: none;
}

.segmented-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 750;
}

.segmented-button.active {
  border-color: rgba(10, 132, 255, 0.32);
  background: var(--surface-tint);
  color: var(--accent-strong);
}

.mail-feedback {
  border-bottom: 1px solid #ffd8d2;
  background: #fff4f2;
  color: var(--danger);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
}

.mail-feedback.notice {
  border-bottom-color: #cce8d6;
  background: #f1fbf5;
  color: #087443;
}

.mail-grid {
  display: grid;
  min-height: 0;
  grid-template-columns: 218px minmax(310px, 430px) minmax(420px, 1fr);
}

.mail-folders,
.mail-list-pane,
.mail-detail-pane {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
}

.mail-detail-pane {
  overflow: auto;
  border-right: 0;
}

.mail-folders {
  background: #fbfcfe;
  padding: 14px 10px 18px;
}

.mail-folders h2 {
  padding: 0 6px 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

.folder-button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  padding: 7px 9px;
  text-align: left;
  font-size: 13px;
  font-weight: 750;
}

.folder-button:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.folder-button.active {
  background: var(--surface-tint);
  color: var(--accent-strong);
}

.folder-glyph {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 7px;
  background: rgba(105, 115, 134, 0.10);
}

.folder-glyph::before {
  content: "";
  width: 14px;
  height: 11px;
  border: 1.8px solid currentColor;
  border-radius: 2px;
}

.folder-button[data-icon="sent"] .folder-glyph::before {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 13px solid currentColor;
  border-right: 0;
}

.folder-button[data-icon="draft"] .folder-glyph::before {
  width: 12px;
  height: 14px;
  border-radius: 2px;
}

.folder-button[data-icon="junk"] .folder-glyph::before,
.folder-button[data-icon="trash"] .folder-glyph::before {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.folder-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.folder-copy strong,
.folder-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-copy small {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 700;
}

.pane-head {
  display: flex;
  height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 0 14px;
}

.pane-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mail-list-head {
  height: 58px;
}

.mail-list-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.message-list {
  overflow: auto;
  height: calc(100% - 58px);
}

.message-row {
  position: relative;
  display: grid;
  width: 100%;
  gap: 7px;
  min-height: 104px;
  border: 0;
  border-bottom: 1px solid rgba(223, 227, 234, 0.82);
  background: #fff;
  color: var(--text);
  padding: 13px 14px 13px 28px;
  text-align: left;
}

.message-row:hover {
  background: #f8fbff;
}

.message-row.active {
  background: var(--surface-tint);
}

.message-row.unread {
  background: #fcfdff;
}

.message-unread-dot {
  position: absolute;
  top: 18px;
  left: 12px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: transparent;
}

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

.message-row-top,
.message-subject-line {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.message-sender,
.message-subject,
.message-preview,
.message-date-short {
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-sender {
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
}

.message-date-short {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.message-subject {
  min-width: 0;
  color: #252b36;
  font-size: 13px;
  font-weight: 750;
}

.message-row:not(.unread) .message-subject,
.message-row:not(.unread) .message-sender {
  font-weight: 650;
}

.message-preview {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.message-attachment {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border: 1.6px solid currentColor;
  border-left: 0;
  border-radius: 8px 8px 8px 0;
  color: var(--muted);
  transform: rotate(-35deg);
}

.state-block {
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  gap: 7px;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.state-block strong {
  color: var(--text);
  font-size: 15px;
}

.state-block p {
  max-width: 280px;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.message-detail {
  padding: 22px;
}

.mobile-back {
  display: none;
  margin-bottom: 12px;
}

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

.message-head h2 {
  margin: 0 0 10px;
  font-size: 24px;
  line-height: 1.22;
}

.message-head-copy {
  min-width: 0;
}

.message-actions {
  flex: 0 0 auto;
}

.message-date {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.message-addresses {
  display: grid;
  gap: 6px;
  margin: 0;
}

.message-addresses div {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 8px;
}

.message-addresses dt,
.message-addresses dd {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
}

.message-addresses dt {
  color: var(--muted);
  font-weight: 750;
}

.message-addresses dd {
  overflow-wrap: anywhere;
  color: #323947;
}

.attachments-list {
  display: grid;
  gap: 10px;
  padding: 16px 0 0;
}

.attachments-list h3 {
  margin: 0;
  font-size: 13px;
}

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

.attachment-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.message-body {
  display: grid;
  gap: 14px;
}

.message-text {
  overflow: auto;
  margin: 18px 0 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbfc;
  color: #1f232b;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.message-html {
  width: 100%;
  min-height: 320px;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.compose-overlay {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  width: min(560px, calc(100vw - 48px));
}

.compose-modal,
.reply-form {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 16px;
}

.compose-modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compose-modal header p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

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

.compose-modal footer {
  display: flex;
  justify-content: flex-end;
}

.reply-form {
  margin-top: 18px;
  background: #fbfcfe;
  box-shadow: none;
}

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

.mobile-nav {
  display: none;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mail-grid {
    grid-template-columns: 190px minmax(280px, 380px) minmax(360px, 1fr);
  }
}

@media (max-width: 900px) {
  .app-shell {
    display: block;
    padding-bottom: 62px;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    min-height: 66px;
    padding: 12px 16px;
  }

  .content {
    padding: 12px;
  }

  .mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    padding: 6px 8px;
    backdrop-filter: blur(18px);
  }

  .mobile-nav .nav-item {
    flex: 0 0 auto;
    justify-content: center;
    height: 46px;
    min-width: 86px;
    padding: 0 10px;
    font-size: 11px;
  }

  .mobile-nav .nav-item svg {
    display: none;
  }

  .mail-module {
    height: calc(100vh - 152px);
    min-height: 520px;
  }

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

  .mail-toolbar .primary-button {
    grid-column: 1 / -1;
  }

  .mail-search-wrap {
    min-width: 0;
  }

  .mail-mobile-switcher {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
    background: #fbfcfe;
  }

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

  .mail-folders,
  .mail-list-pane,
  .mail-detail-pane {
    display: none;
    border-right: 0;
  }

  .mail-module[data-mobile-pane="folders"] .mail-folders,
  .mail-module[data-mobile-pane="list"] .mail-list-pane,
  .mail-module[data-mobile-pane="detail"] .mail-detail-pane {
    display: block;
  }

  .mail-folders {
    border-bottom: 1px solid var(--line);
    padding: 10px;
  }

  .mail-folders h2 {
    display: block;
    padding: 2px 4px 10px;
  }

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

  .folder-button {
    width: 100%;
  }

  .mail-list-pane {
    min-height: 0;
  }

  .mail-detail-pane {
    overflow: auto;
  }

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

  .compose-overlay {
    right: 12px;
    bottom: 76px;
    width: calc(100vw - 24px);
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .session-label {
    max-width: 210px;
  }

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

  .mail-module {
    height: calc(100vh - 186px);
  }

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

  .mail-search-wrap {
    grid-column: 1 / -1;
  }

  .mail-toolbar .secondary-button {
    min-width: 0;
    padding: 0 10px;
  }

  .message-head {
    flex-direction: column;
  }

  .message-head h2 {
    font-size: 20px;
  }
}
