/* ByteMail - application styles. Flat design (no gradients), light/dark themes. */

:root {
  --brand: #1f71b8;
  --brand-strong: #185c97;
  --brand-weak: #e8f1fa;
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface-2: #eef1f5;
  --sidebar: #f3f5f8;
  --border: #e0e4ea;
  --border-strong: #c9d0d9;
  --text: #1d2430;
  --text-2: #3b4655;
  --muted: #627082;
  --row-hover: #f2f6fb;
  --row-selected: #dfeaf7;
  --row-unread-bar: var(--brand);
  --danger: #c0392b;
  --danger-weak: #fdecea;
  --warning: #9a5b00;
  --warning-weak: #fff4e0;
  --success: #1b7f4a;
  --success-weak: #e6f4ec;
  --focus: #1f71b8;
  --shadow: 0 6px 24px rgba(16, 24, 40, .14), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 8px;
  --radius-sm: 5px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --topbar-h: 52px;
  --sidebar-w: 248px;
  --list-w: 400px;
  --row-h: 76px;
  color-scheme: light;
}

[data-theme="dark"] {
  --brand: #4c9be0;
  --brand-strong: #6aaeea;
  --brand-weak: #1b2f44;
  --bg: #16191e;
  --surface: #1d2128;
  --surface-2: #242932;
  --sidebar: #1a1e24;
  --border: #2d333c;
  --border-strong: #3c444f;
  --text: #e5e9ef;
  --text-2: #c7ced8;
  --muted: #98a3b2;
  --row-hover: #20262e;
  --row-selected: #1f3348;
  --danger: #ef6b5e;
  --danger-weak: #3a1f1d;
  --warning: #e3a443;
  --warning-weak: #362a16;
  --success: #4cc28a;
  --success-weak: #17301f;
  --focus: #6aaeea;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

[data-density="compact"] { --row-h: 54px; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 40px; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---------- boot ---------- */
.boot { height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.boot-logo { width: 72px; height: auto; }
.boot-name { font-size: 22px; font-weight: 600; letter-spacing: .2px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
  cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-weak); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--radius-sm); background: transparent; cursor: pointer; color: var(--text-2); flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.active { color: var(--brand); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.fill { fill: currentColor; stroke: none; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .error { font-size: 12px; color: var(--danger); }
.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg); color: var(--text);
}
textarea.input { height: auto; min-height: 90px; padding: 8px 10px; resize: vertical; }
.input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-weak); }
.input.invalid { border-color: var(--danger); }
.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--brand); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }

.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.brand { background: var(--brand-weak); color: var(--brand); }
.badge.danger { background: var(--danger-weak); color: var(--danger); }
.badge.warning { background: var(--warning-weak); color: var(--warning); }
.badge.success { background: var(--success-weak); color: var(--success); }
.count { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--brand); }
.count.muted { color: var(--muted); font-weight: 500; }

.notice { padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); display: flex; gap: 10px; align-items: flex-start; }
.notice.warning { background: var(--warning-weak); border-color: transparent; color: var(--text); }
.notice.danger { background: var(--danger-weak); border-color: transparent; }
.notice.info { background: var(--brand-weak); border-color: transparent; }
.notice.success { background: var(--success-weak); border-color: transparent; }
.notice .icon { margin-top: 2px; }
.notice { flex-wrap: wrap; }
.notice > .grow { flex: 1 1 220px; }

