/* ==========================================================================
   GetPaid — Get-Paid Invoice Engine
   Design system: clean, confident, freelancer-first.
   ========================================================================== */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e8f0;
  --border-strong: #d3d9e6;
  --ink: #10162a;
  --ink-2: #47506a;
  --ink-3: #7d879c;
  --brand: #4f46e5;
  --brand-ink: #3730a3;
  --brand-soft: #eef0fe;
  --paid: #059669;
  --paid-soft: #e7f6ef;
  --overdue: #dc2626;
  --overdue-soft: #fdecec;
  --pending: #b45309;
  --pending-soft: #fdf3e3;
  --shadow-sm: 0 1px 2px rgba(16, 22, 42, .06);
  --shadow: 0 6px 24px rgba(16, 22, 42, .08);
  --shadow-lg: 0 18px 50px rgba(16, 22, 42, .14);
  --radius: 14px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--brand); text-decoration: none; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 22px;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }
.brand-mark { width: 32px; height: 32px; display: block; flex: none; }
.brand-mark svg { width: 100%; height: 100%; display: block; border-radius: 8px; box-shadow: var(--shadow-sm); }
.brand small { color: var(--paid); font-weight: 700; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav button {
  border: none; background: none; color: var(--ink-2);
  padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 14px;
}
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button.active { background: var(--brand-soft); color: var(--brand-ink); }
.topbar-spacer { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
  transition: .15s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); box-shadow: var(--shadow-sm); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn-success { background: var(--paid); border-color: var(--paid); color: #fff; }
.btn-success:hover { filter: brightness(.94); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); box-shadow: none; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Layout ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 26px 22px 80px; }
.builder { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 26px; align-items: start; }
@media (max-width: 940px) { .builder { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 700; margin-bottom: 12px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.input, .textarea, select {
  width: 100%; border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: 9px; padding: 9px 11px; font-size: 14px; color: var(--ink); font-family: inherit;
  transition: .15s;
}
.input:focus, .textarea:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.textarea { resize: vertical; min-height: 66px; line-height: 1.45; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row, .row-3 { grid-template-columns: 1fr; } }

/* ---------- Line items ---------- */
.items-head, .item-row {
  display: grid; grid-template-columns: 1fr 78px 108px 108px 32px; gap: 10px; align-items: center;
}
.items-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 700; padding: 0 2px 6px; }
.item-row { margin-bottom: 8px; }
.item-row .amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); }
.item-del { border: none; background: none; color: var(--ink-3); font-size: 18px; line-height: 1; border-radius: 7px; padding: 4px; }
.item-del:hover { background: var(--overdue-soft); color: var(--overdue); }
@media (max-width: 560px) {
  .items-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; grid-auto-rows: auto; padding: 12px; background: var(--surface-2); border-radius: 10px; }
  .item-row .desc { grid-column: 1 / -1; }
  .item-row .amount { grid-column: 1 / -1; text-align: left; }
}

/* ---------- Preview / invoice ---------- */
.preview-wrap { position: sticky; top: 78px; }
.invoice {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.inv-pad { padding: 34px 38px; }
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 24px; padding-bottom: 20px; border-bottom: 2px solid var(--border-strong); }
.inv-logo { max-height: 60px; max-width: 190px; object-fit: contain; }
.inv-from-name { font-size: 19px; font-weight: 800; }
.inv-meta { text-align: right; }
.inv-title { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; color: var(--ink); line-height: 1; }
.inv-num { color: var(--ink-3); font-size: 13px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.inv-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 700; margin-bottom: 5px; }
.inv-dates { display: flex; gap: 26px; margin-bottom: 22px; flex-wrap: wrap; }
.inv-dates .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 700; }
.inv-dates .v { font-weight: 600; font-variant-numeric: tabular-nums; }

