/* Lumina Mail — design system. Light default, dark via [data-theme] / prefers-color-scheme. */

:root {
  --bg: #f6f7fb;
  --bg-accent: radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, .12), transparent 60%),
               radial-gradient(900px 500px at -10% 110%, rgba(34, 211, 238, .10), transparent 55%);
  --surface: #ffffff;
  --surface-2: #f1f2f7;
  --surface-3: #e9ebf2;
  --border: #e3e6ef;
  --border-strong: #cdd2e0;
  --text: #171923;
  --text-2: #5b6172;
  --text-3: #9096a8;
  --accent: #5b5bd6;
  --accent-strong: #4747c2;
  --accent-soft: rgba(91, 91, 214, .1);
  --gradient: linear-gradient(135deg, #5b5bd6 0%, #7c3aed 55%, #0891b2 130%);
  --gradient-soft: linear-gradient(135deg, rgba(91,91,214,.14), rgba(8,145,178,.12));
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .1);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, .12);
  --warn: #d97706;
  --star: #eab308;
  --shadow-sm: 0 1px 2px rgba(23, 25, 35, .06);
  --shadow-md: 0 4px 16px rgba(23, 25, 35, .08);
  --shadow-lg: 0 16px 48px rgba(23, 25, 35, .16);
  --radius: 14px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0e1017;
  --bg-accent: radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, .16), transparent 60%),
               radial-gradient(900px 500px at -10% 110%, rgba(34, 211, 238, .08), transparent 55%);
  --surface: #171a24;
  --surface-2: #1e2230;
  --surface-3: #262b3b;
  --border: #272c3c;
  --border-strong: #39405a;
  --text: #eef0f6;
  --text-2: #a7adbf;
  --text-3: #6b7186;
  --accent: #7c7cf0;
  --accent-strong: #9d9df5;
  --accent-soft: rgba(124, 124, 240, .14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
  --danger-soft: rgba(248, 113, 113, .14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, .12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* .btn display would otherwise override hidden */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-accent), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-soft); }

h1, h2, h3 { letter-spacing: -0.02em; margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); }
svg { display: block; }

button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- primitives ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font-weight: 600; font-size: 14px;
  cursor: pointer; transition: background .15s, box-shadow .15s, transform .05s, border-color .15s;
  background: var(--surface-2); color: var(--text);
  white-space: nowrap; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--gradient); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-icon { padding: 7px; border-radius: 8px; background: transparent; color: var(--text-2); border: none; }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger); }

.input, select.input, textarea.input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--text-3); }
textarea.input { resize: vertical; min-height: 90px; }
label.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 14px 0 5px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
}

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.success { background: var(--success-soft); color: var(--success); }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin .7s linear infinite; margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 45%, var(--surface-2) 65%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 11px 16px; box-shadow: var(--shadow-lg);
  font-size: 14px; max-width: 340px; animation: toastIn .25s cubic-bezier(.2,.9,.3,1.2);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 20, .5); backdrop-filter: blur(3px);
  z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column; animation: popIn .2s cubic-bezier(.2,.9,.3,1.15);
}
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(8px); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 12px 20px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 18px; }

.empty { text-align: center; padding: 48px 24px; color: var(--text-3); }
.empty svg { margin: 0 auto 14px; opacity: .5; }
.empty h4 { color: var(--text-2); margin: 0 0 6px; font-size: 15px; }
.empty p { margin: 0; font-size: 13.5px; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: background .18s; cursor: pointer; }
.switch .track::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: transform .18s; box-shadow: var(--shadow-sm);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* ---------- header / nav ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px); max-width: 1440px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.02em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .logo { width: 30px; height: 30px; }
.nav { display: flex; align-items: center; gap: 10px; }

.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.lang-switch button { border: none; background: transparent; padding: 5px 12px; font-size: 12.5px; font-weight: 700; color: var(--text-3); cursor: pointer; }
.lang-switch button.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- landing (temp mail) ---------- */

.hero { max-width: 1060px; margin: 0 auto; padding: clamp(20px, 5vw, 56px) clamp(16px, 4vw, 40px) 60px; text-align: center; }
.hero h1 { font-size: clamp(30px, 5vw, 46px); font-weight: 800; line-height: 1.12; }
.hero h1 .grad { background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .sub { color: var(--text-2); font-size: clamp(15px, 2vw, 17.5px); max-width: 640px; margin: 14px auto 0; }
.hero .sub a { font-weight: 600; }

.temp-card { max-width: 720px; margin: 34px auto 0; padding: clamp(20px, 4vw, 34px); text-align: left; }
.address-box {
  display: flex; align-items: center; gap: 10px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px; padding: 8px 8px 8px 16px;
}
.address-box .addr { flex: 1; font-family: var(--mono); font-size: clamp(14px, 2.6vw, 17px); font-weight: 600; overflow-wrap: anywhere; }
.temp-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 14px 22px; margin-top: 16px; }

