/* ===== MailDesk — mobile-only styles ===== */
:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-ink: #ffffff;
  --border: #2b3a52;
  --danger: #f87171;
  --success: #22c55e;
  --unread-bg: rgba(59, 130, 246, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f1f5f9;
  --surface-2: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --unread-bg: rgba(59, 130, 246, 0.07);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #f1f5f9;
    --surface-2: #e2e8f0;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #64748b;
    --border: #e2e8f0;
    --danger: #dc2626;
    --unread-bg: rgba(59, 130, 246, 0.07);
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
#app { position: fixed; inset: 0; overflow: hidden; }
.hidden { display: none !important; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }

/* ----- icons ----- */
.ic {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.ic-xl { width: 56px; height: 56px; stroke-width: 1.4; opacity: .5; }
.starred .ic { fill: #f59e0b; stroke: #f59e0b; }
.spinning .ic { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- buttons & inputs (44px+ touch targets, 16px text avoids iOS zoom) ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 12px; border: 1px solid transparent;
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-block { display: flex; width: 100%; }
.btn-link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 8px; cursor: pointer; min-height: 40px; }
.danger-text { color: var(--danger); }
.btn + .btn, .btn + .btn-link, .card + .btn { margin-top: 12px; }

.icon-btn {
  width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; border-radius: 50%; color: var(--text); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.danger { color: var(--danger); }

.form-group { margin-bottom: 16px; min-width: 0; }
.form-group.no-margin { margin-bottom: 0; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], select {
  width: 100%; min-height: 48px; padding: 0 14px; font-size: 16px; font-family: inherit;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; outline: none; appearance: none; -webkit-appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 16px auto;
}

/* ----- screens ----- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: var(--bg); overflow: hidden;
}
.screen-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px 20px calc(24px + var(--safe-bottom));
}

/* top bar */
.bar {
  flex: none; display: flex; align-items: center; gap: 4px;
  min-height: calc(var(--bar-h) + var(--safe-top));
  padding: var(--safe-top) 6px 0;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.bar h1, .bar h2 { font-size: 19px; font-weight: 700; }
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-left: 4px; }
.bar-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.15; }
.bar-sub { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title-plain { flex: 1; padding-left: 4px; }
.bar-spacer { flex: 1; }

/* ----- auth ----- */
.auth-wrap {
  width: 100%; max-width: 440px; margin: 0 auto; flex: 1;
  padding: calc(40px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  overflow-y: auto;
}
.auth-wrap.center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.logo-large {
  width: 72px; height: 72px; background: var(--accent); color: #fff; border-radius: 20px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 26px; margin: 0 auto 16px;
}
.auth-wrap h1 { text-align: center; font-size: 28px; margin-bottom: 6px; }
.tagline { text-align: center; color: var(--text-2); margin-bottom: 28px; }
.auth-error, .error-box {
  background: rgba(239, 68, 68, .12); color: var(--danger);
  padding: 12px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 16px;
}
.auth-help { text-align: center; color: var(--text-2); font-size: 14px; margin-top: 20px; }
.auth-error { display: none; }
.auth-error.show { display: block; }
.error-box strong { display: block; margin-bottom: 4px; }
.error-box p { word-break: break-word; }

/* ----- setup ----- */
.setup-step.center { text-align: center; padding-top: 60px; }
.setup-info { color: var(--text-2); margin-bottom: 20px; }
.setup-step h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin: 8px 0 12px; }

/* ----- message list ----- */
.search-row { flex: none; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.search-row input { min-height: 44px; border-radius: 22px; }
.list-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(96px + var(--safe-bottom)); }
.message-item {
  display: flex; gap: 12px; padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.message-item:active { background: var(--surface); }
.message-item.unread { background: var(--unread-bg); }
.mi-main { flex: 1; min-width: 0; }
.mi-top { display: flex; align-items: baseline; gap: 8px; }
.mi-from { flex: 1; min-width: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mi-date { flex: none; font-size: 12px; color: var(--text-2); }
.mi-star { color: #f59e0b; font-size: 14px; flex: none; }
.mi-subject { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.mi-preview {
  font-size: 14px; color: var(--text-2); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.message-item.unread .mi-from, .message-item.unread .mi-subject { font-weight: 700; }
.message-item.unread .mi-date { color: var(--accent); font-weight: 600; }

.avatar {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  background: hsl(var(--h, 215), 55%, 45%); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px;
}
.avatar-lg { width: 52px; height: 52px; font-size: 21px; }

.list-empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 80px 32px; text-align: center; color: var(--text-2); }
.load-more { display: flex; margin: 16px auto; }

.fab {
  position: absolute; right: 18px; bottom: calc(18px + var(--safe-bottom));
  width: 60px; height: 60px; border-radius: 20px; border: 0;
  background: var(--accent); color: #fff; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 5;
}
.fab:active { transform: scale(.95); }

/* ----- side menu ----- */
.drawer { position: fixed; inset: 0; z-index: 40; visibility: hidden; transition: visibility 0s .25s; }
.drawer.open { visibility: visible; transition: none; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; transition: opacity .25s; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: absolute; top: 0; bottom: 0; left: 0; width: min(86vw, 320px);
  background: var(--bg); display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow);
  padding-top: var(--safe-top);
}
.drawer.open .drawer-panel { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 14px; padding: 20px 18px 16px; border-bottom: 1px solid var(--border); }
.drawer-user { min-width: 0; display: flex; flex-direction: column; }
.drawer-user strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-user span { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 0; }
.drawer-accounts { padding: 4px 10px 8px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.drawer-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 8px 4px; }
.account-item, .folder-item, .drawer-link {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 48px; padding: 0 14px;
  background: none; border: 0; border-radius: 12px; text-align: left; cursor: pointer; font-size: 16px;
}
.account-item { font-size: 14px; min-height: 44px; }
.account-item span, .folder-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-item.active, .folder-item.active { background: rgba(59, 130, 246, .16); color: var(--accent); font-weight: 600; }
.folder-nav { padding: 0 10px; }
.folder-badge { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; border-radius: 10px; padding: 1px 8px; }
.drawer-foot { border-top: 1px solid var(--border); padding: 8px 10px calc(8px + var(--safe-bottom)); }
.account-item:active, .folder-item:active, .drawer-link:active { background: var(--surface); }

/* ----- full-screen sheets (message / compose / settings) ----- */
.sheet {
  position: fixed; left: 0; right: 0; top: 0; z-index: 30;
  height: var(--vvh, 100dvh);
  background: var(--bg); display: flex; flex-direction: column;
  visibility: hidden; transition: transform .25s ease, visibility 0s .25s;
}
.sheet.open { visibility: visible; transform: none; transition: transform .25s ease; }
.sheet-right { transform: translateX(100%); }
.sheet-up { transform: translateY(100%); z-index: 35; }
#settings-screen { z-index: 32; }
.sheet-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(24px + var(--safe-bottom)); }

/* message view */
.msg-head { padding: 16px 16px 8px; }
.msg-head h2 { font-size: 21px; line-height: 1.25; margin-bottom: 14px; word-break: break-word; }
.msg-from-row { display: flex; align-items: center; gap: 12px; }
.msg-from-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.msg-from-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-from-text span { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-details-toggle { background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; color: var(--text-2); display: flex; align-items: center; justify-content: center; }
.msg-details-toggle.open .ic { transform: rotate(180deg); }
.msg-details { margin-top: 10px; padding: 10px 12px; background: var(--surface); border-radius: 12px; font-size: 13px; color: var(--text-2); word-break: break-word; }
.msg-details div + div { margin-top: 4px; }
.msg-details b { color: var(--text); }
.msg-date { font-size: 13px; color: var(--muted); margin-top: 10px; }
.images-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 8px 16px 0; padding: 4px 12px; background: var(--surface); border-radius: 12px; font-size: 14px; color: var(--text-2);
}
.msg-body-wrap { position: relative; margin: 12px 12px 0; border-radius: 12px; overflow: hidden; background: #fff; min-height: 120px; }
.msg-body-wrap iframe { display: block; width: 100%; border: 0; background: #fff; height: 120px; }
.msg-loading { position: absolute; inset: 0; background: #fff; display: flex; align-items: center; justify-content: center; z-index: 2; }

/* compose */
.btn-send { min-height: 40px; padding: 0 16px; border-radius: 20px; margin: 0 6px 0 2px; }
.btn-send .ic { width: 18px; height: 18px; }
.compose-fields { flex: none; }
.compose-field { display: flex; align-items: center; gap: 8px; min-height: 50px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--border); }
.compose-field label { width: 52px; flex: none; color: var(--text-2); font-size: 14px; }
.compose-field input { flex: 1; min-width: 0; border: 0; background: transparent; border-radius: 0; padding: 0; min-height: 48px; }
.compose-from { flex: 1; min-width: 0; color: var(--text-2); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-editor {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px; outline: none;
  font-size: 16px; line-height: 1.5; word-break: break-word; min-height: 0;
}
.compose-editor:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.compose-editor blockquote { margin: 8px 0 0 4px; padding-left: 10px; border-left: 3px solid var(--muted); color: var(--text-2); }
.compose-toolbar {
  flex: none; display: flex; gap: 6px; padding: 6px 10px calc(6px + var(--safe-bottom));
  border-top: 1px solid var(--border); background: var(--bg); overflow-x: auto;
}
.fmt-btn {
  min-width: 46px; height: 44px; background: var(--surface); border: 0; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 17px; cursor: pointer;
}
.fmt-btn:active { background: var(--surface-2); }

/* settings */
.settings-body { padding: 4px 16px calc(32px + var(--safe-bottom)); }
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 8px; }
.card { background: var(--surface); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; }
.settings-account-row { padding: 12px 0; }
.settings-account-row + .settings-account-row { border-top: 1px solid var(--border); }
.settings-account-row .sa-email { font-weight: 600; word-break: break-all; }
.settings-account-row .sa-meta { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.sa-actions { display: flex; gap: 8px; margin-top: 10px; }
.sa-actions .btn { min-height: 40px; font-size: 14px; padding: 0 14px; margin: 0; background: var(--bg); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.switch-row small { display: block; color: var(--text-2); font-weight: 400; margin-top: 3px; font-size: 13px; }
.switch-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none; width: 52px; height: 32px; border-radius: 16px;
  background: var(--surface-2); position: relative; transition: background .2s; cursor: pointer;
}
.switch-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch-row input[type="checkbox"]:checked { background: var(--accent); }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(20px); }
.help details { padding: 4px 0; }
.help details + details { border-top: 1px solid var(--border); }
.help summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; list-style: none; }
.help summary::-webkit-details-marker { display: none; }
.help summary::after { content: "+"; margin-left: auto; color: var(--text-2); font-size: 20px; }
.help details[open] summary::after { content: "–"; }
.help p { color: var(--text-2); font-size: 15px; padding-bottom: 12px; }
.footnote { text-align: center; color: var(--muted); font-size: 12px; margin-top: 20px; }

/* toast */
#toast-container {
  position: fixed; left: 0; right: 0; bottom: calc(96px + var(--safe-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; padding: 0 16px;
}
.toast {
  background: #1f2937; color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 15px;
  box-shadow: var(--shadow); max-width: 100%; animation: toast-in .2s ease;
}
.toast-error { background: #b91c1c; }
.toast-success { background: #15803d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0s !important; animation-duration: 0s !important; }
}

