:root {
  --bg: #0a1022; --card: #131c33; --raised: #1c2642; --text: #eef2fb; --muted: #93a0bd;
  --blue: #4f7cff; --green: #3ccf8e; --amber: #f5b544; --red: #ff5d6c; --line: rgba(255,255,255,.08);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button { background: var(--raised); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button:hover, .button:hover { filter: brightness(1.15); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--blue); border-color: transparent; font-weight: 600; }
button.danger { color: var(--red); }
button.wide { width: 100%; }
button.link { background: none; border: none; padding: 4px; color: var(--blue); }
button.icon { background: none; border: none; padding: 6px 9px; font-size: 18px; border-radius: 8px; min-width: 36px; }
button.icon:hover { background: var(--raised); }
button.apple { background: #fff; color: #000; }
.small { font-size: 13px; }
button.small, .button.small { padding: 6px 10px; }
input, select, textarea { background: var(--raised); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); }
.muted { color: var(--muted); }
.error { color: var(--red); margin: 0; }
.error.ok { color: var(--green); }
.tight { margin: 0; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }

/* sign in / setup cards */
.center { min-height: 100%; display: grid; place-items: center; padding: 20px 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px; display: grid; gap: 12px; }
.narrow { width: 100%; max-width: 400px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(135deg, #4f7cff, #3ccf8e); font-weight: 800; font-size: 16px; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; }

/* three panes */
#app { display: grid; grid-template-columns: 220px minmax(300px, 400px) 1fr; height: 100vh; height: 100dvh; }
#sidebar { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; padding: 16px 12px; padding-top: max(16px, env(safe-area-inset-top)); min-height: 0; }
.side-brand { padding: 0 4px; }
#folders { display: grid; gap: 2px; overflow-y: auto; flex: 1; align-content: start; }
.folder { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; cursor: pointer; background: none; border: none; justify-content: flex-start; width: 100%; text-align: left; }
.folder:hover { background: var(--raised); filter: none; }
.folder.on { background: rgba(79,124,255,.18); }
.folder .ico { width: 20px; text-align: center; }
.folder .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { font-size: 12px; color: var(--blue); font-weight: 700; }
.folder.nested { padding-left: 28px; }
.side-foot { display: grid; gap: 2px; padding: 0 4px; padding-bottom: env(safe-area-inset-bottom); word-break: break-all; }
.side-foot .link { justify-self: start; padding-left: 0; }

#listPane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pane-head { display: flex; align-items: center; gap: 6px; padding: 12px 12px 8px; padding-top: max(12px, env(safe-area-inset-top)); }
.pane-head h2, .pane-head h3 { margin: 0; flex: 1; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-head h3 { font-size: 17px; text-align: center; }
.search { padding: 0 12px 8px; }
.bulk { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 0 12px 8px; }
.bulk span { font-size: 13px; color: var(--muted); margin-right: auto; }
.list { overflow-y: auto; flex: 1; }
.row { display: grid; grid-template-columns: 18px 1fr auto; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.row:hover { background: rgba(255,255,255,.03); }
.row.on { background: rgba(79,124,255,.16); }
.row .dot { grid-row: 1 / span 3; padding-top: 6px; }
.row .dot i { display: block; width: 9px; height: 9px; border-radius: 50%; background: var(--blue); }
.row.seen .dot i { background: transparent; }
.row .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.seen .who { font-weight: 500; }
.row .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.row .subj { grid-column: 2 / span 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.row .tags { grid-column: 2 / span 2; font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.row .flag { color: var(--amber); }
.row input[type=checkbox] { position: absolute; left: 10px; bottom: 10px; width: 14px; height: 14px; padding: 0; margin: 0; }
.list-foot { padding: 10px 12px; text-align: center; font-size: 13px; color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; }

#readPane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#reader { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.reader-head { border-bottom: 1px solid var(--line); padding-bottom: 10px; flex-wrap: wrap; }
.reader-head select { width: auto; max-width: 150px; padding: 6px 8px; font-size: 13px; }
.reader-body { overflow-y: auto; flex: 1; padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 12px; }
#rSubject { margin: 0; font-size: 22px; line-height: 1.25; word-break: break-word; }
.rmeta { display: flex; gap: 12px; align-items: flex-start; }
.rmeta .muted { overflow-wrap: anywhere; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--raised); flex: none; }
.notice { background: rgba(245,181,68,.12); border: 1px solid rgba(245,181,68,.3); border-radius: 10px; padding: 8px 12px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.att { display: inline-flex; align-items: center; gap: 8px; background: var(--raised); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font-size: 13px; max-width: 100%; }
.att .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.att .x { background: none; border: none; padding: 0 2px; color: var(--muted); }
#rHtml { width: 100%; border: 0; border-radius: 12px; background: #fff; min-height: 200px; flex: none; }
#rText { white-space: pre-wrap; word-break: break-word; font: inherit; margin: 0; }

/* sheets */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.sheet-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 8px 16px 16px; display: grid; gap: 10px; max-height: 100%; overflow-y: auto; }
.sheet-card .pane-head { padding: 8px 0; }
.compose { width: 100%; max-width: 720px; height: min(720px, 100%); grid-template-rows: auto auto auto auto auto 1fr auto auto auto; }
.field { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.field label { color: var(--muted); font-size: 14px; width: 60px; flex: none; }
.field input { background: none; border: none; padding: 9px 0; }
#cBody { min-height: 200px; resize: none; height: 100%; }
.compose-foot { display: flex; align-items: center; gap: 8px; }

#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--raised); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; z-index: 20; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: calc(100% - 32px); }
#toast.bad { color: var(--red); }

.only-phone { display: none; }

/* tablet: folders slide over */
@media (max-width: 1000px) {
  #app { grid-template-columns: minmax(280px, 360px) 1fr; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  #app.menu #sidebar { transform: none; box-shadow: 10px 0 40px rgba(0,0,0,.5); }
  .only-phone { display: inline-flex; }
  #backBtn { display: none; }
}
/* phone: one pane at a time */
@media (max-width: 700px) {
  #app { grid-template-columns: 1fr; }
  #listPane { border-right: none; }
  #readPane { display: none; }
  #app.reading #listPane { display: none; }
  #app.reading #readPane { display: flex; }
  #backBtn { display: inline-flex; }
  .reader-body { padding: 14px 16px 40px; }
  .reader-head { gap: 0; flex-wrap: nowrap; }
  .reader-head button.icon { min-width: 32px; padding: 6px 4px; font-size: 17px; }
  .reader-head select { max-width: 72px; }
  #rFromAddr { display: block; }
  .rmeta { flex-wrap: wrap; }
  #rDate { flex-basis: 100%; padding-left: 50px; }
  .sheet { padding: 0; }
  .sheet-card { border-radius: 0; height: 100%; max-height: none; width: 100%; padding-top: env(safe-area-inset-top); }
  .compose { height: 100%; }
}