.countdown { position: relative; width: 54px; height: 54px; flex-shrink: 0; }
.countdown svg { transform: rotate(-90deg); }
.countdown .ring-bg { stroke: var(--surface-3); }
.countdown .ring { stroke: url(#gradRing); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.countdown .time { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }

.feature-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 44px; text-align: left; }
.feature { padding: 18px; }
.feature .ico { width: 36px; height: 36px; border-radius: 10px; background: var(--gradient-soft);
  display: flex; align-items: center; justify-content: center; color: var(--accent); margin-bottom: 10px; }
.feature h4 { font-size: 14.5px; margin-bottom: 4px; }
.feature p { margin: 0; color: var(--text-2); font-size: 13.5px; }

.token-note { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--warn, #d97706); background: rgba(217, 119, 6, .09); border: 1px dashed rgba(217, 119, 6, .4); font-size: 13px; color: var(--text-2); }
.token-note code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }

/* ---------- message list (temp + webmail) ---------- */

.msg-list { display: flex; flex-direction: column; }
.msg-row {
  display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s;
  position: relative;
}
.msg-row:hover { background: var(--surface-2); }
.msg-row.unread::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--accent); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff; background: var(--gradient);
}
.avatar.h0 { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.avatar.h1 { background: linear-gradient(135deg, #10b981, #0891b2); }
.avatar.h2 { background: linear-gradient(135deg, #8b5cf6, #d946ef); }
.avatar.h3 { background: linear-gradient(135deg, #3b82f6, #6366f1); }
.msg-main { flex: 1; min-width: 0; }
.msg-top { display: flex; align-items: baseline; gap: 8px; }
.msg-from { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-time { margin-left: auto; font-size: 12px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg-subject { font-size: 14px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.msg-row.unread .msg-subject { font-weight: 700; }
.msg-snippet { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.msg-flags { display: flex; gap: 4px; align-items: center; color: var(--text-3); }
.msg-flags .chip { font-size: 11px; }

/* ---------- app shell (webmail/admin) ---------- */

.shell { display: grid; grid-template-columns: 264px 1fr; max-width: 1560px; margin: 0 auto; min-height: calc(100vh - 62px); }
.sidebar {
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 62px; height: calc(100vh - 62px); overflow-y: auto;
}
.sidebar .sec { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 6px; }
.side-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--text-2); font-weight: 550; font-size: 14px; cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  transition: background .12s, color .12s;
}
.side-item:hover { background: var(--surface-2); color: var(--text); }
.side-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.side-item .count { margin-left: auto; font-size: 11.5px; background: var(--surface-3); color: var(--text-2); border-radius: 999px; padding: 1px 8px; font-weight: 700; }
.side-item.active .count { background: var(--accent); color: #fff; }

.content { min-width: 0; display: flex; flex-direction: column; }
.pane { padding: 18px clamp(14px, 3vw, 28px); }
.pane-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.pane-head h2 { font-size: 19px; }
.pane-head .spacer { flex: 1; }

/* webmail split: list + reader */
.mail-split { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; flex: 1; min-height: 0; }
.mail-list-pane { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.mail-list-scroll { overflow-y: auto; flex: 1; }
.reader-pane { overflow-y: auto; padding: 22px clamp(16px, 3vw, 34px); }

.reader-head { display: flex; gap: 14px; align-items: flex-start; }
.reader-head h2 { font-size: 19px; margin-top: 2px; overflow-wrap: anywhere; }
.reader-meta { color: var(--text-2); font-size: 13.5px; margin-top: 6px; overflow-wrap: anywhere; }
.reader-actions { display: flex; gap: 4px; margin-left: auto; flex-shrink: 0; }
.reader-body { margin-top: 18px; }
.reader-body iframe { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff; min-height: 220px; }
.reader-body .text-body { white-space: pre-wrap; font-size: 14.5px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }

.att-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  font-size: 13px; cursor: pointer; transition: border-color .15s;
}
.att-chip:hover { border-color: var(--accent); }
.att-chip .sz { color: var(--text-3); font-size: 11.5px; }

/* tables (admin) */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 640px; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--surface-2); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat .v { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat .k { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 9px 16px; font-weight: 600; font-size: 14px; color: var(--text-2); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* auth pages */
.auth-wrap { min-height: calc(100vh - 62px); display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 420px; padding: 30px; }
.auth-card h2 { font-size: 22px; margin-bottom: 4px; }
.auth-card .sub { color: var(--text-2); font-size: 14px; margin-bottom: 8px; }
.pw-field { position: relative; }
.pw-field .btn-icon { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); }
.pw-rules { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.pw-rules .badge { font-size: 11px; padding: 2px 8px; }
.pw-rules .ok { background: var(--success-soft); color: var(--success); }

/* compose */
.compose-fields .to-line { display: flex; gap: 8px; align-items: center; }
.compose-fields .to-line label { font-size: 12.5px; color: var(--text-3); width: 40px; flex-shrink: 0; text-align: right; }

/* search bar */
.searchbar { position: relative; flex: 1; min-width: 160px; max-width: 380px; }
.searchbar .input { padding-left: 34px; }
.searchbar svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); }

.settings-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: none; }
.settings-row .grow { flex: 1; min-width: 0; }
.settings-row .title { font-weight: 650; font-size: 14.5px; }
.settings-row .desc { color: var(--text-2); font-size: 13px; }

/* ---------- responsive ---------- */

.mobile-only { display: none; }
.menu-btn { display: none; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 150; left: 0; top: 0; bottom: 0; width: 280px;
    transform: translateX(-102%); transition: transform .22s ease; height: 100vh; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(10,12,20,.45); z-index: 140; }
  .menu-btn { display: inline-flex; }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }
  .mail-split { grid-template-columns: 1fr; }
  .mail-split.show-reader .mail-list-pane { display: none; }
  .mail-split:not(.show-reader) .reader-pane { display: none; }
  .reader-pane { position: relative; }
  .back-btn { position: sticky; top: 0; z-index: 5; background: var(--bg); margin: -10px -6px 8px; padding: 6px; }
}

@media (min-width: 1600px) {
  .shell { max-width: 1760px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
