:root {
  --bg: #f6f7fb; --panel: #ffffff; --panel-2: #f1f3f8; --border: #e3e6ee; --text: #1c2230; --muted: #6b7385;
  --accent: #2563eb; --accent-soft: #e8efff; --accent-text: #fff; --danger: #dc2626; --star: #f59e0b;
  --unread: #0f172a; --hover: #f3f5fa; --selected: #e8efff; --shadow: 0 10px 40px rgba(15, 23, 42, .18);
  --radius: 10px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --panel: #161a22; --panel-2: #1c212b; --border: #262c38; --text: #e5e8ef; --muted: #8b93a6;
    --accent: #4f8cff; --accent-soft: #1d2a45; --unread: #ffffff; --hover: #1b202a; --selected: #1d2a45;
    --shadow: 0 10px 40px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* ── buttons ─────────────────────────────────────────────── */
.btn { border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer; background: var(--panel-2); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
select.btn { appearance: auto; }
.icon-btn { border: 0; background: transparent; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 0; font-size: 13px; }
.chip { border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }

/* ── login ───────────────────────────────────────────────── */
.login-view { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; margin: 4px 0 6px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card label.check { flex-direction: row; align-items: center; gap: 8px; }
.login-card input[type=email], .login-card input[type=password], .dialog input:not([type=checkbox]), .dialog textarea {
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 10px 12px; color: var(--text); font-size: 14px; width: 100%;
}
.login-card input:focus, .dialog input:focus, .dialog textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 0; text-align: center; }
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--accent); }
.brand svg { width: 26px; height: 26px; }
.brand.small svg { width: 22px; height: 22px; }

