:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1f2933; --muted: #62707d; --border: #dde1e6;
  --accent: #3b5bdb; --accent-dark: #2f49b3; --side: #1c2434; --side-text: #c4ccd8;
  --err-bg: #fde8e8; --err: #9b1c1c; --ok-bg: #e3f6e8; --ok: #17692b; --info-bg: #e7efff; --info: #23408f;
  --radius: 6px; --side-w: 240px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .4rem; }
a { color: var(--accent); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Forms and buttons */
label { display: block; margin-top: 1rem; font-weight: 600; font-size: .9rem; }
input, textarea { width: 100%; padding: .5rem .6rem; margin-top: .25rem; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; background: #fff; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { font: inherit; cursor: pointer; }
form button[type=submit]:not(.btn) { margin-top: 1.25rem; padding: .55rem 1rem; border: 0; border-radius: var(--radius); background: var(--accent); color: #fff; font-weight: 600; }
form button[type=submit]:not(.btn):hover { background: var(--accent-dark); }
.btn { padding: .35rem .8rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.btn:hover { background: var(--bg); }
.field-error { color: var(--err); font-size: .88rem; margin-top: .25rem; }

/* Flash messages */
.flashes { margin-bottom: 1rem; }
.flash { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; padding: .6rem .8rem; border-radius: var(--radius); margin: .4rem 0; }
.flash.error { background: var(--err-bg); color: var(--err); }
.flash.success { background: var(--ok-bg); color: var(--ok); }
.flash.info { background: var(--info-bg); color: var(--info); }
.flash-close { border: 0; background: none; color: inherit; font-size: 1.2rem; line-height: 1; padding: 0 .2rem; }

/* Centred pages: login, register, reset, errors */
.auth-page { min-height: 100vh; display: flex; justify-content: center; align-items: flex-start; padding: 8vh 1rem 2rem; }
.auth-card { width: 100%; max-width: 26rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.75rem; }
.auth-brand { font-weight: 700; letter-spacing: .02em; color: var(--accent); margin-bottom: 1rem; }

/* Result pages of a clicked verification link (Task 4.4.5) */
.link-result h1 { margin-top: 0; }
.link-result-ok { border-top: 4px solid var(--ok); }
.link-result-ok h1 { color: var(--ok); }
.link-result-warn { border-top: 4px solid var(--info); }
.link-result-warn h1 { color: var(--info); }
.link-result-err { border-top: 4px solid var(--err); }
.link-result-err h1 { color: var(--err); }
.link-result-hint { color: var(--muted); }

/* Signed-in shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--side-w); background: var(--side); color: var(--side-text); flex: none; padding: 1rem .75rem; }
.sidebar-brand { color: #fff; font-weight: 700; letter-spacing: .02em; padding: .25rem .6rem 1rem; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-link { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border-radius: var(--radius); color: var(--side-text); text-decoration: none; font-size: .93rem; }
a.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.14); color: #fff; }
.nav-link.disabled { opacity: .55; cursor: default; }
.badge { margin-left: auto; font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; padding: 0 .4rem; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; height: 52px; padding: 0 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-title { font-weight: 600; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.user-email { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16rem; }
.menu-btn { display: none; border: 0; background: none; padding: .35rem; color: var(--text); }
.content { padding: 1.5rem; max-width: 70rem; width: 100%; }
.sidebar-overlay { display: none; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.stat { padding: .9rem 1rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: .85rem; }
.card { padding: 1.25rem; }
.empty-state { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty-state h2 { color: var(--text); }
.empty-state p { margin: 0 auto; max-width: 30rem; }

/* Mobile: sidebar becomes an off-canvas drawer */
@media (max-width: 800px) {
  .menu-btn { display: inline-flex; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  .nav-open .sidebar { transform: none; }
  .nav-open .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
  .user-email { display: none; }
  .content { padding: 1rem; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* Tables and status badges (projects list) */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .6rem .9rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; white-space: nowrap; }
.cell-name { font-weight: 600; overflow-wrap: anywhere; }
.cell-desc { color: var(--muted); font-size: .85rem; font-weight: 400; overflow-wrap: anywhere; }
.status-badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.status-badge.active { background: var(--ok-bg); color: var(--ok); }
.status-badge.disabled { background: var(--border); color: var(--muted); }

/* Page header with an action, project form */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
a.btn { display: inline-block; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-dark); }
textarea { resize: vertical; min-height: 6rem; }
.form-card { max-width: 36rem; }
.form-hint { color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.form-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1.25rem; }
.form-actions button[type=submit] { margin-top: 0 !important; }
.form-card form > label:first-of-type { margin-top: 0; }

/* Project detail page (tabs) */
.breadcrumb { margin: 0 0 .5rem; font-size: .9rem; }
.project-title { overflow-wrap: anywhere; margin-bottom: .25rem; }
.cell-name a { color: inherit; text-decoration: none; }
.cell-name a:hover { text-decoration: underline; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab { padding: .55rem .9rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel h2 { margin-top: 0; }
.placeholder { color: var(--muted); margin: 0; }
.settings-form { max-width: 32rem; }
.settings-form > label:first-of-type { margin-top: 0; }
.settings-form h3 { margin: 1.5rem 0 0; font-size: 1rem; }
.num-input { max-width: 9rem; }
.head-actions { display: flex; align-items: center; gap: .75rem; }
.head-actions form { margin: 0; }
.notice { margin: 0 0 1rem; padding: .6rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--muted); }
.danger-zone { max-width: 32rem; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.danger-zone h3 { margin: 0 0 .25rem; font-size: 1rem; }
.btn-danger { color: var(--err); border-color: var(--err); }
.btn-danger:hover { background: var(--err); color: #fff; }
.danger-card { border-color: var(--err); }
form button.btn-danger-solid[type=submit] { margin-top: 0; padding: .55rem 1rem; border: 0; border-radius: var(--radius); background: var(--err); color: #fff; font-weight: 600; }
form button.btn-danger-solid[type=submit]:hover { filter: brightness(.9); }
.key-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; }
.key-actions { margin-top: 1rem; }
.key-actions form { margin: 0; }
.table code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.sender-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin: 1rem 0; }
.sender-slot { padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.sender-slot h3 { margin: 0 0 .25rem; font-size: 1rem; }
.sender-state { margin: .75rem 0; color: var(--muted); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn[disabled]:hover { background: var(--surface); }

/* Sender cards (Task 3.3.1) */
.sender-badge { display: inline-block; margin-left: .35rem; padding: .05rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 600; vertical-align: middle; background: var(--border); color: var(--muted); }
.sender-badge.connected { background: var(--ok-bg); color: var(--ok); }
.sender-badge.needs_reconnect, .sender-badge.error { background: var(--err-bg); color: var(--err); }
.sender-facts { margin: .5rem 0 .75rem; font-size: .88rem; }
.sender-facts dt { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; margin-top: .4rem; }
.sender-facts dd { margin: 0; overflow-wrap: anywhere; }
.sender-error { color: var(--err); }
.sender-warning { margin: .5rem 0 .75rem; padding: .5rem .75rem; border: 1px solid var(--err); border-radius: var(--radius); background: var(--err-bg); color: var(--err); font-size: .88rem; }
.sender-slot form { margin: 0; }
.sender-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.sender-actions form { margin: 0; }
.sender-project { margin-bottom: 1.5rem; }
