:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --chip: #eef2ff;
  --ignore: #6b7280; --todo: #2563eb; --unsubscribe: #d97706; --block: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1020; --card: #151b2e; --text: #e5e7eb; --muted: #9ca3af; --line: #26304a; --chip: #1e2a4a; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }

header.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--line); }
header h1 { font-size: 22px; margin: 0; }
main { padding: 12px 12px calc(env(safe-area-inset-bottom) + 76px); max-width: 720px; margin: 0 auto; }

nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { flex: 1; border: 0; background: none; padding: 12px 4px 10px; font-size: 13px; color: var(--muted); min-height: 50px; }
nav.tabs button.active { color: var(--accent); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; margin-left: 2px; }
.badge:empty { display: none; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.card .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .subject { margin: 4px 0 2px; font-weight: 500; }
.card .snippet { color: var(--muted); font-size: 14px; max-height: 3.6em; overflow: hidden; }
.card .body { white-space: pre-wrap; font-size: 14px; margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; max-height: 60vh; overflow: auto; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip); }
.chip.ignore { color: var(--ignore); } .chip.todo { color: var(--todo); } .chip.unsubscribe { color: var(--unsubscribe); } .chip.block { color: var(--block); }
.chip.high { background: #fee2e2; color: var(--bad); }
.proposal { margin-top: 8px; font-size: 14px; }
.proposal .reason { color: var(--muted); }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.actions button { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 10px 2px; font-size: 14px; min-height: 44px; }
.actions button.suggested { border-width: 2px; font-weight: 700; }
.actions button.ignore.suggested { border-color: var(--ignore); } .actions button.todo.suggested { border-color: var(--todo); }
.actions button.unsubscribe.suggested { border-color: var(--unsubscribe); } .actions button.block.suggested { border-color: var(--block); }
.actions button:active { background: var(--chip); }

.todo-edit { margin-top: 8px; display: grid; gap: 6px; }
.todo-edit input { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.todo-edit .buttons { display: flex; gap: 6px; }

.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 12px 16px; font-weight: 600; min-height: 44px; }
.secondary { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-height: 44px; }
.small { padding: 6px 10px; min-height: 34px; font-size: 13px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

.log .note { color: var(--muted); font-size: 13px; margin-top: 4px; }
.status-done { color: var(--ok); } .status-manual { color: var(--warn); } .status-error { color: var(--bad); }

.summary { white-space: normal; font-size: 15px; }
.summary h1, .summary h2, .summary h3 { font-size: 17px; margin: 14px 0 6px; }
.summary ul { padding-left: 20px; margin: 4px 0; }

.setting { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.setting:last-child { border-bottom: 0; }
.setting input[type=number] { width: 90px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); text-align: right; }
.switch { position: relative; width: 50px; height: 30px; appearance: none; background: var(--line); border-radius: 15px; outline: 0; transition: .2s; flex: none; }
.switch:checked { background: var(--ok); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 12px; background: #fff; transition: .2s; }
.switch:checked::after { left: 23px; }
textarea { width: 100%; min-height: 110px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
h2.section { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.rule { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; gap: 8px; }
.rule .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%); background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: .95; }

body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
body.login form { background: var(--card); padding: 28px; border-radius: 16px; width: min(360px, 92vw); display: grid; gap: 12px; }
body.login input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 17px; }
body.login button { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 12px; font-weight: 600; }
body.login button.google { background: #fff; color: #1f1f1f; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 16px; }
body.login .muted { margin: 0; text-align: center; font-size: 13px; }
.err { color: var(--bad); margin: 0; }

body.login .qr { display: flex; justify-content: center; background: #fff; border-radius: 12px; padding: 10px; }
body.login code { font-size: 13px; word-break: break-all; text-align: center; display: block; }
body.login input.code { text-align: center; letter-spacing: 6px; font-size: 22px; }

/* ---- folder model ---- */
.folders { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.fbtn { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 8px 12px; font-size: 13px; min-height: 38px; color: var(--fg); }
.fbtn.suggested { border-width: 2px; font-weight: 700; background: var(--chip); }
.fbtn:active { background: var(--chip); }
.task-edit { margin-top: 8px; display: grid; gap: 6px; }
.task-edit input { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.task-edit .buttons { display: flex; gap: 6px; }
.chip.action { background: #fef3c7; color: #92400e; }
.chip.spam { background: #fee2e2; color: #991b1b; }
.chip.unsub { background: #ede9fe; color: #5b21b6; }
.chip.f-action { color: #b45309; } .chip.f-people { color: #0f766e; } .chip.f-security { color: #b91c1c; }
.chip.f-finance { color: #1d4ed8; } .chip.f-home { color: #047857; } .chip.f-orders { color: #7c3aed; }
.chip.f-travel { color: #0369a1; } .chip.f-tech { color: #4b5563; } .chip.f-newsletters { color: #9a3412; } .chip.f-promotions { color: #be185d; }
.fbtn.f-action.suggested { border-color: #b45309; } .fbtn.f-people.suggested { border-color: #0f766e; } .fbtn.f-security.suggested { border-color: #b91c1c; }
.fbtn.f-finance.suggested { border-color: #1d4ed8; } .fbtn.f-home.suggested { border-color: #047857; } .fbtn.f-orders.suggested { border-color: #7c3aed; }
.fbtn.f-travel.suggested { border-color: #0369a1; } .fbtn.f-tech.suggested { border-color: #4b5563; } .fbtn.f-newsletters.suggested { border-color: #9a3412; } .fbtn.f-promotions.suggested { border-color: #be185d; }
button.danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; border-radius: 10px; padding: 10px 12px; }
.card.unsub .actions { grid-template-columns: repeat(3, 1fr); }
.rule-add { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; margin-bottom: 8px; }
.rule-add input, .rule-add select { padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 14px; min-width: 0; }
.setting select.beh { padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 13px; max-width: 46%; }
nav.tabs button { font-size: 12px; padding: 12px 2px 10px; }