/* ── layout ──────────────────────────────────────────────── */
.app { height: 100%; display: grid; grid-template-columns: 230px minmax(320px, 420px) 1fr; grid-template-rows: 56px 1fr;
  grid-template-areas: "top top top" "side list read"; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar .brand { width: 198px; }
.search { flex: 1; max-width: 640px; }
.search input { width: 100%; border: 1px solid transparent; background: var(--panel-2); border-radius: 999px; padding: 9px 16px; }
.search input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.account { position: relative; margin-left: auto; }
.avatar-btn { border: 0; background: none; padding: 0; cursor: pointer; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 600; font-size: 13px; color: #fff; background: var(--accent); flex-shrink: 0; text-transform: uppercase; }
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.menu { position: absolute; right: 0; top: 42px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); min-width: 240px; padding: 6px; z-index: 40; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu-head { padding: 8px 10px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; word-break: break-all; }

.sidebar { grid-area: side; padding: 14px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.compose-btn { padding: 12px 18px; border-radius: 14px; font-size: 15px; box-shadow: 0 2px 6px rgba(37, 99, 235, .25); align-self: flex-start; margin: 0 4px 6px; }
.folders { display: flex; flex-direction: column; gap: 1px; }
.folder { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 0 18px 18px 0; cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--selected); color: var(--accent); font-weight: 600; }
.folder .ico { width: 20px; text-align: center; }
.folder .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { font-size: 12px; font-weight: 600; }
.folder.drop { outline: 2px dashed var(--accent); }
.sidebar .link-btn { align-self: flex-start; padding-left: 12px; }
.quota { margin-top: auto; padding: 12px; font-size: 12px; color: var(--muted); }
.quota-bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
#quota-fill { height: 100%; background: var(--accent); width: 0; }

/* ── list ────────────────────────────────────────────────── */
.list-pane { grid-area: list; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--border); border-left: 1px solid var(--border); min-height: 0; }
.list-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list-head h2 { font-size: 16px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filters { display: flex; gap: 4px; }
.bulk-bar { display: flex; gap: 6px; align-items: center; padding: 8px 14px; background: var(--accent-soft); flex-wrap: wrap; font-size: 13px; }
.bulk-bar span { font-weight: 600; margin-right: 4px; }
.msg-list { flex: 1; overflow-y: auto; }
.msg { display: grid; grid-template-columns: 22px 22px 1fr auto; grid-template-rows: auto auto; column-gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative; }
.msg:hover { background: var(--hover); }
.msg.selected { background: var(--selected); }
.msg.unread .from, .msg.unread .subj { font-weight: 700; color: var(--unread); }
.msg.unread::before { content: ""; position: absolute; left: 4px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--accent); }
.msg input { grid-row: 1 / 3; align-self: center; margin: 0; }
.msg .star { grid-row: 1 / 3; align-self: center; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; padding: 0; }
.msg .star.on { color: var(--star); }
.msg .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg .subj { grid-column: 3 / 5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.msg .tags { font-size: 12px; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.skeleton { height: 54px; margin: 8px 14px; border-radius: 8px; background: linear-gradient(90deg, var(--panel-2), var(--hover), var(--panel-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ── reader ──────────────────────────────────────────────── */
.reader { grid-area: read; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); }
.reader-empty { margin: auto; text-align: center; color: var(--muted); }
.reader-empty svg { width: 72px; height: 72px; opacity: .45; }
.reader-msg { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.reader-toolbar { display: flex; align-items: center; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.reader-msg h1 { font-size: 20px; margin: 16px 20px 8px; word-break: break-word; }
.reader-meta { display: flex; gap: 12px; align-items: center; padding: 0 20px 12px; }
.reader-meta .who { flex: 1; min-width: 0; }
.reader-meta .who div { overflow: hidden; text-overflow: ellipsis; }
.images-bar { margin: 0 20px 10px; padding: 8px 12px; border-radius: 8px; background: var(--panel-2); font-size: 13px; color: var(--muted); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px; }
.attachments:not(:empty) { padding-bottom: 12px; }
.att { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; text-decoration: none; color: var(--text); max-width: 280px; }
.att:hover { background: var(--hover); }
.att .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .s { color: var(--muted); font-size: 11px; white-space: nowrap; }
.att button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; }
.reader-body { flex: 1; border: 0; width: 100%; min-height: 300px; background: #fff; border-top: 1px solid var(--border); }

/* ── modals ──────────────────────────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.compose, .dialog { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(760px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; position: relative; }
.dialog { width: min(520px, 100%); }
.compose-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--border); }
.compose-head b { flex: 0 0 auto; }
.compose-head .muted { flex: 1; }
.field { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); padding: 0 18px; position: relative; }
.field > span, .field > label { color: var(--muted); font-size: 13px; width: 56px; flex-shrink: 0; }
.field input { flex: 1; border: 0; background: none; padding: 11px 0; outline: none; min-width: 0; }
.field .from { padding: 11px 0; font-size: 13px; }
.ac { position: absolute; left: 84px; right: 18px; top: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); z-index: 5; max-height: 220px; overflow-y: auto; }
.ac button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; cursor: pointer; }
.ac button:hover, .ac button.hl { background: var(--hover); }
.editor-toolbar { display: flex; gap: 2px; padding: 6px 12px; border-bottom: 1px solid var(--border); }
.editor-toolbar button { border: 0; background: none; min-width: 30px; height: 28px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.editor-toolbar button:hover { background: var(--hover); color: var(--text); }
.editor { flex: 1; min-height: 260px; overflow-y: auto; padding: 14px 18px; outline: none; line-height: 1.55; }
.editor blockquote { border-left: 3px solid var(--border); margin: 6px 0; padding-left: 12px; color: var(--muted); }
.editor:empty::before { content: "Write your message…"; color: var(--muted); }
.compose-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px; }
.compose-atts:not(:empty) { padding-bottom: 10px; }
.compose-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.drop-hint { position: absolute; inset: 0; background: rgba(37, 99, 235, .12); border: 2px dashed var(--accent); border-radius: 14px; display: grid; place-items: center; font-weight: 600; color: var(--accent); pointer-events: none; }
.dialog-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dialog-body label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.dialog-body h3 { margin: 6px 0 0; font-size: 14px; }
.dialog-body .row { display: flex; gap: 8px; justify-content: flex-end; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
.kv code { background: var(--panel-2); padding: 1px 6px; border-radius: 4px; }
.kbd { display: grid; grid-template-columns: 70px 1fr; gap: 6px 12px; font-size: 13px; }
.kbd kbd { background: var(--panel-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 1px 7px; font-family: inherit; text-align: center; }
pre.source { white-space: pre-wrap; word-break: break-all; font-size: 12px; max-height: 60vh; overflow: auto; background: var(--panel-2); padding: 12px; border-radius: 8px; margin: 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 90; display: flex; gap: 14px; align-items: center; font-size: 14px; }
.toast.err { background: var(--danger); }
.toast button { background: none; border: 0; color: #93c5fd; font-weight: 600; cursor: pointer; }
.scrim { position: fixed; inset: 56px 0 0 0; background: rgba(0, 0, 0, .35); z-index: 29; }
.only-mobile { display: none; }

/* ── responsive ──────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app { grid-template-columns: 210px 1fr; grid-template-areas: "top top" "side list"; }
  .reader { grid-area: list; display: none; }
  .app.reading .reader { display: flex; }
  .app.reading .list-pane { display: none; }
  .reader .only-mobile { display: inline-grid; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "list"; }
  .only-mobile { display: inline-grid; }
  .topbar .brand span { display: none; }
  .topbar .brand { width: auto; }
  .sidebar { position: fixed; top: 56px; bottom: 0; left: 0; width: 260px; z-index: 30; background: var(--panel); transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .app.menu-open .sidebar { transform: none; }
  .list-pane { border: 0; }
  .filters .chip:last-child { display: none; }
  .modal-bg { padding: 0; }
  .compose, .dialog { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .reader-toolbar .btn.sm { padding: 5px 8px; }
  .reader-msg h1 { font-size: 18px; margin: 12px 14px 6px; }
  .reader-meta, .attachments { padding-left: 14px; padding-right: 14px; }
}
