:root {
  --bg: #070a12;
  --bg-soft: #0f1421;
  --panel: #141b2b;
  --panel-2: #1a2336;
  --border: #273349;
  --border-soft: #1f2a3d;
  --text: #e8edf6;
  --muted: #8b98b0;
  --primary: #5b8cff;
  --primary-2: #3d6ef0;
  --accent: #a86bff;
  --danger: #ff5d6c;
  --ok: #2fd39a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --glow: 0 0 0 1px rgba(91, 140, 255, 0.18), 0 14px 40px rgba(61, 110, 240, 0.18);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
  letter-spacing: 0.1px;
}

h1, h2, .brand-text { font-family: "Sora", "Inter", sans-serif; letter-spacing: -0.2px; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; color: #82a6ff; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
code { background: var(--panel-2); padding: 2px 7px; border-radius: 6px; font-size: 0.85em; color: #b9c6e6; }

/* ---------- Animated background orbs ---------- */
.bg-orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.5; }
.orb-1 { width: 520px; height: 520px; background: #2b50c8; top: -160px; left: -120px; animation: float1 18s ease-in-out infinite; }
.orb-2 { width: 460px; height: 460px; background: #7d3bd6; bottom: -180px; right: -120px; animation: float2 22s ease-in-out infinite; }
.orb-3 { width: 360px; height: 360px; background: #1f7fae; top: 40%; left: 55%; animation: float3 26s ease-in-out infinite; }

@keyframes float1 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(80px,60px); } }
@keyframes float2 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(-70px,-50px); } }
@keyframes float3 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-50px,40px) scale(1.1); } }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: rgba(12, 17, 28, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; z-index: 20;
  animation: slideDown 0.5s ease both;
}
@keyframes slideDown { from { transform: translateY(-100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.brand { display: flex; align-items: center; gap: 11px; color: var(--text); }
.brand-logo {
  display: block;
  width: 36px;
  height: 36px;
  object-fit: contain;
}
.brand:hover .brand-logo { transform: scale(1.04); }
.brand-logo.big {
  width: 120px;
  height: 120px;
  animation: pop 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.4) both;
}
.brand-mark {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  font-family: "Sora", sans-serif; font-weight: 800; font-size: 0.85rem; color: #fff;
  box-shadow: 0 8px 22px rgba(91, 140, 255, 0.4);
  transition: transform 0.25s ease;
}
.brand:hover .brand-mark { transform: rotate(-6deg) scale(1.06); }
.brand-mark.big {
  width: 64px; height: 64px; font-size: 1.5rem; border-radius: 18px;
  animation: pop 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.4) both, glowPulse 3.5s ease-in-out infinite 0.6s;
}
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes glowPulse {
  0%,100% { box-shadow: 0 8px 22px rgba(91,140,255,0.4); }
  50% { box-shadow: 0 8px 34px rgba(168,107,255,0.6); }
}
.brand-text { font-weight: 800; font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-weight: 500; font-family: "Inter", sans-serif; }

.topnav { display: flex; align-items: center; gap: 20px; }
.topnav > a { color: var(--muted); font-weight: 500; position: relative; padding: 4px 0; transition: color 0.2s; }
.topnav > a::after {
  content: ""; position: absolute; left: 0; bottom: -2px; width: 0; height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 2px; transition: width 0.25s ease;
}
.topnav > a:hover { color: var(--text); }
.topnav > a:hover::after { width: 100%; }
.topnav .who { color: var(--muted); font-size: 0.88rem; }
.inline { display: inline; margin: 0; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 940px; margin: 0 auto; padding: 34px 20px; flex: 1; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 1.7rem; }
.count {
  color: var(--muted); font-size: 0.82rem; font-weight: 600;
  background: var(--panel); border: 1px solid var(--border-soft);
  padding: 5px 12px; border-radius: 999px;
}

/* ---------- Reveal animation ---------- */
.reveal { animation: rise 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.reveal:nth-of-type(2) { animation-delay: 0.08s; }
.reveal:nth-of-type(3) { animation-delay: 0.16s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Auth ---------- */
.auth-wrap { flex: 1; display: grid; place-items: center; padding: 40px 18px; }
.auth-card {
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, rgba(26,35,54,0.9), rgba(20,27,43,0.92));
  border: 1px solid var(--border);
  border-radius: 22px; padding: 38px 32px; text-align: center;
  box-shadow: var(--shadow), var(--glow);
  position: relative; overflow: hidden;
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.auth-card::before {
  content: ""; position: absolute; inset: -2px; border-radius: 22px; padding: 1px;
  background: linear-gradient(130deg, rgba(91,140,255,0.6), transparent 40%, transparent 60%, rgba(168,107,255,0.6));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  pointer-events: none; opacity: 0.7;
}
.auth-logo { margin-bottom: 16px; display: flex; justify-content: center; }
.auth-card h1 { margin: 8px 0 4px; font-size: 1.45rem; }
.form { text-align: left; margin-top: 22px; display: grid; gap: 16px; }
.form label { display: grid; gap: 7px; font-size: 0.86rem; color: var(--muted); font-weight: 500; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea {
  width: 100%; padding: 12px 14px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 11px; color: var(--text); font-size: 0.95rem; font-family: inherit;
  outline: none; transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
textarea { resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: #56627a; }
input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,140,255,0.22);
  background: #10182a;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 18px; border: 1px solid transparent; border-radius: 11px;
  font-size: 0.9rem; font-weight: 600; font-family: inherit; cursor: pointer;
  background: var(--panel-2); color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s, background 0.2s, border-color 0.2s;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; box-shadow: 0 10px 24px rgba(61,110,240,0.35);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(61,110,240,0.5); filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--panel-2); border-color: var(--primary); }
.btn-danger { background: transparent; border-color: rgba(255,93,108,0.45); color: var(--danger); }
.btn-danger:hover { background: rgba(255,93,108,0.14); transform: translateY(-1px); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 11px; font-size: 0.78rem; border-radius: 9px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 15px; border-radius: 11px; margin: 16px 0; font-size: 0.9rem; font-weight: 500; }
.alert-err { background: rgba(255,93,108,0.12); border: 1px solid rgba(255,93,108,0.4); color: #ffb1ba; }
.alert-ok { background: rgba(47,211,154,0.12); border: 1px solid rgba(47,211,154,0.4); color: #95efce; }
.shake { animation: shake 0.4s ease; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-7px); } 40%,80% { transform: translateX(7px); } }

/* ---------- Message list ---------- */
.msg-list {
  list-style: none; margin: 0; padding: 0;
  border: 1px solid var(--border-soft); border-radius: 16px; overflow: hidden;
  background: rgba(20,27,43,0.6); backdrop-filter: blur(6px);
}
.msg-row { animation: rowIn 0.5s ease both; animation-delay: calc(var(--i, 0) * 45ms + 0.1s); }
@keyframes rowIn { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: translateX(0); } }
.msg-row + .msg-row { border-top: 1px solid var(--border-soft); }
.msg-link {
  display: grid; grid-template-columns: 14px 220px 1fr 165px; gap: 14px;
  align-items: center; padding: 15px 18px; color: var(--text);
  transition: background 0.18s, padding-left 0.18s; position: relative;
}
.msg-link:hover { background: var(--panel-2); padding-left: 24px; }
.msg-dot { width: 9px; height: 9px; border-radius: 50%; background: transparent; }
.msg-row.unseen .msg-dot {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 0 10px rgba(91,140,255,0.7); animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.3); opacity: 0.7; } }
.msg-row.unseen .msg-link { background: rgba(91,140,255,0.05); }
.msg-row.unseen .msg-subject { font-weight: 700; }
.msg-from { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.92rem; }
.msg-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-date { color: var(--muted); font-size: 0.8rem; text-align: right; white-space: nowrap; }

