/* ----------------------------------------------------------------------
   inboxz.9x.at — minimal monochrome design
   ---------------------------------------------------------------------- */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f5f5f4;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.15);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #a1a1a6;
  --accent: #1d1d1f;
  --accent-soft: rgba(29, 29, 31, 0.06);
  --selection: rgba(0, 0, 0, 0.05);
  --selection-strong: #1d1d1f;
  --hover: rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  --radius: 10px;
  --radius-window: 16px;
  --transition: 0.15s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    --surface: #1a1a1c;
    --surface-2: #232325;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #f5f5f7;
    --text-secondary: #aeaeb2;
    --text-tertiary: #6e6e73;
    --accent: #f5f5f7;
    --accent-soft: rgba(245, 245, 247, 0.08);
    --selection: rgba(255, 255, 255, 0.06);
    --selection-strong: #f5f5f7;
    --hover: rgba(255, 255, 255, 0.04);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}

.hidden { display: none !important; }

/* ----------------------------------------------------------------------
   Splash
   ---------------------------------------------------------------------- */

.splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1000;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------------
   Login (kept from previous step — minimal monochrome)
   ---------------------------------------------------------------------- */

.login-view {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes msFade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg);
}

.auth-bg::before {
  content: "";
  position: absolute;
  top: calc(-12% + 4px);
  left: 50%;
  transform: translateX(-50%);
  width: 640px;
  height: 640px;
  background-image: url("/img/favicon.png");
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.7;
  pointer-events: none;
  image-rendering: -webkit-optimize-contrast;
  -webkit-mask-image: radial-gradient(circle, #000 50%, transparent 80%);
  mask-image: radial-gradient(circle, #000 50%, transparent 80%);
}

.auth-bg::after {
  display: none;
}

@media (prefers-color-scheme: dark) {
  .auth-bg::before {
    opacity: 0.65;
  }
}

.auth-card {
  width: 100%;
  max-width: 440px;
  position: relative;
  background: rgba(255, 255, 255, 0.7);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  backdrop-filter: blur(40px) saturate(180%);
  border-radius: 14px;
  padding: 40px 40px 32px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 20px 50px -12px rgba(0, 0, 0, 0.18),
    0 8px 20px -8px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.6);
  animation: pop 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.auth-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  padding: 1px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.9) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(0, 0, 0, 0.05) 100%
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .auth-card {
    background: rgba(28, 28, 32, 0.65);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.06) inset,
      0 1px 2px rgba(0, 0, 0, 0.4),
      0 20px 50px -12px rgba(0, 0, 0, 0.6),
      0 8px 20px -8px rgba(0, 0, 0, 0.4);
  }
  .auth-card::before {
    background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.18) 0%,
      rgba(255, 255, 255, 0.04) 50%,
      rgba(255, 255, 255, 0) 100%
    );
  }
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
}

.auth-brand-img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.auth-form {
  display: grid;
  gap: 14px;
  animation: msFade 0.22s ease-out;
}

.auth-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

.auth-sub {
  margin: -8px 0 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.auth-field {
  display: grid;
  gap: 6px;
}

.auth-field > span {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.auth-field input {
  width: 100%;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.auth-field input::placeholder {
  color: var(--text-tertiary);
}

.auth-field input:focus {
  outline: none;
  border-color: var(--text);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 4px rgba(29, 29, 31, 0.08);
}

@media (prefers-color-scheme: dark) {
  .auth-field input {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
  }
  .auth-field input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
  }
}

.auth-password { position: relative; }
.auth-password input { padding-right: 44px; }

.auth-pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  padding: 8px;
  border-radius: 8px;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.auth-pw-toggle:hover {
  color: var(--text);
  background: var(--hover);
}

.auth-error {
  color: #d00;
  font-size: 12.5px;
  min-height: 1em;
  margin: -2px 0 0;
}

@media (prefers-color-scheme: dark) {
  .auth-error { color: #ff6b6b; }
}

.auth-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid transparent;
  background: linear-gradient(180deg, #2c2c2e 0%, #1d1d1f 100%);
  color: var(--surface);
  cursor: pointer;
  transition: opacity var(--transition), transform 0.05s, box-shadow var(--transition);
  margin-top: 6px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.15) inset,
    0 4px 12px rgba(0, 0, 0, 0.18);
  letter-spacing: -0.005em;
}

.auth-btn:hover:not(:disabled) {
  opacity: 0.92;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.2) inset,
    0 6px 16px rgba(0, 0, 0, 0.22);
}

.auth-btn:active:not(:disabled) { transform: scale(0.99); }
.auth-btn:disabled { opacity: 0.55; cursor: progress; }

@media (prefers-color-scheme: dark) {
  .auth-btn {
    background: linear-gradient(180deg, #ffffff 0%, #e8e8ea 100%);
    color: #1d1d1f;
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.6) inset,
      0 4px 12px rgba(0, 0, 0, 0.4);
  }
}

.auth-foot {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.auth-foot a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 1px;
}

.auth-foot a:hover { border-bottom-color: var(--text); }

.auth-foot-brand {
  font-family: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.auth-foot-dot {
  color: var(--text-tertiary);
  font-weight: 500;
  margin: 0 0.5px;
}

.auth-account {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px 10px 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-family: inherit;
  cursor: pointer;
  border-radius: 12px;
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 4px;
}

.auth-account:hover {
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--border-strong);
}

@media (prefers-color-scheme: dark) {
  .auth-account {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
  }
  .auth-account:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.18);
  }
}

