/* Tinderbox Labs Mail -- styles. No external resources (CSP: style-src 'self'). */
:root {
  --bg: #f4f5f8; --panel: #ffffff; --panel2: #fafbfc; --text: #1d2330; --muted: #646d7e; --line: #dde1e8;
  --accent: #b5452a; --accent-text: #ffffff; --accent-soft: #fbe9e4; --sel: #fdf0ec; --unread: #1d2330;
  --danger: #b3261e; --ok: #2e7d4f; --shadow: 0 8px 30px rgba(0,0,0,.18);
  --top: 56px; --side: 230px; --listw: 380px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111419; --panel: #1a1e25; --panel2: #161a20; --text: #e5e8ee; --muted: #9aa3b2; --line: #2e3540;
    --accent: #e3714f; --accent-text: #15181d; --accent-soft: #3a2621; --sel: #2c211e; --unread: #ffffff;
    --danger: #ff8a80; --ok: #7fd49c; --shadow: 0 8px 30px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: .45rem .8rem; min-height: 36px; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.danger { color: var(--danger); }
button.small, select.small { padding: .25rem .6rem; min-height: 32px; font-size: .88rem; }
button.icon { border: 0; background: transparent; font-size: 1.25rem; min-width: 40px; padding: .2rem .5rem; }
button.link { border: 0; background: none; color: var(--accent); padding: 0 .25rem; min-height: 0; text-decoration: underline; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; min-height: 38px; }
input:focus, select:focus, textarea:focus, button:focus-visible, [contenteditable]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.grow { flex: 1; }
.hint { color: var(--muted); font-size: .88rem; }
.empty { color: var(--muted); text-align: center; padding: 3rem 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .5rem 0; }
.row input[type=search] { flex: 1 1 12rem; }
.check { display: inline-flex; align-items: center; gap: .45rem; }
.check input { min-height: 0; width: 18px; height: 18px; }
[hidden] { display: none !important; }
.noscript { padding: 2rem; text-align: center; }

/* ---------- sign in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.75rem 1.5rem; text-align: center; }
.login-logo img { display: block; width: min(260px, 80%); height: auto; margin: 0 auto; }
.login-card h1 { font-size: 1.05rem; font-weight: 600; letter-spacing: .25em; text-transform: uppercase; color: var(--muted); margin: .35rem 0 1.1rem; }
.login-card label:not(.check) { display: block; text-align: left; font-weight: 600; margin: .8rem 0; }
.login-card label input:not([type=checkbox]) { display: block; width: 100%; margin-top: .3rem; }
.login-card .check { text-align: left; margin: .4rem 0 1rem; display: flex; }
.login-card button.primary { width: 100%; min-height: 44px; }
.error { color: var(--danger); }
.pw-wrap { display: flex; gap: .4rem; margin-top: .3rem; }
.pw-wrap input { flex: 1; min-width: 0; margin-top: 0 !important; }
.pw-eye { flex: none; min-width: 4.2rem; }

/* ---------- layout ---------- */
.app { height: 100%; display: grid; grid-template-rows: calc(var(--top) + var(--safe-t)) 1fr; grid-template-columns: var(--side) 1fr; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: .5rem; padding: var(--safe-t) .75rem 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; flex: none; width: calc(var(--side) - 1.5rem); min-height: 40px; }
.brand img { display: block; height: 30px; width: auto; }
.brand .brand-icon { display: none; border-radius: 7px; }
.title { font-size: 1.1rem; margin: 0; min-width: 0; flex: 0 1 auto; width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { flex: 1; max-width: 560px; }
.search input { width: 100%; border-radius: 20px; background: var(--panel2); }
.live { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.live.on { background: var(--ok); }
.sidebar { background: var(--panel2); border-right: 1px solid var(--line); padding: .75rem .5rem; overflow-y: auto; }
.compose-btn { width: 100%; min-height: 44px; margin-bottom: .75rem; }
.folders { list-style: none; margin: 0; padding: 0; }
.folder { width: 100%; display: flex; align-items: center; gap: .55rem; border: 0; background: none; text-align: left; border-radius: 8px; padding: .45rem .6rem; min-height: 40px; }
.folder:hover { background: var(--sel); }
.folder.active { background: var(--accent-soft); font-weight: 600; }
.folder .ico { width: 1.3rem; text-align: center; flex: none; }
.folder .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { font-size: .8rem; font-weight: 700; color: var(--accent); }
.folder .del { visibility: hidden; border: 0; background: none; color: var(--muted); padding: 0 .2rem; min-height: 0; }
.folder:hover .del { visibility: visible; }
.sidebar hr { border: 0; border-top: 1px solid var(--line); margin: .75rem .25rem; }
.me { color: var(--muted); font-size: .8rem; padding: .25rem .6rem; word-break: break-all; }
.panes { display: grid; grid-template-columns: var(--listw) 1fr; min-height: 0; min-width: 0; }
.pane { min-height: 0; min-width: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--panel); }
.list-pane { border-right: 1px solid var(--line); }
.page { grid-column: 1 / -1; overflow-y: auto; padding: 1rem 1.25rem calc(1rem + var(--safe-b)); display: block; }
.page h2 { margin: 0 0 .75rem; }
.only-mobile { display: none; }

/* ---------- message list ---------- */
.list-tools { display: flex; align-items: center; gap: .4rem; padding: .4rem .6rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bulk { display: inline-flex; gap: .3rem; flex-wrap: wrap; }
.pager { display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; color: var(--muted); }
.msglist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.msg { display: grid; grid-template-columns: auto 1fr auto; gap: .1rem .6rem; padding: .6rem .7rem; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.msg:hover { background: var(--panel2); }
.msg.active { background: var(--sel); box-shadow: inset 3px 0 var(--accent); }
.msg .sel { grid-row: 1 / span 3; align-self: center; }
.msg .sel input { width: 18px; height: 18px; min-height: 0; }
.msg .who { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .when { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.msg .subj { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.msg .prev { grid-column: 2 / 4; color: var(--muted); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .who, .msg.unread .subj { font-weight: 700; color: var(--unread); }
.msg.unread { box-shadow: inset 3px 0 var(--accent); }
.msg .badges { font-size: .8rem; margin-left: .25rem; }
.star { color: #e6a700; }

/* ---------- reader ---------- */
.read-pane { overflow-y: auto; }
.reader { display: flex; flex-direction: column; min-height: 100%; }
.read-tools { display: flex; gap: .35rem; padding: .5rem .75rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; position: sticky; top: 0; background: var(--panel); z-index: 2; }
.r-subject { font-size: 1.25rem; margin: .9rem 1rem .4rem; overflow-wrap: anywhere; }
.r-head { padding: 0 1rem .6rem; border-bottom: 1px solid var(--line); }
.r-from { overflow-wrap: anywhere; }
.r-meta { font-size: .85rem; display: flex; gap: .75rem; flex-wrap: wrap; justify-content: space-between; margin-top: .2rem; overflow-wrap: anywhere; }
.banner { background: var(--accent-soft); padding: .5rem 1rem; font-size: .88rem; }
.atts { display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem 1rem 0; }
.atts a { display: inline-flex; gap: .35rem; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: .3rem .6rem; text-decoration: none; color: var(--text); font-size: .88rem; max-width: 100%; }
.atts a .sz { color: var(--muted); }
.r-body { flex: 1; display: flex; flex-direction: column; min-height: 300px; }
.r-body iframe { flex: 1; width: 100%; border: 0; background: #fff; min-height: 60vh; }
.r-text { white-space: pre-wrap; overflow-wrap: anywhere; padding: 1rem; margin: 0; font: inherit; }

/* ---------- contacts / settings ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tab { border: 0; border-radius: 0; background: var(--panel); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.clist { list-style: none; padding: 0; margin: .5rem 0; }
.clist li { display: flex; gap: .75rem; align-items: center; padding: .6rem .25rem; border-bottom: 1px solid var(--line); }
.clist .avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.clist .info { flex: 1; min-width: 0; }
.clist .info div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.io { margin-top: 1.5rem; }
.form { display: flex; flex-direction: column; gap: .2rem; max-width: 36rem; }
.form label:not(.check) { display: flex; flex-direction: column; gap: .25rem; font-weight: 600; margin: .45rem 0; }
.form .check { margin: .45rem 0; }
.form > button { align-self: flex-start; margin-top: .5rem; }
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 1.25rem; background: var(--panel); color: var(--text); width: min(32rem, 94vw); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog h3 { margin-top: 0; }

/* ---------- compose ---------- */
.compose { position: fixed; inset: auto 1.25rem 0 auto; width: min(680px, 96vw); height: min(640px, 88vh); z-index: 20; }
.compose-card { height: 100%; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px 12px 0 0; box-shadow: var(--shadow); overflow: hidden; }
.compose-head { display: flex; align-items: center; gap: .6rem; padding: .4rem .5rem .4rem 1rem; background: var(--panel2); border-bottom: 1px solid var(--line); }
.cmp-fields { border-bottom: 1px solid var(--line); }
.field { display: flex; align-items: center; gap: .5rem; padding: 0 .75rem; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field > span { width: 4.2rem; color: var(--muted); font-size: .88rem; flex: none; }
.field input, .field select { flex: 1; border: 0; background: transparent; border-radius: 0; min-width: 0; }
.field input:focus, .field select:focus { outline: 0; }
.editor-tools { display: flex; gap: .2rem; padding: .3rem .5rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.editor-tools button:not(.link) { min-width: 34px; min-height: 32px; padding: .1rem .45rem; background: transparent; }
.editor { flex: 1; overflow-y: auto; padding: .9rem 1rem; outline: 0; min-height: 8rem; border: 0; border-radius: 0; resize: none; overflow-wrap: anywhere; }
.editor.plain { font: inherit; width: 100%; background: var(--panel); }
.editor blockquote { margin: 0 0 0 .4em; padding-left: .8em; border-left: 3px solid var(--line); color: var(--muted); }
.cmp-atts { list-style: none; margin: 0; padding: .3rem .75rem; display: flex; gap: .4rem; flex-wrap: wrap; }
.cmp-atts:empty { display: none; }
.cmp-atts li { border: 1px solid var(--line); border-radius: 8px; padding: .2rem .3rem .2rem .6rem; font-size: .85rem; display: inline-flex; gap: .35rem; align-items: center; max-width: 100%; }
.cmp-atts li.up { opacity: .6; }
.cmp-atts li button { border: 0; background: none; min-height: 0; padding: 0 .3rem; }
.compose-foot { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem calc(.55rem + var(--safe-b)); border-top: 1px solid var(--line); }
.compose-foot .primary { min-width: 6rem; min-height: 40px; }
.attach-btn { cursor: pointer; border: 1px solid var(--line); border-radius: 8px; padding: .35rem .7rem; }
.compose.drag .compose-card { outline: 3px dashed var(--accent); outline-offset: -6px; }
.ac { position: fixed; z-index: 40; list-style: none; margin: 0; padding: .25rem 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; min-width: 240px; }
.ac li { padding: .45rem .8rem; cursor: pointer; }
.ac li.on, .ac li:hover { background: var(--sel); }
.ac li small { color: var(--muted); display: block; }

.toast { position: fixed; left: 50%; bottom: calc(1.25rem + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 60; max-width: 92vw; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }
.fab { position: fixed; right: 1rem; bottom: calc(1rem + var(--safe-b)); width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-text); border: 0; font-size: 1.4rem; box-shadow: var(--shadow); z-index: 15; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }

/* ---------- narrow screens: one pane at a time ---------- */
@media (max-width: 900px) {
  .only-mobile { display: inline-flex; align-items: center; justify-content: center; }
  .app { grid-template-columns: 1fr; }
  .title { width: auto; flex: 0 1 auto; }
  .brand { width: auto; }
  .brand .brand-full { display: none; }
  .brand .brand-icon { display: block; height: 30px; }
  body[data-view="message"] .brand, body[data-view="contacts"] .brand, body[data-view="settings"] .brand { display: none; }
  .search { flex: 1 1 auto; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(80vw, 300px); z-index: 30; transform: translateX(-105%); transition: transform .2s ease; padding-top: calc(.75rem + var(--safe-t)); }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .panes { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; }
  body[data-view="message"] .list-pane, body[data-view="list"] .read-pane { display: none; }
  .msg { padding: .7rem .8rem; }
  .compose { inset: 0; width: 100%; height: 100%; }
  .compose-card { border-radius: 0; border: 0; padding-top: var(--safe-t); }
  .read-tools { gap: .25rem; }
  .page { padding: .9rem .9rem calc(5rem + var(--safe-b)); }
}
@media (max-width: 520px) {
  .search input { padding: .4rem .6rem; }
  .title { max-width: 30vw; }
  .read-tools button.small, .read-tools select.small { padding: .2rem .45rem; }
}
@media (min-width: 901px) {
  body[data-view="message"] .read-pane .empty { display: none; }
}
