/* A definite height at each flex level keeps native scrolling working in Chromium/Yandex. */
[hidden] { display: none !important; }
html { height: 100%; width: 100%; overflow: hidden; touch-action: pan-x pan-y; }
body { position: fixed; top: var(--app-offset-top, 0px); left: 0; width: 100%; height: var(--app-height, 100vh); display: flex; flex-direction: column; overflow: hidden; touch-action: pan-x pan-y; }
.screen { flex: 1 1 0; min-height: 0; }
#login-screen { overflow-y: auto; padding: 16px; }
.login-box { flex-shrink: 0; max-height: 100%; overflow-y: auto; }
.mail-container { height: 100%; max-height: 850px; min-height: 0; margin: 0; }
#mail-screen { padding: 20px 0; }
.sidebar { flex: 0 0 260px; min-height: 0; min-width: 0; overflow-y: auto; }
.logo.small, .compose-btn, .sidebar-footer, .ad-banner { flex-shrink: 0; }
.nav-menu { min-height: 72px; }
.mail-content { overflow: hidden; min-height: 0; }
.mail-header, .action-bar, .reader-header { flex: 0 0 auto; }
.email-list, .reader-body { flex: 1 1 0; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; touch-action: pan-y; }
.reader-body { display: block; }
.mail-reader { min-height: 0; overflow: hidden; }
.reader-header { min-width: 0; }
#reader-subject { overflow-wrap: anywhere; }
.message-wrap, .email-message, .reader-reply-actions { flex-shrink: 0; }
.message-wrap.me { margin-left: auto; }
.message-wrap { margin-bottom: 20px; }
.msg-bubble { white-space: pre-wrap; overflow-wrap: anywhere; }
.single-email, .msg-meta { overflow-wrap: anywhere; }
.structured-email { white-space: normal; }
.email-paragraph { white-space: pre-wrap; margin: 0 0 18px; }
.email-paragraph:last-child { margin-bottom: 0; }
.email-link { color: var(--accent-color); text-underline-offset: 3px; }
.email-link:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 3px; }
.email-content-list { margin: -4px 0 20px; padding-left: 24px; }
.email-content-list li { padding-left: 3px; margin-bottom: 6px; }
.email-divider { border: 0; border-top: 1px solid var(--glass-border); margin: 24px 0; }
.message-image-link { display: block; width: fit-content; max-width: 100%; margin-top: 16px; color: var(--accent-color); text-decoration: none; }
.message-image-link .msg-image { margin-top: 0; }
.image-caption { display: block; margin-top: 8px; font-size: 12px; white-space: normal; }
.mail-attachment { display: flex; flex-direction: column; gap: 6px; max-width: 100%; padding: 14px 16px; margin: 16px 0; border: 1px solid var(--glass-border); border-radius: 10px; background: #38bdf80a; color: var(--text-color); text-decoration: none; white-space: normal; }
.mail-attachment:hover { border-color: var(--accent-color); }
button.mail-attachment { width: 100%; font: inherit; text-align: left; cursor: pointer; }
.attachment-name { font-weight: 600; overflow-wrap: anywhere; }
.attachment-action { color: var(--accent-color); font-size: 12px; }
.attachment-block { margin: 16px 0; }
.attachment-block .mail-attachment { margin: 0; }
.attachment-download { display: inline-flex; margin-top: 8px; color: var(--accent-color); font-size: 12px; text-underline-offset: 3px; }
.msg-meta { user-select: text; }
.email-message { display: flex; flex-direction: column; width: 100%; margin-bottom: 10px; }
.email-item { grid-template-columns: 26px minmax(120px, 180px) minmax(0, 1fr) auto; gap: 12px; padding: 18px 14px; }
.email-sender { min-width: 0; overflow-wrap: anywhere; }
.empty-folder { padding: 24px; text-align: center; color: var(--text-muted); }
.site-disclaimer { flex: 0 0 auto; padding: 8px 16px; color: #b8c2d1; text-align: center; font-size: 11px; line-height: 1.4; background: rgba(15, 23, 42, .45); }
.site-disclaimer a { color: #c3e7ff; }
.has-unread { color: var(--accent-color); position: relative; }
.has-unread::after { content: ''; position: absolute; right: -3px; top: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-color); }
#refresh-btn.is-refreshing { color: var(--accent-color); cursor: wait; }
#refresh-btn.is-refreshing svg { animation: refresh-spin .65s linear infinite; transform-origin: center; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
button:focus-visible, a:focus-visible, .email-item:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 3px; }

/* Popovers sit above native modal dialogs; older browsers use the active dialog. */
.toast-host { position: fixed; inset: auto; top: calc(var(--app-offset-top, 0px) + max(16px, env(safe-area-inset-top))); right: 16px; z-index: 2147483647; width: min(330px, calc(100vw - 32px)); margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast-host[popover]:not(:popover-open) { display: none; }
.toast-host::backdrop { background: transparent; pointer-events: none; }
.mail-toast { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-radius: 12px; border: 1px solid rgba(56, 189, 248, .35); background: #14243c; color: var(--text-color); box-shadow: 0 8px 24px #0005; pointer-events: auto; animation: fadeIn .2s ease; }
.toast-content { flex: 1; min-width: 0; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; display: flex; flex-direction: column; gap: 3px; font-size: 11px; line-height: 1.35; }
button.toast-content { cursor: pointer; }
.toast-content strong { color: #c4ecff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-content span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.toast-close, .dialog-close { flex-shrink: 0; border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 24px; line-height: 1; padding: 0 4px; }
.toast-close { font-size: 20px; min-width: 28px; min-height: 28px; }

.compose-dialog { position: fixed; top: calc(var(--app-offset-top, 0px) + var(--app-height, 100vh) / 2); left: 50%; transform: translate(-50%, -50%); color: var(--text-color); background: #111f35; border: 1px solid var(--glass-border); border-radius: 22px; padding: 0; margin: 0; width: min(960px, calc(100vw - 40px)); height: min(760px, calc(var(--app-height, 100vh) - 64px)); max-height: none; box-shadow: 0 30px 90px #0009; overflow: hidden; }
.compose-dialog[open] { display: flex; flex-direction: column; }
.compose-dialog .toast-host:not([popover]), .dossier-dialog .toast-host:not([popover]) { position: absolute; top: 12px; right: 12px; max-width: calc(100% - 24px); }
.compose-dialog::backdrop { background: rgba(3, 8, 18, .68); backdrop-filter: blur(8px); }
.compose-heading { flex-shrink: 0; display: flex; justify-content: space-between; align-items: center; padding: 22px 26px; border-bottom: 1px solid var(--glass-border); }
.compose-eyebrow { margin-bottom: 5px; font-size: 11px; color: var(--accent-color); letter-spacing: .12em; text-transform: uppercase; }
.compose-heading h2 { font-size: 21px; }
.compose-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px minmax(0, 1fr); }
.compose-addressbook { display: flex; flex-direction: column; min-height: 0; min-width: 0; padding: 20px 14px; border-right: 1px solid var(--glass-border); background: #0c172a; }
.addressbook-title { font-size: 13px; font-weight: 600; margin: 0 6px 12px; }
.contact-search { flex-shrink: 0; width: 100%; border-radius: 9px; padding: 10px 12px; border: 1px solid var(--glass-border); background: #ffffff05; color: #fff; outline: none; margin-bottom: 12px; }
.contact-search:focus { border-color: var(--accent-color); }
.compose-contacts { overflow-y: auto; min-height: 0; touch-action: pan-y; }
.contact-option { display: flex; flex-direction: column; gap: 5px; width: 100%; padding: 12px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text-color); text-align: left; cursor: pointer; margin-bottom: 4px; }
.contact-option:hover { background: #ffffff08; }
.contact-option.selected { border-color: #38bdf870; background: #38bdf815; }
.contact-name { font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.contact-email { font-size: 11px; color: var(--text-muted); overflow-wrap: anywhere; }
.contact-option.selected .contact-email { color: #7dd3fc; }
.compose-form { display: flex; flex-direction: column; min-height: 0; min-width: 0; padding: 24px; overflow-y: auto; }
.compose-from { color: var(--text-muted); font-size: 12px; margin-bottom: 22px; overflow-wrap: anywhere; }
.compose-form .input-group { margin-bottom: 16px; flex-shrink: 0; }
.compose-form .input-group label { font-size: 12px; }
.compose-form .input-group input { padding: 11px 12px; font-size: 13px; }
.compose-form .compose-text-group { flex: 1 0 180px; display: flex; flex-direction: column; min-height: 180px; }
#compose-text { width: 100%; flex: 1; min-height: 140px; border: 1px solid var(--glass-border); border-radius: 12px; background: #0002; padding: 14px; color: #fff; font-size: 14px; line-height: 1.6; resize: none; outline: none; user-select: text; }
#compose-text:focus { border-color: var(--accent-color); }
.compose-error { flex-shrink: 0; min-height: 18px; font-size: 12px; color: #fda4af; margin-bottom: 10px; }
.compose-footer { flex-shrink: 0; display: flex; justify-content: flex-end; gap: 12px; align-items: center; }
.send-btn { width: auto; padding: 12px 20px; font-size: 13px; }
.send-btn:disabled { opacity: .55; cursor: default; }

.dossier-dialog { position: fixed; top: calc(var(--app-offset-top, 0px) + var(--app-height, 100vh) / 2); left: 50%; transform: translate(-50%, -50%); margin: 0; padding: 0; width: min(940px, calc(100vw - 40px)); height: min(840px, calc(var(--app-height, 100vh) - 64px)); max-width: none; max-height: none; color: var(--text-color); background: #111f35; border: 1px solid var(--glass-border); border-radius: 18px; overflow: hidden; box-shadow: 0 30px 90px #0009; }
.dossier-dialog[open] { display: flex; flex-direction: column; }
.dossier-dialog::backdrop { background: rgba(3, 8, 18, .72); backdrop-filter: blur(8px); }
.dossier-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex: 0 0 auto; padding: 12px 20px; border-bottom: 1px solid var(--glass-border); }
.dossier-heading h2 { font-size: 18px; margin: 0; }
.dossier-heading .dialog-close { min-width: 44px; min-height: 44px; }
.dossier-frame { display: block; flex: 1 1 0; width: 100%; min-height: 0; border: 0; background: #eae8e2; }

@media (max-width: 850px) {
    #mail-screen { padding: 0; }
    .mail-container { height: 100%; max-height: none; margin: 0; }
    .sidebar { padding-top: max(24px, env(safe-area-inset-top)); }
    .mail-header { padding-top: max(15px, env(safe-area-inset-top)); }
    .email-item { grid-template-columns: 24px minmax(0, 1fr); padding: 16px; }
    .email-sender { padding-right: 105px; }
    .email-time { right: 16px; }
    .email-info { grid-column: 2; }
    .site-disclaimer { font-size: 7px; line-height: 1.25; padding: 3px 10px; padding-bottom: max(3px, env(safe-area-inset-bottom)); }
    .keyboard-open .site-disclaimer { padding-bottom: 3px; }
    .toast-host { top: calc(var(--app-offset-top, 0px) + max(12px, env(safe-area-inset-top))); right: 12px; width: min(380px, calc(100vw - 24px)); }
    .mail-toast { min-height: 86px; padding: 14px; gap: 10px; border-radius: 14px; }
    .toast-content { gap: 5px; font-size: 13px; line-height: 1.45; }
    .toast-content strong { font-size: 15px; }
    .toast-content span { -webkit-line-clamp: 2; }
    .toast-close { min-width: 32px; min-height: 44px; font-size: 24px; }
    .compose-dialog { width: calc(100vw - 20px); height: calc(var(--app-height, 100vh) - 24px); border-radius: 16px; }
    .dossier-dialog { width: calc(100vw - 20px); height: calc(var(--app-height, 100vh) - 24px); border-radius: 16px; }
    .dossier-heading { padding: 8px 12px; gap: 10px; }
    .dossier-heading h2 { font-size: 16px; }
    .input-group input, .contact-search, .compose-form .input-group input, #compose-text { font-size: 16px; }
    #recovery-box { max-height: calc(var(--app-height, 100vh) - 24px); }
    .compose-heading { padding: 16px; }
    .compose-heading h2 { font-size: 18px; }
    .compose-layout { grid-template-columns: 230px minmax(0, 1fr); }
    .compose-form { padding: 18px; }
}
@media (max-width: 600px) {
    .compose-layout { display: flex; flex-direction: column; overflow-y: auto; }
    .compose-addressbook { flex: 0 0 auto; padding: 12px; border-right: 0; border-bottom: 1px solid var(--glass-border); }
    .addressbook-title { margin-bottom: 8px; }
    .contact-search { margin-bottom: 8px; }
    .compose-contacts { max-height: 148px; }
    .contact-option { padding: 9px; }
    .compose-form { overflow: visible; flex: 1 0 auto; }
    .compose-from { margin-bottom: 14px; }
    .compose-form .compose-text-group { flex-basis: 170px; }
    .send-btn { padding: 12px 15px; }
}
@media (max-height: 560px) {
    .sidebar { padding: 16px; }
    .logo.small { margin-bottom: 16px; }
    .compose-btn { margin-bottom: 12px; padding: 10px; }
    .ad-banner { display: none; }
    .nav-menu { min-height: 48px; margin-bottom: 8px; }
    .sidebar-footer { padding-top: 10px; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
