/* ==========================================================================
   Mavionics Cloud — design system
   Deep-navy surfaces, Mavionics steel→sky gradient as the accent, glass top bar.
   No external fonts or inline styles (the app's CSP allows only 'self').
   ========================================================================== */

:root {
  /* surfaces */
  --bg: #070b14;
  --bg-2: #0b1120;
  --panel: rgba(17, 25, 43, .72);
  --panel-solid: #111a2c;
  --panel-2: #172238;
  --panel-3: #1d2a44;
  --line: rgba(148, 178, 222, .12);
  --line-2: rgba(148, 178, 222, .2);
  /* text */
  --text: #e8eef8;
  --text-2: #c3cfe2;
  --muted: #8494ae;
  /* brand */
  --brand-1: #5a96b9;
  --brand-2: #74bdea;
  --accent: #7cc4f0;
  --accent-strong: #9ad6ff;
  --grad: linear-gradient(135deg, #5a96b9 0%, #74bdea 100%);
  --grad-soft: linear-gradient(135deg, rgba(90, 150, 185, .18), rgba(116, 189, 234, .08));
  /* status */
  --green: #3ccf8e;
  --red: #f06a6f;
  --amber: #f3b54a;
  /* shape */
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 12px 32px -12px rgba(0, 0, 0, .55);
  --shadow-lg: 0 24px 64px -24px rgba(0, 0, 0, .7);
  --ring: 0 0 0 3px rgba(124, 196, 240, .28);
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --font-display: "Inter", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body {
  margin: 0; min-height: 100%;
  color: var(--text); font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(116, 189, 234, .10), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(90, 150, 185, .08), transparent 55%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 40%);
  background-attachment: fixed;
}
::selection { background: rgba(116, 189, 234, .35); }
a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-strong); }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.015em; color: #f4f8ff; }
h1 { font-size: 1.6rem; font-weight: 650; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; font-weight: 620; margin: 1.5rem 0 .75rem; }
h3 { font-size: .95rem; font-weight: 600; }
code { font-family: var(--mono); background: rgba(124, 196, 240, .08); border: 1px solid var(--line); color: var(--text-2);
       padding: 1px 6px; border-radius: 6px; font-size: .85em; }
