:root {
  color-scheme: light;
  --brand-50: #f5f1f9;
  --brand-100: #ece3f4;
  --brand-300: #c4a9da;
  --brand-400: #8a62af;
  --brand-500: #583689;
  --brand-600: #49286f;
  --brand-700: #3c205c;
  --brand-900: #21122f;
  --canvas: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --surface-hover: #eef3f8;
  --surface-selected: #f0eafa;
  --ink: #1f1f1f;
  --ink-soft: #3c4043;
  --muted: #5f6368;
  --muted-2: #8a9096;
  --border: #e1e6eb;
  --border-strong: #d2d8df;
  --green: #14785a;
  --red: #af3542;
  --red-soft: #fff0f2;
  --shadow-sm: 0 2px 8px rgb(60 64 67 / 12%);
  --shadow-lg: 0 24px 70px rgb(33 18 47 / 22%);
  --focus: 0 0 0 3px rgb(88 54 137 / 19%);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  font-family: Inter, "Segoe UI Variable", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html,
body {
  touch-action: pan-x pan-y;
}

[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #100d14;
  --surface: #17131d;
  --surface-2: #1c1722;
  --surface-hover: #241c2d;
  --surface-selected: #2d2039;
  --ink: #f7f3f9;
  --ink-soft: #ded7e3;
  --muted: #aaa2b0;
  --muted-2: #807887;
  --border: #302737;
  --border-strong: #403348;
  --brand-50: #2b1d38;
  --brand-100: #372447;
  --brand-300: #b08ad0;
  --brand-400: #b88cdb;
  --brand-500: #a171ca;
  --red-soft: #342026;
  --shadow-sm: 0 5px 18px rgb(0 0 0 / 18%);
  --shadow-lg: 0 28px 80px rgb(0 0 0 / 45%);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 280px; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--canvas); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 0; box-shadow: var(--focus); }
