:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #12151c;
  --muted: #6b7280;
  --line: #e2e6ec;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --danger: #c02626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }

.muted { color: var(--muted); }
.right { text-align: right; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- controls ---------- */

label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block;
  font-size: 12px;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(31, 111, 235, .35);
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 72px; }

button {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: #c9d0da; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { background: #1a5fd0; }
button.danger { color: var(--danger); border-color: #f0cccc; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: #eef1f5; }
button.sm { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 18px; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .7px;
  text-transform: uppercase;
}
.tag.draft   { background: #eceff3; color: #4b5563; }
.tag.sent    { background: #e5efff; color: #1f6feb; }
.tag.paid    { background: #e3f6ea; color: #12703a; }
.tag.overdue { background: #fdeaea; color: #b32020; }

.notice {
  padding: 10px 13px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 14px;
}
.notice.error { background: #fdeaea; color: #9a1c1c; }
.notice.ok    { background: #e3f6ea; color: #12703a; }

/* ---------- auth screen ---------- */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 30px 18px;
}
.auth {
  width: 100%;
  max-width: 420px;
}
.brand {
  text-align: center;
  margin-bottom: 24px;
}
.brand .mark {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.6px;
}
.brand .mark span { color: var(--accent); }
.tabs {
  display: flex;
  gap: 4px;
  background: #eef1f5;
  padding: 4px;
  border-radius: 9px;
  margin-bottom: 20px;
}
.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* ---------- app shell ---------- */

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .mark { font-weight: 800; font-size: 19px; letter-spacing: -.4px; padding: 14px 0; }
.topbar .mark span { color: var(--accent); }
.nav { display: flex; gap: 2px; }
.nav button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 15px 14px 13px;
}
.nav button.on { color: var(--ink); border-bottom-color: var(--accent); }

.bizswitch { display: flex; gap: 8px; align-items: center; }
.bizswitch select {
  width: auto;
  max-width: 220px;
  padding: 6px 10px;
  font-weight: 600;
}

/* A card whose controls are switched off until the account is paid. */
.card.locked { background: #fbfcfd; }
.card.locked input, .card.locked select, .card.locked button { opacity: .6; }
.lock {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 9px;
  border-radius: 99px;
  background: #e5efff;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  vertical-align: 2px;
}

/* Plan tiles, shown on Settings and in the upgrade prompt. */
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.plan { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.plan.best { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.plan .k { font-size: 11px; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); }
.plan .v { font-size: 26px; font-weight: 700; margin: 2px 0; }

main { max-width: 1080px; margin: 0 auto; padding: 26px 22px 80px; }

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

/* ---------- stats ---------- */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .k { font-size: 11px; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat .v.overdue { color: var(--danger); }

/* ---------- tables ---------- */

table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
table.list td { padding: 12px 14px; border-bottom: 1px solid var(--line); }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr:hover { background: #f8fafc; }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; }
/* Notes can run long, so cap the column rather than letting it stretch the table. */
table.list td.notes { max-width: 300px; word-break: break-word; color: var(--muted); }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.link { color: var(--accent); cursor: pointer; font-weight: 600; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); background: #fff; }

/* ---------- editor ---------- */

table.items { width: 100%; border-collapse: collapse; }
table.items th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 8px 6px;
}
table.items th.num { text-align: right; }
table.items td { padding: 4px 8px 4px 0; vertical-align: top; }
table.items td:last-child { padding-right: 0; }
table.items input { padding: 8px 10px; }
table.items .amount { padding-top: 16px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.totals { margin-left: auto; min-width: 320px; border-collapse: collapse; }
.totals th { text-align: left; font-weight: 400; color: var(--muted); padding: 5px 18px 5px 0; white-space: nowrap; }
.totals td { text-align: right; padding: 5px 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.totals td input { width: 120px; text-align: right; padding: 5px 8px; }
.totals tr.grand th, .totals tr.grand td {
  font-size: 19px; font-weight: 700; color: var(--ink);
  border-top: 2px solid var(--line); padding-top: 11px;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: rgba(244, 246, 249, .94);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--line);
  padding: 14px 0;
  margin-top: 24px;
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ---------- modal ---------- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal { width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; }

@media (max-width: 780px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 0 14px; }
  main { padding: 18px 14px 70px; }
  .table-wrap { overflow-x: auto; }
  table.list { min-width: 760px; }
  table.items { min-width: 560px; }
}
