:root {
  color-scheme: dark;
  --bg: #07060c;
  --panel: rgba(18, 14, 29, 0.88);
  --panel-strong: rgba(23, 17, 39, 0.96);
  --panel-soft: rgba(255, 255, 255, 0.035);
  --border: rgba(186, 140, 255, 0.16);
  --border-strong: rgba(193, 145, 255, 0.32);
  --text: #f6f2ff;
  --muted: #a89eb9;
  --purple: #a56cff;
  --purple-bright: #c293ff;
  --purple-deep: #6e2fff;
  --danger: #ff7f9f;
  --success: #73e3b2;
  --warning: #ffd37a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(117, 57, 255, 0.17), transparent 31rem),
    radial-gradient(circle at 88% 88%, rgba(205, 112, 255, 0.12), transparent 33rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

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

.ambient {
  position: fixed;
  width: 36rem;
  height: 36rem;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
}
.ambient-one { background: #7637ff; top: -15rem; left: -12rem; }
.ambient-two { background: #d05cff; bottom: -17rem; right: -12rem; }

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

.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(9, 7, 15, 0.82);
  backdrop-filter: blur(26px);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 26px; }
.brand-mark, .auth-brand-mark {
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--purple-bright), var(--purple-deep));
  box-shadow: 0 0 30px rgba(159, 91, 255, 0.3);
  color: white;
  font-weight: 800;
}
.brand-mark { width: 40px; height: 40px; border-radius: 12px; }
.brand-title { font-weight: 760; letter-spacing: 0.01em; }
.brand-subtitle { margin-top: 2px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; }

.compose-button, .primary-button {
  border: 0;
  color: white;
  background: linear-gradient(135deg, var(--purple), var(--purple-deep));
  box-shadow: 0 12px 32px rgba(111, 47, 255, 0.24);
}
.compose-button { padding: 13px 16px; border-radius: 12px; font-weight: 700; margin: 0 4px 20px; }
.compose-button:hover, .primary-button:hover { filter: brightness(1.08); }

.nav-list { display: grid; gap: 5px; }
.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 12px 14px;
  border-radius: 10px;
  text-align: left;
}
.nav-item:hover { color: var(--text); background: var(--panel-soft); }
.nav-item.active { color: white; background: rgba(153, 86, 255, 0.12); border-color: var(--border); }
.count { min-width: 24px; text-align: center; color: var(--purple-bright); font-size: 12px; }

.sidebar-footer { margin-top: auto; padding: 18px 5px 0; border-top: 1px solid var(--border); }
.signed-in { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; margin-bottom: 10px; }

.main-panel { min-width: 0; }
.topbar {
  height: 92px;
  padding: 22px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(9, 7, 15, 0.58);
  backdrop-filter: blur(24px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.status-badge {
  color: var(--warning);
  border: 1px solid rgba(255, 211, 122, 0.18);
  background: rgba(255, 211, 122, 0.07);
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 11px;
}

.icon-button, .ghost-button, .secondary-button, .danger-button {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
}
.icon-button { width: 38px; height: 38px; border-radius: 10px; font-size: 18px; }
.ghost-button, .secondary-button, .danger-button { padding: 10px 14px; border-radius: 10px; }
.ghost-button:hover, .secondary-button:hover, .icon-button:hover { border-color: var(--border-strong); background: rgba(164, 104, 255, 0.08); }
.danger-button { color: var(--danger); border-color: rgba(255, 127, 159, 0.2); }
.danger-button:hover { background: rgba(255, 127, 159, 0.07); }
.full-width { width: 100%; }

.content { padding: 28px 32px 48px; }

.mail-list {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.mail-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(240px, 1.5fr) 160px;
  gap: 18px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 16px 20px;
}
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover { background: rgba(159, 91, 255, 0.065); }
.mail-sender { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-subject { color: #ddd4eb; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-date { color: var(--muted); text-align: right; font-size: 12px; }

.card {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.message-header { padding: 24px; border-bottom: 1px solid var(--border); }
.message-subject { margin: 0 0 18px; font-size: 24px; overflow-wrap: anywhere; }
.message-meta { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.message-meta strong { color: var(--text); font-weight: 650; }
.message-body { margin: 0; padding: 28px 24px; white-space: pre-wrap; overflow-wrap: anywhere; color: #e9e2f3; line-height: 1.6; min-height: 160px; }
.message-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 18px 24px; border-top: 1px solid var(--border); }

.form-card { max-width: 860px; padding: 26px; }
.form-card h2 { margin: 0 0 22px; }
.form-grid { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; }
.field label { color: var(--muted); font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em; }
.field input, .field textarea {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--border);
  background: rgba(5, 4, 9, 0.6);
  border-radius: 11px;
  padding: 12px 13px;
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(165, 108, 255, 0.1); }
.field textarea { resize: vertical; min-height: 230px; line-height: 1.5; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.primary-button { padding: 11px 17px; border-radius: 10px; font-weight: 700; }

.reply-box { margin: 0 24px 24px; padding: 18px; border: 1px solid var(--border); border-radius: 13px; background: rgba(255,255,255,0.025); }
.reply-box textarea { width: 100%; min-height: 150px; resize: vertical; border: 1px solid var(--border); border-radius: 10px; padding: 12px; color: var(--text); background: rgba(3,3,7,0.62); outline: none; }
.reply-actions { display: flex; gap: 10px; margin-top: 10px; }

.empty-state, .loading-state, .error-state {
  min-height: 360px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 16px;
  color: var(--muted);
  background: rgba(255,255,255,0.018);
  padding: 32px;
}
.error-state { color: #ffb0c3; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 420px;
  padding: 13px 16px;
  border-radius: 11px;
  background: #191125;
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}
.toast.success { border-color: rgba(115, 227, 178, 0.3); }
.toast.error { border-color: rgba(255, 127, 159, 0.35); }

.auth-screen {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(460px, 100%);
  padding: 42px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(14, 10, 24, 0.88);
  backdrop-filter: blur(28px);
  box-shadow: var(--shadow);
}
.auth-brand-mark { width: 58px; height: 58px; border-radius: 17px; margin: 0 auto 18px; font-size: 24px; }
.auth-card h1 { margin: 0 0 10px; font-size: 29px; }
.auth-card > p { color: var(--muted); line-height: 1.5; }
.security-note { display: flex; align-items: center; justify-content: center; gap: 8px; color: #cbbfe0; font-size: 12px; margin: 24px 0; }
.security-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 14px rgba(115, 227, 178, 0.8); }
.auth-card .primary-button { width: 100%; padding: 13px 16px; }
.auth-message { min-height: 20px; margin-top: 14px !important; color: var(--danger) !important; font-size: 13px; }

.attachment-list { margin: 0 24px 24px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: rgba(255,255,255,0.025); }
.attachment-list h3 { margin: 0 0 10px; font-size: 13px; }
.attachment-item { color: var(--muted); font-size: 12px; padding: 4px 0; }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 14px; }
  .brand { padding-bottom: 14px; }
  .compose-button { margin-bottom: 10px; }
  .nav-list { grid-template-columns: repeat(3, 1fr); }
  .sidebar-footer { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
  .signed-in { flex: 1; margin: 0; }
  .full-width { width: auto; }
  .topbar { position: static; padding: 18px; height: auto; gap: 12px; align-items: flex-start; }
  .status-badge { display: none; }
  .content { padding: 18px; }
  .mail-row { grid-template-columns: 1fr; gap: 6px; }
  .mail-date { text-align: left; }
}
