/* Pleksy Mail. Signal Red + dark navy. Square, hairline, printed-matter feel: no glows, no gloss, no blobs. */
:root {
  --navy: #0e1f38; --navy-2: #16294a; --navy-3: #22385e; --navy-ink: #c9d3e3; --navy-faint: #7f8fa9;
  --paper: #f7f5f0; --surface: #ffffff; --raise: #efece5; --hover: #f1eee7; --sel: #e6ebf3;
  --line: #e2ddd3; --line-strong: #c9c2b4;
  --text: #0b0d12; --muted: #4f5563; --faint: #858a96;
  --accent: #d7192a; --accent-hi: #b9111f; --accent-lo: #fbe4e6; --on-accent: #fff;
  --ok: #157f4f; --warn: #a15c07; --danger: #a3111e;
  --r: 2px; --hard: 3px 3px 0 var(--navy);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --rail: 248px; --list: 408px; --bar: 56px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --navy: #070f1c; --navy-2: #0f1c31; --navy-3: #1b2c49; --navy-ink: #c9d3e3; --navy-faint: #73839c;
  --paper: #0b1424; --surface: #0f1a2d; --raise: #15233a; --hover: #142139; --sel: #1b2d4d;
  --line: #1f2f4a; --line-strong: #2d4064;
  --text: #eef1f6; --muted: #a4adbd; --faint: #737d8f;
  --accent: #ef3344; --accent-hi: #ff4d5c; --accent-lo: #3a0d14; --on-accent: #fff;
  --hard: 3px 3px 0 #000;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--text); font: 400 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; letter-spacing: -0.003em; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
::selection { background: var(--navy); color: #fff; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
svg.g { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: square; stroke-linejoin: miter; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail) var(--list) 1fr; height: 100dvh; }
.rail { background: var(--navy); color: var(--navy-ink); display: flex; flex-direction: column; min-height: 0; border-right: 1px solid #000; }
.brand { display: flex; align-items: center; gap: 10px; height: var(--bar); padding: 0 18px; border-bottom: 1px solid var(--navy-3); }
.brand img { width: 26px; height: 26px; border-radius: 6px; outline: 1px solid var(--navy-3); }
.brand b { color: #fff; font-size: 15px; letter-spacing: -0.02em; }
.brand span { color: var(--navy-faint); font-weight: 500; }
.compose-btn { margin: 16px 16px 10px; height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--accent); color: #fff; border: 1px solid #000; border-radius: var(--r); font-weight: 650; letter-spacing: -0.01em; cursor: pointer; box-shadow: 3px 3px 0 #000; transition: transform .06s, box-shadow .06s; }
.compose-btn:hover { background: var(--accent-hi); }
.compose-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.compose-btn kbd { margin-left: auto; font: 600 11px var(--mono); opacity: .7; }
.nav { padding: 6px 8px; overflow: auto; flex: 1; }
.nav h4 { margin: 18px 10px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--navy-faint); }
.nav button { width: 100%; display: flex; align-items: center; gap: 11px; height: 34px; padding: 0 10px; border: 0; background: none; color: var(--navy-ink); border-radius: var(--r); cursor: pointer; text-align: left; font-weight: 500; position: relative; }
.nav button:hover { background: var(--navy-2); color: #fff; }
.nav button[aria-current="true"] { background: var(--navy-3); color: #fff; font-weight: 650; }
.nav button[aria-current="true"]::before { content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px; width: 3px; background: var(--accent); }
.nav .count { margin-left: auto; font: 600 12px var(--font); font-variant-numeric: tabular-nums; color: #fff; }
.nav .addr { font-family: var(--mono); font-size: 12.5px; letter-spacing: -0.02em; }
.nav .addr i { font-style: normal; color: var(--navy-faint); }
.rail-foot { display: flex; gap: 4px; padding: 10px; border-top: 1px solid var(--navy-3); }
.rail-foot button { flex: 1; height: 34px; display: grid; place-items: center; background: none; border: 1px solid transparent; color: var(--navy-faint); border-radius: var(--r); cursor: pointer; }
.rail-foot button:hover { color: #fff; border-color: var(--navy-3); }

/* ---------- list ---------- */
.listpane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); border-right: 1px solid var(--line-strong); }
.topbar { height: var(--bar); display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--line-strong); background: var(--surface); }
.search { flex: 1; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; background: var(--paper); border: 1px solid var(--line-strong); border-radius: var(--r); }
.search:focus-within { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); background: var(--surface); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; height: 100%; }
.search svg { color: var(--faint); }
.iconbtn { height: 34px; min-width: 34px; display: inline-grid; place-items: center; padding: 0 8px; border: 1px solid transparent; background: none; border-radius: var(--r); color: var(--muted); cursor: pointer; }
.iconbtn:hover { border-color: var(--line-strong); color: var(--text); background: var(--hover); }
.iconbtn.on { color: var(--accent); }
.menu-btn { display: none; }
.listhead { display: flex; align-items: baseline; gap: 10px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.listhead h2 { margin: 0; font-size: 19px; letter-spacing: -0.03em; font-weight: 750; }
.listhead .meta { color: var(--faint); font-size: 12px; font-family: var(--mono); }
.listhead .grow { flex: 1; }
.list { flex: 1; overflow: auto; overscroll-behavior: contain; }
.row { display: grid; grid-template-columns: 14px 1fr auto; column-gap: 8px; row-gap: 1px; padding: 11px 14px 12px 10px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; background: var(--surface); }
.row:hover { background: var(--hover); }
.row[aria-selected="true"] { background: var(--sel); box-shadow: inset 3px 0 0 var(--navy); }
.row .dot { grid-row: 1; align-self: center; width: 8px; height: 8px; border-radius: 50%; }
.row.unread .dot { background: var(--accent); }
.row .who { grid-column: 2; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .who .n { color: var(--faint); font-weight: 500; font-size: 12px; margin-left: 4px; }
.row.unread .who { font-weight: 750; }
.row .when { grid-column: 3; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row.unread .when { color: var(--text); font-weight: 650; }
.row .subj { grid-column: 2 / 4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.row.unread .subj { font-weight: 650; }
.row .snip { grid-column: 2 / 4; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.row .tags { grid-column: 2 / 4; display: flex; gap: 6px; align-items: center; margin-top: 5px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 19px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: var(--r); font: 500 11px var(--mono); color: var(--muted); letter-spacing: -0.02em; background: var(--paper); }
.chip.navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.row .star { position: absolute; right: 12px; bottom: 9px; color: var(--accent); }
.row .clip { color: var(--faint); }
.row .clip svg, .row .star svg { width: 14px; height: 14px; }
.more { margin: 14px auto; display: block; }
.empty { padding: 56px 28px; text-align: left; color: var(--muted); }
.empty .seat { width: 44px; height: 44px; margin-bottom: 16px; }
.seatbig { width: 56px; height: 56px; color: var(--text); }
.empty .seat { color: var(--text); }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 17px; letter-spacing: -0.02em; }
.empty p { margin: 0; max-width: 32ch; }

/* skeleton */
.sk { padding: 13px 14px 13px 32px; border-bottom: 1px solid var(--line); }
.sk i { display: block; height: 10px; background: var(--raise); margin: 6px 0; animation: sk 1.2s ease-in-out infinite alternate; }
.sk i:nth-child(1) { width: 40%; } .sk i:nth-child(2) { width: 78%; } .sk i:nth-child(3) { width: 62%; }
@keyframes sk { to { opacity: .45; } }

/* ---------- reader ---------- */
.reader { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.readbar { height: var(--bar); display: flex; align-items: center; gap: 2px; padding: 0 14px; border-bottom: 1px solid var(--line-strong); background: var(--surface); }
.readbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.readbar .grow { flex: 1; }
.back-btn { display: none; }
.readscroll { flex: 1; overflow: auto; padding: 26px clamp(16px, 3vw, 40px) 60px; }
.thread-h { display: flex; align-items: flex-start; gap: 14px; margin: 0 0 20px; max-width: 920px; }
.thread-h h1 { margin: 0; font-size: clamp(20px, 2.1vw, 26px); line-height: 1.18; letter-spacing: -0.035em; font-weight: 760; flex: 1; overflow-wrap: anywhere; }
.msg { max-width: 920px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r); margin-bottom: 10px; }
.msg.open { box-shadow: var(--hard); border-color: var(--navy); margin-bottom: 16px; }
.msg-h { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; background: var(--navy); color: #fff; font-weight: 700; font-size: 14px; border-radius: var(--r); letter-spacing: -0.02em; }
.avatar.me { background: var(--accent); }
.msg-h .from { min-width: 0; }
.msg-h .from b { font-weight: 700; }
.msg-h .from .em { color: var(--faint); font-family: var(--mono); font-size: 12px; margin-left: 6px; }
.msg-h .to { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-h .date { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.msg:not(.open) .msg-h .to { display: none; }
.msg.open .snip-c { display: none; }
.msg .snip-c { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.msg-b { border-top: 1px solid var(--line); padding: 4px 0 0; }
.imgbar { display: flex; align-items: center; gap: 10px; margin: 10px 16px 0; padding: 8px 10px; background: var(--paper); border: 1px dashed var(--line-strong); font-size: 12.5px; color: var(--muted); }
.imgbar button { margin-left: auto; }
.msg-b iframe { display: block; width: 100%; border: 0; min-height: 60px; background: #fff; }
.msg-b pre { margin: 0; padding: 16px 18px 20px; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.6 var(--font); }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; border-top: 1px dashed var(--line); }
.att { display: flex; align-items: center; gap: 10px; min-width: 200px; max-width: 280px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--paper); text-decoration: none; }
.att:hover { border-color: var(--navy); }
.att .ext { width: 34px; height: 34px; display: grid; place-items: center; background: var(--navy); color: #fff; font: 700 9.5px var(--mono); text-transform: uppercase; flex: none; }
.att .nm { min-width: 0; }
.att .nm b { display: block; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att .nm span { color: var(--faint); font-size: 11.5px; font-family: var(--mono); }
.msg-f { display: flex; gap: 8px; padding: 0 16px 16px; }
.replybar { display: flex; gap: 10px; max-width: 920px; margin-top: 18px; }
.btn { height: 36px; display: inline-flex; align-items: center; gap: 8px; padding: 0 14px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--r); font-weight: 600; cursor: pointer; color: var(--text); text-decoration: none; }
.btn:hover { border-color: var(--navy); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: #000; color: #fff; box-shadow: 2px 2px 0 #000; }
.btn-primary:hover { background: var(--accent-hi); border-color: #000; }
.btn-navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .55; cursor: progress; }
.noread { height: 100%; display: grid; place-items: center; color: var(--faint); text-align: center; padding: 40px; }
.noread .big { font-size: 13px; letter-spacing: .14em; text-transform: uppercase; font-weight: 700; color: var(--muted); margin: 18px 0 6px; }
.noread kbd, .help kbd { display: inline-block; min-width: 20px; padding: 1px 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: var(--r); font: 600 11px var(--mono); background: var(--surface); color: var(--text); }

/* ---------- compose ---------- */
.compose { position: fixed; right: 24px; bottom: 0; width: min(600px, calc(100vw - 32px)); height: min(620px, calc(100dvh - 40px)); display: flex; flex-direction: column; background: var(--surface); border: 1px solid #000; border-bottom: 0; box-shadow: 5px 0 0 var(--navy), 0 -1px 0 #000; z-index: 40; }
.compose.min { height: auto; }
.compose.min .c-body { display: none; }
.c-head { height: 42px; display: flex; align-items: center; gap: 6px; padding: 0 6px 0 14px; background: var(--navy); color: #fff; cursor: default; }
.c-head b { flex: 1; font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-head .iconbtn { color: var(--navy-ink); height: 30px; min-width: 30px; }
.c-head .iconbtn:hover { color: #fff; background: var(--navy-3); border-color: transparent; }
.c-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.c-field { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.c-field label { width: 52px; color: var(--faint); font-size: 12.5px; flex: none; }
.c-field input, .c-field select { flex: 1; min-width: 0; height: 38px; border: 0; outline: 0; background: none; }
.c-field select { font-family: var(--mono); font-size: 13px; cursor: pointer; }
.c-field .linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12.5px; padding: 4px; }
.c-field .linkbtn:hover { color: var(--text); text-decoration: underline; }
.c-tools { display: flex; gap: 2px; padding: 4px 10px; border-bottom: 1px solid var(--line); background: var(--paper); }
.c-tools .iconbtn { height: 28px; min-width: 28px; font-weight: 700; font-size: 13px; }
.c-edit { flex: 1; overflow: auto; padding: 14px 16px; outline: 0; line-height: 1.55; font-size: 14.5px; }
.c-edit:empty::before { content: attr(data-ph); color: var(--faint); }
.c-edit blockquote { margin: 8px 0; padding-left: 12px; border-left: 2px solid var(--line-strong); color: var(--muted); }
.c-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.c-atts .chip button { border: 0; background: none; cursor: pointer; padding: 0 0 0 2px; color: var(--faint); }
.c-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.c-foot .grow { flex: 1; }
.c-foot .hint { color: var(--faint); font-size: 11.5px; font-family: var(--mono); }
.c-err { margin: 0 14px 8px; padding: 8px 10px; border: 1px solid var(--accent); background: var(--accent-lo); color: var(--text); font-size: 13px; }

/* ---------- dialogs / toast ---------- */
dialog { border: 1px solid #000; border-radius: var(--r); padding: 0; background: var(--surface); color: var(--text); box-shadow: 6px 6px 0 var(--navy); width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(7, 15, 28, .45); }
.dlg-h { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-h h3 { margin: 0; flex: 1; font-size: 16px; letter-spacing: -0.02em; }
.dlg-b { padding: 16px 18px; max-height: 70dvh; overflow: auto; }
.dlg-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--paper); }
.fld { display: block; margin-bottom: 14px; }
.fld > span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.fld input, .fld textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); }
.fld textarea { min-height: 70px; resize: vertical; font-size: 13.5px; }
.fld input:focus, .fld textarea:focus { outline: 0; border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); }
.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; }
.check small { display: block; color: var(--muted); }
.help table { width: 100%; border-collapse: collapse; }
.help td { padding: 6px 0; border-bottom: 1px solid var(--line); }
.help td:first-child { width: 110px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 16px; background: var(--navy); color: #fff; border: 1px solid #000; box-shadow: 3px 3px 0 #000; z-index: 60; font-weight: 500; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 0; color: #ffb3ba; font-weight: 700; cursor: pointer; text-transform: uppercase; font-size: 12px; letter-spacing: .08em; }
.fab { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--rail) 1fr; }
  .shell .reader { display: none; }
  .shell.reading .listpane { display: none; }
  .shell.reading .reader { display: flex; }
  .back-btn { display: inline-grid; }
}
@media (max-width: 760px) {
  :root { --bar: 54px; }
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; inset: 0 auto 0 0; width: min(300px, 84vw); z-index: 50; transform: translateX(-102%); transition: transform .18s ease-out; }
  .shell.nav-open .rail { transform: none; box-shadow: 6px 0 0 rgba(0, 0, 0, .35); }
  .scrim { position: fixed; inset: 0; background: rgba(7, 15, 28, .45); z-index: 45; }
  .menu-btn { display: inline-grid; }
  .row { padding: 12px 12px 13px 8px; }
  .readscroll { padding: 18px 10px 90px; }
  .msg.open { box-shadow: 2px 2px 0 var(--navy); }
  .msg-h { grid-template-columns: 34px 1fr auto; padding: 10px; gap: 10px; }
  .avatar { width: 34px; height: 34px; }
  .msg-h .from .em { display: none; }
  .compose { inset: 0; width: 100%; height: 100dvh; border: 0; box-shadow: none; }
  .fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: 18px; width: 56px; height: 56px; background: var(--accent); color: #fff; border: 1px solid #000; box-shadow: 3px 3px 0 #000; border-radius: var(--r); z-index: 30; }
  .shell.reading ~ .fab { display: none; }
  .replybar .btn span { display: none; }
  .att { min-width: 0; max-width: 100%; flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