[hidden] { display: none !important; }
.icon { display: block; width: 20px; height: 20px; flex: 0 0 auto; }
.primary { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 42px; padding: 0 20px; border: 0; border-radius: 10px; color: #fff; background: linear-gradient(135deg, #6e42a3, #4c296f); box-shadow: 0 8px 22px rgb(88 54 137 / 22%); font-weight: 700; text-decoration: none; cursor: pointer; }
.primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.primary:disabled { opacity: .62; transform: none; cursor: wait; }
.primary.wide { width: 100%; min-height: 49px; }
.icon-button { display: grid; width: 40px; height: 40px; padding: 0; place-items: center; border: 0; border-radius: 10px; background: transparent; cursor: pointer; }
.icon-button:hover { background: var(--surface-hover); }
.mobile-only { display: none; }

/* Login */
.login-body { overflow: auto; }
.login-page { display: grid; grid-template-columns: minmax(380px, .95fr) minmax(440px, 1.05fr); min-height: 100dvh; background: var(--surface); }
.login-brand { position: relative; display: flex; min-height: 100%; padding: clamp(38px, 7vw, 98px); align-items: center; overflow: hidden; color: #fff; background: radial-gradient(circle at 15% 12%, rgb(196 150 231 / 55%), transparent 30%), radial-gradient(circle at 92% 85%, rgb(113 57 155 / 85%), transparent 34%), linear-gradient(145deg, #684093 0%, #3d205f 60%, #28143e 100%); }
.login-brand::before, .login-brand::after { content: ""; position: absolute; border: 1px solid rgb(255 255 255 / 13%); border-radius: 50%; }
.login-brand::before { width: 540px; height: 540px; top: -250px; right: -220px; }
.login-brand::after { width: 340px; height: 340px; bottom: -170px; left: -130px; }
.brand-copy { position: relative; z-index: 1; max-width: 610px; }
.brand-copy > img { width: min(230px, 60%); height: auto; margin-bottom: clamp(58px, 10vh, 110px); }
.eyebrow { margin: 0 0 16px; color: rgb(255 255 255 / 68%); font-size: 11px; font-weight: 800; letter-spacing: .17em; }
.eyebrow.purple { color: var(--brand-500); }
.brand-copy h1 { max-width: 580px; margin: 0; font-size: clamp(38px, 4.2vw, 68px); font-weight: 720; letter-spacing: -.045em; line-height: 1.02; }
.brand-copy > p:not(.eyebrow) { max-width: 530px; margin: 25px 0 0; color: rgb(255 255 255 / 76%); font-size: clamp(16px, 1.45vw, 20px); line-height: 1.55; }
.brand-points { display: flex; gap: 22px; margin-top: 44px; flex-wrap: wrap; }
.brand-points span { display: inline-flex; gap: 8px; align-items: center; color: rgb(255 255 255 / 80%); font-size: 13px; }
.login-panel { display: grid; min-height: 100%; padding: 38px; place-items: center; background: radial-gradient(circle at 100% 0, var(--brand-50), transparent 40%), var(--surface); }
.login-card { display: grid; width: min(100%, 430px); gap: 22px; }
.login-logo { display: none; width: 165px; margin-bottom: 25px; }
.login-card h2 { margin: 0; color: var(--ink); font-size: clamp(30px, 3vw, 42px); letter-spacing: -.035em; }
.login-intro { margin: 10px 0 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
.login-card label { display: grid; gap: 8px; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.login-card input { width: 100%; height: 51px; padding: 0 15px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--ink); }
.login-card input::placeholder { color: var(--muted-2); }
.form-error { padding: 12px 14px; border: 1px solid rgb(175 53 66 / 24%); border-radius: 10px; color: var(--red); background: var(--red-soft); font-size: 13px; line-height: 1.45; }
.form-error.compact { margin: 10px 16px 0; }
.demo-link { justify-self: center; color: var(--brand-500); font-size: 13px; font-weight: 700; text-decoration: none; }
.login-help { margin: 9px 0 0; padding-top: 22px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; text-align: center; }

/* Main shell */
.mail-app { display: grid; grid-template-rows: 64px minmax(0, 1fr); width: 100%; height: 100dvh; overflow: hidden; }
.mail-app.impersonating { grid-template-rows: 36px 64px minmax(0, 1fr); }
.impersonation-banner { position: relative; z-index: 40; display: flex; min-width: 0; gap: 12px; align-items: center; justify-content: center; padding: 0 16px; color: #fff; background: #9a5a10; font-size: 11px; }
.impersonation-banner span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.impersonation-banner a { color: #fff; font-weight: 800; }
.topbar { position: relative; z-index: 30; display: grid; grid-template-columns: 220px minmax(280px, 720px) minmax(180px, 1fr); gap: 16px; align-items: center; padding: 0 16px; color: var(--ink-soft); background: var(--canvas); }
.topbar-brand { display: flex; min-width: 0; gap: 13px; align-items: center; }
.topbar-brand img { width: 122px; height: auto; }
.topbar-brand span { height: 21px; padding: 4px 0 0 13px; border-left: 1px solid var(--border-strong); color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .13em; }
[data-theme="dark"] .topbar-brand img { filter: brightness(0) invert(1); }
.topbar .icon-button:hover { background: var(--surface-hover); }
.global-search { display: flex; height: 46px; gap: 11px; align-items: center; padding: 0 15px; border: 1px solid transparent; border-radius: 14px; background: #eaf0f7; }
[data-theme="dark"] .global-search { background: var(--surface-2); }
.global-search:focus-within { border-color: var(--border-strong); background: var(--surface); box-shadow: var(--shadow-sm); }
.global-search input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 14px; }
.global-search input::placeholder { color: var(--muted); }
.global-search button { display: grid; width: 28px; height: 28px; padding: 0; place-items: center; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; }
.global-search button .icon { width: 16px; }
.top-actions { display: flex; justify-content: flex-end; align-items: center; gap: 2px; }
.top-actions .icon { width: 19px; }
.logout-form { margin: 0; }
.account-avatar { display: grid; width: 38px; height: 38px; margin-left: 8px; place-items: center; border: 3px solid var(--surface); border-radius: 50%; color: #fff; background: var(--brand-500); box-shadow: var(--shadow-sm); font-size: 12px; font-weight: 800; }
.workspace { position: relative; display: grid; grid-template-columns: 236px minmax(340px, 390px) minmax(0, 1fr); min-height: 0; padding: 0 8px 8px 0; overflow: hidden; background: var(--canvas); }

/* Sidebar */
.sidebar { position: relative; z-index: 15; display: flex; min-height: 0; padding: 12px 10px 10px 0; flex-direction: column; background: var(--canvas); }
.compose-button { display: flex; width: 166px; min-height: 50px; gap: 11px; align-items: center; justify-content: flex-start; padding: 0 20px; border: 0; border-radius: 0 16px 16px 0; color: var(--brand-600); background: var(--brand-100); box-shadow: var(--shadow-sm); font-size: 13px; font-weight: 750; cursor: pointer; }
.compose-button:hover { background: var(--brand-50); box-shadow: 0 3px 10px rgb(60 64 67 / 18%); }
.compose-button .icon { width: 19px; }
.current-account { display: none; min-width: 0; gap: 10px; align-items: center; margin-top: 13px; padding: 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow-sm); }
.current-account > .icon { width: 18px; color: var(--brand-500); }
.current-account div { display: grid; min-width: 0; gap: 3px; }
.current-account strong { font-size: 11px; }
.current-account span { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-heading { display: flex; margin: 18px 12px 8px; align-items: center; justify-content: space-between; color: var(--muted-2); font-size: 9px; font-weight: 800; letter-spacing: .14em; }
.sidebar-heading button { padding: 3px 0; border: 0; color: var(--brand-500); background: transparent; font-size: 9px; font-weight: 800; letter-spacing: 0; cursor: pointer; }
.folders { display: grid; min-height: 0; padding-right: 2px; gap: 3px; align-content: start; flex: 1 1 auto; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-color: var(--border-strong) transparent; scrollbar-width: thin; }
.folders::-webkit-scrollbar { width: 6px; }
.folders::-webkit-scrollbar-thumb { border-radius: 6px; background: var(--border-strong); }
.folders::-webkit-scrollbar-track { background: transparent; }
.folders button, .sidebar-bottom button { display: flex; width: 100%; min-height: 36px; gap: 12px; align-items: center; padding: 0 14px 0 18px; border: 0; border-radius: 0 18px 18px 0; color: var(--ink-soft); background: transparent; font-size: 13px; text-align: left; cursor: pointer; }
.folders button:hover, .sidebar-bottom button:hover { background: var(--surface-hover); }
.folders button.active { color: var(--brand-500); background: var(--surface-selected); font-weight: 750; }
.folders button .icon, .sidebar-bottom button .icon { width: 17px; }
.folders button span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folders button b { display: grid; min-width: 20px; height: 20px; padding: 0 5px; place-items: center; border-radius: 10px; color: var(--brand-500); background: var(--brand-100); font-size: 9px; }
.folders button[data-depth="1"] { padding-left: 27px; }
.folders button[data-depth="2"] { padding-left: 42px; }
.folders button[data-depth="3"] { padding-left: 57px; }
.sidebar-bottom { display: grid; flex: 0 0 auto; gap: 3px; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.drawer-backdrop { display: none; }

/* List */
.message-column { display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) 48px; min-width: 0; min-height: 0; overflow: hidden; border-right: 1px solid var(--border); border-radius: 16px 0 0 16px; background: var(--surface); }
.message-column-header { display: flex; min-height: 68px; align-items: center; justify-content: space-between; padding: 12px 16px 7px; }
.message-column-header p { margin: 0 0 2px; color: var(--muted); font-size: 11px; }
.message-column-header h1 { margin: 0; font-size: 20px; letter-spacing: -.025em; }
.filter-row { display: flex; min-height: 44px; gap: 6px; align-items: center; padding: 0 13px 9px; border-bottom: 1px solid var(--border); }
.filter-row button { min-height: 29px; padding: 0 10px; border: 1px solid transparent; border-radius: 8px; color: var(--muted); background: var(--surface-hover); font-size: 10px; font-weight: 700; cursor: pointer; }
.filter-row button.active { border-color: var(--brand-100); color: var(--brand-500); background: var(--brand-50); }
.filter-row > span { display: flex; gap: 3px; align-items: center; margin-left: auto; color: var(--muted); font-size: 9px; white-space: nowrap; }
.filter-row > span .icon { width: 12px; }
.bulk-toolbar { display: flex; min-height: 36px; gap: 8px; align-items: center; padding: 4px 13px; border-bottom: 1px solid var(--border); color: var(--muted); background: var(--surface-2); font-size: 9px; }
.bulk-toolbar label { display: flex; gap: 6px; align-items: center; white-space: nowrap; cursor: pointer; }
.bulk-toolbar input, .message-check { accent-color: var(--brand-500); }
.bulk-toolbar > div { display: flex; min-width: 0; gap: 3px; overflow-x: auto; }
.bulk-toolbar button { min-height: 26px; padding: 0 7px; border: 1px solid var(--border); border-radius: 7px; color: var(--ink-soft); background: var(--surface); font-size: 9px; cursor: pointer; white-space: nowrap; }
.message-list { min-height: 0; overflow-x: hidden; overflow-y: auto; }
.message-row { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr) 24px; min-height: 76px; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.message-check { width: 15px; height: 15px; margin: 0; }
.message-row:hover { background: var(--surface-hover); }
.message-row.selected { background: var(--surface-selected); }
.message-row.selected::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--brand-500); }
.sender-avatar { position: relative; display: none; width: 35px; height: 35px; place-items: center; border-radius: 50%; color: var(--brand-600); background: var(--brand-100); font-size: 10px; font-weight: 800; }
.message-row.unread .sender-avatar::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 7px; height: 7px; border: 2px solid var(--surface); border-radius: 50%; background: var(--brand-500); }
.message-summary { min-width: 0; }
.message-line { display: flex; min-width: 0; gap: 8px; align-items: center; }
.message-line strong { min-width: 0; flex: 1; overflow: hidden; color: var(--ink-soft); font-size: 13px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.message-line time { color: var(--muted-2); font-size: 10px; white-space: nowrap; }
.message-row.unread .message-line strong, .message-row.unread .message-subject { color: var(--ink); font-weight: 700; }
.message-row.unread .message-line time { color: var(--ink); font-weight: 700; }
.message-subject { margin-top: 3px; overflow: hidden; color: var(--ink-soft); font-size: 13px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.message-summary p { margin: 3px 0 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.row-indicators { display: grid; gap: 8px; justify-items: center; color: var(--muted-2); }
.row-indicators button { width: 22px; height: 22px; padding: 0; border: 0; color: var(--muted-2); background: transparent; cursor: pointer; }
.row-indicators .icon { width: 15px; }
.row-indicators button.starred, #readerStar.starred { color: #d38b13; }
.list-pagination { display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 10px; }
.list-pagination div { display: flex; gap: 5px; }
.list-pagination button { display: grid; width: 30px; height: 30px; padding: 0; place-items: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.list-pagination button:disabled { opacity: .35; cursor: default; }
.list-pagination .icon { width: 15px; }
.message-list.loading { opacity: .55; pointer-events: none; }
.list-empty, .reader-empty { display: flex; height: 100%; min-height: 250px; padding: 30px; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.list-empty .icon { width: 35px; height: 35px; margin-bottom: 13px; color: var(--brand-400); }
.list-empty strong { color: var(--ink); }
.list-empty span { margin-top: 5px; font-size: 12px; }

/* Reader */
.reader { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; overflow: hidden; border-radius: 0 16px 16px 0; background: var(--surface); }
.reader.empty { grid-template-rows: 1fr; }
.reader-toolbar { position: relative; display: flex; min-height: 54px; gap: 3px; align-items: center; padding: 0 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.reader-toolbar > button { display: inline-flex; width: 38px; height: 38px; gap: 6px; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: transparent; font-size: 11px; cursor: pointer; }
.reader-toolbar > button > span { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.reader-toolbar > button:hover { color: var(--brand-500); background: var(--surface-hover); }
.reader-toolbar .icon { width: 18px; }
.reader-toolbar i { min-width: 8px; flex: 1; }
.reader-more-menu { position: absolute; z-index: 20; top: 47px; right: 12px; display: grid; width: 210px; padding: 7px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-lg); }
.reader-more-menu button, .reader-more-menu a { display: flex; min-height: 34px; align-items: center; padding: 0 10px; border: 0; border-radius: 7px; color: var(--ink-soft); background: transparent; font-size: 10px; text-align: left; text-decoration: none; cursor: pointer; }
.reader-more-menu button:hover, .reader-more-menu a:hover { color: var(--brand-500); background: var(--surface-hover); }
.reader-back { display: none !important; }
.reader-empty .empty-envelope { display: grid; width: 82px; height: 70px; margin-bottom: 18px; place-items: center; border-radius: 20px; color: var(--brand-400); background: var(--brand-50); }
.reader-empty .empty-envelope .icon { width: 40px; height: 40px; }
.reader-empty h2 { margin: 0; color: var(--ink); font-size: 16px; }
.reader-empty p { margin: 8px 0 0; font-size: 11px; }
.reader-content { min-height: 0; padding: clamp(22px, 3vw, 36px) clamp(24px, 4vw, 56px) 48px; overflow-y: auto; scrollbar-gutter: stable; }
.reader-content > * { width: min(100%, 900px); margin-inline: auto; }
.reader-content.loading { opacity: .48; pointer-events: none; }
.reader-title { display: flex; gap: 16px; align-items: flex-start; }
.reader-title h2 { min-width: 0; flex: 1; margin: 0; font-size: clamp(21px, 2vw, 26px); font-weight: 650; letter-spacing: -.025em; line-height: 1.28; }
.reader-title button { width: 38px; height: 38px; padding: 8px; border: 0; color: var(--muted); background: transparent; cursor: pointer; }
.sender-card { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center; margin-top: 24px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.sender-card .sender-avatar.large { display: grid; width: 40px; height: 40px; border-radius: 50%; }
.sender-card > div { display: grid; min-width: 0; gap: 2px; }
.sender-card strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.sender-card span, .sender-card small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.sender-card time { align-self: start; color: var(--muted); font-size: 11px; white-space: nowrap; }
.thread-list { display: flex; gap: 6px; padding: 12px 0; overflow-x: auto; border-bottom: 1px solid var(--border); }
.thread-list button { min-width: 150px; max-width: 220px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; color: var(--ink-soft); background: var(--surface-2); font-size: 9px; text-align: left; cursor: pointer; }
.thread-list button.active { border-color: var(--brand-300); background: var(--brand-50); }
.thread-list button strong, .thread-list button span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-list button span { margin-top: 3px; color: var(--muted); }
.message-body { min-height: 0; padding: 26px 0 24px; color: var(--ink-soft); font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.plain-message { margin: 0; white-space: pre-wrap; font: inherit; }
.mail-body-part + .mail-body-part, .html-message-part + .html-message-part, .mail-body-part + .html-message-part, .html-message-part + .mail-body-part { margin-top: 16px; }
.html-message-part { min-width: 0; }
.html-message { display: block; width: 100%; height: 1px; min-height: 0; overflow: auto; border: 0; background: #fff; color-scheme: light; vertical-align: top; }
.html-message.height-clamped { overflow: auto; }
.message-expand { display: block; min-height: 34px; margin: 10px auto 0; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 8px; color: var(--brand-500); background: var(--surface); font-size: 10px; font-weight: 700; cursor: pointer; }
.message-expand:hover { border-color: var(--brand-300); background: var(--brand-50); }
.inline-message-image { display: block; max-width: 100%; height: auto; margin: 0 auto 16px; }
.mail-unsupported-part { margin: 0 0 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); background: var(--surface-2); font-size: 11px; }
.message-body-warning { margin: 0 0 14px; padding: 10px 12px; border: 1px solid rgb(184 120 22 / 28%); border-radius: 9px; color: #805714; background: #fff8e8; font-size: 11px; line-height: 1.45; }
.attachments { padding: 18px 0; border-top: 1px solid var(--border); }
.attachments h3 { display: flex; gap: 7px; align-items: center; margin: 0 0 12px; font-size: 13px; }
.attachments h3 .icon { width: 16px; color: var(--brand-500); }
.attachment-list { display: flex; gap: 9px; flex-wrap: wrap; }
.attachment-card { display: grid; grid-template-columns: 30px minmax(90px, 1fr) 22px; min-width: 210px; gap: 9px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); background: var(--surface-2); text-decoration: none; }
.attachment-card:hover { border-color: var(--brand-300); }
.attachment-card > .icon { color: var(--brand-500); }
.attachment-card span { display: grid; min-width: 0; }
.attachment-card strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.attachment-card small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.attachment-card .download-icon { width: 15px; color: var(--muted); }
.reader-replies { display: flex; gap: 8px; padding-top: 24px; border-top: 1px solid var(--border); }
.reader-replies button { display: inline-flex; height: 38px; gap: 7px; align-items: center; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 9px; color: var(--ink-soft); background: var(--surface); font-size: 11px; font-weight: 650; cursor: pointer; }
.reader-replies button:hover { border-color: var(--brand-300); color: var(--brand-500); }
.reader-replies .icon { width: 16px; }

/* Composer and panels */
.compose-layer { position: fixed; z-index: 80; inset: 0; display: flex; padding: 0 20px 12px; align-items: flex-end; justify-content: flex-end; background: transparent; pointer-events: none; }
.compose-window { display: flex; width: min(650px, calc(100vw - 40px)); height: min(690px, calc(100dvh - 82px)); overflow: hidden; flex-direction: column; border: 1px solid var(--border); border-radius: 12px 12px 0 0; background: var(--surface); box-shadow: 0 12px 42px rgb(32 33 36 / 30%); pointer-events: auto; }
.compose-window > header { display: flex; min-height: 42px; align-items: center; justify-content: space-between; padding: 0 10px 0 16px; color: #fff; background: #48315f; }
.compose-window > header h2 { margin: 0; font-size: 14px; }
.compose-window > header button { display: grid; width: 34px; height: 34px; padding: 0; place-items: center; border: 0; border-radius: 8px; color: #fff; background: transparent; cursor: pointer; }
.compose-window > header button:hover { background: rgb(255 255 255 / 12%); }
.compose-window > header .icon { width: 18px; }
.compose-field { display: grid; grid-template-columns: 58px minmax(0, 1fr); min-height: 44px; align-items: center; border-bottom: 1px solid var(--border); }
.compose-field label { padding-left: 16px; color: var(--muted); font-size: 10px; font-weight: 700; }
.compose-field input { width: 100%; height: 43px; padding: 0 15px 0 0; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 12px; }
.compose-field select { width: calc(100% - 12px); height: 34px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; color: var(--ink); background: var(--surface); font-size: 11px; }
.compose-field.small-labels { grid-template-columns: 38px minmax(0, 1fr) 38px minmax(0, 1fr); }
.editor-toolbar { display: flex; min-height: 37px; gap: 3px; align-items: center; padding: 4px 12px; overflow-x: auto; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.editor-toolbar button { min-width: 29px; height: 28px; padding: 0 8px; border: 1px solid transparent; border-radius: 7px; color: var(--ink-soft); background: transparent; font-size: 10px; cursor: pointer; }
.editor-toolbar button:hover { border-color: var(--border); background: var(--surface); }
.compose-editor { min-height: 180px; padding: 18px; flex: 1 1 auto; overflow-y: auto; outline: 0; color: var(--ink); background: var(--surface); font-size: 13px; line-height: 1.6; }
.compose-editor:empty::before { content: attr(data-placeholder); color: var(--muted-2); pointer-events: none; }
.compose-files { display: flex; max-height: 76px; gap: 6px; padding: 8px 15px; overflow: auto; flex-wrap: wrap; border-top: 1px solid var(--border); }
.compose-files:empty { display: none; }
.compose-file-chip { display: inline-flex; min-width: 0; height: 34px; gap: 6px; align-items: center; padding: 0 4px 0 8px; border: 1px solid color-mix(in srgb, var(--brand-400) 28%, var(--border)); border-radius: 9px; color: var(--brand-500); background: var(--brand-50); }
.compose-file-chip .icon { width: 14px; flex: 0 0 auto; }
.compose-file-copy { display: grid; min-width: 0; line-height: 1.05; }
.compose-file-copy strong { max-width: 150px; overflow: hidden; color: var(--ink-soft); font-size: 9px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.compose-file-copy small { margin-top: 2px; color: var(--muted); font-size: 8px; }
.compose-file-remove { display: grid; width: 25px; height: 25px; padding: 0; place-items: center; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-size: 17px; line-height: 1; cursor: pointer; }
.compose-file-remove:hover { color: var(--danger); background: var(--surface-hover); }
.compose-files-summary { display: inline-flex; align-items: center; padding: 0 4px; color: var(--muted); font-size: 9px; white-space: nowrap; }
.compose-window > footer { display: flex; min-height: 58px; gap: 7px; align-items: center; padding: 8px 13px; border-top: 1px solid var(--border); background: var(--surface-2); }
.compose-window > footer .primary { min-height: 39px; }
.compose-window > footer .icon { width: 16px; }
.compose-window > footer > button:not(.primary) { min-height: 38px; padding: 0 11px; border: 1px solid var(--border); border-radius: 9px; color: var(--ink-soft); background: var(--surface); font-size: 10px; font-weight: 700; cursor: pointer; }
.attach-button { display: inline-flex; height: 38px; gap: 7px; align-items: center; padding: 0 11px; border-radius: 9px; color: var(--muted); font-size: 10px; font-weight: 700; cursor: pointer; }
.attach-button:hover { color: var(--brand-500); background: var(--brand-50); }
.attach-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.draft-note { margin-left: auto; color: var(--muted-2); font-size: 9px; }
.secondary-panel { position: fixed; z-index: 75; inset: 64px 0 0 236px; overflow-y: auto; background: var(--canvas); }
.impersonating .secondary-panel { top: 100px; }
.secondary-panel > header { display: flex; height: 70px; gap: 10px; align-items: center; padding: 0 clamp(20px, 4vw, 54px); border-bottom: 1px solid var(--border); background: var(--surface); }
.secondary-panel h1 { margin: 0; font-size: 23px; }
.secondary-content { width: min(760px, calc(100% - 40px)); margin: 36px auto; }
.secondary-empty { display: flex; min-height: 440px; padding: 50px; flex-direction: column; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); text-align: center; }
.secondary-empty > .icon { width: 44px; height: 44px; color: var(--brand-400); }
.secondary-empty h2 { margin: 20px 0 7px; }
.secondary-empty p { max-width: 470px; margin: 0 0 24px; color: var(--muted); line-height: 1.55; }
.settings-list { display: grid; gap: 10px; }
.settings-row { display: flex; min-height: 74px; gap: 16px; align-items: center; padding: 14px 18px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
.settings-row > .icon { color: var(--brand-500); }
.settings-row span { display: grid; gap: 4px; flex: 1; font-size: 12px; font-weight: 700; }
.settings-row small { color: var(--muted); font-weight: 400; }
.settings-row button { min-height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.panel-toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-toolbar input { width: min(390px, 100%); height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 9px; color: var(--ink); background: var(--surface); }
.card-list, .settings-sections, .filter-rules { display: grid; gap: 10px; }
.data-card, .panel-card, .rule-card { display: flex; gap: 14px; align-items: center; padding: 15px 17px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.data-card > span, .panel-card > span { display: grid; min-width: 0; gap: 4px; flex: 1; }
.data-card strong, .panel-card strong { overflow: hidden; text-overflow: ellipsis; }
.data-card small, .panel-card small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; }
.card-actions { display: flex; gap: 5px; }
.card-actions button, .panel-button { min-height: 34px; padding: 0 11px; border: 1px solid var(--border); border-radius: 8px; color: var(--ink-soft); background: var(--surface); font-size: 10px; cursor: pointer; }
.panel-form { display: grid; gap: 13px; padding: 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.panel-form h2 { margin: 0 0 5px; }
.panel-form label { display: grid; gap: 6px; color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.panel-form input, .panel-form textarea, .panel-form select { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 8px; color: var(--ink); background: var(--surface); font-size: 11px; }
.panel-form textarea { min-height: 110px; resize: vertical; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.rule-card { display: grid; grid-template-columns: 1fr 1fr 1.4fr 1fr 1.2fr auto; padding: 10px; }
.rule-card select, .rule-card input { width: 100%; min-height: 35px; padding: 0 8px; border: 1px solid var(--border); border-radius: 7px; color: var(--ink); background: var(--surface); font-size: 10px; }
.quota-meter { height: 8px; overflow: hidden; border-radius: 4px; background: var(--border); }
.quota-meter i { display: block; height: 100%; background: var(--brand-500); }
.mobile-compose, .mobile-tabs { display: none; }
.toast { position: fixed; z-index: 110; right: 22px; bottom: 22px; max-width: min(380px, calc(100% - 40px)); padding: 13px 16px; border: 1px solid rgb(255 255 255 / 14%); border-radius: 11px; color: #fff; background: #2d1d38; box-shadow: var(--shadow-lg); font-size: 12px; }
.global-error { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: flex; max-width: 470px; gap: 10px; align-items: center; padding: 12px; border: 1px solid rgb(175 53 66 / 25%); border-radius: 11px; color: var(--red); background: var(--red-soft); box-shadow: var(--shadow-lg); font-size: 11px; }
.global-error span { flex: 1; }
.global-error button { border: 0; color: var(--red); background: transparent; font-weight: 700; cursor: pointer; }
.error-page { display: flex; min-height: 100dvh; padding: 30px; flex-direction: column; align-items: center; justify-content: center; background: var(--surface); text-align: center; }
.error-page img { width: 180px; margin-bottom: 45px; }
.error-page h1 { margin: 0; }
.error-page p { margin: 12px 0 25px; color: var(--muted); }

@media print {
  body { overflow: visible; background: #fff; }
  .topbar, .sidebar, .message-column, .reader-toolbar, .reader-empty, .reader-replies, .mobile-tabs, .mobile-compose, .impersonation-banner { display: none !important; }
  .mail-app, .workspace, .reader { display: block; height: auto; overflow: visible; }
  .reader-content { display: block !important; padding: 0; overflow: visible; color: #000; }
  .html-message { overflow: visible; }
}

@media (max-width: 1040px) {
  .workspace { grid-template-columns: 72px minmax(320px, 365px) minmax(0, 1fr); }
  .sidebar { padding-right: 8px; }
  .compose-button { width: 52px; min-height: 50px; justify-content: center; padding: 0; border-radius: 0 16px 16px 0; font-size: 0; }
  .compose-button .icon { width: 20px; }
  .sidebar-heading { display: none; }
  .folders { margin-top: 15px; }
  .folders button { min-height: 42px; justify-content: center; padding: 0; font-size: 0; }
  .folders button .icon { width: 19px; }
  .folders button span, .folders button b { display: none; }
  .sidebar-bottom { display: none; }
  .reader-toolbar button span { display: none; }
  .secondary-panel { left: 72px; }
}

@media (max-width: 799px) {
  body { overflow: hidden; }
  .desktop-only { display: none !important; }
  .mobile-only { display: grid; }
  .mail-app { grid-template-rows: 58px minmax(0, 1fr) 58px; }
  .mail-app.impersonating { grid-template-rows: 34px 58px minmax(0, 1fr) 58px; }
  .impersonation-banner { gap: 6px; justify-content: flex-start; padding: 0 10px; font-size: 9px; }
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 0 10px; }
  .topbar-brand { gap: 6px; }
  .topbar-brand img { width: 112px; }
  .topbar-brand span { display: none; }
  .topbar-brand .icon-button { color: var(--ink-soft); }
  .global-search { display: none; }
  .top-actions .icon-button:first-child { display: none; }
  .account-avatar { width: 34px; height: 34px; }
  .workspace { display: block; min-height: 0; }
  .sidebar { position: fixed; z-index: 70; inset: 58px auto 0 0; width: min(300px, 86vw); padding-bottom: 78px; transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
  .sidebar .compose-button { width: 166px; justify-content: flex-start; padding: 0 20px; font-size: 13px; }
  .sidebar .sidebar-heading { display: flex; }
  .sidebar .folders { margin-top: 0; }
  .sidebar .folders button { min-height: 38px; justify-content: flex-start; padding: 0 14px 0 18px; font-size: 13px; }
  .sidebar .folders button span { display: block; }
  .sidebar .folders button b { display: grid; }
  .sidebar .sidebar-bottom { display: grid; }
  .impersonating .sidebar { top: 92px; }
  .sidebar.open { transform: translateX(0); }
  .drawer-backdrop { position: fixed; z-index: 65; inset: 58px 0 0; display: block; border: 0; background: rgb(14 9 18 / 48%); opacity: 0; visibility: hidden; transition: opacity .2s; }
  .impersonating .drawer-backdrop { top: 92px; }
  .drawer-backdrop.visible { opacity: 1; visibility: visible; }
  .message-column { width: 100%; height: 100%; border: 0; }
  .message-column-header { min-height: 67px; }
  .message-column-header h1 { font-size: 19px; }
  .filter-row { min-height: 42px; }
  .message-row { grid-template-columns: 18px 36px minmax(0, 1fr) 24px; min-height: 82px; }
  .message-row .sender-avatar { display: grid; }
  .reader { position: fixed; z-index: 45; inset: 58px 0 58px; display: grid; transform: translateX(102%); transition: transform .22s ease; }
  .impersonating .reader { inset: 92px 0 58px; }
  .mobile-reader-open .reader { transform: translateX(0); }
  .reader-toolbar { min-height: 45px; padding: 0 6px; }
  .reader-toolbar .reader-back { display: inline-flex !important; }
  .reader-content { padding: 21px 18px 40px; }
  .reader-title h2 { font-size: 21px; }
  .sender-card { grid-template-columns: 40px minmax(0, 1fr); }
  .sender-card time { grid-column: 2; }
  .mobile-compose { position: fixed; z-index: 42; right: 17px; bottom: 72px; display: grid; width: 50px; height: 50px; padding: 0; place-items: center; border: 0; border-radius: 16px; color: #fff; background: linear-gradient(135deg, #7547a6, #4c286e); box-shadow: 0 12px 30px rgb(60 32 92 / 35%); }
  .mobile-compose .icon { width: 22px; }
  .mobile-tabs { position: relative; z-index: 50; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--border); background: var(--surface); }
  .mobile-tabs button { display: flex; gap: 3px; align-items: center; justify-content: center; flex-direction: column; border: 0; color: var(--muted); background: transparent; font-size: 8px; }
  .mobile-tabs button.active { color: var(--brand-500); }
  .mobile-tabs .icon { width: 18px; height: 18px; }
  .compose-layer { padding: 0; align-items: stretch; background: var(--surface); pointer-events: auto; }
  .compose-window { width: 100%; height: 100dvh; border: 0; border-radius: 0; box-shadow: none; }
  .compose-window > header { min-height: 58px; }
  .compose-editor { min-height: 180px; }
  .draft-note { display: none; }
  .secondary-panel { z-index: 60; inset: 58px 0 58px; }
  .impersonating .secondary-panel { inset: 92px 0 58px; }
  .secondary-panel > header { height: 62px; padding: 0 13px; }
  .secondary-content { margin-top: 18px; }
  .secondary-empty { min-height: 360px; padding: 28px; }
  .toast { right: 14px; bottom: 72px; }
}

@media (max-width: 560px) {
  .bulk-toolbar { padding-inline: 8px; }
  .rule-card { grid-template-columns: 1fr 1fr; }
  .panel-toolbar { align-items: stretch; flex-direction: column; }
  .data-card { align-items: flex-start; }
  .card-actions { flex-direction: column; }
}

@media (max-width: 680px) {
  .login-page { display: block; min-height: 100dvh; background: var(--surface); }
  .login-brand { display: none; }
  .login-panel { min-height: 100dvh; padding: 28px 22px; }
  .login-logo { display: block; }
  .login-card { gap: 19px; }
  .login-card h2 { font-size: 31px; }
}

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