/*
  Plain, flat, dense. One accent (postal blue), square-ish corners,
  lists are ruled tables rather than floating cards, no blur, no glow.
  Radius scale: 3px controls, 5px panels/dialogs, round only for avatars.
*/
:root {
  --bg: #eef0f2;
  --surface: #ffffff;
  --surface-2: #f6f7f8;
  --text: #1b232c;
  --muted: #5b6672;
  --border: #d5dade;
  --border-strong: #b7bfc6;
  --primary: #1d5c8c;
  --primary-hover: #154670;
  --primary-soft: #e6eef5;
  --success: #2d6e35;
  --success-soft: #e7f1e7;
  --danger: #a8231b;
  --danger-soft: #f8e9e7;
  --warn: #a45f00;
  --r-sm: 3px;
  --r: 5px;
  --radius: var(--r);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
}

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .25rem; font-weight: 700; }
h2 { font-size: 1.25rem; line-height: 1.3; margin: 0 0 .2rem; font-weight: 700; }
.muted { color: var(--muted); margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: .6rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--surface); color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
.tab:focus-visible, .menu-btn:focus-visible, .folders button:focus-visible, .close-x:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.secondary { background: var(--surface); }
.btn.ghost { background: transparent; border-color: transparent; padding: .45rem .7rem; font-size: .95rem; font-weight: 500; color: var(--text); }
.btn.ghost:hover { background: var(--surface); border-color: var(--border); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #8a1c15; }
.btn.danger:disabled { cursor: not-allowed; }
.btn.danger-ghost { color: var(--danger); background: var(--surface); }
.btn.danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.link { background: none; border-color: transparent; color: var(--primary); font-weight: 500; padding: .4rem .3rem; text-decoration: underline; text-underline-offset: 2px; }
.btn.link:hover { color: var(--primary-hover); }
.btn.big { padding: .8rem 1.25rem; font-size: 1.05rem; }
.btn.block { width: 100%; }
a.btn { text-decoration: none; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; padding: 12vh 16px 24px; }
.auth-card {
  width: 100%; max-width: 400px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--border); border-top: 4px solid var(--primary); border-radius: var(--r); padding: 28px 28px 24px;
}
.auth-card form { display: grid; gap: 16px; }
.auth-card h1 { margin-top: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; margin-bottom: 20px; }
.brand.small { margin: 0; font-size: 1rem; }
.brand img { border-radius: var(--r-sm); }

/* ---------- form fields ---------- */
.field { display: grid; gap: 5px; }
.field > span { font-weight: 600; font-size: .95rem; }
.field .hint { font-size: .88rem; color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=search], input:not([type]), input[inputmode], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: .6rem .75rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: inset 0 0 0 1px var(--primary); }
textarea { resize: vertical; min-height: 8rem; }
.code-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; font-family: var(--mono); }

.email-row { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); overflow: hidden; }
.email-row:focus-within { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.email-row input, .email-row select { border: 0; border-radius: 0; background: transparent; min-width: 0; box-shadow: none !important; }
.email-row input { flex: 1 1 50%; }
.email-row .at { display: grid; place-items: center; padding: 0 .3rem; color: var(--muted); font-weight: 600; }
.email-row select, .email-row .domain-fixed { flex: 1 1 50%; color: var(--muted); background: var(--surface-2); border-left: 1px solid var(--border); }
.email-row .domain-fixed { display: flex; align-items: center; padding: 0 .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.domain-picks { border: 0; margin: 0; padding: 0; min-width: 0; }
.domain-picks legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: 5px; }
.domain-picks .pick { display: flex; align-items: center; gap: 10px; padding: .45rem .1rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.domain-picks .pick:last-of-type { border-bottom: 0; }
.domain-picks .pick input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: none; }
.domain-picks .pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-list { max-height: 34vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r); padding: 0 .6rem; }
.pick-list .pick:last-child { border-bottom: 0; }
.pick-search { margin-bottom: 6px; }
.field-title { font-weight: 600; font-size: .95rem; margin: 0 0 5px; }
.domain-picks .hint { font-size: .85rem; color: var(--muted); }
#key-boxes { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-sm); padding: 0 .6rem; }

/* ruled lists inside dialogs */
.keys, .rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--r); overflow-y: auto; }
.keys { max-height: 50vh; }
.rows { max-height: 40vh; }
.keys li, .rows li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.keys li:last-child, .rows li:last-child { border-bottom: 0; }
.key-main { flex: 1; min-width: 0; }
.rows .row-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .row-main small { display: block; color: var(--muted); font-size: .85rem; }
.rows li.warn { background: var(--danger-soft); box-shadow: inset 3px 0 0 var(--danger); }

.code { margin: 0; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); font: .85rem/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; }
.example summary { cursor: pointer; font-weight: 600; font-size: .95rem; margin-bottom: 8px; }