/* ---------- app layout ---------- */
.app { display: grid; grid-template-rows: var(--topbar-h) 1fr; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--bg); min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 650; font-size: 16px; width: calc(var(--sidebar-w) - 56px); min-width: 0; }
.brand img { height: 26px; width: auto; }
.search { flex: 1; max-width: 640px; position: relative; }
.search .input { padding-left: 34px; height: 36px; background: var(--surface); border-color: transparent; }
.search .input:focus { background: var(--bg); border-color: var(--brand); }
.search > .icon { position: absolute; left: 10px; top: 9px; color: var(--muted); pointer-events: none; }
.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.net-pill { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 13px; font-size: 12px; font-weight: 600; background: var(--warning-weak); color: var(--warning); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; color: #fff; background: var(--brand); flex: none; overflow: hidden; border: 0; cursor: pointer; padding: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.bell { position: relative; }
.bell .dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.main { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 0; }
.app.sidebar-collapsed .main { grid-template-columns: 56px minmax(0, 1fr); }

/* ---------- sidebar ---------- */
.sidebar { background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.sidebar-top { padding: 12px; display: flex; gap: 6px; }
.compose-btn { flex: 1; height: 40px; font-size: 14.5px; }
.nav { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.nav-section { margin-top: 10px; }
.nav-heading { display: flex; align-items: center; gap: 6px; padding: 6px 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); cursor: pointer; user-select: none; border-radius: var(--radius-sm); }
.nav-heading:hover { background: var(--surface-2); }
.nav-heading .acct-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.nav-heading .chev { transition: transform .15s; width: 14px; height: 14px; }
.nav-section.collapsed .chev { transform: rotate(-90deg); }
.nav-section.collapsed .nav-items { display: none; }
.nav-item {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-2); text-decoration: none; user-select: none; position: relative; border: 0; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--row-selected); color: var(--text); font-weight: 600; }
.nav-item.drop-target { outline: 2px dashed var(--brand); }
.nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: inherit; font-weight: inherit; color: inherit; }
.nav-item .warn { color: var(--danger); }
.sidebar-footer { border-top: 1px solid var(--border); padding: 10px 12px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.sync-line { display: flex; align-items: center; gap: 6px; }
.meter { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--brand); }
.app.sidebar-collapsed .sidebar .label, .app.sidebar-collapsed .sidebar .count, .app.sidebar-collapsed .nav-heading, .app.sidebar-collapsed .sidebar-footer, .app.sidebar-collapsed .compose-btn span { display: none; }
.app.sidebar-collapsed .compose-btn { padding: 0; }

/* ---------- mail view ---------- */
.mail { display: grid; grid-template-columns: var(--list-w) 6px minmax(0, 1fr); min-height: 0; flex: 1; }
.mail.pane-bottom { grid-template-columns: 1fr; grid-template-rows: minmax(160px, 45%) 6px minmax(0, 1fr); }
.mail.pane-off { grid-template-columns: 1fr; }
.mail.pane-off .reader, .mail.pane-off .splitter { display: none; }
.mail.pane-off.reading .list-pane, .mail.pane-off.reading .splitter { display: none; }
.mail.pane-off.reading .reader { display: flex; }
.splitter { cursor: col-resize; background: transparent; border-left: 1px solid var(--border); }
.mail.pane-bottom .splitter { cursor: row-resize; border-left: 0; border-top: 1px solid var(--border); }
.splitter:hover { background: var(--brand-weak); }

