:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #15171a;
  --muted: #6b7280;
  --line: #e6e8eb;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --good: #1a7f37;
  --warn: #9a6700;
  --bad: #cf222e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ---------- Auth ---------- */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #eef2ff, var(--bg));
}
.auth-card {
  background: var(--panel);
  padding: 36px 32px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.auth-mark { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.auth-sub { margin: 0 0 8px; color: var(--muted); }
.auth-card input {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card button {
  padding: 11px 12px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  font-weight: 600;
}
.auth-err { color: var(--bad); margin: 4px 0 0; font-size: 13px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px;
  background: #111418;
  color: #cbd2da;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 4px;
}
.brandmark { color: #fff; font-weight: 700; font-size: 18px; padding: 6px 10px 18px; letter-spacing: -0.02em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav button {
  background: transparent;
  border: 0;
  color: #cbd2da;
  text-align: left;
  padding: 9px 10px;
  border-radius: 7px;
}
.sidebar nav button:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav button.active { background: var(--accent); color: #fff; }
.logout { background: transparent; border: 0; color: #8b95a1; text-align: left; padding: 9px 10px; }
.logout:hover { color: #fff; }

.content { flex: 1; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 650; }
#view { padding: 24px 28px; }

/* ---------- Buttons ---------- */
.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  padding: 9px 14px;
  border-radius: 8px;
  font-weight: 600;
}
.ghost { background: transparent; border: 1px solid var(--line); padding: 9px 14px; border-radius: 8px; }
.icon-btn { background: transparent; border: 0; font-size: 22px; line-height: 1; color: var(--muted); }
.link-btn { background: transparent; border: 0; color: var(--accent); padding: 0; font-size: 13px; }
.link-btn.danger { color: var(--bad); }

/* ---------- Cards / metrics ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.metric .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.metric .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.metric .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.note { color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 14px 16px; }

/* ---------- Table ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
td .row-actions { display: flex; gap: 14px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.active { background: #dcfce7; color: var(--good); }
.pill.inactive, .pill.paused { background: #fef3c7; color: var(--warn); }
.pill.cancelled { background: #fee2e2; color: var(--bad); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 6px; border: 1px solid rgba(0,0,0,0.1); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border-radius: 14px; width: 520px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
#modalForm { padding: 20px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 64px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); }
.form-err { color: var(--bad); margin: 0; padding: 0 22px; font-size: 13px; }

/* ---------- Invoice editor ---------- */
.inv-2col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.inv-head, .inv-row {
  display: grid;
  grid-template-columns: 1fr 80px 100px 90px 28px;
  gap: 8px;
  align-items: center;
}
.inv-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 6px; }
.inv-row { margin-bottom: 8px; }
.inv-row input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; width: 100%; }
.inv-row .i-amt { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.inv-total { text-align: right; font-size: 16px; padding: 8px 0; border-top: 1px solid var(--line); }
.inv-total strong { font-size: 18px; margin-left: 8px; }
table a.link-btn { text-decoration: none; }

/* ---------- Dashboard ---------- */
.dash-filters { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.dash-filters label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dash-filters select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
@media (max-width: 760px) { .dash-grid { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 14px 16px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.panel table { width: 100%; border-collapse: collapse; }
.panel .empty { padding: 28px 16px; }
.recurring-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; color: var(--muted); }
.recurring-line { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.recurring-line span { color: var(--ink); }

/* ---------- Invoice preview ---------- */
.preview-card { background: var(--panel); border-radius: 14px; width: 880px; max-width: 100%; height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,0.25); overflow: hidden; }
.preview-card .modal-head { flex-wrap: nowrap; }
.preview-head-actions { display: flex; align-items: center; gap: 16px; }
.preview-head-actions .link-btn { text-decoration: none; font-size: 13px; }
.preview-card iframe { flex: 1; width: 100%; border: 0; background: #f1f3f5; }

/* ---------- Email / send log ---------- */
.muted-sub { font-size: 12px; color: var(--muted); }
.send-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow-y: auto; }
.send-log li { font-size: 13px; line-height: 1.5; }
.send-log .pill { margin-left: 4px; }
.email-actions { display: flex; gap: 10px; align-items: center; }
.pay-summary { display: flex; gap: 24px; padding: 12px 14px; background: #fafbfc; border: 1px solid var(--line); border-radius: var(--radius); }
.pay-summary > div > div { font-size: 16px; font-weight: 600; margin-top: 2px; }
.send-log li .link-btn { margin-left: 6px; }
