:root {
  --navy: #0b1f3a;
  --navy-2: #12305a;
  --char: #1d2126;
  --char-2: #2a3037;
  --line: #3a424b;
  --green: #9be800;
  --green-d: #6fb000;
  --warn: #ffb020;
  --red: #ff5a4d;
  --text: #f2f5f8;
  --muted: #a9b4c0;
  --r: 14px;
  --tap: 60px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 18px; }
body {
  margin: 0; background: var(--char); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4; padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
h1 { font-size: 1.6rem; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); border-bottom: 4px solid var(--green);
  padding: calc(.7rem + env(safe-area-inset-top)) 1rem .7rem;
}
.brand { text-decoration: none; font-weight: 900; letter-spacing: .12em; font-size: 1.1rem; }
.brand span { color: var(--green); }
.brand-mark { color: var(--green); }
.icon-btn { background: var(--navy-2); color: var(--text); border: 2px solid var(--line); border-radius: 12px; min-width: 56px; height: 48px; font-size: 1.5rem; }

main { max-width: 760px; margin: 0 auto; padding: 1rem; }
.card { background: var(--char-2); border: 2px solid var(--line); border-radius: var(--r); padding: 1rem; margin-bottom: 1rem; }

/* Buttons: big, high contrast */
.btn {
  display: flex; align-items: center; justify-content: center; gap: .6rem; width: 100%;
  min-height: var(--tap); padding: .8rem 1.2rem; border-radius: var(--r);
  border: 3px solid var(--line); background: var(--navy-2); color: var(--text);
  font: inherit; font-weight: 800; font-size: 1.05rem; text-transform: uppercase; letter-spacing: .04em;
  cursor: pointer; text-decoration: none; text-align: center; touch-action: manipulation;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--green); border-color: var(--green-d); color: #0a1400; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { width: auto; min-height: 48px; padding: .4rem 1rem; font-size: .9rem; }
.btn.huge {
  min-height: 150px; font-size: 1.7rem; line-height: 1.15; flex-direction: column;
  box-shadow: 0 6px 0 var(--green-d), 0 0 0 4px rgba(155,232,0,.18); margin-bottom: 1.4rem;
}
.btn.huge .plus { font-size: 3rem; line-height: 1; }
.btn-row { display: grid; gap: .75rem; margin-top: 1rem; }
@media (min-width: 560px) { .btn-row.two { grid-template-columns: 1fr 1fr; } }

/* Dashboard */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--navy); border: 2px solid var(--line); border-radius: var(--r); padding: .9rem; }
.stat.hero { grid-column: 1 / -1; border-color: var(--green); }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; }
.stat .value { font-size: 1.9rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat.hero .value { font-size: 2.6rem; color: var(--green); }
.inv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.inv-list a {
  display: grid; grid-template-columns: 1fr auto; gap: .1rem .75rem; align-items: center; text-decoration: none;
  background: var(--char-2); border: 2px solid var(--line); border-radius: var(--r); padding: .85rem 1rem; min-height: var(--tap);
}
.inv-list .name { font-weight: 800; }
.inv-list .sub { color: var(--muted); font-size: .85rem; }
.inv-list .amt { font-weight: 900; text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; border: 2px solid; }
.badge.Draft { color: var(--warn); border-color: var(--warn); }
.badge.Sent { color: #ff9a8f; border-color: #ff9a8f; }
.badge.Paid { color: var(--green); border-color: var(--green); }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }

/* Forms */
label { display: block; font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: .8rem 0 .3rem; }
input, textarea, select {
  width: 100%; min-height: var(--tap); padding: .7rem .9rem; font: inherit; font-size: 1.05rem;
  color: var(--text); background: var(--char); border: 3px solid var(--line); border-radius: 12px;
}
textarea { min-height: 100px; }
input:focus, textarea:focus, select:focus, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 4px solid var(--green); outline-offset: 2px; border-color: var(--green); }
input[type=file] { display: none; }

