/* Mail Depot Admin
   One design system for the whole admin: calm surfaces, one accent colour,
   status colours only where they carry meaning. */

:root{
  --bg:#f4f6f9;
  --surface:#ffffff;
  --surface-2:#f8fafc;
  --surface-3:#eef2f7;
  --border:#e3e8ef;
  --border-strong:#cfd7e3;
  --text:#0f172a;
  --text-2:#334155;
  --muted:#64748b;
  --faint:#94a3b8;

  --primary:#2b63b8;
  --primary-hover:#1f4f9a;
  --primary-soft:#eaf1fb;
  --primary-text:#1b4fa1;
  --accent:#ff8a00;

  --ok:#15803d;
  --ok-soft:#ecfdf3;
  --ok-border:#abefc6;
  --warn:#b45309;
  --warn-soft:#fffaeb;
  --warn-border:#fedf89;
  --danger:#b42318;
  --danger-hover:#912018;
  --danger-soft:#fef3f2;
  --danger-border:#fecdca;

  --radius:10px;
  --radius-sm:7px;
  --shadow-sm:0 1px 2px rgba(15,23,42,.05);
  --shadow:0 4px 16px rgba(15,23,42,.08);
  --shadow-lg:0 18px 48px rgba(15,23,42,.22);

  --topbar-h:56px;
  --sidebar-w:236px;

  --sans:ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  /* Kept for modules that still reference the previous palette. */
  --blue-950:#0b2a56;
  --blue-700:var(--primary-text);
  --blue-600:var(--primary);
  --card:var(--surface);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family:var(--sans);
  font-size:14px;
  line-height:1.5;
  color:var(--text);
  background:var(--bg);
  -webkit-font-smoothing:antialiased;
}
a{ color:var(--primary-text); text-decoration:none; }
a:hover{ text-decoration:underline; }
code{ font-family:var(--mono); font-size:.92em; background:var(--surface-3); padding:1px 5px; border-radius:4px; }
h1,h2,h3,h4{ color:var(--text); margin:0; line-height:1.3; }
p{ margin:0; }
[hidden]{ display:none !important; }
:focus-visible{ outline:2px solid var(--primary); outline-offset:2px; }
.mono{ font-family:var(--mono); font-size:.92em; }
.muted{ color:var(--muted); font-size:13px; }
.nowrap{ white-space:nowrap; }
.sr-only{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
.icon{ width:16px; height:16px; flex-shrink:0; stroke:currentColor; fill:none; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }

/* ---------- App shell ---------- */
.topbar{
  position:fixed; inset:0 0 auto 0; z-index:30;
  height:var(--topbar-h);
  display:flex; align-items:center; gap:12px;
  padding:0 16px 0 12px;
  background:var(--surface);
  border-bottom:1px solid var(--border);
}
.brand{ display:flex; align-items:center; gap:10px; color:var(--text); font-weight:650; font-size:15px; padding:6px 8px; border-radius:8px; }
.brand:hover{ text-decoration:none; background:var(--surface-2); }
.brand-mark{
  width:30px; height:30px; border-radius:8px; display:grid; place-items:center;
  background:linear-gradient(135deg, var(--primary), #1b4fa1); color:#fff;
}
.brand-mark .icon{ width:17px; height:17px; }
.brand-tag{ color:var(--muted); font-weight:500; }
.topbar-right{ margin-left:auto; display:flex; align-items:center; gap:8px; min-width:0; }
.conn-pill{
  display:flex; align-items:center; gap:8px; min-width:0;
  padding:5px 12px; border-radius:999px; border:1px solid var(--border);
  background:var(--surface-2); color:var(--text-2); font-size:13px;
}
.conn-pill span:last-child{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:320px; }
.dot{ width:8px; height:8px; border-radius:50%; background:#ef4444; flex-shrink:0; box-shadow:0 0 0 3px rgba(239,68,68,.18); }
.dot.ok{ background:#22c55e; box-shadow:0 0 0 3px rgba(34,197,94,.18); }

.sidebar{
  position:fixed; z-index:25; left:0; top:var(--topbar-h); bottom:0;
  width:var(--sidebar-w);
  display:flex; flex-direction:column;
  background:var(--surface);
  border-right:1px solid var(--border);
  overflow-y:auto;
  padding:12px 10px;
}
.nav-section{ margin:16px 10px 6px; font-size:11px; font-weight:650; letter-spacing:.06em; text-transform:uppercase; color:var(--faint); }
.nav-section:first-child{ margin-top:4px; }
.menubtn{
  display:flex; align-items:center; gap:10px; width:100%;
  padding:8px 10px; margin:1px 0; border-radius:8px; border:0;
  background:transparent; color:var(--text-2); font:inherit; font-size:14px; font-weight:500;
  cursor:pointer; text-align:left;
}
.menubtn:hover{ background:var(--surface-3); color:var(--text); text-decoration:none; }
.menubtn.active{ background:var(--primary-soft); color:var(--primary-text); font-weight:600; }
.menubtn .icon{ width:17px; height:17px; color:var(--muted); }
.menubtn.active .icon{ color:var(--primary); }
.menubtn .nav-count{ margin-left:auto; min-width:20px; padding:0 6px; border-radius:999px; font-size:11px; font-weight:650; line-height:18px; text-align:center; background:var(--danger-soft); color:var(--danger); }
.sidebar-foot{ margin-top:auto; padding-top:12px; border-top:1px solid var(--border); }
.sidebar-backdrop{ display:none; }

.content{
  margin-left:var(--sidebar-w);
  padding:calc(var(--topbar-h) + 24px) 32px 48px;
  min-height:100%;
}
.page{ max-width:1320px; margin:0 auto; }

.sidebar-btn{ display:none; }
.icon-btn, .iconbtn{
  display:inline-grid; place-items:center;
  width:34px; height:34px; padding:0;
  border:1px solid transparent; border-radius:8px;
  background:transparent; color:var(--muted); cursor:pointer; font-size:16px;
}
.icon-btn:hover, .iconbtn:hover{ background:var(--surface-3); color:var(--text); }

/* Not connected: show only the connection screen. */
body.is-guest .sidebar, body.is-guest .sidebar-btn, body.is-guest #btnLogoutTop{ display:none !important; }
body.is-guest .content{ margin-left:0; }

/* ---------- Page header ---------- */
.page-head{ display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:20px; flex-wrap:wrap; }
.page-head h1{ font-size:22px; font-weight:650; letter-spacing:-.01em; }
.page-desc{ margin-top:4px; color:var(--muted); max-width:760px; }
.page-actions{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }

/* ---------- Cards ---------- */
.card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow-sm); }
.card + .card, .card + .grid-2, .grid-2 + .card, .kpi-grid + .card, .card + .kpi-grid, .notice + .card{ margin-top:20px; }
.card-head{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:14px 20px; border-bottom:1px solid var(--border); flex-wrap:wrap; }
.card-head h2{ font-size:15px; font-weight:650; }
.card-head .muted{ margin-top:2px; }
.card-body{ padding:20px; }
.card-foot{ padding:12px 20px; border-top:1px solid var(--border); background:var(--surface-2); border-radius:0 0 var(--radius) var(--radius); display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.grid-2{ display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:20px; }
.grid-2 > .card + .card{ margin-top:0; }

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  height:36px; padding:0 14px;
  border:1px solid var(--border-strong); border-radius:var(--radius-sm);
  background:var(--surface); color:var(--text-2);
  font:inherit; font-size:14px; font-weight:550; line-height:1; white-space:nowrap;
  cursor:pointer; text-decoration:none;
  transition:background-color .15s, border-color .15s, box-shadow .15s, color .15s;
}
.btn:hover{ background:var(--surface-2); border-color:#b8c3d3; color:var(--text); text-decoration:none; }
.btn:disabled, .btn[aria-disabled="true"]{ opacity:.5; cursor:not-allowed; }
.btn .icon{ width:15px; height:15px; }
.btn-primary{ background:var(--primary); border-color:var(--primary); color:#fff; }
.btn-primary:hover{ background:var(--primary-hover); border-color:var(--primary-hover); color:#fff; }
.btn-secondary{ background:var(--surface); }
.btn-ghost{ background:transparent; border-color:transparent; color:var(--text-2); }
.btn-ghost:hover{ background:var(--surface-3); border-color:transparent; }
.btn-danger{ background:var(--danger); border-color:var(--danger); color:#fff; }
.btn-danger:hover{ background:var(--danger-hover); border-color:var(--danger-hover); color:#fff; }
.btn.danger{ color:var(--danger); }
.btn.danger:hover{ background:var(--danger-soft); border-color:var(--danger-border); }
.btn-sm, .btn.small{ height:30px; padding:0 10px; font-size:13px; border-radius:6px; }
.btn-md{ height:36px; }
.btn[aria-busy="true"]{ position:relative; color:transparent !important; pointer-events:none; }
.btn[aria-busy="true"]::after{
  content:""; position:absolute; width:14px; height:14px; border-radius:50%;
  border:2px solid currentColor; border-color:var(--muted) transparent var(--muted) transparent;
  animation:spin .8s linear infinite;
}
.btn-primary[aria-busy="true"]::after, .btn-danger[aria-busy="true"]::after{ border-color:#fff transparent #fff transparent; }
@keyframes spin{ to{ transform:rotate(360deg); } }
.btn-row{ display:flex; gap:8px; flex-wrap:wrap; align-items:center; }

/* ---------- Forms ---------- */
label{ display:block; margin:0 0 6px; font-size:13px; font-weight:600; color:var(--text-2); }
.optional{ font-weight:400; color:var(--faint); }
.form-control, textarea{
  width:100%;
  height:36px; padding:0 10px;
  font:inherit; font-size:14px; color:var(--text);
  background:var(--surface); border:1px solid var(--border-strong); border-radius:var(--radius-sm);
  transition:border-color .15s, box-shadow .15s;
}
textarea, textarea.form-control{ height:auto; min-height:88px; padding:8px 10px; resize:vertical; font-family:var(--mono); font-size:12.5px; line-height:1.5; }
.form-control:hover, textarea:hover{ border-color:#b8c3d3; }
.form-control:focus, textarea:focus{ outline:none; border-color:var(--primary); box-shadow:0 0 0 3px rgba(43,99,184,.15); }
.form-control:disabled, textarea:disabled{ background:var(--surface-2); color:var(--faint); cursor:not-allowed; }
.form-control[readonly], textarea[readonly]{ background:var(--surface-2); }
.form-control[aria-invalid="true"], textarea[aria-invalid="true"]{ border-color:var(--danger); box-shadow:0 0 0 3px rgba(180,35,24,.12); }
select.form-control{ padding-right:28px; }
.field{ margin-bottom:16px; min-width:0; }
.field:last-child{ margin-bottom:0; }
.help{ display:block; margin-top:6px; font-size:12.5px; line-height:1.5; color:var(--muted); }
.field-error{ display:block; margin-top:6px; font-size:12.5px; color:var(--danger); }
.row{ display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:0 16px; }
.row > div{ min-width:0; }
.row-3{ grid-template-columns:repeat(3, minmax(0,1fr)); }
.mb-1{ margin-bottom:16px; }
.input-group{ display:flex; gap:8px; align-items:center; }
.input-group > .form-control{ flex:1; min-width:0; }
.input-suffix{ position:relative; }
.input-suffix > .form-control{ padding-right:64px; }
.input-suffix > .suffix{ position:absolute; right:10px; top:0; bottom:0; display:flex; align-items:center; color:var(--muted); font-size:13px; pointer-events:none; }
.secret-field{ position:relative; }
.secret-field > .form-control{ padding-right:44px; }
.secret-field > .reveal{ position:absolute; right:2px; top:1px; width:34px; height:34px; }

.check{
  display:flex; align-items:flex-start; gap:10px;
  margin:0; padding:0; font-size:14px; font-weight:500; color:var(--text);
  cursor:pointer; user-select:none;
}
.check input{ width:16px; height:16px; margin:2px 0 0; flex-shrink:0; accent-color:var(--primary); cursor:pointer; }
.check input:disabled, .check input:disabled + span{ cursor:not-allowed; opacity:.6; }
.check .check-text{ display:block; }
.check .check-desc{ display:block; font-weight:400; font-size:12.5px; color:var(--muted); margin-top:2px; }

/* Toggle switch (checkbox semantics). */
.switch{ display:inline-flex; align-items:center; gap:10px; margin:0; font-size:14px; font-weight:500; color:var(--text); cursor:pointer; user-select:none; }
.switch input{
  appearance:none; -webkit-appearance:none; margin:0; flex-shrink:0;
  width:36px; height:20px; border-radius:999px; background:#cbd5e1; position:relative; cursor:pointer;
  transition:background-color .15s;
}
.switch input::before{ content:""; position:absolute; top:2px; left:2px; width:16px; height:16px; border-radius:50%; background:#fff; box-shadow:0 1px 2px rgba(0,0,0,.2); transition:transform .15s; }
.switch input:checked{ background:var(--primary); }
.switch input:checked::before{ transform:translateX(16px); }
.switch input:focus-visible{ outline:2px solid var(--primary); outline-offset:2px; }

/* Grouped form sections inside dialogs. */
.form-section{ padding:20px 0; border-top:1px solid var(--border); }
.form-section:first-child{ padding-top:0; border-top:0; }
.form-section:last-child{ padding-bottom:0; }
.form-section-head{ margin-bottom:14px; }
.form-section-head h3{ font-size:14.5px; font-weight:650; display:flex; align-items:center; gap:8px; }
.form-section-head p{ margin-top:2px; font-size:13px; color:var(--muted); }
.step-num{ display:inline-grid; place-items:center; width:20px; height:20px; border-radius:50%; background:var(--primary-soft); color:var(--primary-text); font-size:11.5px; font-weight:700; }
.subpanel{ padding:14px; border:1px solid var(--border); border-radius:8px; background:var(--surface-2); }
.subpanel + .subpanel, .field + .subpanel, .subpanel + .field{ margin-top:16px; }
.danger-zone{ border-color:var(--danger-border); background:var(--danger-soft); }

/* ---------- Disclosures ---------- */
details{ border:1px solid var(--border); border-radius:8px; background:var(--surface); }
details + details{ margin-top:10px; }
summary{
  display:flex; align-items:center; gap:8px;
  padding:10px 14px; cursor:pointer; list-style:none;
  font-size:14px; font-weight:600; color:var(--text-2);
  border-radius:8px;
}
summary::-webkit-details-marker{ display:none; }
summary::before{
  content:""; width:7px; height:7px; flex-shrink:0;
  border-right:2px solid var(--muted); border-bottom:2px solid var(--muted);
  transform:rotate(-45deg); transition:transform .15s; margin-right:2px;
}
details[open] > summary::before{ transform:rotate(45deg); }
summary:hover{ background:var(--surface-2); }
summary .summary-hint{ font-weight:400; color:var(--muted); font-size:13px; }
.details-body{ padding:4px 14px 14px; }
details > :not(summary):not(.details-body){ margin-left:14px; margin-right:14px; }
details > :last-child:not(summary){ margin-bottom:14px; }

/* ---------- Badges, tags, status ---------- */
.badge{
  display:inline-flex; align-items:center; gap:4px;
  padding:1px 8px; border-radius:999px;
  border:1px solid var(--border); background:var(--surface-2); color:var(--text-2);
  font-size:12px; font-weight:600; line-height:18px; white-space:nowrap;
}
.badge.on{ background:var(--primary-soft); border-color:#c9daf3; color:var(--primary-text); }
.badge.ok{ background:var(--ok-soft); border-color:var(--ok-border); color:var(--ok); }
.badge.off, .badge.err{ background:var(--danger-soft); border-color:var(--danger-border); color:var(--danger); }
.badge.warn{ background:var(--warn-soft); border-color:var(--warn-border); color:var(--warn); }
.tag{
  display:inline-flex; align-items:center; gap:4px; max-width:100%;
  padding:0 7px; border-radius:5px; background:var(--surface-3); color:var(--text-2);
  font-size:12px; line-height:20px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.tag.mono{ font-family:var(--mono); font-size:11.5px; }
.tag.danger{ background:var(--danger-soft); color:var(--danger); }
.tags{ display:flex; flex-wrap:wrap; gap:4px; margin-top:4px; }
.status{ display:inline-flex; align-items:center; gap:6px; font-size:13px; font-weight:550; color:var(--text-2); white-space:nowrap; }
.status::before{ content:""; width:8px; height:8px; border-radius:50%; background:var(--faint); }
.status.ok::before{ background:#22c55e; }
.status.warn::before{ background:#f59e0b; }
.status.err::before{ background:#ef4444; }
.status.off{ color:var(--muted); }
.kbd{ font-family:var(--mono); font-size:11px; padding:1px 6px; border-radius:5px; border:1px solid var(--border); background:var(--surface); color:var(--text-2); font-weight:600; }
.hr{ height:1px; background:var(--border); margin:14px 0; }

/* ---------- Notices ---------- */
.notice, .hint{
  display:flex; align-items:flex-start; gap:10px;
  padding:10px 14px; border-radius:8px;
  border:1px solid #c9daf3; background:var(--primary-soft); color:var(--text-2);
  font-size:13px; line-height:1.5;
}
.notice .icon{ width:16px; height:16px; margin-top:2px; color:var(--primary); }
.notice.warn{ border-color:var(--warn-border); background:var(--warn-soft); }
.notice.warn .icon{ color:var(--warn); }
.notice.danger{ border-color:var(--danger-border); background:var(--danger-soft); }
.notice.danger .icon{ color:var(--danger); }
.notice.ok{ border-color:var(--ok-border); background:var(--ok-soft); }
.notice.ok .icon{ color:var(--ok); }
.notice + .field, .notice + .row, .field + .notice{ margin-top:16px; }
.notice strong{ color:var(--text); }

/* ---------- List pages ---------- */
.list-toolbar{ display:flex; align-items:center; gap:8px; padding:12px 16px; border-bottom:1px solid var(--border); flex-wrap:wrap; }
.list-toolbar .form-control{ width:auto; min-width:180px; }
.list-toolbar .spacer{ flex:1; }
.search-field{ position:relative; flex:1 1 260px; max-width:380px; }
.search-field > .icon{ position:absolute; left:10px; top:50%; transform:translateY(-50%); color:var(--faint); pointer-events:none; }
.search-field > .form-control{ width:100%; padding-left:32px; }
.table-responsive{ overflow-x:auto; position:relative; }
table{ width:100%; border-collapse:collapse; }
thead th{
  padding:10px 16px; text-align:left; white-space:nowrap;
  font-size:12px; font-weight:600; color:var(--muted);
  background:var(--surface-2); border-bottom:1px solid var(--border);
}
tbody td{ padding:12px 16px; border-bottom:1px solid #edf1f6; vertical-align:top; font-size:14px; color:var(--text-2); }
tbody tr:last-child td{ border-bottom:0; }
tbody tr:hover td{ background:#fafcff; }
.data-table{ min-width:860px; }
td.actions-cell{ width:1%; white-space:nowrap; text-align:right; }
.row-actions{ display:inline-flex; gap:6px; align-items:center; justify-content:flex-end; }
.cell-title{ font-weight:600; color:var(--text); overflow-wrap:anywhere; }
.cell-sub{ margin-top:2px; font-size:12.5px; color:var(--muted); overflow-wrap:anywhere; }
.cell-sub + .cell-sub{ margin-top:0; }
.cell-issue{ margin-top:6px; padding:6px 8px; border-radius:6px; background:var(--danger-soft); border:1px solid var(--danger-border); font-size:12.5px; color:var(--text-2); max-width:420px; }
.cell-issue.warn{ background:var(--warn-soft); border-color:var(--warn-border); }
.cell-issue .issue-title{ display:flex; align-items:center; gap:6px; font-weight:600; color:var(--danger); }
.cell-issue.warn .issue-title{ color:var(--warn); }
.cell-issue .issue-text{ overflow-wrap:anywhere; }
.link-btn{ border:0; background:none; padding:0; font:inherit; color:var(--primary-text); cursor:pointer; }
.link-btn:hover{ text-decoration:underline; }
.table-state td{ padding:40px 16px; text-align:center; color:var(--muted); }
.table-state:hover td{ background:transparent; }

.empty{ max-width:440px; margin:0 auto; text-align:center; }
.empty .empty-icon{ width:44px; height:44px; margin:0 auto 12px; border-radius:50%; display:grid; place-items:center; background:var(--primary-soft); color:var(--primary); }
.empty .empty-icon .icon{ width:20px; height:20px; }
.empty h3{ font-size:15px; font-weight:650; color:var(--text); }
.empty p{ margin-top:4px; color:var(--muted); font-size:13.5px; }
.empty .btn{ margin-top:14px; }
.spinner{ display:inline-block; width:14px; height:14px; border-radius:50%; border:2px solid var(--border-strong); border-top-color:var(--primary); animation:spin .8s linear infinite; vertical-align:-2px; margin-right:8px; }

.pager{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:10px 16px; border-top:1px solid var(--border); flex-wrap:wrap; }
.pager-right{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.pager .form-control{ width:auto; height:30px; font-size:13px; }

/* Row action menu */
.menu-pop{
  position:fixed; z-index:60; min-width:200px; padding:4px;
  background:var(--surface); border:1px solid var(--border); border-radius:8px; box-shadow:var(--shadow);
}
.menu-pop[popover]{ margin:0; inset:auto; }
.menu-item{
  display:flex; align-items:center; gap:8px; width:100%;
  padding:8px 10px; border:0; border-radius:6px; background:transparent;
  font:inherit; font-size:13.5px; color:var(--text-2); text-align:left; cursor:pointer;
}
.menu-item:hover, .menu-item:focus-visible{ background:var(--surface-3); color:var(--text); outline:none; }
.menu-item.danger{ color:var(--danger); }
.menu-item.danger:hover, .menu-item.danger:focus-visible{ background:var(--danger-soft); }
.menu-sep{ height:1px; margin:4px 2px; background:var(--border); }

/* ---------- Dialogs ---------- */
dialog{
  width:min(720px, calc(100% - 32px));
  max-height:calc(100dvh - 32px);
  padding:0; border:0; border-radius:12px;
  background:transparent; color:var(--text);
  overflow:hidden;
}
dialog.dialog-lg{ width:min(880px, calc(100% - 32px)); }
dialog.dialog-sm{ width:min(480px, calc(100% - 32px)); }
dialog::backdrop{ background:rgba(15,23,42,.45); }
.modal{
  display:flex; flex-direction:column;
  max-height:calc(100dvh - 32px);
  background:var(--surface); border-radius:12px; box-shadow:var(--shadow-lg);
  overflow:hidden;
}
.modal-head{ flex-shrink:0; padding:16px 20px; border-bottom:1px solid var(--border); }
.modal-head-row{ display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.modal-head h2{ font-size:17px; font-weight:650; }
.modal-head .muted{ margin-top:2px; }
.modal-head .iconbtn{ margin:-6px -8px 0 0; }
.modal-body{ flex:1 1 auto; min-height:0; overflow-y:auto; overflow-x:hidden; padding:20px; }
.modal-foot{
  flex-shrink:0; display:flex; align-items:center; justify-content:flex-end; gap:8px;
  padding:12px 20px; border-top:1px solid var(--border); background:var(--surface-2);
}
.modal-foot .foot-note{ margin-right:auto; font-size:12.5px; color:var(--muted); }
.entity-card{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 14px; border:1px solid var(--border); border-radius:8px; background:var(--surface-2); }
.confirm-list{ margin:12px 0 0; padding-left:18px; color:var(--text-2); }
.confirm-list li + li{ margin-top:4px; }

/* ---------- Toasts ---------- */
.toastwrap{
  position:fixed; inset:auto 20px 20px auto; z-index:9999;
  margin:0; padding:0; border:0; background:transparent;
  max-width:calc(100vw - 40px); max-height:calc(100dvh - 40px); overflow:auto;
  display:flex; flex-direction:column; gap:10px;
}
.toastwrap[popover]:not(:popover-open){ display:none; }
.toast{
  width:380px; max-width:100%;
  display:flex; align-items:flex-start; gap:10px;
  padding:12px 12px 12px 14px;
  background:var(--surface); border:1px solid var(--border); border-left:4px solid var(--primary);
  border-radius:8px; box-shadow:var(--shadow);
}
.toast.ok{ border-left-color:#22c55e; }
.toast.err{ border-left-color:#ef4444; }
.toast .ticon{ display:none; }
.toast .ttext{ min-width:0; font-size:13.5px; line-height:1.45; color:var(--text-2); overflow-wrap:anywhere; }
.toast .ttext b{ display:block; color:var(--text); font-weight:650; margin-bottom:1px; }
.toast .tclose{ margin-left:auto; flex-shrink:0; border:0; background:transparent; color:var(--muted); cursor:pointer; font-size:14px; width:26px; height:26px; border-radius:6px; }
.toast .tclose:hover{ background:var(--surface-3); color:var(--text); }

.connection-result{
  margin-bottom:16px; padding:12px 14px;
  border:1px solid var(--border); border-radius:8px; background:var(--surface-2);
  white-space:pre-wrap; overflow-wrap:anywhere; font-size:13.5px;
}
.connection-result[data-state="error"]{ border-color:var(--danger-border); background:var(--danger-soft); }
.connection-result[data-state="warning"]{ border-color:var(--warn-border); background:var(--warn-soft); }
.connection-result[data-state="ok"]{ border-color:var(--ok-border); background:var(--ok-soft); }
.connection-result[data-state="running"]{ color:var(--muted); }

/* ---------- Connection screen ---------- */
.auth-wrap{ max-width:480px; margin:6vh auto 0; }
.auth-wrap .card-body{ padding:28px; }
.auth-title{ display:flex; align-items:center; gap:12px; margin-bottom:6px; }
.auth-title .brand-mark{ width:36px; height:36px; }
.auth-title h1{ font-size:20px; }
.auth-sub{ color:var(--muted); margin-bottom:22px; }

/* ---------- Overview ---------- */
.kpi-grid{ display:grid; grid-template-columns:repeat(auto-fit, minmax(190px, 1fr)); gap:16px; }
.kpi{ padding:16px 18px; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow-sm); min-width:0; }
.kpi-label{ font-size:13px; color:var(--muted); font-weight:500; }
.kpi-value{ margin-top:4px; font-size:26px; font-weight:650; letter-spacing:-.02em; color:var(--text); line-height:1.2; font-variant-numeric:tabular-nums; }
.kpi-sub{ margin-top:2px; font-size:12.5px; color:var(--muted); }
.kpi.is-bad .kpi-value{ color:var(--danger); }
.kpi.is-good .kpi-value{ color:var(--ok); }
a.kpi:hover{ text-decoration:none; border-color:#b8c3d3; }
.stat-list{ display:grid; grid-template-columns:repeat(auto-fill, minmax(200px,1fr)); gap:4px 24px; margin:0; }
.stat-list > div{ display:flex; justify-content:space-between; gap:12px; padding:8px 0; border-bottom:1px solid #edf1f6; font-size:13.5px; }
.stat-list dt{ color:var(--muted); }
.stat-list dd{ margin:0; font-weight:600; font-variant-numeric:tabular-nums; }

.attention-list{ list-style:none; margin:0; padding:0; }
.attention-item{ display:flex; align-items:flex-start; gap:12px; padding:14px 20px; border-bottom:1px solid #edf1f6; }
.attention-item:last-child{ border-bottom:0; }
.attention-icon{ width:30px; height:30px; flex-shrink:0; border-radius:8px; display:grid; place-items:center; background:var(--danger-soft); color:var(--danger); }
.attention-item.warn .attention-icon{ background:var(--warn-soft); color:var(--warn); }
.attention-body{ flex:1; min-width:0; }
.attention-title{ font-weight:600; color:var(--text); overflow-wrap:anywhere; }
.attention-text{ font-size:13px; color:var(--muted); overflow-wrap:anywhere; }
.attention-item .btn{ flex-shrink:0; }
.all-good{ display:flex; align-items:center; gap:12px; padding:18px 20px; color:var(--text-2); }
.all-good .attention-icon{ background:var(--ok-soft); color:var(--ok); }

.steps{ list-style:none; margin:0; padding:0; display:grid; grid-template-columns:repeat(auto-fit, minmax(210px,1fr)); gap:12px; }
.step{ display:flex; gap:12px; padding:14px; border:1px solid var(--border); border-radius:8px; background:var(--surface); }
.step-mark{ width:26px; height:26px; flex-shrink:0; border-radius:50%; display:grid; place-items:center; font-size:12.5px; font-weight:700; background:var(--surface-3); color:var(--muted); }
.step.done .step-mark{ background:var(--ok-soft); color:var(--ok); }
.step.current{ border-color:#9fbbe6; box-shadow:0 0 0 3px var(--primary-soft); }
.step.current .step-mark{ background:var(--primary); color:#fff; }
.step-title{ font-weight:600; }
.step-text{ font-size:12.5px; color:var(--muted); margin-top:1px; }
.step .link-btn{ font-size:13px; margin-top:6px; font-weight:550; }

.run-list{ list-style:none; margin:0; padding:0; }
.run-item{ padding:10px 20px; border-bottom:1px solid #edf1f6; }
.run-item:last-child{ border-bottom:0; }
.run-msg{ color:var(--text-2); overflow-wrap:anywhere; }
.run-meta{ font-size:12.5px; color:var(--muted); }
.run-item.is-error .run-msg{ color:var(--danger); }

/* ---------- Tools ---------- */
.tool-card .card-body{ display:flex; flex-direction:column; gap:16px; }
.tool-card .tool-desc{ color:var(--muted); font-size:13.5px; }
.tool-actions{ display:flex; align-items:center; gap:12px; flex-wrap:wrap; }
.tool-status{ font-size:13px; color:var(--muted); }
.subject-regrab-textarea{ min-height:130px; }

/* ---------- Activity ---------- */
.audit-table{ min-width:1000px; }
.audit-pager{ border-top:1px solid var(--border); }
.audit-attachments{ display:flex; flex-direction:column; gap:3px; min-width:160px; max-width:260px; }
.audit-attachment{ display:flex; justify-content:space-between; gap:10px; white-space:nowrap; font-size:12.5px; }
.audit-attachment > span:first-child{ min-width:0; overflow:hidden; text-overflow:ellipsis; }
.audit-attachment > span:first-child span{ display:block; overflow:hidden; text-overflow:ellipsis; }
.event-pill{ display:inline-flex; padding:1px 8px; border-radius:999px; font-size:12px; font-weight:600; background:var(--surface-3); color:var(--text-2); white-space:nowrap; }
.event-pill.collected{ background:var(--primary-soft); color:var(--primary-text); }
.event-pill.consumed{ background:var(--ok-soft); color:var(--ok); }
.event-pill.peeked{ background:#f4f0ff; color:#5b3fb5; }
.event-pill.summary{ background:var(--warn-soft); color:var(--warn); }
.debug-json{ min-height:320px; }

/* ---------- Mails ---------- */
.filter-grid{ display:grid; grid-template-columns:minmax(220px,1.4fr) minmax(150px,.8fr) minmax(200px,1.2fr) auto; gap:12px; align-items:end; }
.filter-grid .field{ margin:0; }
.mails-meta{ display:flex; gap:8px; flex-wrap:wrap; align-items:center; font-size:13px; color:var(--muted); }
.mails-meta:empty{ display:none; }
.mail-list{ display:flex; flex-direction:column; }
.mail-card{ border-bottom:1px solid #edf1f6; }
.mail-card:last-child{ border-bottom:0; }
.mail-card details{ border:0; border-radius:0; background:transparent; }
.mail-card details + details{ margin:0; }
.mail-summary{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 20px; border-radius:0; }
.mail-summary::before{ align-self:center; }
.mail-card details[open] > .mail-summary{ background:var(--surface-2); }
.mail-title{ display:flex; flex-direction:column; gap:2px; min-width:0; flex:1; }
.mail-title b{ font-size:14px; font-weight:600; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.mail-sub{ display:flex; flex-wrap:wrap; gap:4px 14px; font-size:12.5px; font-weight:400; color:var(--muted); }
.mail-sub .muted{ font-size:12.5px; }
.mail-actions{ display:flex; gap:6px; flex-wrap:wrap; align-items:center; justify-content:flex-end; }
.mail-side{ display:flex; gap:6px; align-items:center; flex-shrink:0; }
.mail-body{ padding:6px 20px 20px 36px; display:grid; grid-template-columns:minmax(0,1fr); gap:14px; background:var(--surface-2); }
.mail-toolbar{ display:flex; gap:6px; flex-wrap:wrap; }
.mail-grid{ display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.mail-block{ border:1px solid var(--border); border-radius:8px; padding:12px 14px; background:var(--surface); min-width:0; }
.mail-block h4{ margin:0 0 8px; font-size:12px; font-weight:650; letter-spacing:.04em; text-transform:uppercase; color:var(--muted); }
.mail-pre{ margin:0; white-space:pre-wrap; word-break:break-word; font-family:var(--mono); font-size:12px; color:var(--text); background:var(--surface-2); border-radius:6px; padding:10px; max-height:280px; overflow:auto; }
.mail-iframe{ width:100%; height:360px; border:1px solid var(--border); border-radius:8px; background:#fff; }
.pdf-preview{ width:100%; height:min(720px, 70vh); min-height:420px; border:1px solid var(--border); border-radius:8px; background:#fff; }
.raw-json-details{ background:var(--surface); }
.attach-list{ display:flex; flex-direction:column; gap:8px; }
.attach-item{ border:1px solid var(--border); border-radius:8px; padding:10px 12px; background:var(--surface); }
.attach-head{ display:flex; justify-content:space-between; align-items:center; gap:10px; flex-wrap:wrap; }
.attach-name{ font-weight:600; color:var(--text); overflow-wrap:anywhere; }
.attach-preview{ margin-top:10px; display:none; }
.attach-preview.open{ display:block; }
.fetch-panel{ display:flex; align-items:center; gap:16px; flex-wrap:wrap; }
.fetch-panel .field{ margin:0; }
.fetch-panel.is-consuming{ }
#mailsFetch.is-danger{ background:var(--danger); border-color:var(--danger); color:#fff; }
.routing-details{ background:var(--surface); }

/* Routing guidance is part of the controls. */
.routing-help{ display:block; color:var(--muted); font-size:12.5px; line-height:1.5; margin:6px 0 10px; }

/* ---------- Postbox editor widgets ---------- */
.directory-picker{ display:grid; gap:10px; margin-top:10px; padding:12px; border:1px solid var(--border); border-radius:8px; background:var(--surface-2); }
.directory-picker-actions{ display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
.directory-picker-actions .form-control{ flex:1 1 200px; width:auto; height:30px; font-size:13px; }
.directory-select{ height:180px !important; min-height:180px; padding:4px; font-family:var(--mono); font-size:12.5px; }
.directory-select option{ padding:4px 6px; border-radius:4px; }
.directory-combobox{ position:relative; min-width:0; }
.directory-combobox > input{ padding-right:40px; }
.directory-toggle{ position:absolute; right:3px; top:3px; bottom:3px; width:30px; border:0; border-radius:6px; background:transparent; color:var(--muted); cursor:pointer; }
.directory-toggle:hover{ background:var(--surface-3); }
.directory-toggle:disabled{ cursor:not-allowed; opacity:.5; }
.directory-options{ position:absolute; z-index:20; top:calc(100% + 5px); left:0; right:0; max-height:240px; overflow-y:auto; background:var(--surface); border:1px solid var(--border); border-radius:8px; box-shadow:var(--shadow); padding:4px; }
.directory-option{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:8px 10px; border-radius:6px; cursor:pointer; font-size:13.5px; }
.directory-option > span{ min-width:0; overflow-wrap:anywhere; }
.directory-option small{ color:var(--muted); flex-shrink:0; font-size:11px; }
.directory-option:hover, .directory-option.active{ background:var(--primary-soft); }
.directory-option[aria-selected="true"]{ color:var(--primary-text); font-weight:600; }
.directory-option-note{ padding:8px 10px; color:var(--muted); font-size:12px; }
.directory-options[hidden], .help-tooltip[hidden]{ display:none !important; }
#postboxDirectoryStatus{ font-size:12.5px; overflow-wrap:anywhere; }
#postboxPatternFolderHint{ font-size:12.5px; }

.mailbox-pattern-settings{ padding:14px; border:1px solid #c9daf3; border-radius:8px; background:var(--primary-soft); }
.mailbox-pattern-settings p{ margin:6px 0 10px; font-size:12.5px; line-height:1.5; }
.mailbox-pattern-settings textarea{ min-height:64px; }
.mailbox-queue-summary{ font-weight:600; overflow-wrap:anywhere; }
#postbox_patternError{ color:var(--danger); }
#postbox_mailboxPreviewList{ max-height:230px; overflow:auto; margin-top:8px; }
#postbox_mailboxPreview{ background:var(--surface); }
#postbox_mailboxPreview > :not(summary){ margin-left:12px; margin-right:12px; }
.mailbox-preview-row{ display:flex; justify-content:space-between; align-items:center; gap:8px; padding:8px 2px; border-bottom:1px solid var(--border); font-size:12.5px; }
.mailbox-preview-row > div{ min-width:0; overflow-wrap:anywhere; }
.mailbox-preview-row .badge{ flex-shrink:0; }
#postbox_recipientExceptions{ min-height:64px; }

.archive-marker-settings{ padding:14px; border:1px solid var(--border); border-radius:8px; background:var(--surface-2); }
.archive-marker-settings p{ font-size:12.5px; line-height:1.5; margin:8px 0; }
.archive-marker-input{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.archive-marker-input input{ flex:1; min-width:150px; }
.archive-marker-error{ color:var(--danger); }
.archive-subject-option{ margin-top:12px; }
#postbox_archiveMarkerPreview{ overflow-wrap:anywhere; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px){
  .filter-grid{ grid-template-columns:1fr 1fr; }
}
@media (max-width: 980px){
  .grid-2{ grid-template-columns:1fr; }
  .mail-grid{ grid-template-columns:1fr; }
}
@media (max-width: 900px){
  .sidebar-btn{ display:inline-grid; }
  .sidebar{ top:0; z-index:40; width:min(280px, 85vw); transform:translateX(-102%); transition:transform .18s ease; box-shadow:var(--shadow-lg); padding-top:16px; }
  .sidebar.open{ transform:translateX(0); }
  .sidebar-backdrop{ position:fixed; inset:0; z-index:35; background:rgba(15,23,42,.35); }
  .sidebar.open + .sidebar-backdrop{ display:block; }
  .content{ margin-left:0; padding:calc(var(--topbar-h) + 16px) 16px 40px; }
  .conn-pill span:last-child{ max-width:150px; }
}
@media (max-width: 720px){
  .row, .row-3{ grid-template-columns:1fr; }
  .filter-grid{ grid-template-columns:1fr; }
  .page-head h1{ font-size:20px; }
  .card-body{ padding:16px; }
  .modal-body{ padding:16px; }
  .modal-head, .modal-foot{ padding-left:16px; padding-right:16px; }
  .list-toolbar .form-control{ flex:1 1 100%; min-width:0; }
  .search-field{ max-width:none; flex-basis:100%; }
  .mail-summary{ flex-direction:column; align-items:stretch; padding:12px 16px; }
  .mail-summary::before{ display:none; }
  .mail-side{ justify-content:flex-start; }
  .mail-title b{ white-space:normal; }
  .mail-body{ padding:6px 16px 16px; }
  .brand-tag{ display:none; }
  .conn-pill{ padding:5px 10px; }
  .conn-pill span:last-child{ display:none; }
  .routing-details, .routing-help{ overflow-wrap:anywhere; }
  .attention-item{ flex-wrap:wrap; }
}

/* Mail rows sit flush inside their disclosure. */
.mail-card details > .mail-body{ margin:0; }
.mail-lists{ flex:1; min-width:0; }
.mail-lists .badge{ font:inherit; font-size:12px; font-weight:600; }
.page > * + *{ margin-top:20px; }
.page-head{ margin-bottom:0; }
.tool-card .field{ margin-bottom:0; }
.tool-card .row{ gap:16px; }
@media (max-width: 720px){
  .kpi-grid{ grid-template-columns:repeat(2, minmax(0,1fr)); gap:12px; }
  .kpi{ padding:12px 14px; }
  .kpi-value{ font-size:21px; }
  .attention-body{ flex-basis:calc(100% - 42px); }
  .attention-item .btn{ margin-left:42px; }
  .attention-title{ overflow-wrap:break-word; }
}

/* ---------- Info tips ("i" next to labels and headings) ---------- */
.help-trigger{
  display:inline-grid; place-items:center; vertical-align:-3px;
  width:20px; height:20px; margin-left:4px; padding:0;
  border:0; border-radius:50%; background:transparent; color:var(--faint);
  font:inherit; font-size:12px; font-weight:500; cursor:help;
}
.help-trigger .icon{ width:15px; height:15px; }
.help-trigger:hover, .help-trigger[aria-expanded="true"]{ color:var(--primary); background:var(--primary-soft); }
.help-trigger:focus-visible{ outline:2px solid var(--primary); outline-offset:1px; }
h1 .help-trigger{ width:24px; height:24px; vertical-align:-2px; }
h1 .help-trigger .icon{ width:17px; height:17px; }
.form-section-head h3 .help-trigger{ margin-left:0; }
.help-chip{ display:inline-flex; gap:4px; width:auto; height:24px; padding:0 9px 0 6px; margin:0 6px 6px 0; border:1px solid var(--border); border-radius:999px; background:var(--surface-2); color:var(--primary-text); }
.help-tooltip[role="tooltip"]{
  display:block; position:fixed; z-index:100; margin:0; max-width:none;
  padding:10px 12px; border-radius:8px; box-shadow:var(--shadow);
  background:#0f1d33; color:#e8eef8; border:0;
  font-size:13px; font-weight:400; line-height:1.5; text-align:left; letter-spacing:normal; text-transform:none;
  overflow-wrap:anywhere; white-space:normal;
}
.help-tooltip[role="tooltip"][hidden]{ display:none !important; }
.help-tooltip[role="tooltip"] strong{ color:#fff; }
.help-tooltip[role="tooltip"] code{ color:inherit; background:rgba(255,255,255,.14); }
.help-tooltip[role="tooltip"] a{ color:#9ec5ff; text-decoration:underline; }

/* Keyboard hint inside search fields. */
.search-kbd{ position:absolute; right:8px; top:50%; transform:translateY(-50%); pointer-events:none; color:var(--faint); }
.search-field > .form-control:focus + .search-kbd, .search-field > .form-control:not(:placeholder-shown) + .search-kbd{ display:none; }
.search-field > .form-control{ padding-right:30px; }

/* Whole rows open the editor. */
tr[data-row-edit]{ cursor:pointer; }

.fetch-panel{ display:flex; align-items:flex-end; gap:16px; flex-wrap:wrap; }
.fetch-panel .field{ margin:0; }
details.card > summary{ padding:14px 20px; font-size:15px; font-weight:650; color:var(--text); }
details.card > .details-body{ padding:4px 20px 20px; }

@media (max-width: 720px){
  .search-kbd{ display:none; }
  details.card > summary, details.card > .details-body{ padding-left:16px; padding-right:16px; }
}
.directory-toggle:focus-visible{ outline:2px solid var(--primary); outline-offset:2px; }

.cell-issue .issue-text{ display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.cell-issue .issue-when{ font-weight:400; color:var(--muted); }
.truncate{ max-width:240px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.inline-details{ border:0; background:transparent; margin-top:6px; }
.inline-details > summary{ display:inline-flex; padding:2px 0; font-size:13px; font-weight:550; color:var(--primary-text); }
.inline-details > summary:hover{ background:transparent; text-decoration:underline; }
.inline-details > .details-body{ padding:8px 0 0; }

.collection-controls label{ display:grid; gap:4px; color:var(--muted); font-size:12px; }
.collection-controls{ align-items:end; }
.collection-table{ font-variant-numeric:tabular-nums; }
.collection-table :is(th,td):not(:first-child){ text-align:right; }
.collection-table tfoot :is(th,td){ padding:10px 16px; background:var(--surface-2); font-weight:600; }
.collection-table tfoot th{ text-align:left; }
.collection-issue{ color:var(--warn); }
