:root {
  color-scheme: dark;
  --bg: #0d1218;
  --panel: #111820;
  --panel-2: #151d26;
  --panel-3: #1a2430;
  --line: #2a3541;
  --text: #f3f6fa;
  --muted: #929eaa;
  --accent: #2f7df6;
  --accent-hover: #4b91ff;
  --danger: #ff5a5f;
  --success: #61c982;
  --radius: 12px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid #79aaff; outline-offset: 2px; }

.brand { display: inline-flex; align-items: center; gap: 13px; font-size: 20px; font-weight: 700; letter-spacing: -.03em; white-space: nowrap; }
.brand-mark { position: relative; width: 31px; height: 24px; display: inline-block; background: var(--accent); clip-path: polygon(0 0, 50% 43%, 100% 0, 100% 100%, 0 100%); }
.brand-mark i { position: absolute; inset: 3px 5px auto; height: 12px; border-left: 2px solid #0d1218; border-bottom: 2px solid #0d1218; transform: rotate(-45deg); }
.brand-mark.muted { opacity: .42; transform: scale(1.4); margin-bottom: 18px; }

.primary-button, .secondary-button, .danger-button, .quiet-button { min-height: 42px; border-radius: 8px; border: 1px solid transparent; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; font-weight: 650; cursor: pointer; transition: background .16s ease, border-color .16s ease, transform .16s ease; }
.primary-button { color: white; background: var(--accent); }
.primary-button:hover { background: var(--accent-hover); }
.primary-button:active, .secondary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: .42; cursor: not-allowed; }
.secondary-button { color: var(--text); background: transparent; border-color: var(--line); }
.secondary-button:hover { background: var(--panel-3); }
.danger-button { color: white; background: var(--danger); }
.quiet-button { min-height: 36px; padding: 0 13px; color: var(--muted); background: transparent; border-color: var(--line); }
.quiet-button:hover { color: var(--text); background: var(--panel-2); }
.icon-button { display: inline-grid; place-items: center; border: 0; color: var(--muted); background: transparent; border-radius: 7px; min-width: 38px; min-height: 38px; cursor: pointer; }
.icon-button:hover { color: var(--text); background: var(--panel-3); }

.auth-page { background: radial-gradient(circle at 50% 42%, #172331 0, var(--bg) 45%); }
.auth-shell { min-height: 100vh; display: grid; grid-template-rows: 1fr auto 1fr; align-items: center; justify-items: center; padding: 32px 20px 24px; }
.auth-brand { align-self: end; margin-bottom: 34px; font-size: 29px; }
.auth-brand .brand-mark { width: 55px; height: 43px; }
.auth-panel { width: min(100%, 424px); padding: 39px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(20, 28, 37, .94); box-shadow: 0 28px 70px rgba(0, 0, 0, .3); }
.auth-panel h1 { margin: 0 0 30px; font-size: 28px; letter-spacing: -.035em; }
.auth-form { display: grid; gap: 19px; }
label { display: grid; gap: 8px; color: #c5cdd6; font-size: 14px; font-weight: 550; }
input, textarea, select { width: 100%; color: var(--text); background: #10171f; border: 1px solid var(--line); border-radius: 7px; padding: 12px 13px; }
input:hover, textarea:hover, select:hover { border-color: #3d4a58; }
input:focus, textarea:focus, select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47, 125, 246, .18); }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 49px; }
.eye-button { position: absolute; right: 3px; top: 3px; }
.form-error { color: #ff777b; margin: -9px 0 0; font-size: 13px; }
.auth-form .primary-button { margin-top: 6px; width: 100%; }
.auth-help { color: var(--muted); text-align: center; font-size: 13px; margin: 25px 0 14px; }
.telegram-link { width: 100%; color: #5a9aff; border-color: var(--accent); }
.auth-footer { align-self: end; color: #6e7a86; font-size: 13px; margin: 60px 0 0; }

.topbar { height: 70px; display: flex; align-items: center; gap: 16px; padding: 0 22px; border-bottom: 1px solid var(--line); background: #0f151c; }
.topbar-spacer { flex: 1; }
.user-name { color: var(--muted); font-size: 14px; }
.mobile-menu { display: none; }
.mail-shell { height: calc(100vh - 70px); min-height: 560px; display: grid; grid-template-columns: 250px minmax(330px, 430px) minmax(440px, 1fr); }
.sidebar, .message-list, .reading-pane { min-width: 0; border-right: 1px solid var(--line); background: var(--panel); }
.sidebar { padding: 18px 13px; display: flex; flex-direction: column; }
.compose-trigger { width: 100%; justify-content: flex-start; padding-left: 22px; }
.main-nav { margin: 17px 0; }
.main-nav a, .mailbox-link, .danger-link { width: 100%; min-height: 42px; display: flex; align-items: center; gap: 12px; padding: 0 13px; border-radius: 7px; color: #c4ccd5; }
.main-nav a.active { color: white; background: var(--panel-3); box-shadow: inset 3px 0 0 var(--accent); }
.section-title { display: flex; color: var(--muted); font-size: 13px; font-weight: 700; padding: 13px 12px 9px; border-top: 1px solid var(--line); }
.mailbox-link { font-size: 13px; overflow: hidden; }
.mailbox-link span:last-child { overflow: hidden; text-overflow: ellipsis; }
.mailbox-link.active { color: white; background: #182330; }
.address-dot, .unread-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--accent); }
.empty-note { color: var(--muted); padding: 0 12px; font-size: 13px; }
.sidebar-bottom { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.danger-link { color: #ff777b; border: 0; background: transparent; cursor: pointer; text-align: left; }
.danger-link:hover { background: rgba(255, 90, 95, .08); }

.message-list { display: flex; flex-direction: column; background: #10171f; }
.panel-header { min-height: 80px; padding: 17px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.panel-header h1 { margin: 0; font-size: 20px; letter-spacing: -.025em; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.message-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.message-rows { overflow: auto; }
.message-row { position: relative; min-height: 105px; display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 12px; padding: 18px 17px; border-bottom: 1px solid var(--line); }
.message-row:hover { background: #161f29; }
.message-row.selected { background: #192738; box-shadow: inset 3px 0 0 var(--accent); }
.message-row .unread-dot { margin-top: 7px; }
.message-copy { display: grid; gap: 3px; min-width: 0; }
.message-copy strong, .message-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-copy strong { font-size: 14px; }
.message-copy .subject { color: #e0e5eb; }
.message-copy .preview { color: var(--muted); font-size: 13px; }
.message-row time { color: var(--muted); font-size: 11px; }
.empty-state, .empty-reading { min-height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 40px; }
.empty-state h2, .empty-reading h2 { color: #ccd4dc; margin: 0 0 8px; font-size: 18px; }
.empty-state p, .empty-reading p { margin: 0; max-width: 290px; line-height: 1.5; }

.reading-pane { border-right: 0; padding: 0 28px 35px; overflow: auto; background: #0f161e; }
.reading-header { min-height: 155px; display: flex; justify-content: space-between; gap: 24px; padding: 27px 0 24px; border-bottom: 1px solid var(--line); }
.reading-header h2 { margin: 0 0 15px; font-size: 24px; letter-spacing: -.025em; }
.reading-header p { margin: 5px 0; color: var(--muted); }
.reading-header p strong { color: var(--text); }
.reading-header time { color: var(--muted); white-space: nowrap; font-size: 12px; }
.message-body { padding: 28px 0; white-space: pre-wrap; line-height: 1.68; color: #d0d7df; max-width: 850px; }
.reading-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: 25px; transform: translateX(-50%); min-width: 280px; padding: 14px 45px 14px 18px; border: 1px solid var(--line); border-radius: 9px; background: #17212b; box-shadow: 0 18px 50px rgba(0,0,0,.45); }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

.modal { width: min(92vw, 650px); max-height: 90vh; padding: 0; color: var(--text); border: 1px solid #394552; border-radius: var(--radius); background: #151d26; box-shadow: 0 30px 100px rgba(0,0,0,.58); }
.modal::backdrop { background: rgba(4, 8, 12, .7); backdrop-filter: blur(3px); }
.modal form { display: grid; gap: 17px; padding: 22px; }
.modal header, .modal footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.modal header h2 { margin: 0; font-size: 19px; }
.modal textarea { min-height: 220px; resize: vertical; line-height: 1.55; }
.body-label { min-height: 0; }
.attachment-control { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.attachment-control input { width: auto; max-width: 250px; padding: 0; border: 0; background: transparent; }
.attachment-control span { color: var(--muted); font-size: 12px; margin-left: auto; }
.modal footer { justify-content: flex-end; padding-top: 5px; }
.notice { margin: 0; padding: 12px 14px; border-radius: 7px; font-size: 13px; line-height: 1.45; }
.notice.warning { color: #ffd78b; background: rgba(255, 179, 61, .08); border: 1px solid rgba(255, 179, 61, .25); }
.delete-modal { width: min(92vw, 470px); }
.delete-modal p { color: #b4bec8; line-height: 1.55; }
.mobile-nav { display: none; }

@media (max-width: 1050px) {
  .mail-shell { grid-template-columns: 225px minmax(320px, 390px) 1fr; }
  .reading-pane { padding-inline: 22px; }
  .reading-header { display: block; }
  .reading-header time { display: block; margin-top: 12px; }
}

@media (max-width: 800px) {
  body { overflow: hidden; }
  .topbar { height: 68px; padding: 0 14px; }
  .topbar .brand { font-size: 18px; gap: 9px; }
  .topbar .brand-mark { width: 25px; height: 20px; }
  .user-name { display: none; }
  .mobile-menu { display: inline-grid; }
  .mail-shell { height: calc(100vh - 68px - 64px); min-height: 0; display: block; }
  .sidebar { position: fixed; z-index: 15; inset: 68px auto 64px 0; width: min(84vw, 310px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 20px 0 55px rgba(0,0,0,.45); }
  .sidebar.open { transform: translateX(0); }
  .message-list { height: 100%; border: 0; }
  .panel-header { min-height: 72px; }
  .message-row { min-height: 100px; }
  .reading-pane { display: none; }
  .mobile-nav { position: fixed; z-index: 12; inset: auto 0 0; height: 64px; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: #10171f; }
  .mobile-nav a, .mobile-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); background: transparent; border: 0; font-size: 11px; }
  .mobile-nav .active { color: var(--accent); }
  .modal { width: 100vw; max-width: none; max-height: 100dvh; height: 100dvh; border-radius: 0; border: 0; }
  .modal form { min-height: 100%; grid-template-rows: auto auto auto auto 1fr auto auto; padding: 18px; }
  .modal textarea { min-height: 180px; height: 100%; }
  .toast { bottom: 78px; width: calc(100% - 28px); min-width: 0; }
}

@media (max-width: 480px) {
  .auth-page { background: var(--bg); }
  .auth-shell { padding: 28px 18px 20px; }
  .auth-brand { font-size: 25px; margin-bottom: 26px; }
  .auth-brand .brand-mark { width: 44px; height: 34px; }
  .auth-panel { padding: 28px 22px; }
  .auth-panel h1 { font-size: 24px; }
  .quiet-button { padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