pre { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.inline { display: inline; margin: 0; }
.eyebrow { display: inline-block; font-size: .7rem; font-weight: 650; letter-spacing: .14em; text-transform: uppercase;
           background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; margin: 0 0 .35rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: #2a3956 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #24324d; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

.avatar { display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%;
          background: var(--grad); color: #06121f; font-weight: 750; font-size: .85rem;
          box-shadow: 0 0 0 2px rgba(7, 11, 20, .9), 0 0 0 3px rgba(124, 196, 240, .25); }
.avatar-sm { width: 28px; height: 28px; font-size: .75rem; }

/* ---------- Layout ---------- */
.container { max-width: 1320px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.container-wide { padding: 1.25rem 1.5rem 2.5rem; }
.container-inner { max-width: 1100px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.4rem;
        box-shadow: var(--shadow); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card + .card, .table + .card, .card + .table { margin-top: 1.25rem; }
.narrow { max-width: 540px; margin: 2rem auto; }
.narrow.wide { max-width: 880px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.stack { display: flex; flex-direction: column; gap: .95rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head p { margin: .2rem 0 0; }
.head-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.qr { background: #fff; padding: 14px; border-radius: 14px; width: max-content; margin: 1.25rem auto; box-shadow: var(--shadow-lg); }
.qr svg { display: block; width: 210px; height: 210px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
       height: 36px; padding: 0 1rem; border-radius: 10px; border: 1px solid var(--line-2);
       background: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .015));
       color: var(--text); font: 550 .9rem/1 var(--font); cursor: pointer; white-space: nowrap;
       transition: transform .08s, border-color .15s, background .15s, box-shadow .15s; }
.btn:hover { border-color: rgba(124, 196, 240, .5); color: #fff; background: rgba(124, 196, 240, .08); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primary { border: 0; color: #04111e; background: var(--grad); font-weight: 650;
               box-shadow: 0 6px 18px -6px rgba(116, 189, 234, .55), inset 0 1px 0 rgba(255, 255, 255, .35); }
.btn-primary:hover { color: #04111e; filter: brightness(1.07); background: var(--grad);
                     box-shadow: 0 10px 24px -8px rgba(116, 189, 234, .7), inset 0 1px 0 rgba(255, 255, 255, .35); }
.btn-danger { border-color: rgba(240, 106, 111, .45); color: #ffb3b6; background: rgba(240, 106, 111, .06); }
.btn-danger:hover { border-color: var(--red); color: #fff; background: rgba(240, 106, 111, .18); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(255, 255, 255, .05); border-color: var(--line); }
.btn-admin { border-color: rgba(243, 181, 74, .45); color: #ffd58f; background: rgba(243, 181, 74, .06); }
.btn-admin:hover, .btn-admin.active { border-color: var(--amber); color: #1a1205; background: linear-gradient(135deg, #f3b54a, #f7cf7d); }
.btn-sm { height: 30px; padding: 0 .7rem; font-size: .82rem; border-radius: 8px; }
.btn-lg { height: 44px; font-size: .98rem; border-radius: 12px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link-btn:hover { color: var(--accent-strong); text-decoration: underline; }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%; padding: .6rem .75rem; border-radius: 10px;
  border: 1px solid var(--line-2); background: rgba(5, 9, 18, .55); color: var(--text);
  font: 400 .93rem/1.4 var(--font); transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder, textarea::placeholder { color: #5f6f8a; }
input:hover, select:hover, textarea:hover { border-color: rgba(148, 178, 222, .3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); background: rgba(5, 9, 18, .8); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; padding: 0; accent-color: var(--brand-2); flex: none; }
input[type=file] { padding: .45rem; background: transparent; border-style: dashed; }
input[type=file]::file-selector-button { margin-right: .75rem; height: 30px; padding: 0 .8rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--panel-3); color: var(--text); font: 550 .82rem var(--font); }
input[type=date] { color-scheme: dark; }
select { appearance: none; padding-right: 2rem; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
textarea { min-height: 5.5rem; resize: vertical; }
label { display: block; color: var(--muted); font-size: .8rem; font-weight: 550; letter-spacing: .01em; }
label > input, label > select, label > textarea { margin-top: .35rem; }
label.check { display: flex; align-items: center; gap: .55rem; color: var(--text-2); font-size: .9rem; font-weight: 450; margin: .35rem 0; cursor: pointer; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: .75rem 1rem; margin: 0; background: rgba(5, 9, 18, .25); }
fieldset[disabled] { opacity: .75; }
legend { color: var(--muted); padding: 0 .4rem; font-size: .8rem; font-weight: 600; }
details summary { cursor: pointer; }
details summary::marker { color: var(--muted); }

/* ---------- Flash & badges ---------- */
.flash { position: relative; padding: .75rem 1rem .75rem 2.6rem; border-radius: 12px; margin-bottom: 1.1rem;
         border: 1px solid var(--line-2); background: rgba(23, 34, 56, .75); color: var(--text-2); box-shadow: var(--shadow); }
.flash::before { content: ""; position: absolute; left: 1rem; top: 50%; width: 10px; height: 10px; margin-top: -5px;
                 border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px currentColor; }
.flash-success { border-color: rgba(60, 207, 142, .35); background: rgba(60, 207, 142, .07); }
.flash-success::before { background: var(--green); color: var(--green); }
.flash-error { border-color: rgba(240, 106, 111, .4); background: rgba(240, 106, 111, .08); }
.flash-error::before { background: var(--red); color: var(--red); }
.flash-warning { border-color: rgba(243, 181, 74, .4); background: rgba(243, 181, 74, .07); }
.flash-warning::before { background: var(--amber); color: var(--amber); }
.flash-info { border-color: rgba(124, 196, 240, .35); background: rgba(124, 196, 240, .06); }
.flash-info::before { color: var(--accent); }
.badge { display: inline-flex; align-items: center; gap: .3rem; height: 20px; padding: 0 .55rem; border-radius: 999px;
         font-size: .7rem; font-weight: 650; letter-spacing: .02em; vertical-align: middle; white-space: nowrap;
         background: rgba(148, 178, 222, .08); border: 1px solid var(--line-2); color: var(--text-2); }
.badge-red { background: rgba(240, 106, 111, .1); border-color: rgba(240, 106, 111, .4); color: #ffb3b6; }
.badge-green { background: rgba(60, 207, 142, .1); border-color: rgba(60, 207, 142, .4); color: #98f0c6; }
.badge-amber { background: rgba(243, 181, 74, .1); border-color: rgba(243, 181, 74, .4); color: #ffd58f; }
.badge-blue { background: rgba(124, 196, 240, .1); border-color: rgba(124, 196, 240, .4); color: #b9e3ff; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line);
         border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: .7rem .9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table th { background: rgba(23, 34, 56, .65); color: var(--muted); font-weight: 650; font-size: .7rem;
            text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
.table th a { color: var(--muted); }
.table th a:hover, .table th a.sorted { color: var(--text); }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: rgba(124, 196, 240, .045); }
.table tr.selected { background: rgba(124, 196, 240, .08); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .details { max-width: 420px; word-break: break-word; color: var(--muted); font-family: var(--mono); font-size: .78rem; }
.table.small td, .table.small th { padding: .5rem .7rem; }
.amount-in { color: #79e2ac; font-variant-numeric: tabular-nums; }
.amount-out { color: var(--text); font-variant-numeric: tabular-nums; }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: 1.1rem; }
.filters > label:not(.check) { display: flex; flex-direction: column; gap: .35rem; }
.filters > label:not(.check) > input, .filters > label:not(.check) > select { margin-top: 0; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters input[type=checkbox] { min-width: 0; }
.filters label.check { align-self: center; margin: 0; }
.pager { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; color: var(--muted); }
.tabs, .segmented { display: inline-flex; gap: .2rem; padding: .25rem; margin-bottom: 1.1rem; border-radius: 12px;
                    background: rgba(5, 9, 18, .55); border: 1px solid var(--line); }
.segmented { margin: 0; }
.tabs a, .segmented a { padding: .4rem .9rem; border-radius: 9px; color: var(--muted); font-weight: 550; font-size: .88rem; }
.tabs a:hover, .segmented a:hover { color: var(--text); }
.tabs a.active, .segmented a.active { color: #fff; background: var(--panel-3); box-shadow: inset 0 0 0 1px var(--line-2), 0 4px 12px -6px rgba(0, 0, 0, .6); }
.search { display: flex; gap: .4rem; align-items: center; margin: 0; }
.search input { width: 260px; padding-left: 2.1rem;
  background-image: radial-gradient(circle at 50% 50%, transparent 4px, var(--muted) 4.6px, var(--muted) 5.6px, transparent 6.2px),
                    linear-gradient(45deg, transparent 46%, var(--muted) 46%, var(--muted) 56%, transparent 56%);
  background-size: 16px 16px, 6px 6px; background-position: 10px 50%, 22px calc(50% + 6px); background-repeat: no-repeat; }

/* ---------- Upload ---------- */
.dropzone { display: flex; flex-wrap: wrap; align-items: center; gap: .9rem; margin-bottom: 1.25rem; padding: 1.1rem 1.25rem;
            border: 1.5px dashed rgba(124, 196, 240, .3); border-radius: var(--radius-lg); background: var(--grad-soft); transition: border-color .15s, background .15s; }
.dropzone.dragover { border-color: var(--brand-2); background: rgba(116, 189, 234, .14); }
.dropzone input[type=file] { width: auto; border: 0; padding: 0; }
.dropzone select { width: auto; }

/* ---------- Invoice detail ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(380px, 1fr); gap: 1.25rem; height: calc(100vh - 2.5rem - 3rem); }
.split .pdf { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: var(--radius-lg); background: #fff; box-shadow: var(--shadow-lg); }
.split .side { overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
.form-grid .full { grid-column: 1 / -1; }
.extracted { white-space: pre-wrap; max-height: 280px; overflow: auto; background: rgba(5, 9, 18, .55); border: 1px solid var(--line);
             border-radius: 10px; padding: .75rem; font: .78rem/1.5 var(--mono); color: var(--muted); }

/* ---------- Pairing ---------- */
.pairing-split { display: grid; grid-template-columns: 310px minmax(0, 1fr); gap: 1.25rem; margin-top: 1.25rem; align-items: start; }
.invoice-picker { max-height: calc(100vh - 60px); overflow-y: auto; position: sticky; top: 1.25rem; padding: .8rem; }
.pair-invoice { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 1rem; align-items: start; }
.pair-invoice .pdf { width: 100%; height: 75vh; min-height: 420px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: #fff; }
.pair-meta { margin-top: .8rem; }
.pair-meta > summary { cursor: pointer; font-weight: 600; margin-bottom: .6rem; }
.invoice-picker h2 { margin: .2rem .4rem .6rem; }
.pick { display: flex; flex-direction: column; gap: .15rem; padding: .6rem .7rem; border-radius: 10px; color: var(--text);
        border: 1px solid transparent; transition: background .12s, border-color .12s; }
.pick:hover { background: rgba(255, 255, 255, .035); }
.pick.active { border-color: rgba(124, 196, 240, .45); background: rgba(124, 196, 240, .08); }
.pick .badge { align-self: flex-start; }
.pair-form { display: flex; gap: .4rem; align-items: center; margin: 0; }
.amount-input { width: 8rem; text-align: right; font-variant-numeric: tabular-nums; padding: .4rem .6rem; }
.actions { white-space: nowrap; }
.actions form { margin-right: .3rem; }

/* ---------- Mail ---------- */
.mail-main { min-width: 0; }
.mail-list { margin: 0; }
.mail-row { display: grid; grid-template-columns: minmax(140px, 26%) minmax(0, 1fr) auto; gap: 1rem; align-items: center;
            padding: .8rem 1.1rem; color: var(--text-2); border-bottom: 1px solid var(--line); transition: background .12s; }
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover { background: rgba(124, 196, 240, .05); color: var(--text); }
.mail-row.unread { color: #fff; background: rgba(124, 196, 240, .025); }
.mail-row.unread .mail-from, .mail-row.unread .mail-subject { font-weight: 680; }
.mail-row.unread .mail-from::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: .5rem; border-radius: 50%;
                                      background: var(--brand-2); box-shadow: 0 0 8px rgba(116, 189, 234, .8); vertical-align: middle; }
.mail-from, .mail-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-date { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.mail-row .count { display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 .35rem; margin-left: .35rem;
                   border-radius: 999px; font-size: .7rem; font-weight: 700; color: var(--text); background: var(--panel-3); }
.clip { opacity: .7; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); margin: 0; }
.message-view h1 { font-size: 1.3rem; }
.mail-body { width: 100%; height: 72vh; border: 1px solid var(--line); border-radius: 12px; background: #fff; margin-top: .9rem; box-shadow: var(--shadow-lg); }
.thread-msg .mail-body { height: 56vh; }
.mail-text { white-space: pre-wrap; word-wrap: break-word; font: .92rem/1.6 var(--font); background: rgba(5, 9, 18, .5);
             border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem; margin-top: .9rem; color: var(--text-2); }
.attachments { display: flex; flex-direction: column; gap: .45rem; margin: .9rem 0; padding: .75rem .9rem; border: 1px solid var(--line);
               border-radius: 12px; background: rgba(5, 9, 18, .35); }
.attachment { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.images-blocked { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-top: .9rem; padding: .55rem .9rem;
                  border-radius: 10px; border: 1px solid rgba(243, 181, 74, .3); background: rgba(243, 181, 74, .06); color: #ffd58f; }
.compose { max-width: 920px; margin: 0 auto; }
.mail-compose { min-height: 280px; }
.signature-box, .signature-preview { border: 1px solid var(--line); border-radius: 12px; padding: .75rem 1rem; background: rgba(5, 9, 18, .35); }
.signature-box .signature-preview { border: 0; padding: .25rem 0 0 1.6rem; background: none; }
.signature-preview { color: var(--text-2); font-size: .9rem; }
.signature-preview img { display: block; margin-top: .5rem; max-width: 100%; height: auto; background: #fff; border-radius: 6px; padding: 4px; }
.signature-preview .eyebrow { display: block; }
.quoted-box textarea.quoted { margin-top: .5rem; min-height: 140px; font: .82rem/1.5 var(--mono); color: var(--muted); }

/* conversation */
.thread-msg { padding: 0; margin-bottom: .9rem; overflow: hidden; }
.thread-msg > summary { list-style: none; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .9rem; align-items: center;
                        padding: .9rem 1.1rem; transition: background .12s; }
.thread-msg > summary::-webkit-details-marker { display: none; }
.thread-msg > summary:hover { background: rgba(255, 255, 255, .025); }
.thread-who { display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; min-width: 0; text-align: left; }
.thread-name { display: flex; align-items: center; gap: .45rem; color: var(--text); }
.thread-who .snippet { max-width: 100%; }
.thread-msg .snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-msg[open] .snippet { display: none; }
.thread-msg[open] > summary { border-bottom: 1px solid var(--line); }
.thread-body { padding: 1rem 1.1rem 1.2rem; }

/* ---------- Auth pages ---------- */
.auth-page main { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-page body, body.auth-page {
  background:
    radial-gradient(700px 420px at 50% 0%, rgba(116, 189, 234, .18), transparent 70%),
    radial-gradient(600px 400px at 100% 100%, rgba(90, 150, 185, .12), transparent 70%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 420px; padding: 2.25rem 2rem 2rem; border-radius: 22px; border: 1px solid var(--line-2);
             background: linear-gradient(180deg, rgba(23, 34, 56, .82), rgba(12, 19, 33, .88));
             box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, .02) inset;
             backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.auth-card h1 { font-size: 1.55rem; margin: 0 0 .3rem; }
.auth-card > p { margin: 0 0 1.4rem; }
.auth-card form { margin-top: .5rem; }
.auth-card .btn-lg { width: 100%; margin-top: .3rem; }
.auth-logo { display: block; height: 22px; width: auto; margin: 0 0 1.6rem; }
.auth-foot { margin-top: 1.5rem; color: #4f5d77; font-size: .78rem; letter-spacing: .04em; }

/* ---------- Guide / admin bits ---------- */
.guide { max-width: 920px; margin: 0 auto; line-height: 1.7; }
.guide li { margin: .35rem 0; }
.guide h2 { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.bot-panel { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.5rem;
             background: var(--grad-soft), var(--panel); }
.bot-panel h2 { margin: 0 0 .25rem; }
.bot-panel p { margin: 0; }
.bot-panel.off { border-color: rgba(240, 106, 111, .45); background: rgba(240, 106, 111, .06); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-2, .split, .form-grid { grid-template-columns: 1fr; }
  .split { height: auto; }
  .split .pdf { height: 70vh; }
  .pairing-split { grid-template-columns: 1fr; }
  .pair-invoice { grid-template-columns: 1fr; }
  .pair-invoice .pdf { height: 70vh; }
  .invoice-picker { position: static; max-height: 40vh; }
  .mail-row { grid-template-columns: 1fr auto; }
  .mail-row .mail-subject { grid-column: 1 / -1; grid-row: 2; }
  .search input { width: 100%; }
  .container { padding: 1.25rem 1rem 3rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Compose window (floating, Mailspring-like) ---------- */
[hidden] { display: none !important; }
.compose-root { position: fixed; right: 24px; bottom: 0; z-index: 60; }
.compose-window { display: flex; flex-direction: column; width: min(760px, calc(100vw - 32px)); height: min(680px, calc(100vh - 90px));
  background: #0d1424; border: 1px solid var(--line-2); border-bottom: 0; border-radius: 14px 14px 0 0; overflow: hidden;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .8), 0 0 0 1px rgba(255, 255, 255, .03) inset;
  animation: cw-in .18s ease-out; }
@keyframes cw-in { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.compose-window.minimized { height: auto; width: 340px; }
.compose-window.minimized .cw-body { display: none; }
.compose-window.minimized .cw-head { cursor: pointer; }
.compose-window.fullscreen { position: fixed; inset: 24px; width: auto; height: auto; border-radius: 16px; border-bottom: 1px solid var(--line-2); }
body.compose-fullscreen::after { content: ""; position: fixed; inset: 0; z-index: 55; background: rgba(3, 6, 12, .6); backdrop-filter: blur(3px); }
.compose-window.page { width: 100%; max-width: 980px; height: calc(100vh - 100px); margin: 0 auto; border-radius: 16px; border-bottom: 1px solid var(--line-2); animation: none; }
.cw-head { display: flex; align-items: center; gap: .75rem; height: 42px; padding: 0 .5rem 0 1rem; flex: none;
  background: linear-gradient(180deg, #1a2742, #141f35); border-bottom: 1px solid var(--line); user-select: none; }
.cw-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: #f1f6ff; }
.cw-buttons { display: flex; gap: .15rem; }
.cw-buttons button, .cw-buttons a { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; border: 0;
  background: none; color: var(--text-2); font-size: .95rem; cursor: pointer; }
.cw-buttons button:hover, .cw-buttons a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.cw-buttons [data-win="close"]:hover { background: rgba(240, 106, 111, .25); }
.cw-body { flex: 1; min-height: 0; display: flex; }
.compose-form { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cf-row { display: flex; align-items: center; gap: .6rem; padding: 0 1rem; min-height: 44px; border-bottom: 1px solid var(--line); flex: none; }
.cf-label { flex: none; width: 64px; color: var(--muted); font-size: .85rem; font-weight: 500; }
.cf-input, .cf-from { flex: 1; border: 0; background: transparent; padding: .5rem 0; border-radius: 0; box-shadow: none !important; }
.cf-input:focus, .cf-input:hover, .cf-from:hover, .cf-from:focus { background: transparent; border: 0; }
.cf-from { flex: 0 1 auto; max-width: 100%; padding: .35rem 2rem .35rem .7rem; border: 1px solid var(--line-2); border-radius: 8px; background-color: rgba(5, 9, 18, .4); }
.cf-subject { font-size: 1rem; font-weight: 550; }
.cf-toggles { display: flex; gap: .7rem; font-size: .82rem; }
.cf-toggles .link-btn { color: var(--muted); }
.cf-toggles .link-btn:hover { color: var(--accent); }
.rte-toolbar { display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; padding: .35rem .75rem; border-bottom: 1px solid var(--line); flex: none; background: rgba(5, 9, 18, .35); }
.rte-toolbar button { min-width: 30px; height: 30px; padding: 0 .4rem; border: 0; border-radius: 7px; background: none; color: var(--text-2); cursor: pointer; font: 600 .9rem var(--font); }
.rte-toolbar button:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.rte-toolbar select { width: auto; height: 30px; padding: 0 1.8rem 0 .55rem; font-size: .82rem; border-color: transparent; background-color: transparent; }
.rte-toolbar select:hover { border-color: var(--line-2); }
.rte-color { display: grid; place-items: center; width: 30px; height: 30px; margin: 0; border-radius: 7px; cursor: pointer; }
.rte-color:hover { background: rgba(255, 255, 255, .08); }
.rte-color input { width: 18px; height: 18px; padding: 0; border: 1px solid var(--line-2); border-radius: 4px; cursor: pointer; background: none; }
.rte-sep { width: 1px; height: 18px; margin: 0 .35rem; background: var(--line-2); }
.cf-paper { flex: 1; min-height: 0; overflow-y: auto; background: #fff; color: #111; padding: 1rem 1.25rem; }
.rte { min-height: 140px; outline: none; font: 14px/1.55 "Segoe UI", Arial, sans-serif; color: #111; word-wrap: break-word; }
.rte:empty::before { content: "Write your message…"; color: #9aa3b2; }
.rte blockquote { margin: .5rem 0; padding-left: .8rem; border-left: 3px solid #c9d3e2; color: #475266; }
.rte a { color: #1a73c9; }
.rte-fallback { width: 100%; min-height: 220px; border: 0; background: transparent; color: #111; padding: 0; resize: vertical; box-shadow: none !important; }
.cf-signature { margin-top: 1.25rem; padding-top: .5rem; color: #333; font: 13px/1.5 "Segoe UI", Arial, sans-serif; }
.cf-signature.off { opacity: .3; }
.cf-signature img { display: block; margin-top: .5rem; max-width: 100%; height: auto; }
.cf-quoted { margin-top: 1rem; }
.cf-quoted summary { display: inline-block; padding: 0 .5rem; border-radius: 6px; background: #eef1f6; color: #66708a; font-weight: 700; letter-spacing: .1em; list-style: none; }
.cf-quoted summary::-webkit-details-marker { display: none; }
.cf-quoted textarea.quoted { margin-top: .5rem; min-height: 160px; background: #f7f9fc; color: #4a5468; border: 1px solid #e3e8f0; font: .82rem/1.5 var(--mono); }
.cf-note, .cf-files { padding: .45rem 1rem 0; color: var(--text-2); flex: none; }
.cf-files { display: flex; flex-wrap: wrap; gap: .4rem; }
.cf-files:empty { display: none; }
.file-chip { padding: .2rem .55rem; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel-3); }
.cf-footer { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; border-top: 1px solid var(--line); flex: none; background: #0d1424; }
.cf-send { min-width: 110px; height: 38px; }
.cf-sig-toggle { display: flex; align-items: center; gap: .4rem; margin: 0; color: var(--text-2); font-size: .84rem; cursor: pointer; }
.cf-attach { cursor: pointer; margin: 0; color: var(--text-2); }
.cf-spacer { flex: 1; }
.cf-discard:hover { color: #ffb3b6; background: rgba(240, 106, 111, .12); }
@media (max-width: 700px) {
  .compose-root { right: 0; left: 0; }
  .compose-window:not(.page) { width: 100vw; height: calc(100vh - 60px); border-radius: 14px 14px 0 0; }
}

/* ---------- Filters, stars ---------- */
.filter-chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: -.25rem 0 1rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; height: 30px; padding: 0 .85rem; border-radius: 999px;
        border: 1px solid var(--line-2); color: var(--text-2); font-size: .84rem; font-weight: 550; background: rgba(5, 9, 18, .35);
        transition: border-color .15s, background .15s, color .15s; }
.chip:hover { color: #fff; border-color: rgba(124, 196, 240, .45); }
.chip.active { color: #04111e; background: var(--grad); border-color: transparent; box-shadow: 0 6px 16px -8px rgba(116, 189, 234, .7); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand-2); }
.chip.active .dot { background: #04111e; }

.mail-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .25rem; align-items: center; padding: 0 1.1rem 0 .5rem; }
.mail-link { display: grid; grid-template-columns: minmax(140px, 26%) minmax(0, 1fr) auto; gap: 1rem; align-items: center;
             padding: .8rem 0; color: inherit; min-width: 0; }
.mail-link:hover { color: inherit; }
.star-form { display: inline-flex; margin: 0; }
.star { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; cursor: pointer;
        color: #5b6a86; font-size: 1.1rem; line-height: 1; transition: color .15s, background .15s, transform .1s; }
.star:hover { color: #f3c969; background: rgba(243, 201, 105, .1); }
.star:active { transform: scale(.88); }
.star.on { color: #f5c451; text-shadow: 0 0 10px rgba(245, 196, 81, .55); }
.star[disabled] { opacity: .5; }
h1.with-star { display: flex; align-items: center; gap: .35rem; }
@media (max-width: 900px) {
  .mail-link { grid-template-columns: 1fr auto; }
  .mail-link .mail-subject { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- Compose resize corner ---------- */
.compose-window { position: relative; }
.cw-resize { position: absolute; left: 0; top: 0; z-index: 2; width: 16px; height: 16px; cursor: nwse-resize; touch-action: none;
             border-top-left-radius: 14px; }
.cw-resize::before { content: ""; position: absolute; left: 4px; top: 4px; width: 8px; height: 8px;
                     border-left: 2px solid rgba(154, 214, 255, .55); border-top: 2px solid rgba(154, 214, 255, .55); border-top-left-radius: 3px; }
.cw-resize:hover::before { border-color: var(--accent-strong); }
.compose-window.fullscreen .cw-resize, .compose-window.minimized .cw-resize, .compose-window.page .cw-resize { display: none; }
.compose-window.resizing { user-select: none; animation: none; }
.compose-window.resizing iframe { pointer-events: none; }

/* ---------- Signature editor ---------- */
.sig-editor-box { border: 1px solid var(--line-2); border-radius: 14px; overflow: hidden; background: rgba(5, 9, 18, .35); }
.sig-editor-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
.sig-editor-head .eyebrow { margin: 0; }
.sig-paper { background: #fff; color: #111; padding: 1rem 1.2rem; min-height: 150px; }
.sig-editor { min-height: 120px; font: 13px/1.5 "Segoe UI", Arial, sans-serif; color: #222; }
.sig-editor:empty::before { content: "Type your signature, or use the business-card layout…"; color: #9aa3b2; }
.sig-editor table td { padding: 0; }
.sig-editor img, .cf-signature img { max-width: 100%; height: auto; }
.sig-paper .rte-fallback { min-height: 120px; }

/* ---------- Read / unread badges ---------- */
.mail-row { grid-template-columns: auto auto minmax(0, 1fr); gap: .1rem; }
.mail-row.unread .mail-from::before { content: none; }          /* replaced by the read badge */
.seen-form { display: inline-flex; margin: 0; }
.read-badge { display: grid; place-items: center; width: 28px; height: 32px; border: 0; border-radius: 8px; background: none; cursor: pointer; }
.read-badge .dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid rgba(148, 178, 222, .28);
                   transition: transform .15s, background .15s, border-color .15s, box-shadow .15s; }
.read-badge:hover { background: rgba(124, 196, 240, .08); }
.read-badge:hover .dot { border-color: var(--accent); transform: scale(1.15); }
.read-badge.unread .dot { border: 0; background: var(--grad); box-shadow: 0 0 0 3px rgba(116, 189, 234, .16), 0 0 10px rgba(116, 189, 234, .75); }
.read-badge[disabled] { opacity: .5; }
.mail-row:not(.unread) .read-badge .dot { opacity: .55; }
.mail-row:not(.unread):hover .read-badge .dot { opacity: 1; }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count-badge { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 .45rem; border-radius: 999px;
               font-size: .72rem; font-weight: 750; color: #04111e; background: var(--grad);
               box-shadow: 0 4px 10px -4px rgba(116, 189, 234, .8); font-variant-numeric: tabular-nums; }
.pick.active .count-badge { box-shadow: 0 0 0 2px rgba(7, 11, 20, .9), 0 4px 10px -4px rgba(116, 189, 234, .8); }

/* Inline row of controls inside a table cell (e.g. password · Update · Disconnect) */
.cell-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: nowrap; }
.cell-actions form { margin: 0; }
.cell-actions input[type=password] { width: 150px; padding: .4rem .6rem; }
.cell-actions input[type=password] { width: 130px; }
@media (max-width: 900px) { .hide-narrow { display: none; } }

/* ==========================================================================
   App shell: module rail · module menu (drawer) · content
   Desktop: icon rail (64px, expandable) + module menu column.
   Phones (<900px): top bar with a burger; rail + module menu slide in as one drawer.
   ========================================================================== */
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
     stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0;
            background: none; color: var(--text-2); cursor: pointer; transition: background .15s, color .15s; }
.icon-btn:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.icon-btn .i { width: 22px; height: 22px; }

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.mobilebar, .drawer-close, .scrim, .fab { display: none; }

.shell { display: flex; min-height: 100vh; }
.shell > main { flex: 1; min-width: 0; }
.drawer { position: sticky; top: 0; height: 100vh; display: flex; flex: none; z-index: 30; }

/* ---------- module rail ---------- */
.rail { --rail-w: 64px; width: var(--rail-w); display: flex; flex-direction: column; gap: .35rem; padding: .7rem .6rem;
        background: rgba(6, 10, 19, .82); border-right: 1px solid var(--line); transition: width .18s ease; }
body.rail-wide .rail { --rail-w: 212px; }
.rail-brand { display: flex; align-items: center; justify-content: center; height: 44px; margin-bottom: .6rem; border-radius: 12px; }
.rail-mark { width: 30px; height: 30px; border-radius: 8px; }
.rail-logo { display: none; height: 17px; width: auto; }
body.rail-wide .rail-brand { justify-content: flex-start; padding-left: .55rem; }
body.rail-wide .rail-mark { display: none; }
body.rail-wide .rail-logo { display: block; }
.rail-group { display: flex; flex-direction: column; gap: .3rem; }
.rail-bottom { margin-top: auto; }
.rail-form { margin: 0; display: flex; }
.rail-item { position: relative; display: flex; align-items: center; gap: .8rem; width: 100%; height: 44px; padding: 0 .7rem;
             border-radius: 12px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 560;
             cursor: pointer; transition: background .15s, color .15s; white-space: nowrap; }
.rail-item .i { width: 22px; height: 22px; }
.rail-item:hover { color: #fff; background: rgba(255, 255, 255, .05); }
.rail-item.active { color: #fff; background: rgba(124, 196, 240, .14); }
.rail-item.active::before { content: ""; position: absolute; left: -.6rem; top: 10px; bottom: 10px; width: 3px;
                            border-radius: 0 3px 3px 0; background: var(--grad); box-shadow: 0 0 10px rgba(116, 189, 234, .7); }
.rail-item.active .i { stroke: var(--accent-strong); }
.rail-admin { color: #e8b964; }
.rail-admin.active { background: rgba(243, 181, 74, .14); }
.rail-admin.active::before { background: linear-gradient(180deg, #f3b54a, #f7cf7d); box-shadow: 0 0 10px rgba(243, 181, 74, .6); }
.rail-admin.active .i { stroke: #ffd58f; }
.rail-who { padding-left: .55rem; }
.rail-who .avatar { width: 28px; height: 28px; }
.rail-label { overflow: hidden; text-overflow: ellipsis; }
.rail-toggle .i { transition: transform .18s; }
body:not(.rail-wide) .rail-toggle .i { transform: scaleX(-1); }

/* collapsed rail: labels become tooltips */
body:not(.rail-wide) .rail-item { justify-content: center; padding: 0; }
body:not(.rail-wide) .rail-label { position: absolute; left: calc(100% + 12px); top: 50%; transform: translate(-4px, -50%);
  padding: .32rem .65rem; border-radius: 8px; background: #1b2740; color: #fff; font-size: .8rem; font-weight: 600;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .8), 0 0 0 1px var(--line-2); pointer-events: none; opacity: 0;
  transition: opacity .12s, transform .12s; z-index: 50; }
body:not(.rail-wide) .rail-item:hover .rail-label,
body:not(.rail-wide) .rail-item:focus-visible .rail-label { opacity: 1; transform: translate(0, -50%); }

/* ---------- module menu (Gmail-drawer style) ---------- */
.module-nav { width: 252px; display: flex; flex-direction: column; gap: .2rem; padding: .9rem .7rem 1rem;
              background: rgba(10, 16, 29, .6); border-right: 1px solid var(--line); overflow-y: auto; }
.modnav-title { margin: .35rem .8rem .8rem; font: 650 1.05rem/1.2 var(--font-display); color: #f4f8ff; letter-spacing: -.01em; }
.modnav-list { display: flex; flex-direction: column; gap: .1rem; }
.module-nav .pick { flex-direction: row; align-items: center; gap: .85rem; height: 42px; padding: 0 .9rem 0 1rem;
                    border: 0; border-radius: 999px; color: var(--text-2); font-weight: 540; }
.module-nav .pick .i { color: var(--muted); }
.module-nav .pick:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.module-nav .pick.active { background: rgba(124, 196, 240, .16); color: #fff; font-weight: 650; }
.module-nav .pick.active .i { color: var(--accent-strong); }
.module-nav .compose-btn { display: inline-flex; align-items: center; justify-content: center; gap: .55rem; height: 48px;
                           margin: .2rem .15rem .9rem; border-radius: 16px; font-size: .95rem; }

/* mailbox (account) switcher */
.acct-switch { position: relative; margin: 0 0 .7rem; }
.acct-switch summary { display: flex; align-items: center; gap: .65rem; padding: .5rem .6rem; border-radius: 14px; cursor: pointer;
                       list-style: none; border: 1px solid var(--line); background: rgba(255, 255, 255, .02); }
.acct-switch summary::-webkit-details-marker { display: none; }
.acct-switch summary:hover, .acct-switch[open] summary { border-color: var(--line-2); background: rgba(255, 255, 255, .05); }
.acct-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.acct-title { font-weight: 640; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-mail { font-size: .76rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-caret { color: var(--muted); transition: transform .15s; }
.acct-switch[open] .acct-caret { transform: rotate(180deg); }
.acct-menu { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 40; padding: .35rem; border-radius: 14px;
             background: #111a2c; border: 1px solid var(--line-2); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: .1rem; }
.acct-item { display: flex; align-items: center; gap: .65rem; padding: .5rem .55rem; border-radius: 10px; color: var(--text-2); }
.acct-item:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.acct-item.active { background: rgba(124, 196, 240, .12); }
.acct-item > .i { width: 28px; color: var(--muted); }

/* ---------- Mail: list + reading pane (Mailspring-like) ---------- */
.list-pane { container-type: inline-size; min-width: 0; }
.reading-pane, .pane-resizer { display: none; }
.back-link { flex: none; margin-left: -.4rem; }
.msg-head { flex-wrap: nowrap; align-items: flex-start; }
.msg-head h1, .msg-head-text { flex: 1; min-width: 0; }
.message-view .msg-head { flex-wrap: wrap; }
.message-view .msg-head .actions { display: flex; flex-wrap: wrap; gap: .4rem; flex-basis: 100%; padding-left: 2.6rem; }
.mail-row.selected { background: rgba(124, 196, 240, .12); box-shadow: inset 3px 0 0 var(--brand-2); }

/* narrow list column: two-line rows (sender + date / subject) */
@container (max-width: 680px) {
  .mail-link { grid-template-columns: minmax(0, 1fr) auto; gap: .1rem .75rem; padding: .7rem 0; }
  .mail-link .mail-subject { grid-column: 1 / -1; grid-row: 2; color: var(--muted); font-size: .88rem; }
  .mail-row.unread .mail-link .mail-subject { color: var(--text-2); }
  .page-head { align-items: flex-start; }
  .head-actions { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
}

@media (min-width: 1100px) {
  body.mail-app main.container-wide { height: 100vh; display: flex; flex-direction: column; padding-top: 1rem; padding-bottom: 1rem; }
  body.mail-app main.container-wide > * { flex: none; }
  body.mail-app main.container-wide > .mail-panes { flex: 1; }
  .mail-panes { --list-w: 38%; min-height: 0; display: grid; grid-template-columns: var(--list-w) 10px minmax(0, 1fr); }
  .mail-panes.resizing { user-select: none; }
  .mail-panes.resizing iframe { pointer-events: none; }
  .list-pane { display: flex; flex-direction: column; min-height: 0; }
  .list-pane .mail-list { flex: 1; min-height: 0; overflow-y: auto; }
  .list-pane .pager { flex: none; }
  .pane-resizer { display: block; cursor: col-resize; position: relative; touch-action: none; }
  .pane-resizer::after { content: ""; position: absolute; top: 0; bottom: 0; left: 4px; width: 2px; border-radius: 2px;
                         background: var(--line); transition: background .15s; }
  .pane-resizer:hover::after, .mail-panes.resizing .pane-resizer::after, .pane-resizer:focus-visible::after { background: var(--accent); }
  .reading-pane { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; border-radius: var(--radius-lg);
                  border: 1px solid var(--line); background: var(--panel); transition: opacity .15s; }
  .reading-pane.loading { opacity: .55; }
  .reading-pane > .message-pane > * { flex: none; }
  .reading-pane > .message-pane { flex: 1 0 auto; display: flex; flex-direction: column; border: 0; box-shadow: none;
                                   background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .reading-pane > .message-view .mail-body { flex: 1; min-height: 360px; height: auto; }
  .reading-pane > .mail-main { padding: 1.2rem; }
  .reading-pane .back-link { display: none; }
  .pane-empty { margin: auto; text-align: center; color: var(--muted); }
  .pane-empty .i { width: 56px; height: 56px; stroke-width: 1.2; opacity: .5; }
  .pane-empty p { margin: .5rem 0 0; }
}

/* ---------- phones & small tablets ---------- */
@media (max-width: 899.98px) {
  .mobilebar { position: sticky; top: 0; z-index: 25; display: flex; align-items: center; gap: .6rem; height: 56px; padding: 0 .6rem;
               background: rgba(8, 13, 24, .85); backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
               border-bottom: 1px solid var(--line); }
  .mobilebar-title { flex: 1; font-weight: 650; font-size: 1.02rem; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobilebar .avatar { margin-right: .3rem; }
  .shell { display: block; min-height: calc(100vh - 56px); }

  .drawer { position: fixed; top: 0; bottom: 0; left: 0; height: auto; width: min(360px, 88vw); z-index: 70;
            background: #0b1222; box-shadow: 24px 0 64px -24px rgba(0, 0, 0, .9); border-radius: 0 20px 20px 0; overflow: hidden;
            transform: translateX(-105%); transition: transform .22s cubic-bezier(.2, .8, .2, 1), visibility .22s; visibility: hidden; }
  .nav-toggle:checked ~ .shell .drawer { transform: none; visibility: visible; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(2, 5, 12, .6); opacity: 0; pointer-events: none;
           transition: opacity .2s; }
  .nav-toggle:checked ~ .shell .scrim { opacity: 1; pointer-events: auto; }
  body.drawer-open { overflow: hidden; }
  .drawer-close { display: grid; position: absolute; top: .55rem; right: .5rem; }

  /* rail inside the drawer: icons with small captions; full width when the module has no menu */
  .rail, body.rail-wide .rail { --rail-w: 72px; padding: .7rem .35rem; background: rgba(4, 8, 16, .6); }
  .rail-toggle { display: none; }
  .rail-brand, body.rail-wide .rail-brand { justify-content: center; padding: 0; }
  body.rail-wide .rail-mark { display: block; }
  body.rail-wide .rail-logo { display: none; }
  body .rail .rail-item { flex-direction: column; justify-content: center; gap: .15rem; height: 58px; padding: 0 .2rem; }
  body .rail .rail-label { position: static; opacity: 1; transform: none; padding: 0; background: none; box-shadow: none;
                      font-size: .64rem; font-weight: 600; max-width: 100%; color: inherit; pointer-events: none; }
  .rail-who .rail-label .badge { display: none; }
  .rail-item.active::before { left: -.35rem; }
  body:not(.has-modnav) .rail { flex: 1; --rail-w: auto; padding: 1rem .8rem; }
  body:not(.has-modnav) .rail .rail-item { flex-direction: row; justify-content: flex-start; gap: .9rem; height: 48px; padding: 0 .9rem; }
  body:not(.has-modnav) .rail .rail-label { font-size: .95rem; }
  body:not(.has-modnav) .rail-brand { justify-content: flex-start; padding-left: .9rem; }
  body:not(.has-modnav) .rail-mark { display: none; }
  body:not(.has-modnav) .rail-logo { display: block; }

  .module-nav { flex: 1; width: auto; min-width: 0; padding-top: 3.4rem; background: none; border-right: 0; }
  .module-nav .pick { height: 46px; }

  .container, .container-wide { padding: 1rem .8rem 5.5rem; }
  /* wide tables scroll sideways instead of widening the whole page */
  .table { display: block; overflow-x: auto; max-width: 100%; }
  .shell > main { overflow-x: clip; }

  /* Gmail-like list & message */
  .mail-app .page-head h1 { font-size: 1.3rem; }
  .mail-app .filter-chips { flex-wrap: nowrap; overflow-x: auto; margin-bottom: .75rem; padding-bottom: .15rem; }
  .mail-app .chip { flex: none; }
  .mail-list.card { border-radius: 14px; }
  .mail-row { padding: 0 .6rem 0 .2rem; }
  .fab { position: fixed; right: 16px; bottom: 18px; z-index: 50; display: inline-flex; align-items: center; gap: .55rem; height: 54px;
         padding: 0 1.25rem 0 1.05rem; border-radius: 18px; background: var(--grad); color: #04111e; font-weight: 700;
         box-shadow: 0 14px 30px -10px rgba(116, 189, 234, .7); }
  .fab:hover { color: #04111e; }
  .fab .i { width: 22px; height: 22px; stroke-width: 2; }
  .message-view { padding: .9rem; border-radius: 14px; }
  .message-view .msg-head .actions { width: 100%; }
  .message-view .msg-head .actions .btn { flex: 1 1 auto; }
  .message-view .mail-body { height: 70vh; }
  .compose-window:not(.page) { height: calc(100vh - 56px); }
}
@media (max-width: 899.98px) and (prefers-reduced-motion: reduce) { .drawer { transition: none; } }


/* ---------- Quoted earlier messages (folded) ---------- */
details.quoted { margin-top: .5rem; }
details.quoted > summary { display: inline-block; list-style: none; cursor: pointer; padding: 0 .65rem; border-radius: 10px;
  background: rgba(148, 178, 222, .14); color: var(--text-2); font: 700 .8rem/1.4rem var(--font); letter-spacing: .15em; }
details.quoted > summary::-webkit-details-marker { display: none; }
details.quoted > summary:hover { background: rgba(148, 178, 222, .24); color: #fff; }
details.quoted[open] > summary { margin-bottom: .5rem; }
.quoted-text { white-space: pre-wrap; word-wrap: break-word; margin: 0; padding: .7rem .9rem; border-left: 3px solid var(--line-2);
               color: var(--muted); font: .84rem/1.5 var(--font); background: rgba(5, 9, 18, .35); border-radius: 0 10px 10px 0;
               max-height: 75vh; overflow: auto; }

/* ---------- Conversation (messenger-like: received right, sent left) ---------- */
.chat { display: flex; flex-direction: column; gap: .9rem; padding: .25rem 0 1rem; }
.bubble { width: fit-content; min-width: min(380px, 100%); max-width: min(88%, 1100px); padding: .75rem .95rem .7rem;
          border-radius: 18px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.bubble.in { align-self: flex-end; border-bottom-right-radius: 6px; border-color: rgba(124, 196, 240, .32);
             background: linear-gradient(135deg, rgba(90, 150, 185, .26), rgba(116, 189, 234, .14)); }
.bubble.out { align-self: flex-start; border-bottom-left-radius: 6px; background: var(--panel-2); }
.bubble.unread { box-shadow: 0 0 0 2px rgba(116, 189, 234, .55), var(--shadow); }
.bubble-head { display: flex; align-items: center; gap: .55rem; }
.bubble-who { flex: 1; min-width: 0; display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.bubble-who strong { color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble-head time { white-space: nowrap; }
.bubble-head .star { width: 28px; height: 28px; }
.badge-in { color: #bfe6ff; background: rgba(116, 189, 234, .18); }
.badge-out { color: #c9d3e4; background: rgba(148, 178, 222, .16); }
.bubble-to { margin: .15rem 0 .5rem 2.3rem; }
.bubble-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; color: var(--text); line-height: 1.55; }
.bubble .attachments { margin-top: .6rem; }
.bubble-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .7rem; padding-top: .6rem; border-top: 1px solid var(--line); }
@media (max-width: 899.98px) {
  .bubble { max-width: 94%; min-width: 0; padding: .65rem .75rem; }
  .bubble-to { margin-left: 0; }
  .bubble-actions .btn { flex: 1 1 auto; }
}
.reading-pane .message-view .msg-head .actions { padding-left: 0; }
@media (max-width: 899.98px) { .message-view .msg-head .actions { padding-left: 0; } }

/* Conversations entry in the mail menu */
.modnav-sep { border: 0; border-top: 1px solid var(--line); margin: .35rem .9rem; }
.sent-mark { display: inline-flex; vertical-align: -3px; margin-right: .35rem; color: var(--muted); }
.sent-mark .i { width: 14px; height: 14px; }

/* every person writing to us gets their own bubble colour (c0 = the first one, as before) */
.bubble.in.c1 { border-color: rgba(60, 207, 160, .38); background: linear-gradient(135deg, rgba(40, 160, 130, .28), rgba(60, 207, 160, .12)); }
.bubble.in.c2 { border-color: rgba(167, 139, 250, .4); background: linear-gradient(135deg, rgba(124, 92, 220, .3), rgba(167, 139, 250, .12)); }
.bubble.in.c3 { border-color: rgba(243, 181, 74, .4); background: linear-gradient(135deg, rgba(200, 140, 40, .28), rgba(243, 181, 74, .1)); }
.bubble.in.c4 { border-color: rgba(244, 114, 182, .4); background: linear-gradient(135deg, rgba(200, 70, 140, .28), rgba(244, 114, 182, .1)); }
.bubble.in.c5 { border-color: rgba(132, 204, 22, .38); background: linear-gradient(135deg, rgba(100, 160, 20, .26), rgba(132, 204, 22, .1)); }
.bubble.in.c1 .avatar { background: linear-gradient(135deg, #2fb592, #6ee7c4); }
.bubble.in.c2 .avatar { background: linear-gradient(135deg, #8b6cf0, #c4b5fd); }
.bubble.in.c3 .avatar { background: linear-gradient(135deg, #e0a33a, #f7cf7d); }
.bubble.in.c4 .avatar { background: linear-gradient(135deg, #e0559f, #f9a8d4); }
.bubble.in.c5 .avatar { background: linear-gradient(135deg, #79b41d, #bef264); }
.bubble.out .avatar { background: linear-gradient(135deg, #5b6a86, #94a3bd); }
.bubble-subject { margin: .35rem 0 0; font-weight: 650; color: #fff; font-size: .9rem; }

/* HTML mail inside a conversation bubble: rendered as written, the frame grows to the mail height */
.bubble.has-html { width: min(88%, 1100px); }
.bubble .fit-frame { display: block; width: 100%; height: 180px; margin: .55rem 0 0; border: 0; border-radius: 12px;
                     background: #fff; box-shadow: none; }
.bubble .images-blocked { margin-top: .5rem; }
@media (max-width: 899.98px) { .bubble.has-html { width: 100%; max-width: 100%; } }

/* "Show older" at the top of a conversation */
.load-older { display: flex; align-items: center; justify-content: center; gap: .7rem; padding: .3rem 0 .2rem; }
.load-older .btn[aria-busy] { opacity: .6; pointer-events: none; }

/* conversations keep their own scroll anchor (static/js/mail.js) — the browser's would fight it */
.reading-pane { overflow-anchor: none; }
html:has([data-region="conversation"]) { overflow-anchor: none; }

/* ── Mailbox storage use (mail drawer + settings) ── */
.mail-usage { display: grid; gap: .35rem; margin: 1rem .75rem .5rem; padding: .6rem .7rem; border-radius: 10px;
  color: var(--muted); font-size: .78rem; text-decoration: none; border: 1px solid var(--line); }
.mail-usage:hover { color: var(--text-2); border-color: var(--line-2); }
.mail-usage.warn { color: var(--amber); border-color: rgba(243, 181, 74, .35); }
.mail-usage.full { color: var(--red); border-color: rgba(240, 106, 111, .45); }
.usage-bar, .mail-usage progress { width: 100%; height: 6px; border: 0; border-radius: 999px; overflow: hidden;
  background: var(--panel-3); appearance: none; -webkit-appearance: none; }
.usage-bar::-webkit-progress-bar, .mail-usage progress::-webkit-progress-bar { background: var(--panel-3); border-radius: 999px; }
.usage-bar::-webkit-progress-value, .mail-usage progress::-webkit-progress-value { background: var(--grad); border-radius: 999px; }
.usage-bar::-moz-progress-bar, .mail-usage progress::-moz-progress-bar { background: var(--grad); border-radius: 999px; }
.warn > .usage-bar::-webkit-progress-value, .mail-usage.warn progress::-webkit-progress-value { background: var(--amber); }
.warn > .usage-bar::-moz-progress-bar, .mail-usage.warn progress::-moz-progress-bar { background: var(--amber); }
.full > .usage-bar::-webkit-progress-value, .mail-usage.full progress::-webkit-progress-value { background: var(--red); }
.full > .usage-bar::-moz-progress-bar, .mail-usage.full progress::-moz-progress-bar { background: var(--red); }
.usage-cell { display: grid; gap: .3rem; min-width: 11rem; }
.usage-cell.warn .usage-text { color: var(--amber); }
.usage-cell.full .usage-text { color: var(--red); }
.usage-folders { margin: .2rem 0 0; padding: 0; list-style: none; }
.usage-folders li { display: flex; justify-content: space-between; gap: 1rem; }
.quota-form input { width: 5.5rem; }

/* ── Compose: limit warnings before sending ── */
.cf-warnings { padding: .35rem 1rem 0; flex: none; display: grid; gap: .3rem; }
.cf-warnings:not(:has(.cf-warn:not([hidden]))) { display: none; }
.cf-warn { margin: 0; padding: .4rem .65rem; border-radius: 8px; color: var(--amber);
  background: rgba(243, 181, 74, .1); border: 1px solid rgba(243, 181, 74, .3); }
.cf-warn.full { color: var(--red); background: rgba(240, 106, 111, .1); border-color: rgba(240, 106, 111, .35); }
.cf-send:disabled { opacity: .5; cursor: not-allowed; }

/* ── Attachment preview (eye button + viewer dialog) ── */
.att-preview { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  color: var(--muted); border: 1px solid var(--line); }
.att-preview:hover, .att-preview:focus-visible { color: var(--accent-strong); border-color: var(--line-2); background: rgba(255, 255, 255, .05); }
.att-preview .i { width: 17px; height: 17px; }
.att-viewer { width: min(1100px, 96vw); height: min(92vh, 1400px); max-width: none; max-height: none; padding: 0;
  border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel-solid); color: var(--text);
  display: none; flex-direction: column; overflow: hidden; }
.att-viewer[open] { display: flex; }
.att-viewer::backdrop { background: rgba(3, 6, 12, .72); }
.att-viewer-bar { display: flex; align-items: center; gap: .4rem; padding: .4rem .5rem .4rem .8rem; border-bottom: 1px solid var(--line); flex: none; }
.att-viewer-bar .icon-btn { width: 34px; height: 34px; font-size: 1.15rem; }
.att-viewer-bar .icon-btn:disabled { opacity: .35; cursor: default; }
.att-viewer-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.att-viewer-body { flex: 1; min-height: 0; display: grid; place-items: center; background: #1a1f29; overflow: auto; }
iframe.att-viewer-content { width: 100%; height: 100%; border: 0; background: #fff; }
img.att-viewer-content { max-width: 100%; max-height: 100%; object-fit: contain; }
@media (max-width: 700px) {
  .att-viewer { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
  .att-viewer-bar [data-viewer="tab"] { display: none; }
}
