:root {
  --bg: #f5f6f8; --panel: #ffffff; --side: #eef0f4; --line: #e2e5ea; --text: #1d2330; --muted: #6b7280;
  --accent: #2f5bea; --accent-soft: #e6ecff; --hover: #f0f2f6; --sel: #dfe7ff; --danger: #c62828; --unread: #1d2330;
  --shadow: 0 10px 40px rgba(15, 23, 42, .18);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c; --panel: #1b1e24; --side: #121419; --line: #2a2e36; --text: #e6e8ec; --muted: #9aa1ad;
    --accent: #6d8dff; --accent-soft: #252f4d; --hover: #232731; --sel: #2a3558; --unread: #ffffff;
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { padding: 2px; height: 38px; width: 60px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 8px; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: wait; }
.link { background: none; border: 0; padding: 6px 0; color: var(--text); }
.icon-btn { background: none; border: 0; font-size: 18px; width: 34px; height: 34px; border-radius: 8px; }
.icon-btn:hover { background: var(--hover); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.error { color: var(--danger); }

/* Layout: folders | list | reading */
.app { display: grid; grid-template-columns: 250px minmax(300px, 420px) 1fr; height: 100vh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-top { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.compose-btn { width: 100%; padding: 9px; }
.folders { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.side-bottom { border-top: 1px solid var(--line); padding: 8px 14px; display: flex; flex-direction: column; }
.group { margin-top: 10px; }
.group-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-radius: 6px; cursor: pointer; user-select: none; }
.group-head:hover { background: var(--hover); }
.group-head .caret { width: 10px; transition: transform .15s; }
.group.closed .caret { transform: rotate(-90deg); }
.group.closed .group-body { display: none; }
.group-head .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.group-head .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }
.group-head .warn { color: var(--danger); font-size: 14px; }
.folder { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: none; padding: 6px 8px; border-radius: 6px; }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--sel); font-weight: 600; }
.folder .ico { width: 18px; text-align: center; flex: none; }
.folder .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .badge { font-size: 12px; font-weight: 700; color: var(--accent); }
.folder.drop { outline: 2px dashed var(--accent); }

.list-pane { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; }
.list-title { flex: 1; font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-tools { display: flex; gap: 10px; align-items: center; padding: 0 12px 8px; border-bottom: 1px solid var(--line); }
.list-tools label { white-space: nowrap; display: flex; gap: 4px; align-items: center; }
.bulk { display: flex; gap: 6px; align-items: center; padding: 6px 12px; background: var(--accent-soft); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bulk span { font-weight: 600; margin-right: auto; }
.list { flex: 1; overflow-y: auto; }
.row { display: grid; grid-template-columns: 6px 18px 1fr auto; gap: 4px 8px; padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.row:hover { background: var(--hover); }
.row.active { background: var(--sel); }
.row.checked { background: var(--accent-soft); }
.row .bar { grid-row: 1 / 3; border-radius: 0 3px 3px 0; }
.row .chk { grid-row: 1 / 3; align-self: center; margin: 0; }
.row .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .when { color: var(--muted); font-size: 12px; white-space: nowrap; text-align: right; }
.row .subj { grid-column: 3 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.row .marks { font-size: 12px; text-align: right; white-space: nowrap; }
.row.unread .who, .row.unread .subj { font-weight: 700; color: var(--unread); }
.row.unread::after { content: ""; position: absolute; left: 12px; top: 15px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.row.unread .chk { opacity: 0; } .row:hover .chk, .row.checked .chk { opacity: 1; }
.row .acc { font-size: 11px; color: var(--muted); font-weight: 400; }
.list-foot { padding: 14px; text-align: center; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.read-pane { background: var(--panel); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.empty { margin: auto; color: var(--muted); }
.reader { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.r-tools { display: flex; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.r-tools .sp { flex: 1; }
.r-tools select { width: auto; padding: 5px 8px; font-size: 13px; }
.r-head { padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.r-subj { font-size: 19px; font-weight: 700; margin: 0 0 10px; word-break: break-word; }
.r-meta { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; }
.r-meta dt { color: var(--muted); } .r-meta dd { margin: 0; word-break: break-word; }
.r-acc { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--hover); margin-bottom: 8px; }
.r-acc i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.r-atts { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.att { display: inline-flex; gap: 6px; align-items: center; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--text); font-size: 13px; max-width: 280px; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att:hover { background: var(--hover); }
.r-images { padding: 8px 18px; background: var(--accent-soft); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.r-body { flex: 1; min-height: 0; }
.r-body iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.r-text { padding: 18px; white-space: pre-wrap; word-break: break-word; overflow-y: auto; height: 100%; margin: 0; font-family: inherit; }
.loading { padding: 30px; color: var(--muted); text-align: center; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.dialog { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(760px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.dialog > header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 10px; }
.dialog > header h2 { margin: 0; font-size: 17px; flex: 1; }
.dialog .body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.dialog > footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); align-items: center; }
.dialog > footer .msg { margin-right: auto; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
.compose textarea { min-height: 280px; resize: vertical; }
.compose .line { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; }
.compose .line > span { color: var(--muted); font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--hover); }
.acc-list { display: flex; flex-direction: column; gap: 8px; }
.acc-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.acc-item .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.acc-item .info { flex: 1; min-width: 0; }
.acc-item .info b { display: block; }
.acc-item .info small { color: var(--muted); }
.acc-item .err { color: var(--danger); font-size: 12px; }
.kinds { display: flex; gap: 8px; flex-wrap: wrap; }
.kinds label { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; gap: 6px; align-items: center; cursor: pointer; }
.kinds label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.help { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.45; }
.help a { color: var(--accent); }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details[open] summary { margin-bottom: 10px; }
.section-title { font-weight: 700; margin: 6px 0 0; }

.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: 380px; }
.toast { background: var(--text); color: var(--panel); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; }
.toast.err { background: var(--danger); color: #fff; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); padding: 28px; border-radius: 16px; box-shadow: var(--shadow); width: min(380px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 12px; }
.login-card .brand { font-size: 22px; margin-bottom: 6px; }

.only-mobile { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .app.menu .side { transform: none; }
  .read-pane { position: fixed; inset: 0; z-index: 30; display: none; }
  .app.reading .read-pane { display: flex; }
  .only-mobile { display: inline-block; }
  .row2, .row3 { grid-template-columns: 1fr; }
}