.empty {
  text-align: center; padding: 64px 24px;
  border: 1px dashed var(--border); border-radius: 18px; color: var(--muted);
  background: rgba(20,27,43,0.4);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.empty h1 { color: var(--text); }

/* ---------- Message view ---------- */
.back-link { display: inline-block; margin-bottom: 16px; color: var(--muted); font-weight: 500; transition: transform 0.2s, color 0.2s; }
.back-link:hover { color: var(--text); transform: translateX(-4px); }
.message { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.message-head { padding: 24px 26px; border-bottom: 1px solid var(--border-soft); background: linear-gradient(180deg, rgba(91,140,255,0.06), transparent); }
.message-head h1 { margin: 0 0 16px; font-size: 1.4rem; }
.meta { margin: 0; display: grid; gap: 8px; }
.meta > div { display: flex; gap: 12px; font-size: 0.9rem; }
.meta dt { color: var(--muted); width: 88px; margin: 0; font-weight: 500; }
.meta dd { margin: 0; }
.message-body { padding: 26px; }
.text-body { white-space: pre-wrap; word-wrap: break-word; font-family: inherit; margin: 0; line-height: 1.6; }
.html-body {
  background: #ffffff;
  color: #111827;
  padding: 20px;
  border-radius: 12px;
  overflow-x: auto;
  line-height: 1.65;
  font-size: 0.95rem;
  word-wrap: break-word;
}
.html-body,
.html-body p,
.html-body td,
.html-body th,
.html-body div,
.html-body span,
.html-body li,
.html-body font,
.html-body center {
  color: #111827 !important;
}
.html-body h1,
.html-body h2,
.html-body h3,
.html-body h4,
.html-body strong,
.html-body b {
  color: #0f172a !important;
}
.html-body a,
.html-body a span {
  color: #1d4ed8 !important;
  text-decoration: underline;
}
.html-body img { max-width: 100%; height: auto; }
.html-body table { max-width: 100%; }
.message-actions { padding: 0 26px 24px; }

/* ---------- Cards / admin ---------- */
.card { background: var(--panel); border: 1px solid var(--border-soft); border-radius: 18px; padding: 24px 26px; margin-bottom: 24px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 6px; font-size: 1.15rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.card-head h2 { margin: 0; }
.search { display: flex; align-items: center; gap: 8px; }
.search input[type="search"] { width: 240px; padding: 9px 12px; }
.table-wrap { overflow-x: auto; }

.pw {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  background: var(--bg-soft); border: 1px solid var(--border-soft);
  padding: 4px 9px; border-radius: 7px; letter-spacing: 1px; font-size: 0.85rem;
  display: inline-block; min-width: 86px; text-align: center;
}
.pw.revealed { letter-spacing: 0; color: #9af0cf; border-color: rgba(47,211,154,0.4); }
.form-inline { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 16px; align-items: end; margin-top: 16px; }
.field { display: grid; gap: 7px; }
.field label { font-size: 0.82rem; color: var(--muted); font-weight: 500; }
.field-or label { color: var(--primary); }
.addr-input { display: flex; align-items: stretch; }
.addr-input input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.addr-domain {
  display: inline-flex; align-items: center; padding: 0 13px;
  background: var(--panel-2); border: 1px solid var(--border); border-left: none;
  border-top-right-radius: 11px; border-bottom-right-radius: 11px;
  color: var(--muted); font-size: 0.85rem; white-space: nowrap;
}

.table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border-soft); }
.table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.table tbody tr { transition: background 0.15s; }
.table tbody tr:hover { background: var(--panel-2); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; }
.badge-admin { background: rgba(168,107,255,0.16); color: #cda9ff; border: 1px solid rgba(168,107,255,0.4); }
.badge-user { background: rgba(91,140,255,0.14); color: #a9c1ff; border: 1px solid rgba(91,140,255,0.35); }
.badge-ext { background: rgba(47,211,154,0.16); color: #95efce; border: 1px solid rgba(47,211,154,0.4); margin-left: 6px; }

.email-link { font-weight: 600; color: var(--text); border-bottom: 1px dashed transparent; }
.email-link:hover { color: var(--primary); border-bottom-color: var(--primary); }

.info-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 28px; margin: 18px 0 4px; }
.info-grid > div { display: grid; gap: 5px; }
.info-grid dt { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; margin: 0; }
.info-grid dd { margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.detail-actions { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border-soft); }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 0.85rem; }
.card h2 .count { margin-left: 8px; vertical-align: middle; }
.actions-cell { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline-mini { display: inline-flex; gap: 6px; margin: 0; align-items: center; }
.inline-mini input { padding: 7px 9px; font-size: 0.8rem; width: 135px; }

.site-foot { text-align: center; padding: 22px; color: var(--muted); font-size: 0.8rem; border-top: 1px solid var(--border-soft); display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.site-foot a { color: var(--primary); font-weight: 500; }
.site-foot a:hover { color: #82a6ff; }
.foot-sep { opacity: 0.5; }

/* Compose button in nav */
.compose-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
}

/* Compose form */
.compose-form { margin-top: 4px; }
.file-field input[type="file"] {
  width: 100%; padding: 11px 12px; background: var(--bg-soft);
  border: 1px dashed var(--border); border-radius: 11px; color: var(--muted);
  font-size: 0.88rem; cursor: pointer;
}
.file-field input[type="file"]::file-selector-button {
  margin-right: 12px; padding: 7px 13px; border: none; border-radius: 8px;
  background: var(--panel-2); color: var(--text); font-weight: 600; cursor: pointer;
}
.compose-actions { display: flex; gap: 12px; align-items: center; margin-top: 4px; }

/* Attachments in message view */
.attachments { padding: 4px 26px 24px; border-top: 1px solid var(--border-soft); }
.attachments h3 { font-size: 0.95rem; color: var(--muted); margin: 18px 0 12px; }
.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.attach-card {
  background: var(--bg-soft); border: 1px solid var(--border-soft);
  border-radius: 13px; overflow: hidden; display: flex; flex-direction: column;
  transition: border-color 0.18s, transform 0.12s;
}
.attach-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.attach-preview {
  height: 170px; background: #0b0f17; display: flex; align-items: center; justify-content: center;
  overflow: hidden; border-bottom: 1px solid var(--border-soft);
}
.attach-preview a { display: flex; width: 100%; height: 100%; }
.attach-preview img { width: 100%; height: 100%; object-fit: contain; }
.attach-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.attach-noprev { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); }
.attach-icon { font-size: 1.1rem; }
.attach-icon.big { font-size: 2.4rem; }
.attach-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 4px; }
.attach-name { font-weight: 500; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-size { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.attach-buttons { display: flex; gap: 8px; padding: 8px 12px 12px; }
.attach-buttons .btn { flex: 1; }
.attach-warn { margin-top: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .msg-link { grid-template-columns: 14px 1fr; gap: 6px 12px; }
  .msg-link .msg-date { grid-column: 2; text-align: left; }
  .form-inline { grid-template-columns: 1fr; }
  .topnav { gap: 13px; }
  .topnav .who { display: none; }
  .page-head h1 { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