.list-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.list-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 8px 14px; border-bottom: 1px solid var(--border); min-height: 52px; }
.list-title { font-size: 17px; font-weight: 650; display: flex; align-items: center; gap: 8px; min-width: 0; }
.list-filters { display: flex; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.chip { height: 26px; padding: 0 10px; border-radius: 13px; border: 1px solid var(--border-strong); background: var(--bg); cursor: pointer; font-size: 12.5px; white-space: nowrap; }
.chip.on { background: var(--brand-weak); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.bulkbar { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: var(--brand-weak); }
.list-scroll { flex: 1; overflow-y: auto; position: relative; contain: strict; }
.list-spacer { position: relative; }
.msg-row {
  position: absolute; left: 0; right: 0; height: var(--row-h); display: grid; grid-template-columns: 28px 1fr auto;
  gap: 0 8px; padding: 9px 10px 9px 6px; border-bottom: 1px solid var(--border); cursor: pointer; background: var(--bg); user-select: none;
}
.msg-row:hover { background: var(--row-hover); }
.msg-row.selected { background: var(--row-selected); }
.msg-row.focused { box-shadow: inset 0 0 0 1px var(--brand); }
.msg-row.unread::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--row-unread-bar); }
.msg-row .sel { display: flex; align-items: flex-start; justify-content: center; padding-top: 2px; }
.msg-row .sel input { accent-color: var(--brand); width: 15px; height: 15px; margin: 0; cursor: pointer; }
.msg-row .body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.msg-row .line1 { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.msg-row .from { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.msg-row.unread .from, .msg-row.unread .subject { font-weight: 650; }
.msg-row .thread-n { font-size: 11.5px; color: var(--muted); border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 5px; flex: none; }
.msg-row .subject { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.msg-row.unread .subject { color: var(--brand); }
.msg-row .preview { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg-row .meta .icons { display: flex; gap: 2px; align-items: center; }
.msg-row .meta .icon { width: 15px; height: 15px; }
.msg-row .star.on { color: #d4a017; }
.msg-row .imp { color: var(--danger); font-weight: 800; }
.msg-row .acct-tag { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.msg-row .offline-dot { color: var(--success); }
[data-density="compact"] .msg-row .preview { display: none; }
.list-empty { padding: 50px 24px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.list-empty .icon { width: 40px; height: 40px; stroke-width: 1.2; }
.list-footer { padding: 8px 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }

/* ---------- reader ---------- */
.reader { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.reader-toolbar { display: flex; align-items: center; gap: 2px; padding: 8px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; min-height: 52px; }
.reader-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.reader-toolbar .btn { height: 32px; padding: 0 10px; }
.reader-scroll { flex: 1; overflow-y: auto; padding: 18px 24px 40px; }
.reader-subject { font-size: 21px; font-weight: 600; margin: 0 0 14px; word-break: break-word; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.msg-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; background: var(--bg); }
.msg-card.collapsed .msg-content { display: none; }
.msg-head { display: flex; gap: 12px; padding: 12px 14px; align-items: flex-start; cursor: default; }
.msg-card.collapsed .msg-head { cursor: pointer; }
.msg-head .who { min-width: 0; flex: 1; }
.msg-head .who .name { font-weight: 600; }
.msg-head .who .addr { color: var(--muted); font-size: 13px; }
.msg-head .rcpts { font-size: 12.5px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.msg-head .when { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.msg-content { padding: 0 14px 14px; }
.msg-banner { margin: 0 0 10px; }
.mail-frame { width: 100%; border: 0; display: block; min-height: 80px; background: #fff; border-radius: 4px; }
[data-theme="dark"] .mail-frame { background: #fff; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.att { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; min-width: 200px; max-width: 280px; background: var(--surface); }
.att .ext { width: 34px; height: 34px; border-radius: 4px; background: var(--brand-weak); color: var(--brand); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; text-transform: uppercase; flex: none; }
.att .info { min-width: 0; flex: 1; }
.att .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .size { font-size: 11.5px; color: var(--muted); }
.invite { border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--surface); }
.reader-empty { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; color: var(--muted); gap: 12px; padding: 20px; text-align: center; }
.reader-empty img { width: 110px; opacity: .55; }
.not-downloaded { padding: 30px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); }

/* ---------- composer ---------- */
.composer-layer { position: fixed; inset: 0; z-index: 40; pointer-events: none; display: flex; justify-content: flex-end; align-items: flex-end; padding: 0 16px; }
.composer {
  pointer-events: auto; width: min(760px, 100%); height: min(680px, calc(100vh - 70px)); background: var(--bg);
  border: 1px solid var(--border-strong); border-bottom: 0; border-radius: 10px 10px 0 0; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0;
}
.composer.maximized { position: fixed; inset: 24px 40px; width: auto; height: auto; border-radius: 10px; border-bottom: 1px solid var(--border-strong); }
.composer.minimized { height: 44px; width: 340px; }
.composer.minimized > :not(.composer-head) { display: none; }
.composer-head { display: flex; align-items: center; gap: 4px; padding: 0 6px 0 14px; height: 44px; border-bottom: 1px solid var(--border); background: var(--surface); border-radius: 10px 10px 0 0; cursor: default; }
.composer-head .title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-fields { padding: 0 14px; }
.cf-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); min-height: 40px; }
.cf-row > .cf-label { width: 52px; color: var(--muted); font-size: 13px; flex: none; }
.cf-row select, .cf-row .bare { border: 0; background: transparent; height: 38px; flex: 1; min-width: 0; outline: none; }
.cf-row select { cursor: pointer; font-weight: 600; }
.cf-row .bare:focus, .cf-row select:focus { box-shadow: none; }
.cf-toggles { display: flex; gap: 2px; }
.cf-toggles button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12.5px; padding: 4px 6px; border-radius: 4px; }
.cf-toggles button:hover { background: var(--surface-2); color: var(--text); }
.recipients { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; padding: 5px 0; align-items: center; min-width: 0; position: relative; }
.recipients input { flex: 1; min-width: 140px; border: 0; outline: none; background: transparent; height: 28px; }
.rchip { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 9px; border-radius: 13px; background: var(--surface-2); font-size: 13px; max-width: 100%; }
.rchip.invalid { background: var(--danger-weak); color: var(--danger); }
.rchip button { border: 0; background: none; cursor: pointer; color: var(--muted); width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.rchip button:hover { background: var(--border); }
.suggest { position: absolute; top: 100%; left: 0; z-index: 5; min-width: 300px; max-width: 100%; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 4px; }
.suggest div { padding: 6px 8px; border-radius: 4px; cursor: pointer; display: flex; flex-direction: column; }
.suggest div.active, .suggest div:hover { background: var(--row-selected); }
.suggest small { color: var(--muted); }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.editor-toolbar .icon-btn { width: 30px; height: 30px; }
.editor-toolbar .sep { width: 1px; background: var(--border); margin: 4px 4px; }
.editor-wrap { flex: 1; overflow-y: auto; min-height: 0; position: relative; }
.editor { min-height: 100%; padding: 14px 16px 30px; outline: none; word-wrap: break-word; line-height: 1.5; }
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor blockquote, .mail-quote { margin: 8px 0 8px 2px; padding-left: 12px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.editor .bm-signature { color: var(--text-2); }
.editor img { max-width: 100%; }
textarea.editor { width: 100%; height: 100%; border: 0; resize: none; background: transparent; font-family: var(--mono); font-size: 13px; }
.editor-wrap.drag { outline: 2px dashed var(--brand); outline-offset: -8px; }
.composer-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 14px; border-top: 1px solid var(--border); }
.composer-atts:empty { display: none; }
.catt { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 12.5px; background: var(--surface); max-width: 260px; }
.catt .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catt.pending { border-style: dashed; }
.catt.error { border-color: var(--danger); color: var(--danger); }
.composer-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.send-group { display: inline-flex; }
.send-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.send-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: 1px solid rgba(255,255,255,.35); padding: 0 8px; }
.save-state { font-size: 12px; color: var(--muted); }

/* ---------- pages (settings, contacts, calendar, admin) ---------- */
.page { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 0; }
.page-nav { border-right: 1px solid var(--border); padding: 14px 8px; overflow-y: auto; background: var(--bg); }
.page-nav h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 4px 10px 10px; }
.page-body { overflow-y: auto; padding: 24px 32px 60px; min-width: 0; }
.page-body.wide { padding: 20px 24px 60px; }
.page-title { font-size: 22px; font-weight: 650; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 20px; }
.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); padding: 18px 20px; margin-bottom: 16px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .card-sub { color: var(--muted); margin: 0 0 14px; font-size: 13px; }
.card-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.card-row:first-of-type { border-top: 0; }
.form-narrow { max-width: 560px; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:hover td { background: var(--row-hover); }
.table-wrap { overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--bg); }
.stat .v { font-size: 26px; font-weight: 650; }
.stat .k { color: var(--muted); font-size: 12.5px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: 1px; height: 100%; position: relative; }
.bars .bar span { display: block; border-radius: 2px 2px 0 0; min-height: 0; }
.bars .bar .ok { background: var(--brand); }
.bars .bar .bad { background: var(--danger); }
.bars .bar .unc { background: var(--warning); }
.bars-labels { display: flex; gap: 6px; font-size: 10.5px; color: var(--muted); margin-top: 4px; }
.bars-labels span { flex: 1; text-align: center; overflow: hidden; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.steps { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.step { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; }
.step .st { width: 20px; height: 20px; flex: none; }
.step.ok .st { color: var(--success); }
.step.bad .st { color: var(--danger); }
.step.skip { color: var(--muted); }
.wizard-steps { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }
.wizard-steps span { font-size: 12.5px; padding: 4px 10px; border-radius: 12px; background: var(--surface-2); color: var(--muted); }
.wizard-steps span.on { background: var(--brand); color: #fff; }
.wizard-steps span.done { background: var(--brand-weak); color: var(--brand); }
.provider-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.provider { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; cursor: pointer; background: var(--bg); text-align: left; font-size: 13px; }
.provider:hover, .provider.on { border-color: var(--brand); background: var(--brand-weak); }
.identity-preview { font-family: var(--font); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13.5px; }
.identity-preview b { font-weight: 600; }
.sig-editor { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); min-height: 100px; padding: 10px; outline: none; background: var(--bg); }
.sig-editor:focus { border-color: var(--brand); }

/* Rich signature editor. The canvas is always "paper white" so what you
   design is exactly what recipients see, in light and dark themes. */
.sig-editor-wrap { border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.sig-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); background: var(--surface); }
.sig-toolbar .icon-btn { width: 30px; height: 30px; }
.sig-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.sig-toolbar select.sig-select { height: 30px; width: auto; flex: none; max-width: 150px; padding: 0 6px; font-size: 12.5px; }
.sig-colorwrap { position: relative; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-2); }
.sig-colorwrap:hover { background: var(--surface-2); }
.sig-colorwrap input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.sig-canvas { min-height: 150px; max-height: 420px; overflow: auto; padding: 14px 16px; outline: none; background: #fff; color: #1d2430; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 1.45; }
.sig-canvas:empty::before { content: "Type your signature, or choose a template…"; color: #8a94a3; }
.sig-canvas img { max-width: 100%; height: auto; cursor: pointer; }
.sig-canvas img.sig-selected { outline: 2px solid #1f71b8; outline-offset: 2px; }
.sig-canvas a { color: #1f71b8; }
.sig-canvas table { border-collapse: collapse; }
.sig-source { min-height: 200px; border: 0; border-radius: 0; font-size: 12px; }
.sig-imgbar { padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--brand-weak); }
.sig-imgbar input[type=range] { width: 160px; accent-color: var(--brand); }
.sig-templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.sig-template { text-align: left; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 10px; cursor: pointer; color: var(--text); }
.sig-template:hover { border-color: var(--border-strong); }
.sig-template.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-weak); }
.sig-template-preview { background: #fff; color: #1d2430; border-radius: 4px; padding: 10px; overflow: hidden; max-height: 210px; pointer-events: none; }
.sig-template-preview img { max-width: 100%; height: auto; }
.sig-preview-frame { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; min-height: 40px; margin-top: 8px; }

/* The message being written is shown on white "paper" like the recipient sees it. */
.editor { background: #fff; color: #1d2430; }
.editor:empty::before { color: #8a94a3; }
.editor a { color: #1f71b8; }
.editor blockquote, .editor .mail-quote { border-left-color: #c9d0d9; color: #3b4655; }
.editor .bm-signature { color: inherit; }
.editor-wrap { background: #fff; }
textarea.editor { color: #1d2430; }

/* contacts */
.contacts { display: grid; grid-template-columns: 220px 340px minmax(0, 1fr); min-height: 0; }
.contacts .col { border-right: 1px solid var(--border); overflow-y: auto; min-height: 0; }
.contact-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.contact-row:hover { background: var(--row-hover); }
.contact-row.active { background: var(--row-selected); }

/* calendar */
.calendar { display: flex; flex-direction: column; min-height: 0; padding: 16px 20px; gap: 12px; overflow: auto; }
.cal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--border); border-top: 1px solid var(--border); flex: 1; min-height: 480px; grid-auto-rows: minmax(92px, 1fr); }
.cal-dow { font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); }
.cal-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px 6px; min-width: 0; cursor: pointer; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal-cell:hover { background: var(--row-hover); }
.cal-cell.other { background: var(--surface); color: var(--muted); }
.cal-cell .d { font-size: 12.5px; font-weight: 600; }
.cal-cell.today .d { background: var(--brand); color: #fff; border-radius: 10px; padding: 0 7px; align-self: flex-start; }
.cal-ev { font-size: 12px; background: var(--brand-weak); color: var(--text); border-left: 3px solid var(--brand); padding: 1px 5px; border-radius: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-ev.cancelled { text-decoration: line-through; opacity: .6; }

/* ---------- auth screens ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--surface); overflow-y: auto; height: 100vh; }
.auth-card { width: 100%; max-width: 420px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 30px 30px 26px; box-shadow: 0 2px 10px rgba(16,24,40,.05); }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-logo img { height: 40px; }
.auth-logo .name { font-size: 22px; font-weight: 700; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card .lead { color: var(--muted); margin: 0 0 20px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 16px; font-size: 13px; flex-wrap: wrap; gap: 8px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ---------- overlays ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 28, .45); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; padding: 16px 18px 8px; gap: 8px; }
.modal-head h2 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 8px 18px 16px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.menu { position: fixed; z-index: 80; min-width: 210px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow); padding: 5px; max-height: 70vh; overflow-y: auto; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 7px 10px; border: 0; background: none; border-radius: 5px; cursor: pointer; text-align: left; color: var(--text); white-space: nowrap; }
.menu button:hover, .menu button:focus { background: var(--row-selected); outline: none; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu .menu-label { padding: 6px 10px 2px; font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: #1f2530; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; max-width: min(560px, calc(100vw - 32px)); font-size: 13.5px; animation: toast-in .18s ease-out; }
[data-theme="dark"] .toast { background: #e9edf2; color: #11151a; }
.toast.error { background: var(--danger); color: #fff; }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; padding: 0; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel { position: fixed; top: calc(var(--topbar-h) + 4px); right: 12px; width: 380px; max-width: calc(100vw - 24px); max-height: 70vh; overflow-y: auto; z-index: 70; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 650; gap: 8px; }
.notif { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.notif.unread { background: var(--brand-weak); }
.notif .t { font-weight: 600; font-size: 13.5px; }
.notif .b { font-size: 13px; color: var(--text-2); }
.notif .w { font-size: 11.5px; color: var(--muted); }
.kbd { font-family: var(--mono); font-size: 12px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); }

/* ---------- responsive ---------- */
.mobile-only { display: none !important; }
@media (max-width: 1100px) {
  :root { --list-w: 340px; --sidebar-w: 220px; }
  .contacts { grid-template-columns: 300px minmax(0, 1fr); }
  .contacts .col:first-child { display: none; }
}
@media (max-width: 820px) {
  body { font-size: 15px; }
  .mobile-only { display: inline-flex !important; }
  .mobile-only[hidden] { display: none !important; }
  .desktop-only { display: none !important; }
  .brand { width: auto; }
  .brand span { display: none; }
  .main, .app.sidebar-collapsed .main { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: 280px; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .app.nav-open .sidebar { transform: none; }
  .app.sidebar-collapsed .sidebar .label, .app.sidebar-collapsed .sidebar .count, .app.sidebar-collapsed .nav-heading, .app.sidebar-collapsed .sidebar-footer { display: revert; }
  .scrim { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,.35); z-index: 45; }
  .mail, .mail.pane-bottom { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .mail .splitter { display: none; }
  .mail .reader { display: none; }
  .mail.reading .list-pane { display: none; }
  .mail.reading .reader { display: flex; }
  .reader-scroll { padding: 14px 14px 40px; }
  .composer-layer { padding: 0; }
  .composer, .composer.maximized { position: fixed; inset: 0; width: 100%; height: 100%; border-radius: 0; }
  .composer-head { border-radius: 0; }
  .page { grid-template-columns: 1fr; }
  .page-nav { display: flex; gap: 4px; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .page-nav h2 { display: none; }
  .page-nav .nav-item { width: auto; flex: none; }
  .page-body { padding: 16px 16px 60px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .contacts { grid-template-columns: 1fr; }
  .contacts .col:nth-child(3) { display: none; }
  .contacts.detail .col:nth-child(2) { display: none; }
  .contacts.detail .col:nth-child(3) { display: block; }
  .search { max-width: none; }
  .topbar { gap: 6px; padding: 0 8px; }
  .cal-grid { grid-auto-rows: minmax(64px, 1fr); }
  .cal-ev { font-size: 10.5px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print {
  .topbar, .sidebar, .list-pane, .reader-toolbar, .splitter { display: none !important; }
  body { overflow: visible; }
  .app, .main, .mail { display: block; height: auto; }
}
