:root {
  --accent: #1155CC;
  --accent-dark: #0B3F99;
  --accent-soft: #E8F0FC;
  --ink: #0F1B33;
  --muted: #4A5468;
  --line: #DDE3EC;
  --line-soft: #EEF1F6;
  --input-line: #C9D2DF;
  --bg: #F4F6FA;
  --panel: #FFFFFF;
  --panel-alt: #F8FAFD;
  --ok-fg: #1A7A36; --ok-bg: #E3F4E8;
  --warn-fg: #7A5000; --warn-bg: #FFF3D6;
  --error-fg: #A11A1A; --error-bg: #FDE8E8;
  --info-fg: #0B3F99; --info-bg: #E8F0FC;
  --muted-bg: #EEF1F6;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 Poppins, "Segoe UI", system-ui, sans-serif;
}
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
button, input, select { font-family: inherit; }
h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1360px; margin: 0 auto; padding: 12px 28px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 32px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.brand-name span { color: var(--accent); }
.pill { font-size: 12px; font-weight: 600; color: var(--muted); padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 auto; }
.nav a { min-height: 44px; padding: 0 16px; border-radius: 8px; color: var(--muted); font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.nav a.on { background: var(--accent-soft); color: var(--accent-dark); }
.count-badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--error-fg); color: #fff; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.user { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-meta form { margin: 0; }
.linklike { padding: 0; border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; text-align: left; }
.linklike:hover { color: var(--accent); }

main { max-width: 1360px; margin: 0 auto; padding: 28px 28px 48px; display: flex; flex-direction: column; gap: 24px; }

/* Buttons */
.btn { min-height: 44px; padding: 0 16px; border: 1px solid var(--input-line); border-radius: 10px; background: var(--panel); color: var(--ink); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { background: var(--error-fg); border-color: var(--error-fg); color: #fff; }
.btn-warn { background: var(--warn-fg); border-color: var(--warn-fg); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn[disabled], .btn.is-busy { opacity: .55; cursor: not-allowed; }
.btn svg { flex: none; }

/* Page head */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head .title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; color: var(--muted); }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; }
.kpi-hint { font-size: 12.5px; color: var(--muted); }
.tone-warn { color: var(--warn-fg); } .tone-error { color: var(--error-fg); } .tone-ok { color: var(--ok-fg); }

/* Filters + search */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--ink); font-size: 13.5px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.chip .n { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--muted-bg); font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.on .n { background: rgba(255,255,255,.18); }
.search { position: relative; flex: 0 1 340px; min-width: 220px; }
.search svg { position: absolute; left: 14px; top: 13px; color: var(--muted); }
.search input { width: 100%; min-height: 44px; padding: 0 14px 0 42px; border: 1px solid var(--input-line); border-radius: 10px; font-size: 14px; background: var(--panel); color: var(--ink); }

/* Tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; min-width: 1000px; }
table.grid th { text-align: left; padding: 12px 20px; background: var(--panel-alt); border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
table.grid td { padding: 12px 20px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid .agency a { font-weight: 600; text-decoration: none; }
table.grid .sub { display: block; font-size: 12.5px; color: var(--muted); }
table.compact { min-width: 640px; }
table.compact th, table.compact td { padding: 10px 6px; }
table.compact th { background: none; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.error { background: var(--error-bg); color: var(--error-fg); }
.badge.info { background: var(--info-bg); color: var(--info-fg); }
.badge.muted { background: var(--muted-bg); color: var(--muted); }
.tag { padding: 4px 12px; border-radius: 999px; background: var(--muted-bg); font-size: 13px; }
.tag.blue { background: var(--accent-soft); color: var(--accent-dark); }

/* Detail layout */
.back { min-height: 44px; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-decoration: none; }
.detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 16px; }
.detail-head .meta { display: flex; flex-direction: column; gap: 8px; }
.tags, .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions { gap: 10px; }
.actions form { margin: 0; }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.col-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.col-side { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.panel h2 + p { margin-top: -10px; color: var(--muted); font-size: 13.5px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }

/* Alerts / messages */
.alert { border-radius: 12px; padding: 14px 18px; font-weight: 500; display: flex; gap: 10px; align-items: flex-start; }
.alert svg { flex: none; margin-top: 2px; }
.alert.ok, .alert.success { background: var(--ok-bg); color: var(--ok-fg); }
.alert.warn, .alert.warning { background: var(--warn-bg); color: var(--warn-fg); }
.alert.error { background: var(--error-bg); color: var(--error-fg); }
.alert.info { background: var(--info-bg); color: var(--info-fg); }
.messages { display: flex; flex-direction: column; gap: 10px; }

/* Charge form */
.charge-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 240px; }
.field label, .label { font-size: 13px; font-weight: 600; }
.money-input { display: flex; align-items: center; border: 1px solid var(--input-line); border-radius: 10px; background: var(--panel); min-height: 50px; padding: 0 14px; gap: 6px; }
.money-input span { color: var(--muted); font-weight: 600; font-size: 18px; }
.money-input input { border: 0; flex: 1; min-width: 0; font-size: 18px; font-weight: 600; color: var(--ink); background: transparent; min-height: 44px; outline: none; font-variant-numeric: tabular-nums; }
.money-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.lines { border: 1px solid var(--line-soft); border-radius: 10px; overflow: hidden; }
.lines .line { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.lines .total { display: flex; justify-content: space-between; gap: 12px; padding: 14px 16px; background: var(--panel-alt); font-weight: 700; }
.lines .cap { padding: 10px 16px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; background: var(--panel-alt); border-bottom: 1px solid var(--line-soft); }
.hidden { display: none !important; }

/* Card on file */
.cc { border-radius: 12px; padding: 18px; background: var(--ink); color: #fff; display: flex; flex-direction: column; gap: 18px; }
.cc-top, .cc-bottom { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.cc-top small { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--input-line); }
.cc-number { font-size: 18px; letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.cc-bottom { font-size: 12.5px; color: var(--input-line); }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.note { font-size: 12.5px; color: var(--muted); }
.link-box { display: flex; gap: 8px; }
.link-box input { flex: 1; min-width: 0; min-height: 40px; padding: 0 12px; border: 1px solid var(--input-line); border-radius: 10px; font-size: 12.5px; color: var(--muted); background: var(--panel-alt); }
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.events li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; }
.events li:last-child { border-bottom: 0; }
.events .ev-err { color: var(--error-fg); }

/* Forms (new client, login) */
.form-card { max-width: 720px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input[type=text], .form-grid input[type=email], .form-grid input[type=password], .form-grid select {
  width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--input-line); border-radius: 10px; font-size: 14px; background: var(--panel); color: var(--ink);
}
.form-grid input:focus, .form-grid select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.errorlist { list-style: none; margin: 4px 0 0; padding: 0; color: var(--error-fg); font-size: 12.5px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

@media (max-width: 640px) {
  .topbar-inner, main { padding-left: 16px; padding-right: 16px; }
  .panel, .form-card { padding: 18px; }
}
