:root {
  --bg: #f4f6f9; --surface: #ffffff; --text: #17212b; --muted: #6b7a89; --line: #e1e6ec;
  --brand: #0f2a43; --accent: #1f7ae0; --accent-text: #ffffff; --unread: #e8f1fc; --danger: #c62828; --gold: #c9a227;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d141b; --surface: #16202a; --text: #e8eef4; --muted: #93a3b3; --line: #243240;
    --brand: #0a1a2a; --unread: #1a2b3d; --accent: #4a9bf0; --accent-text: #08121c; --danger: #ef6a6a;
  }
}
@media (prefers-color-scheme: dark) { :root { --brand: #0a1a2a; } }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
#app { height: 100%; display: flex; flex-direction: column; }

.hdr {
  background: var(--brand); color: #fff; display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px; min-height: 52px; flex: none;
}
.hdr h1 { font-size: 18px; margin: 0 0 0 4px; flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib {
  background: none; border: 0; color: inherit; width: 44px; height: 44px; border-radius: 50%;
  font-size: 22px; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.ib:active { background: rgba(255,255,255,.15); }
.ib[disabled] { opacity: .4; }

.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--surface); }
.row {
  display: block; width: 100%; text-align: left; background: var(--surface); border: 0;
  border-bottom: 1px solid var(--line); padding: 10px 14px; position: relative;
}
.row:active { background: var(--bg); }
.row.unread { background: var(--unread); }
.row.unread .r-from, .row.unread .r-subj { font-weight: 700; }
.r-top { display: flex; gap: 8px; align-items: baseline; }
.r-from { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-date { color: var(--muted); font-size: 12px; flex: none; }
.r-subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.r-prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-star { color: var(--gold); margin-right: 4px; }
.empty, .state { color: var(--muted); text-align: center; padding: 48px 20px; }
.more { display: block; margin: 12px auto; padding: 10px 22px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); }

.fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); height: 56px; padding: 0 20px;
  border: 0; border-radius: 28px; background: var(--accent); color: var(--accent-text); font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); font-size: 16px;
}

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(84vw, 320px); background: var(--surface); z-index: 21;
  display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); overflow-y: auto;
}
.d-user { background: var(--brand); color: #fff; padding: 22px 16px 16px; word-break: break-all; }
.d-user b { display: block; font-size: 13px; opacity: .7; font-weight: 400; }
.d-item {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 16px; background: none; border: 0; text-align: left;
}
.d-item.on { background: var(--unread); color: var(--accent); font-weight: 600; }
.d-item .cnt { margin-left: auto; font-size: 13px; color: var(--muted); }
.d-sep { height: 1px; background: var(--line); margin: 6px 0; }
.d-lang { display: flex; gap: 8px; padding: 8px 16px; align-items: center; }
.d-lang button { padding: 6px 14px; border: 1px solid var(--line); border-radius: 16px; background: none; }
.d-lang button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.overlay { position: fixed; inset: 0; z-index: 10; background: var(--surface); display: flex; flex-direction: column; }
.reader { flex: 1; overflow-y: auto; padding: 14px 16px calc(env(safe-area-inset-bottom) + 24px); -webkit-overflow-scrolling: touch; }
.reader h2 { font-size: 20px; margin: 0 0 10px; word-break: break-word; }
.meta { font-size: 14px; color: var(--muted); margin-bottom: 14px; word-break: break-word; }
.meta b { color: var(--text); font-weight: 600; }
.txt { white-space: pre-wrap; word-break: break-word; }
iframe.html { width: 100%; border: 0; min-height: 120px; background: #fff; border-radius: 6px; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0; }
.atts { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.att { display: block; width: 100%; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 6px 0; word-break: break-all; }
.bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px); border-top: 1px solid var(--line); background: var(--surface); flex: none; }
.bar button { flex: 1 1 auto; padding: 10px 12px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; font-size: 14px; }
.bar .danger { color: var(--danger); }

.comp { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.f { display: flex; align-items: center; gap: 8px; padding: 2px 14px; border-bottom: 1px solid var(--line); }
.f label { color: var(--muted); width: 56px; flex: none; font-size: 14px; }
.f input { flex: 1; border: 0; background: none; padding: 12px 0; outline: none; min-width: 0; }
.f .lnk { background: none; border: 0; color: var(--accent); padding: 8px; }
.comp textarea { flex: 1; min-height: 240px; border: 0; background: none; padding: 14px; resize: none; outline: none; }
.send { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 20px; padding: 8px 16px; font-weight: 600; margin-right: 4px; }

.login { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; background: var(--brand); color: #fff; }
.login img { width: 96px; height: 96px; border-radius: 22px; }
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0; opacity: .75; max-width: 300px; }
.login .btn { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 26px; padding: 14px 40px; font-weight: 600; font-size: 17px; }
.login .err { color: #ffb4b4; max-width: 320px; word-break: break-word; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 18px; border-radius: 22px; z-index: 50; opacity: 0;
  transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; font-size: 14px;
}
#toast.on { opacity: .95; }