.pw-row { display: flex; gap: 8px; }
.pw-row .pw-wrap { position: relative; flex: 1; min-width: 0; }
.pw-row input { padding-right: 3rem; font-family: var(--mono); font-size: 1rem; }
.icon-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--muted); padding: 7px; border-radius: var(--r-sm); cursor: pointer; display: grid;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* password rules: a plain checklist, not pills */
.rules { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-wrap: wrap; column-gap: 16px; row-gap: 2px; }
.rules li { font-size: .85rem; color: var(--muted); }
.rules li::before { content: "○ "; }
.rules li.ok { color: var(--success); }
.rules li.ok::before { content: "✓ "; }

.error { margin: 0; padding: .6rem .8rem; border-left: 3px solid var(--danger); background: var(--danger-soft); color: var(--danger); font-weight: 500; font-size: .95rem; }

/* ---------- app ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.who { display: flex; align-items: center; gap: 4px; min-width: 0; }
.who #who-name { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 8px; }

.container { max-width: 920px; margin: 0 auto; padding: 28px 24px 64px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.search { position: relative; flex: 1; display: block; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; }
.toolbar select { width: auto; max-width: 45%; }

/* account / alias list: one ruled panel, rows separated by lines */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }
.list:empty { display: none; }
.item { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: .95rem; text-transform: uppercase;
}
.avatar.alias { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); font-size: 1.15rem; }
.item-main { flex: 1 1 240px; min-width: 0; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-email { color: var(--muted); font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { width: 80px; height: 5px; background: var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.bar.high > i { background: var(--warn); }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.item-actions .btn { padding: .45rem .8rem; font-size: .95rem; }
.badge { font-size: .78rem; font-weight: 600; padding: 0 5px; border: 1px solid var(--danger); border-radius: var(--r-sm); color: var(--danger); }
.chip { font-size: .82rem; color: var(--primary); }

.empty { padding: 40px 24px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r); color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 1.1rem; margin-bottom: 2px; }

.skeleton { height: 66px; border-bottom: 1px solid var(--border); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.skeleton:last-child { border-bottom: 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border-strong); padding: 0; border-radius: var(--r); width: min(480px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 10px 30px rgb(0 0 0 / .18);
}
dialog::backdrop { background: rgb(20 26 33 / .5); }
.dialog-inner { display: grid; gap: 16px; padding: 22px 22px 20px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.close-x { border: 0; background: none; color: var(--muted); width: 32px; height: 32px; border-radius: var(--r-sm); font-size: 1.4rem; line-height: 1; cursor: pointer; flex: none; }
.close-x:hover { color: var(--text); background: var(--surface-2); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.actions .btn.primary, .actions .btn.danger { min-width: 40%; }

.done { display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: center; }
.done .done-icon { grid-row: span 2; }
.done h2 { margin: 0 !important; }
.done-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--success-soft); color: var(--success); display: grid; place-items: center; }
.done-icon svg { width: 28px; height: 28px; }
.creds { border: 1px solid var(--border); border-radius: var(--r); padding: 0 14px; text-align: left; }
.creds div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.creds div:last-child { border-bottom: 0; }
.creds dt { color: var(--muted); font-size: .9rem; margin: 0; }
.creds dd { margin: 0; font-weight: 600; font-family: var(--mono); font-size: .95rem; word-break: break-all; text-align: right; }
.creds dd .copy-one { margin-left: 8px; padding: .15rem .5rem; font-family: system-ui, sans-serif; font-size: .85rem; }
.settings-title { font-size: .95rem; margin: 16px 0 6px; }
.warn-note { font-size: .88rem; color: var(--muted); margin: 0; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; margin-bottom: 14px; border-bottom: 1px solid var(--border-strong); }
.tab {
  border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
  padding: .55rem .8rem; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--primary); }
.tab .count { font-weight: 500; color: var(--muted); margin-left: 2px; font-variant-numeric: tabular-nums; }

/* ---------- "More" dialog and its sub-pages ---------- */
.menu { display: grid; border: 1px solid var(--border); border-radius: var(--r); }
.menu-btn {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; cursor: pointer;
  padding: 12px 14px; border: 0; border-bottom: 1px solid var(--border); background: var(--surface); font: inherit; color: var(--text);
}
.menu-btn:last-child { border-bottom: 0; }
.menu-btn::after { content: "›"; margin-left: auto; color: var(--muted); font-size: 1.4rem; line-height: 1; }
.menu-btn:hover { background: var(--surface-2); }
.menu-btn:hover strong { color: var(--primary); }
.menu-btn strong { display: block; }
.menu-btn small { color: var(--muted); font-size: .88rem; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: none; }
.status { padding: .6rem .8rem; border-left: 3px solid var(--success); background: var(--success-soft); color: var(--success); font-weight: 500; font-size: .95rem; margin: 0; }
.status.off { background: var(--surface-2); color: var(--muted); border-left-color: var(--border-strong); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: #fff; padding: .65rem 1.1rem; border-radius: var(--r-sm); font-weight: 500;
  max-width: calc(100vw - 32px);
}

/* ---------- reading mail ---------- */
.container.wide { max-width: 1280px; }
.mail-who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 12px; }
.mail-layout { display: grid; grid-template-columns: 200px 1fr; gap: 20px; align-items: start; }
.mail-side { position: sticky; top: 64px; }
.folders { list-style: none; margin: 0; padding: 0; display: grid; }
.folders button {
  width: 100%; display: flex; justify-content: space-between; gap: 8px; text-align: left; cursor: pointer;
  border: 0; border-left: 3px solid transparent; background: none; font: inherit; color: var(--text); padding: .35rem .6rem;
}
.folders button:hover { background: var(--surface); }
.folders button[aria-current="true"] { border-left-color: var(--primary); background: var(--surface); font-weight: 600; }
.folders .n { font-size: .82rem; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.folder-tools { display: flex; flex-wrap: wrap; gap: 0 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.folder-tools .btn { font-size: .88rem; padding: .25rem .3rem; }
.mail-main { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px; }
.mail-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.mail-tools .search { flex: 1 1 260px; min-width: 220px; }
.mail-tools .btn { padding: .5rem .8rem; font-size: .95rem; }
.mail-tools select, .msg-actions select, .checkup-tools select, .bulk select { width: auto; }
.mail-tools select { padding-top: .5rem; padding-bottom: .5rem; }
.readmode { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 8px; margin-bottom: 8px; background: var(--primary-soft); border-left: 3px solid var(--primary); }
.bulk .btn { padding: .35rem .7rem; font-size: .9rem; }
.mail-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .95rem; border-top: 1px solid var(--border); }
.mail-table td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.mail-table td.pick { width: 36px; cursor: default; text-overflow: clip; }
.mail-table td.from { width: 26%; }
.mail-table td.when { width: 92px; text-align: right; color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; }
.mail-table tr:hover td { background: var(--surface-2); }
.mail-table tr.unread td.from, .mail-table tr.unread td.subj { font-weight: 700; }
.mail-table tr.unread td.pick { box-shadow: inset 3px 0 0 var(--primary); }
.mail-table .ic { color: var(--muted); font-size: .85rem; margin-left: 6px; }
.mail-table .empty-row td { text-align: center; color: var(--muted); cursor: default; padding: 2rem; white-space: normal; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.pager .btn { padding: .35rem .8rem; font-size: .9rem; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.msg-actions .btn, .msg-actions select { padding: .4rem .75rem; font-size: .92rem; }
.msg-subject { margin: 4px 0 8px; word-break: break-word; }
.msg-head { display: grid; gap: 1px; margin: 0 0 12px; font-size: .92rem; }
.msg-head div { display: flex; gap: 10px; }
.msg-head dt { color: var(--muted); width: 56px; flex: none; }
.msg-head dd { margin: 0; word-break: break-word; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.att { padding: .3rem .6rem; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--text); text-decoration: none; font-size: .9rem; }
.att:hover { border-color: var(--primary); color: var(--primary); }
.att small { color: var(--muted); }
.msg-frame { width: 100%; height: 65vh; border: 1px solid var(--border); background: #fff; }
.msg-text { white-space: pre-wrap; word-break: break-word; font: .95rem/1.55 var(--mono); margin: 0; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); max-height: 65vh; overflow: auto; }
.small { font-size: .85rem; }

/* check-up: numbers in a ruled strip, not floating tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin: 12px 0; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.stat { padding: 10px 14px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 0 -1px -1px 0; }
.stat b { display: block; font-size: 1.45rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .88rem; }
.stat.bad b { color: var(--danger); }
.warns { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; }
.warns li { padding: .5rem .8rem; border-left: 3px solid var(--danger); background: var(--danger-soft); color: var(--danger); font-weight: 500; }
.warns li.fine { border-left-color: var(--success); background: var(--success-soft); color: var(--success); }
.checkup-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
#cu-rows .row-main { white-space: normal; }

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .mail-layout { grid-template-columns: 1fr; gap: 12px; }
  .mail-side { position: static; }
  .folders { display: flex; flex-wrap: wrap; gap: 2px; }
  .folders button { width: auto; border-left: 0; border-bottom: 2px solid transparent; }
  .folders button[aria-current="true"] { border-bottom-color: var(--primary); }
  .mail-table td.from { width: 34%; }
  .readmode { margin-left: 0; }
}
@media (max-width: 600px) {
  body { font-size: 16px; }
  .topbar { padding: 6px 12px; }
  .who #who-name { display: none; }
  .container { padding: 18px 16px 48px; }
  .hero .btn { width: 100%; }
  .toolbar { flex-direction: column; }
  .toolbar select { max-width: none; width: 100%; }
  .item { padding: 12px; }
  .item-actions { width: 100%; justify-content: flex-start; }
  .email-row { flex-direction: column; }
  .email-row .at { display: none; }
  .email-row select, .email-row .domain-fixed { border-left: 0; border-top: 1px solid var(--border); padding: .6rem .75rem; }
  .actions { flex-direction: column-reverse; }
  .actions .btn { width: 100%; }
  .auth { padding-top: 6vh; }
  .auth-card { padding: 22px 18px; }
  .creds div { flex-direction: column; gap: 2px; }
  .creds dd { text-align: left; }
  .mail-tools .search { min-width: 0; }
}
.chip.ready { color: var(--success); }
