:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --border: #dedcd6;
  --text: #1f2328;
  --muted: #646a73;
  --accent: #1d4f8c;
  --accent-text: #ffffff;
  --danger: #b42318;
  --ok: #2f7d32;
  --warn-bg: #fff4e0;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
code { background: #efeee9; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; background: #1f2a37; color: #fff; flex-wrap: wrap; }
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; letter-spacing: .02em; }
.topbar nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar nav a, .topbar .link { color: #cfd6df; text-decoration: none; }
.topbar nav a.active, .topbar nav a:hover { color: #fff; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
.narrow { max-width: 420px; margin: 10vh auto; padding: 0 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.warn { background: var(--warn-bg); border-radius: 6px; padding: 8px 10px; }
.error-text { color: var(--danger); font-size: 0.85rem; }

form.inline { display: inline; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.narrow-form { max-width: 420px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.9rem; margin-bottom: 12px; }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
input[type=checkbox] { width: auto; }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; line-height: 1.45; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; align-items: end; }
fieldset { border: 0; border-top: 1px solid var(--border); padding: 16px 0 4px; margin: 0; }
fieldset:first-of-type { border-top: 0; padding-top: 0; }
legend { font-weight: 700; padding-right: 8px; }
.days { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.days label { margin: 0; }
.small-input { width: 150px; padding: 4px 8px; }

button, .button { font: inherit; display: inline-block; padding: 7px 14px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
button:hover, .button:hover { border-color: #bdbab2; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); border-color: #e7b4ae; }
button.small { padding: 4px 10px; font-size: 0.85rem; }
button.link { background: none; border: 0; padding: 0; color: #cfd6df; }
button:disabled { opacity: .6; cursor: wait; }
.danger-zone { margin-top: 8px; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; border: 1px solid; }
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.flash-success { background: #ecf6ec; border-color: #b9dcbb; }
.flash-info { background: #eaf1fa; border-color: #b8cce6; }
.flash-error { background: #fbeceb; border-color: #efbdb7; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td.actions { white-space: nowrap; }
td.actions form { margin-right: 6px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; background: #ecebe6; color: var(--muted); }
.badge-success { background: #e3f2e4; color: var(--ok); }
.badge-failed { background: #fbe5e3; color: var(--danger); }
.badge-running { background: #eaf1fa; color: var(--accent); }

.email-preview { width: 100%; min-height: 80vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }

@media (max-width: 640px) {
  .container { padding: 16px 12px 40px; }
  .card { padding: 14px; }
}

/* Password show/hide */
.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 64px; }
.password-wrap .pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); padding: 3px 10px; font-size: 0.8rem; border: 0; background: transparent; color: var(--accent); font-weight: 600; }
.password-wrap .pw-toggle:hover { background: #eef2f8; }
.small-input + .pw-toggle, .password-wrap:has(.small-input) { display: inline-block; }
.password-wrap .small-input { width: 190px; }

/* Connections */
h3 { font-size: 0.95rem; margin: 0 0 6px; }
.overall { margin: 2px 0 0; font-weight: 600; }
.overall-ok { color: var(--ok); }
.overall-warn { color: #8a5a00; }
.overall-fail { color: var(--danger); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.status::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: #a8a6a0; }
.status-ok { color: var(--ok); } .status-ok::before { background: var(--ok); }
.status-warn { color: #8a5a00; } .status-warn::before { background: #d08a00; }
.status-fail { color: var(--danger); } .status-fail::before { background: var(--danger); }
.hint { margin-top: 3px; font-size: 0.82rem; color: var(--muted); }
.conn-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.conn-details p { margin: 0 0 8px; }

/* Run log stage tag */
.stage { display: inline-block; padding: 0 7px; border-radius: 4px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; background: #fbe5e3; color: var(--danger); margin-right: 4px; }
td.detail { min-width: 280px; }

.stage-warn { background: var(--warn-bg); color: #8a5a00; }
.warn-text { font-size: 0.85rem; color: #7a4b00; white-space: pre-line; }
.match-ok { color: var(--ok); font-weight: 600; }

/* Branding in the app header */
.topbar .brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-firm { font-weight: 500; color: #9fb0c2; padding-left: 10px; margin-left: 2px; border-left: 1px solid #3a4757; }

/* Setup checklist */
.card.setup { border-left: 4px solid #8fa4b8; }
.setup-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.setup-list li { display: flex; align-items: center; gap: 10px; }
.setup-list .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #8fa4b8; display: inline-grid; place-items: center; font-size: .8rem; color: #fff; }
.setup-list li.done { color: var(--muted); }
.setup-list li.done .tick { background: var(--ok); border-color: var(--ok); }

/* Settings */
.radio-set { border: 0; padding: 0; margin: 0 0 6px; }
.radio-set legend { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.radio-set label { margin-bottom: 6px; }
.conn-status { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.clio-form { max-width: 720px; }
input[type=radio] { width: auto; }
.radio-set label.check { display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: 8px; font-weight: 500; }
