:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #1b2230;
  --muted: #667085;
  --primary: #2f5bea;
  --primary-600: #2448c7;
  --primary-soft: #eef2fe;
  --danger: #c62a1f;
  --danger-soft: #fdf0ef;
  --warn: #a65103;
  --warn-soft: #fff6e5;
  --soon: #8a6100;
  --soon-soft: #fdf6d3;
  --ok: #08744a;
  --ok-soft: #e8f8ef;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1d222c;
    --border: #2a303c;
    --border-strong: #3a4250;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --primary: #7b9bff;
    --primary-600: #98b1ff;
    --primary-soft: #1f2843;
    --danger: #ff8378;
    --danger-soft: #3a1c1a;
    --warn: #ffb44d;
    --warn-soft: #3a2a12;
    --soon: #f3d36b;
    --soon-soft: #353014;
    --ok: #5bd69b;
    --ok-soft: #13301f;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.3; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; }
p { margin: 0 0 12px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
.icon { flex: none; vertical-align: -3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 10px 18px; color: var(--text); font-weight: 700; font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--primary); color: #fff; flex: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.me { display: flex; flex-direction: column; min-width: 0; }
.me span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .btn { justify-content: flex-start; padding-left: 0; }
.main { padding: 28px 32px 56px; min-width: 0; width: 100%; max-width: 1320px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.breadcrumb a { color: var(--muted); }
.head-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; }

.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.layout-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head-split { border-top: 1px solid var(--border); flex-wrap: wrap; }
.card-body { padding: 16px; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.muted-link { color: var(--muted); font-size: 13px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow); }
.stat:hover { text-decoration: none; border-color: var(--border-strong); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-critical .stat-value, .stat-expired .stat-value { color: var(--danger); }
.stat-soon .stat-value { color: var(--warn); }
.money-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 4px 0; font-variant-numeric: tabular-nums; }
.money-row strong { font-size: 18px; }
.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; text-align: center; font-size: 12px; color: var(--muted); }
.mini-stats span { display: block; font-size: 20px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.mini-stats .text-danger span { color: var(--danger); }

/* ---------- tables & lists ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap;
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { border-top: 1px solid var(--border); border-bottom: 0; background: var(--surface-2); }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table-form td { vertical-align: middle; }
.table-form input, .table-form select { min-width: 120px; }
.nowrap { white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions form { display: inline; }
.is-dim td { color: var(--muted); }
.strong { font-weight: 600; }
.sub { font-size: 12px; color: var(--muted); }
.text-danger { color: var(--danger) !important; }
.pre { white-space: pre-wrap; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list-main { display: flex; flex-direction: column; min-width: 0; color: var(--text); }
.list-main:hover { text-decoration: none; }
.list-main:hover .strong { color: var(--primary); }
.list-main > span { overflow: hidden; text-overflow: ellipsis; }

.dl { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.dl-stack { grid-template-columns: 1fr; gap: 2px; }
.dl-stack dd { margin-bottom: 10px; }
.dl-stack dd:last-child { margin-bottom: 0; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 20px;
}
.b-expired { background: var(--danger); color: #fff; }
.b-critical { background: var(--danger-soft); color: var(--danger); }
.b-warning { background: var(--warn-soft); color: var(--warn); }
.b-soon { background: var(--soon-soft); color: var(--soon); }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-info { background: var(--primary-soft); color: var(--primary); }
.b-muted { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }

/* ---------- alerts ---------- */
.flash, .alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.flash .icon, .alert .icon { margin-top: 1px; }
.flash-success { background: var(--ok-soft); color: var(--ok); }
.flash-error, .alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--primary-soft); color: var(--primary); }
.alert a, .flash a { color: inherit; font-weight: 600; text-decoration: underline; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.inset { padding: 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border-strong); }
label, .label { font-weight: 600; font-size: 13px; }
.opt { font-weight: 400; color: var(--muted); }
.help { font-size: 12px; color: var(--muted); font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; padding: 8px 11px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
}
input[type="color"] { width: 64px; height: 38px; padding: 3px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); }
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
.input-sm { max-width: 90px; min-width: 70px !important; }
.input-group { display: flex; gap: 8px; }
.input-group > input { flex: 1; min-width: 0; }
.input-group > select { width: auto; flex: none; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0; display: flex; flex-direction: column; gap: 14px; }
.fieldset legend { font-weight: 700; padding: 0 6px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { margin: 3px 0 0; width: 16px; height: 16px; flex: none; accent-color: var(--primary); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check-box { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.check-box.is-warning { background: var(--warn-soft); border-color: transparent; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.is-disabled { opacity: 0.5; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type="search"] { flex: 1 1 240px; max-width: 340px; }
.filters select { width: auto; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  padding: 8px 14px; font: inherit; font-weight: 600; color: var(--text); cursor: pointer;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.inline { display: inline; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; overflow-x: auto; overflow-y: hidden; margin-bottom: 18px; box-shadow: inset 0 -1px 0 var(--border); }
.tabs a { padding: 9px 12px; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.pills { display: flex; gap: 4px; flex-wrap: wrap; }
.pills a { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--muted); }
.pills a:hover { background: var(--surface-2); text-decoration: none; }
.pills a.active { background: var(--primary-soft); color: var(--primary); }

/* ---------- reminder timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 14px; top: 14px; bottom: 14px; width: 2px; background: var(--border); }
.timeline li { position: relative; display: flex; gap: 12px; align-items: flex-start; padding: 7px 0; }
.tl-dot {
  position: relative; z-index: 1; display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%; font-size: 12px; font-weight: 700;
  background: var(--surface); color: var(--muted); box-shadow: inset 0 0 0 2px var(--border-strong);
}
.tl-sent .tl-dot { background: var(--ok-soft); color: var(--ok); box-shadow: inset 0 0 0 2px var(--ok); }
.tl-test .tl-dot { background: var(--primary-soft); color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.tl-due .tl-dot { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 2px var(--warn); }
.tl-failed .tl-dot { background: var(--danger-soft); color: var(--danger); box-shadow: inset 0 0 0 2px var(--danger); }
.tl-skipped .tl-dot { text-decoration: line-through; opacity: 0.6; }
.tl-end .tl-dot { background: var(--surface-2); color: var(--text); }
.steps-list { margin: 0 0 12px; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }

/* ---------- email preview ---------- */
.email-frame { display: block; width: 100%; height: 680px; border: 0; border-top: 1px solid var(--border); background: #f3f4f6; }

/* ---------- template chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: 12px ui-monospace, Consolas, monospace; padding: 3px 7px; cursor: pointer; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- sign-in ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card-body { padding: 28px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; font-size: 15px; }

/* ---------- spacing utilities ---------- */
.m0 { margin: 0; }
.mb { margin-bottom: 10px; }
.mt { margin-top: 6px; }
.mt-lg { margin-top: 16px; }
.muted { color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .layout-2, .layout-editor { grid-template-columns: minmax(0, 1fr); }
  .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; gap: 4px;
    padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0 6px 0 0; }
  .brand-name { display: none; }
  .nav { flex-direction: row; gap: 2px; flex: 1; overflow-x: auto; }
  .nav a { padding: 8px 10px; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; }
  .sidebar-foot .me, .sidebar-foot .btn span { display: none; }
  .sidebar-foot .btn { padding: 8px; }
  .main { padding: 20px 16px 48px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .nav a span { display: none; }
  .nav { justify-content: space-around; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid-4 { grid-template-columns: minmax(0, 1fr); }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .filters input[type="search"] { max-width: none; flex-basis: 100%; }
  .page-head .actions { width: 100%; }
  .email-frame { height: 560px; }
}