table.lines { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
table.lines th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 700; padding: 8px 8px; border-bottom: 2px solid var(--border-strong);
}
table.lines th.num, table.lines td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.lines td { padding: 11px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.lines td.desc { font-weight: 500; }

.totals { display: flex; justify-content: flex-end; }
.totals-box { width: 260px; }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals-row.grand {
  border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px;
  font-size: 19px; font-weight: 800;
}
.totals-row .lbl { color: var(--ink-2); }

.inv-notes { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }
.pay-block {
  margin-top: 18px; padding: 16px 18px; background: var(--paid-soft);
  border: 1px solid #bfe6d3; border-radius: 12px;
}
.pay-block h4 { color: var(--brand-ink); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; display: flex; align-items: center; gap: 7px; }
.pay-methods { display: grid; gap: 8px; }
.pay-method { display: flex; gap: 8px; font-size: 13.5px; }
.pay-method .pm-label { font-weight: 700; min-width: 84px; color: var(--ink); }
.pay-method .pm-val { color: var(--ink-2); word-break: break-word; white-space: pre-wrap; }

/* status pill */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.pill.paid { background: var(--paid-soft); color: var(--paid); }
.pill.unpaid { background: var(--pending-soft); color: var(--pending); }
.pill.overdue { background: var(--overdue-soft); color: var(--overdue); }
.pill.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* stamp on invoice */
.stamp {
  position: absolute; top: 30px; right: 40px; transform: rotate(-12deg);
  border: 3px solid var(--paid); color: var(--paid); font-weight: 800; font-size: 22px;
  letter-spacing: .08em; padding: 4px 16px; border-radius: 8px; opacity: .85; text-transform: uppercase;
}
.stamp.overdue { border-color: var(--overdue); color: var(--overdue); }

/* ---------- Action bar under preview ---------- */
.actionbar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actionbar .btn { flex: 1 1 auto; }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
@media (max-width: 720px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat { padding: 18px; }
.stat .k { font-size: 12px; color: var(--ink-3); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 26px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat.due .v { color: var(--overdue); }
.stat.paid .v { color: var(--paid); }

.inv-list { width: 100%; border-collapse: collapse; }
.inv-list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.inv-list td { padding: 13px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.inv-list tr:hover td { background: var(--surface-2); }
.inv-list .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.inv-list .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty { text-align: center; padding: 60px 20px; color: var(--ink-3); }
.empty .big { font-size: 44px; margin-bottom: 12px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 22, 42, .5);
  display: none; align-items: center; justify-content: center; z-index: 60; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 22px; }
.modal-x { border: none; background: none; font-size: 22px; color: var(--ink-3); border-radius: 8px; padding: 2px 8px; line-height: 1; }
.modal-x:hover { background: var(--surface-2); }

/* reminder tone tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tabs button { flex: 1; border: none; background: none; padding: 8px; border-radius: 7px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.reminder-text { width: 100%; min-height: 200px; border: 1px solid var(--border-strong); border-radius: 10px; padding: 14px; font-family: inherit; font-size: 14px; line-height: 1.6; resize: vertical; }

/* share box */
.share-url { display: flex; gap: 8px; }
.share-url input { flex: 1; font-size: 13px; font-family: ui-monospace, Menlo, monospace; color: var(--ink-2); }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 10px; font-weight: 600;
  font-size: 14px; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: .25s; z-index: 80;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* screen-reader-only (accessibility + SEO) */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* app footer */
.app-foot { display: flex; justify-content: center; align-items: center; gap: 9px; flex-wrap: wrap; padding: 22px 20px; margin-top: 8px; border-top: 1px solid var(--border); color: var(--ink-3); font-size: 13px; }
.app-foot a { color: var(--ink-2); font-weight: 600; }
.app-foot a:hover { color: var(--brand); }
.app-foot-sep { color: var(--border-strong); }

/* inline line-icons */
.icn { flex: none; vertical-align: -0.15em; }
.empty .big .icn { vertical-align: middle; color: var(--ink-3); }

/* backup reminder bar */
.backup-bar { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; background: var(--pending-soft); color: var(--pending); border-bottom: 1px solid #f1e2c2; padding: 10px 18px; font-size: 13.5px; font-weight: 600; }
.backup-bar[hidden] { display: none; }
.backup-bar b { color: inherit; }
.backup-bar .bb-actions { display: flex; gap: 8px; }

/* dashboard header + backup actions */
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.dash-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.dash-sub { color: var(--ink-3); font-size: 13px; margin-top: 4px; max-width: 460px; }
.dash-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* helper text */
.hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.inline-link { background: none; border: none; color: var(--brand); font-weight: 600; padding: 0; font-size: 13px; }
.inline-link:hover { text-decoration: underline; }
.badge-new { background: var(--paid); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 5px; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Payment view (shared link) ---------- */
.payview { max-width: 640px; margin: 0 auto; padding: 30px 20px 80px; }
.payview .pv-hero { text-align: center; margin-bottom: 22px; }
.payview .pv-hero .amt { font-size: 46px; font-weight: 800; letter-spacing: -0.03em; margin: 6px 0; }
.payview .pv-hero .due { color: var(--ink-2); }
.pv-cta { display: grid; gap: 10px; margin-top: 20px; }

/* print */
@media print {
  .topbar, .actionbar, .no-print, .builder > .col-form { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; max-width: none; }
  .builder { display: block; }
  .preview-wrap { position: static; }
  .invoice { border: none; box-shadow: none; border-radius: 0; }
  .inv-pad { padding: 0; }
}