.auth-account-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--surface-2), rgba(255, 255, 255, 0.3));
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  .auth-account-avatar {
    background: linear-gradient(135deg, #2a2a2c, #1c1c1e);
  }
}

.auth-account-text {
  flex: 1;
  display: grid;
  text-align: left;
  min-width: 0;
}

.auth-account-label {
  font-size: 10.5px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.auth-account-email {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.auth-account svg {
  color: var(--text-tertiary);
  flex: 0 0 auto;
}

@media (max-width: 480px) {
  .login-view { padding: 16px; }
  .auth-card {
    max-width: 100%;
    border: 0;
    box-shadow: none;
    background: transparent;
  }
}

/* ----------------------------------------------------------------------
   App layout
   ---------------------------------------------------------------------- */

.app {
  position: fixed;
  inset: 24px;
  display: grid;
  grid-template-columns: 240px 360px 1fr;
  background: var(--surface);
  border-radius: var(--radius-window);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  border: 1px solid var(--border);
  animation: pop 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ----------------------------------------------------------------------
   Sidebar
   ---------------------------------------------------------------------- */

.sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-top {
  height: 38px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  -webkit-app-region: drag;
}

.traffic-lights {
  display: flex;
  gap: 8px;
}

.tl {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  background: var(--border-strong);
  border: 0.5px solid var(--border);
}

.account-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 12px 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  flex: 0 0 auto;
  text-transform: uppercase;
  border: 1px solid var(--border);
}

.account-info {
  min-width: 0;
  flex: 1;
}

.account-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-email {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  width: 100%;
  display: block;
  transition: color var(--transition);
}

.account-email:hover {
  color: var(--text);
}

.account-email.copied {
  color: var(--text);
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 6px;
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icon-btn:disabled:hover {
  background: transparent;
  color: var(--text-secondary);
}

#purge-btn:hover:not(:disabled) {
  color: #d00;
  background: rgba(208, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  #purge-btn:hover:not(:disabled) {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
  }
}

.folders {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding: 12px 10px 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.folder {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 0;
  text-align: left;
  width: 100%;
  font-family: inherit;
  transition: background var(--transition);
}

.folder:hover {
  background: var(--hover);
}

.folder.active {
  background: var(--selection-strong);
  color: var(--surface);
}

.folder.active .ico,
.folder.active .badge {
  color: var(--surface);
}

.folder .ico {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: var(--text-secondary);
}

.folder.active .ico { color: var(--surface); }

.folder-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 18px;
  text-align: right;
}

/* ----------------------------------------------------------------------
   List pane
   ---------------------------------------------------------------------- */

.list-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  height: 60px;
  border-bottom: 1px solid var(--border);
}

.list-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.list-count {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  font-weight: 500;
}

.search-wrap {
  position: relative;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.search-wrap input {
  padding: 9px 12px 9px 32px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-wrap input:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-ico {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.messages {
  list-style: none;
  margin: 0;
  padding: 8px 10px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 12px;
}

.loading-spin {
  display: grid;
  place-items: center;
  padding: 40px 20px;
}

.loading-spin::after {
  content: "";
  width: 22px;
  height: 22px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-reader {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

.message {
  position: relative;
  padding: 12px 16px 12px 28px;
  cursor: pointer;
  display: grid;
  gap: 3px;
  border: 1px solid transparent;
  border-radius: 10px;
  transition: background var(--transition), border-color var(--transition);
}

.message:hover {
  background: var(--hover);
}

.message.active {
  background: var(--selection);
  border-color: var(--border);
}

.message.active::after {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--text);
  border-radius: 0 2px 2px 0;
}

.message.unread::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 18px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text);
}

.m-row1 {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.m-from {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}

.m-date {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  flex: 0 0 auto;
  font-weight: 500;
}

.m-subject {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-preview {
  font-size: 12px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
  margin-top: 1px;
}

.attach-icon {
  margin-right: 4px;
  font-size: 11px;
  color: var(--text-secondary);
}

/* ----------------------------------------------------------------------
   Reader
   ---------------------------------------------------------------------- */

.reader {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.reader-toolbar {
  position: relative;
  height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
}

.reader-brand {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  pointer-events: none;
}

.reader-brand svg {
  width: 20px;
  height: 20px;
}

.reader-brand-name {
  font-family: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  position: relative;
  z-index: 1;
}

.reader-brand-img {
  height: 32px;
  width: auto;
  display: block;
  position: relative;
  z-index: 1;
}

@media (prefers-color-scheme: dark) {
  .reader-brand-img {
    /* Invert dark logos so they remain visible on dark backgrounds.
       Remove this rule if your image is already light. */
    filter: brightness(0) invert(1);
  }
}

.reader-brand-dot {
  color: var(--text-tertiary);
  font-weight: 500;
  margin: 0 0.5px;
}

/* Sparkle stars orbiting the brand */
.sparkle {
  position: absolute;
  font-size: 10px;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 0 6px currentColor;
  animation: sparkleTwinkle 3.2s ease-in-out infinite;
}

.sparkle-1 {
  top: -12px;
  left: -14px;
  font-size: 11px;
  animation-delay: 0s;
}

.sparkle-2 {
  top: -8px;
  right: -10px;
  font-size: 9px;
  animation-delay: 0.6s;
}

.sparkle-3 {
  bottom: -10px;
  left: 30%;
  font-size: 8px;
  animation-delay: 1.2s;
}

.sparkle-4 {
  top: 50%;
  left: -20px;
  transform: translateY(-50%);
  font-size: 9px;
  animation-delay: 1.8s;
}

.sparkle-5 {
  top: 50%;
  right: -18px;
  transform: translateY(-50%);
  font-size: 11px;
  animation-delay: 2.4s;
}

@keyframes sparkleTwinkle {
  0%, 100% {
    opacity: 0;
    transform: scale(0.4) rotate(0deg);
  }
  20% {
    opacity: 1;
    transform: scale(1) rotate(90deg);
  }
  40% {
    opacity: 0.6;
    transform: scale(0.8) rotate(180deg);
  }
  60% {
    opacity: 0;
    transform: scale(0.3) rotate(270deg);
  }
}

/* Override transform for the side sparkles so the translateY(-50%) is preserved */
.sparkle-4,
.sparkle-5 {
  animation-name: sparkleTwinkleSide;
}

@keyframes sparkleTwinkleSide {
  0%, 100% {
    opacity: 0;
    transform: translateY(-50%) scale(0.4) rotate(0deg);
  }
  20% {
    opacity: 1;
    transform: translateY(-50%) scale(1) rotate(90deg);
  }
  40% {
    opacity: 0.6;
    transform: translateY(-50%) scale(0.8) rotate(180deg);
  }
  60% {
    opacity: 0;
    transform: translateY(-50%) scale(0.3) rotate(270deg);
  }
}

.toolbar-spacer { flex: 1; }

.toolbar-actions {
  display: flex;
  gap: 2px;
}

.back-btn { display: none; }

.reader-empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
}

.reader-empty-inner {
  text-align: center;
  display: grid;
  gap: 12px;
  justify-items: center;
}

.reader-empty-inner svg { opacity: 0.4; }

.reader-empty-inner p {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
}

.reader-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 28px 36px 0;
  max-width: 100%;
  width: 100%;
  margin: 0 auto;
}

.reader-head {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.reader-head h1 {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text);
}

.reader-from {
  display: flex;
  align-items: center;
  gap: 12px;
}

.reader-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  flex: 0 0 auto;
  text-transform: uppercase;
  border: 1px solid var(--border);
}

.reader-from-text {
  flex: 1;
  min-width: 0;
}

.reader-from-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-from-addr {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-date {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 500;
}

.reader-recipients {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  display: grid;
  gap: 3px;
}

.reader-recipients strong {
  color: var(--text);
  font-weight: 600;
  margin-right: 4px;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.attachment {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.attachment strong {
  color: var(--text);
  font-weight: 600;
}

.reader-body {
  flex: 1;
  min-height: 0;
  display: flex;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  color: var(--text);
  padding-bottom: 24px;
}

.mail-frame {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  background: #ffffff;
  border-radius: 10px;
  display: block;
}

.mail-text {
  flex: 1;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  margin: 0;
  padding: 16px 20px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* ----------------------------------------------------------------------
   Modal
   ---------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: msFade 0.2s ease-out;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.3);
  animation: pop 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-body {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.modal-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.modal-section-sub {
  margin: -8px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.modal-actions .auth-btn { margin-top: 0; }

.auth-btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}

.auth-btn-ghost:hover:not(:disabled) {
  background: var(--hover);
  opacity: 1;
  box-shadow: none;
}

@media (prefers-color-scheme: dark) {
  .auth-btn-ghost {
    color: var(--text);
  }
}

/* ----------------------------------------------------------------------
   Toast
   ---------------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 9999;
  animation: toastIn 0.25s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ----------------------------------------------------------------------
   Scrollbars
   ---------------------------------------------------------------------- */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.28);
  background-clip: padding-box;
}

@media (prefers-color-scheme: dark) {
  ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); background-clip: padding-box; }
  ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); background-clip: padding-box; }
}

/* ----------------------------------------------------------------------
   Responsive
   ---------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .app { grid-template-columns: 220px 320px 1fr; }
}

/* ---- Mobile (≤880px): single-pane navigation ---- */
@media (max-width: 880px) {
  .app {
    inset: 0;
    border-radius: 0;
    border: 0;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    box-shadow: none;
  }

  .sidebar,
  .list-pane,
  .reader {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    height: 100%;
    border: 0;
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
  }

  /* Stack panes; reveal them by translating */
  .sidebar { transform: translateX(-100%); z-index: 3; }
  .list-pane { transform: translateX(0); z-index: 1; }
  .reader { transform: translateX(100%); z-index: 2; }

  .app[data-pane="sidebar"] .sidebar { transform: translateX(0); }
  .app[data-pane="reader"] .reader { transform: translateX(0); }
  .app[data-pane="reader"] .list-pane { transform: translateX(-25%); }

  .app[data-pane="sidebar"] .list-pane,
  .app[data-pane="sidebar"] .reader {
    pointer-events: none;
  }

  /* Sidebar adjustments on mobile */
  .sidebar {
    background: var(--surface-2);
    border-right: 1px solid var(--border);
    max-width: 320px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.18);
  }

  .sidebar-top { display: none; }

  /* List pane: needs a header with menu button */
  .list-header {
    height: 56px;
    padding: 8px 14px 8px 8px;
    gap: 8px;
  }

  .list-header > div:first-child {
    flex: 1;
    min-width: 0;
  }

  .list-title { font-size: 16px; }

  .mobile-menu-btn {
    display: inline-flex !important;
  }

  /* Reader needs a visible back button */
  .reader-toolbar {
    height: 56px;
    padding: 0 8px;
  }

  .back-btn {
    display: inline-flex !important;
  }

  /* Brand stays centered but smaller */
  .reader-brand-name { font-size: 16px; }
  .sparkle { font-size: 9px !important; }

  /* Reader content: tighter padding */
  .reader-content {
    padding: 16px 16px 0;
  }

  .reader-head h1 {
    font-size: 18px;
    margin-bottom: 12px;
  }

  .reader-head {
    padding-bottom: 14px;
    margin-bottom: 14px;
  }

  .reader-from {
    flex-wrap: wrap;
    gap: 10px;
  }

  .reader-date {
    flex-basis: 100%;
    margin-left: 46px;
    margin-top: -4px;
  }

  /* App layout: messages, padding adjustments */
  .messages { padding: 6px 8px; }

  .message {
    padding: 11px 14px 12px 26px;
  }

  .message.unread::before {
    left: 10px;
    top: 17px;
  }

  /* Account card on mobile sidebar */
  .account-card {
    margin: 14px 12px 12px;
  }

  /* Modal: full-screen sheet */
  .modal { padding: 0; }

  .modal-card {
    max-width: 100%;
    height: 100%;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
  }

  .modal-body { flex: 1; overflow-y: auto; }

  /* Search input: bigger tap target */
  .search-wrap input { padding: 11px 14px 11px 32px; }
  .search-ico { left: 26px; }

  /* Login: full-bleed card */
  .login-view { padding: 16px; }

  .auth-card {
    max-width: 100%;
    padding: 32px 24px 24px;
  }

  .auth-bg::before {
    width: 380px;
    height: 380px;
    top: -8%;
  }

  .toast {
    bottom: 24px;
    left: 16px;
    right: 16px;
    transform: none;
    text-align: center;
  }

  @keyframes toastIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

/* ---- Hide mobile-only things on desktop by default ---- */
.mobile-menu-btn { display: none; }

@media (min-width: 881px) {
  .back-btn { display: none !important; }
}

/* ---- Phones: even tighter ---- */
@media (max-width: 480px) {
  .reader-content { padding: 14px 14px 0; }
  .reader-head h1 { font-size: 17px; }
  .toolbar-actions { gap: 0; }

  .auth-card {
    padding: 28px 20px 20px;
  }

  .login-view { padding: 12px; }
}

/* ---- Touch tweaks ---- */
@media (hover: none) and (pointer: coarse) {
  .icon-btn, .auth-btn, .folder, .message, .ms-btn {
    -webkit-tap-highlight-color: transparent;
  }
}

