:root {
  --bg: #f5f5f5; --surface: #ffffff; --ink: #000000; --muted: #6f6f6f; --line: #e2e2e2; --soft: #f7f7f7;
  --accent: #be161d; --accent-dark: #9c1118; --navy: #1a3f71; --side: #ffffff; --side-ink: #393939;
  --green: #17734a; --green-bg: #e4f4ea; --amber: #8a5a00; --amber-bg: #fdf0cf; --red: #be161d; --red-bg: #fbe4e5;
  --blue: #1a3f71; --blue-bg: #e4ebf5; --grey: #5b6472; --grey-bg: #ececec;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 "Rethink Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; font-weight: 700; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 20px 14px; display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--line); }
.brand { padding: 2px 10px 18px; }
.brand img { display: block; width: 100%; max-width: 168px; height: auto; margin-bottom: 8px; }
.brand b { display: block; color: var(--ink); font-weight: 700; font-size: 17px; line-height: 1.2; }
.brand span { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.side a { color: var(--side-ink); padding: 8px 10px; border-radius: 3px; display: block; }
.side a:hover { background: #f3f3f3; text-decoration: none; }
.side a.on { background: var(--accent); color: #fff; }
.side .sep { margin: 12px 10px 4px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.side .who { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line); font-size: 13px; }
.side .who b { display: block; color: var(--ink); font-weight: 600; }
.side .who form { margin-top: 8px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; }
.linkbtn:hover { color: var(--accent); text-decoration: underline; }

.main { padding: 28px 32px 60px; min-width: 0; }
.pagehead { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.pagehead .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 18px 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.cardhead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.cardhead h2 { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 16px 18px; color: var(--ink); display: block; }
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .n { font-size: 30px; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tile.warn .n { color: var(--amber); }
.tile.bad .n { color: var(--red); }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 3px; font: inherit; font-weight: 550; cursor: pointer; line-height: 1.3; }
.btn:hover { border-color: #9a9a9a; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 4px 10px; font-size: 13px; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: var(--soft); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px 20px; color: var(--muted); text-align: center; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.active, .badge.paid { background: var(--green-bg); color: var(--green); }
.badge.due, .badge.pending { background: var(--amber-bg); color: var(--amber); }
.badge.lapsed { background: var(--red-bg); color: var(--red); }
.badge.upcoming, .badge.complimentary { background: var(--blue-bg); color: var(--blue); }
.badge.renewed, .badge.cancelled, .badge.plain { background: var(--grey-bg); color: var(--grey); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filters label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 3px; }
.filters .grow { flex: 1 1 220px; }
input[type=text], input[type=tel], input[type=url], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #c9c9c9; border-radius: 3px; background: #fff; color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 84px; resize: vertical; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form .full { grid-column: 1 / -1; }
.form .third { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; grid-column: 1 / -1; }
.field label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 4px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }
.formfoot { display: flex; gap: 10px; margin-top: 18px; }

.flash { padding: 10px 14px; border-radius: 3px; margin-bottom: 16px; border: 1px solid; }
.flash.ok { background: var(--green-bg); color: var(--green); border-color: #b9dfc8; }
.flash.err { background: var(--red-bg); color: var(--red); border-color: #efc0bb; }
.note { background: var(--amber-bg); color: #5c3d00; border-radius: 3px; padding: 10px 14px; margin-bottom: 16px; }

.dl { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.inline { display: inline; }
.rowform { display: flex; gap: 6px; }
.rowform input { min-width: 150px; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.authbox { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 28px; }
.authbox .brand { padding: 0 0 18px; }
.authbox .brand img { max-width: 200px; }
.authbox .field { margin-bottom: 14px; }
.authbox .btn { width: 100%; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; }
  .brand { padding: 0 10px 0 4px; }
  .brand span, .side .sep { display: none; }
  .side .who { margin: 0 0 0 auto; padding: 0; border: 0; display: flex; gap: 10px; align-items: center; }
  .side .who form { margin: 0; }
  .main { padding: 18px 16px 48px; }
  .form, .cols, .form .third { grid-template-columns: minmax(0, 1fr); }
  .dl { grid-template-columns: 110px minmax(0, 1fr); }
}
@media print { .side, .pagehead .actions, .filters { display: none; } .shell { display: block; } }

/* email template editor */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid #c9c9c9; border-bottom: 0; border-radius: 3px 3px 0 0; background: var(--soft); }
.toolbar select { width: auto; padding: 4px 8px; font-size: 13px; }
.rich { min-height: 320px; padding: 14px 16px; border: 1px solid #c9c9c9; border-radius: 0 0 3px 3px; background: #fff; overflow-wrap: anywhere; }
.rich:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.rich p { margin: 0 0 12px; } .rich a.button { display: inline-block; background: var(--accent); color: #fff; padding: 8px 18px; border-radius: 3px; text-decoration: none; font-weight: 600; }
textarea.source { min-height: 320px; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; border-radius: 0 0 3px 3px; }
.preview { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 3px; background: #f5f5f5; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
@media (max-width: 1100px) { .editor-grid { grid-template-columns: minmax(0, 1fr); } }
/* public forms */
.pub { max-width: 620px; margin: 0 auto; padding: 28px 16px 60px; }
.pub .logo { display: block; max-width: 200px; height: auto; margin-bottom: 22px; }
.pub h1 { margin-bottom: 10px; }
.pub .field { margin-bottom: 14px; }
.pub .err { color: var(--red); font-size: 13px; margin-top: 3px; }
.pub .plan { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid #c9c9c9; border-radius: 3px; margin-bottom: 8px; background: #fff; cursor: pointer; }
.pub .plan input { width: auto; margin-top: 4px; }
.pub .hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