/* Capture */
.capture-grid { display: grid; gap: .75rem; }
.preview-img { width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; border: 2px solid var(--line); background: #000; margin-top: .75rem; }
.rec-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.btn.recording { background: var(--red); border-color: #b32d22; color: #fff; }
audio { width: 100%; margin-top: .75rem; }
.hint { color: var(--muted); font-size: .9rem; margin: .5rem 0 0; }
.spinner { width: 22px; height: 22px; border: 4px solid rgba(0,0,0,.25); border-top-color: #0a1400; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-note { border-left: 6px solid var(--green); }
.ai-note pre { white-space: pre-wrap; margin: .3rem 0 0; font: inherit; font-size: .9rem; color: var(--muted); }

/* Line items */
.item { background: var(--char); border: 2px solid var(--line); border-radius: var(--r); padding: .75rem; margin-bottom: .75rem; display: grid; gap: .5rem; grid-template-columns: 1fr 1fr 1fr; }
.item .desc { grid-column: 1 / -1; }
.item .kind { grid-column: 1 / 3; }
.item .del { grid-column: 3; align-self: end; }
.item .line-total { align-self: end; font-weight: 900; text-align: right; font-size: 1.2rem; min-height: var(--tap); display: flex; align-items: center; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.item label { margin: 0 0 .2rem; }
.grand { display: flex; justify-content: space-between; align-items: baseline; background: var(--navy); border: 3px solid var(--green); border-radius: var(--r); padding: 1rem; margin-top: 1rem; }
.grand .amt { font-size: 2.2rem; font-weight: 900; color: var(--green); font-variant-numeric: tabular-nums; }
@media (min-width: 640px) {
  .item { grid-template-columns: 110px 1fr 90px 120px 110px 60px; align-items: end; }
  .item .desc, .item .kind { grid-column: auto; }
  .item .kind { order: 1; } .item .desc { order: 2; } .item .qty { order: 3; } .item .price { order: 4; } .item .line-total { order: 5; } .item .del { order: 6; grid-column: auto; }
}

/* Invoice paper (always light, print-safe) */
.paper { background: #fff; color: #14202e; border-radius: 6px; padding: 1.4rem; margin-bottom: 1rem; box-shadow: 0 4px 0 rgba(0,0,0,.4); font-size: 16px; }
.paper .head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 6px solid #0b1f3a; padding-bottom: 1rem; }
.paper .title { font-size: 2.2rem; font-weight: 900; letter-spacing: .08em; color: #0b1f3a; margin: 0; }
.paper .meta { text-align: right; font-size: .9rem; line-height: 1.6; }
.paper .meta b { display: inline-block; min-width: 5.5em; color: #5b6b7c; text-transform: uppercase; font-size: .72rem; letter-spacing: .08em; text-align: right; }
.paper .stamp { display: inline-block; border: 3px solid; padding: .1rem .6rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; transform: rotate(-3deg); }
.paper .stamp.Draft { color: #b36b00; } .paper .stamp.Sent { color: #c62828; } .paper .stamp.Paid { color: #2f8a00; }
.paper .parties { display: grid; gap: 1rem; margin: 1.2rem 0; }
@media (min-width: 560px) { .paper .parties { grid-template-columns: 1fr 1fr; } }
.paper .parties h3 { margin: 0 0 .25rem; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: #5b6b7c; }
.paper table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.paper th { background: #0b1f3a; color: #fff; text-align: left; padding: .55rem .5rem; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.paper td { padding: .6rem .5rem; border-bottom: 1px solid #d5dce4; vertical-align: top; }
.paper th.r, .paper td.r { text-align: right; font-variant-numeric: tabular-nums; }
.paper .kindtag { font-size: .7rem; color: #5b6b7c; text-transform: uppercase; letter-spacing: .08em; display: block; }
.paper .totals { margin-top: 1rem; margin-left: auto; width: min(100%, 300px); }
.paper .totals div { display: flex; justify-content: space-between; padding: .3rem 0; }
.paper .totals .due { border-top: 4px solid #6fb000; margin-top: .3rem; padding-top: .6rem; font-size: 1.4rem; font-weight: 900; color: #0b1f3a; }
.paper .foot { margin-top: 1.5rem; font-size: .85rem; color: #5b6b7c; border-top: 1px solid #d5dce4; padding-top: .8rem; }

/* Send sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet { background: var(--char-2); border-top: 5px solid var(--green); border-radius: 20px 20px 0 0; width: 100%; max-width: 760px; padding: 1.2rem 1rem calc(1.2rem + env(safe-area-inset-bottom)); display: grid; gap: .75rem; }

#toast { position: fixed; left: 1rem; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); max-width: 520px; margin: 0 auto; background: var(--green); color: #0a1400; font-weight: 800; padding: 1rem; border-radius: var(--r); text-align: center; opacity: 0; pointer-events: none; transform: translateY(20px); transition: .2s; z-index: 60; }
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--red); color: #fff; }

/* PDF / print: only the invoice paper */
@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  .topbar, #toast, .no-print, .sheet-bg { display: none !important; }
  main { max-width: none; padding: 0; }
  .paper { box-shadow: none; padding: 0; margin: 0; border-radius: 0; }
  .paper th, .paper .stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Paper is read at arm's length, not thumb-tapped: tighten everything so a normal invoice fits one page. */
  html { font-size: 13px; }
  .paper { font-size: 12.5px; line-height: 1.35; }
  .paper .logo { max-height: 56px; max-width: 170px; margin-bottom: .35rem; }
  .paper .title { font-size: 1.9rem; }
  .paper .head { padding-bottom: .6rem; border-bottom-width: 4px; }
  .paper .parties { margin: .7rem 0; gap: .6rem; }
  .paper td { padding: .38rem .45rem; }
  .paper th { padding: .4rem .45rem; }
  .paper table { font-size: 1rem; }
  .paper .totals { margin-top: .6rem; }
  .paper .totals .due { font-size: 1.15rem; border-top-width: 3px; }
  .paper .foot { margin-top: .9rem; padding-top: .5rem; }
  .paper tr, .paper .totals, .paper .foot, .paper .note { break-inside: avoid; }
  .paper thead { display: table-header-group; }
}

/* Phase 1 additions */
.top-actions { display: flex; gap: .5rem; align-items: center; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
body.public .topbar .top-actions { display: none; }
.banner { background: #3a2f00; border: 2px solid var(--warn); color: #ffe39a; border-radius: var(--r); padding: .8rem 1rem; margin-bottom: 1rem; font-weight: 600; }
.banner.ok { background: #0f2a10; border-color: var(--green); color: #cfeea0; }
.link-btn { background: none; border: 0; color: var(--green); font: inherit; font-weight: 700; text-decoration: underline; padding: .75rem 0; min-height: 48px; cursor: pointer; width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
textarea#transcript { min-height: 120px; }
.item.check { border-color: var(--warn); }
.item .flag { grid-column: 1 / -1; color: var(--warn); font-weight: 800; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.breakdown { margin-top: 1rem; display: grid; gap: .3rem; }
.breakdown > div { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.paper .biz { font-size: .85rem; line-height: 1.5; color: #3b4a5a; margin-top: .4rem; }
.paper .biz strong { display: block; font-size: 1.15rem; color: #0b1f3a; }
.paper .totals .row { color: #3b4a5a; }
.paper .note { margin-top: 1rem; font-size: .9rem; white-space: pre-wrap; }
.public-note { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 1rem; }
.listening { background: var(--red); border-color: #b32d22; color: #fff; }

/* Logo */
input#logo-input { display: none; }
.logo-preview { display: block; max-width: 220px; max-height: 120px; object-fit: contain; background: #fff; border-radius: 10px; padding: .5rem; margin: .25rem 0 .5rem; }
.paper .logo { display: block; max-width: 200px; max-height: 90px; object-fit: contain; margin-bottom: .6rem; }

/* How to pay */
.req { color: var(--green); font-size: .7rem; border: 2px solid var(--green); border-radius: 99px; padding: .05rem .5rem; margin-left: .4rem; vertical-align: middle; letter-spacing: .06em; }
.privacy-note { background: #1b2430; border-left: 6px solid var(--warn); border-radius: 10px; padding: .75rem .9rem; font-size: .88rem; color: #ffe39a; margin: .4rem 0 .2rem; }
.paper .howtopay { margin-top: 1rem; border: 2px solid #0b1f3a; border-radius: 8px; padding: .7rem .9rem; background: #f3f7fb; }
.paper .howtopay h3 { margin: 0 0 .25rem; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: #5b6b7c; }
.paper .howtopay div { white-space: pre-wrap; font-weight: 600; word-break: break-word; }
@media print { .paper .howtopay { break-inside: avoid; padding: .45rem .65rem; margin-top: .6rem; -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* Terms and Privacy pages, and the footer links */
.legal { max-width: 40rem; margin: 0 auto; padding: 1rem 1.1rem 3rem; line-height: 1.55; }
.legal h1 { font-size: 1.6rem; margin: .6rem 0 .1rem; }
.legal h2 { font-size: 1.1rem; margin: 1.6rem 0 .4rem; color: var(--green); }
.legal a, .site-foot a { color: var(--green); }
.legal .muted { color: var(--muted); font-size: .85rem; }
.site-foot { text-align: center; padding: 1.2rem 1rem 2rem; color: var(--muted); font-size: .85rem; }
@media print { .site-foot { display: none; } } /* never let the footer push an invoice onto a second PDF page */

/* Invoice credits */
.credits { display: flex; align-items: center; gap: .9rem; border: 3px solid var(--line); border-radius: var(--r); padding: .8rem 1rem; margin-bottom: 1rem; background: var(--char-2); }
.credits .credits-n { font-size: 2.2rem; font-weight: 900; min-width: 2.2rem; text-align: center; font-variant-numeric: tabular-nums; }
.credits span { color: var(--muted); font-size: .88rem; }
.credits.ok { border-color: var(--green); } .credits.ok .credits-n { color: var(--green); }
.credits.low { border-color: var(--warn); } .credits.low .credits-n { color: var(--warn); }
.credits.out { border-color: var(--red); } .credits.out .credits-n { color: var(--red); }

.credits .credits-body { flex: 1; min-width: 0; }
.credits .buy { margin-top: .6rem; width: 100%; }
.testmode { display: block; margin-top: .4rem; font-size: .72rem; font-weight: 800; letter-spacing: .04em; color: var(--warn); }
