:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #17212b;
  --muted: #5d6b78;
  --border: #dde3e9;
  --primary: #1f4e79;
  --primary-ink: #ffffff;
  --primary-soft: #e6eef6;
  --good: #1e7a46;
  --good-soft: #e3f4ea;
  --warn: #b3261e;
  --warn-soft: #fbe9e7;
  --amber: #8a5a00;
  --amber-soft: #fff3d6;
  --wa: #128c4a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --tabbar-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.5rem; }
.muted { color: var(--muted); }
.pre { white-space: pre-line; }
.center { text-align: center; margin: 1rem 0; }
.loading { padding: 2rem; color: var(--muted); }

/* ---------------------------------------------------------------- layout */
#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr;
  min-height: 100vh;
}
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; min-height: 58px;
  background: var(--surface); color: var(--text);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { color: inherit; text-decoration: none; }
.logo { display: inline-flex; align-items: center; gap: 9px; font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; color: var(--text); }
.logo-mark { flex-shrink: 0; display: block; }
.biz {
  color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;
  padding-left: 14px; border-left: 1px solid var(--border);
}
.topbar-settings { color: var(--muted); display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; }
.topbar-settings:hover { background: var(--bg); color: var(--text); }
.topbar-settings svg { width: 22px; height: 22px; }

.sidebar { display: none; }
.content { padding: 16px 16px calc(var(--tabbar-h) + 24px); width: 100%; max-width: 860px; margin: 0 auto; min-width: 0; }
.page-title { font-size: 1.5rem; margin: 4px 0 12px; }
#app.is-bare { display: block; }
.bare { padding: 16px; max-width: 860px; margin: 0 auto; width: 100%; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav-link {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
.nav-link svg { width: 24px; height: 24px; }
.nav-link.active { color: var(--primary); }
.dot {
  position: absolute; top: 6px; left: 50%; margin-left: 6px;
  background: var(--warn); color: #fff; border-radius: 999px; font-size: 0.68rem; min-width: 18px; height: 18px;
  display: grid; place-items: center; padding: 0 5px;
}
.demo-banner {
  background: var(--amber-soft); color: var(--amber); padding: 8px 16px; font-size: 0.9rem; text-align: center;
}
.demo-banner a { color: inherit; font-weight: 600; }

@media (min-width: 900px) {
  #app { grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: auto auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .demo-banner { grid-column: 2; }
  .sidebar {
    display: flex; flex-direction: column; gap: 2px; padding: 16px 10px;
    grid-row: 2 / span 2; grid-column: 1;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .sidebar .nav-link { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; border-radius: 8px; font-size: 0.95rem; }
  .sidebar .nav-link.active { background: var(--primary-soft); }
  .sidebar .dot { position: static; margin-left: auto; }
  .side-more { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; }
  .side-link { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.92rem; }
  .side-link.active { background: var(--primary-soft); color: var(--primary); }
  .content { grid-column: 2; padding-bottom: 32px; }
  .tabbar { display: none; }
}

/* ------------------------------------------------------------- components */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card.highlight { border-color: var(--primary); background: var(--primary-soft); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.summary p { font-size: 1.05rem; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: var(--text); box-shadow: var(--shadow);
}
.stat span { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.stat strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stat.warn strong { color: var(--warn); }
.stat.good strong { color: var(--good); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b9c4cf; }
.btn:focus-visible, .chip:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #8fb3d9; outline-offset: 1px;
}
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #183f63; border-color: #183f63; }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn-danger { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-danger-outline { color: var(--warn); }
.btn-link { border-color: transparent; background: transparent; color: var(--primary); }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 0.85rem; }
.btn-lg { min-height: 52px; font-size: 1.05rem; width: 100%; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  font-size: 1.2rem; cursor: pointer; color: var(--muted);
}

.row-gap { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.row-end { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; max-width: 100%; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font: inherit; font-size: 0.88rem; font-weight: 600; cursor: pointer; color: var(--muted); white-space: nowrap;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.search { flex: 1; min-width: 200px; }

.list { list-style: none; margin: 0; padding: 0; }
.list.card { padding: 0 16px; }
.list > li + li { border-top: 1px solid var(--border); }
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; color: var(--text); text-decoration: none; min-width: 0;
}
.row > div:first-child { min-width: 0; }
.row strong, .row small { display: block; overflow-wrap: anywhere; }
.row small { color: var(--muted); }
.row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; flex-shrink: 0; }
.compact .row { padding: 10px 0; }
.faded { opacity: 0.55; }
.mini-actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.owed { color: var(--warn); font-weight: 600; }

.badge, .pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700;
  background: #eef1f4; color: var(--muted); white-space: nowrap;
}
.badge-sent { background: var(--primary-soft); color: var(--primary); }
.badge-accepted, .badge-paid { background: var(--good-soft); color: var(--good); }
.badge-overdue, .badge-declined { background: var(--warn-soft); color: var(--warn); }
.badge-expired { background: var(--amber-soft); color: var(--amber); }
.pill-invoice { background: var(--warn-soft); color: var(--warn); }
.pill-quote { background: var(--primary-soft); color: var(--primary); }
.pill-service { background: var(--good-soft); color: var(--good); }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.notice { background: var(--amber-soft); color: var(--amber); border-radius: 10px; padding: 10px 12px; }
.notice.good { background: var(--good-soft); color: var(--good); }
.error { color: var(--warn); font-weight: 600; }

/* ------------------------------------------------------------------ forms */
.form h2 { margin-top: 4px; }
.section-title { margin-top: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 0.88rem; font-weight: 600; color: var(--muted); }
.field-link { font-size: 0.88rem; margin-top: 2px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid #c8d1da; border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 500; }
.check input { width: 20px; height: 20px; min-height: 0; }
.grid-2, .grid-3 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}

.lines-head, .line {
  display: grid; gap: 6px; align-items: center;
  grid-template-columns: minmax(0, 1fr) 64px 90px 84px 36px;
}
.lines-head { font-size: 0.8rem; font-weight: 700; color: var(--muted); padding: 0 2px 4px; }
.line { margin-bottom: 8px; }
.line input { padding: 8px 10px; }
.ln-total { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.92rem; }
@media (max-width: 559px) {
  .lines-head { display: none; }
  .line {
    grid-template-columns: 1fr 1fr 1fr 36px;
    padding: 10px; border: 1px solid var(--border); border-radius: 10px;
  }
  .line input[data-k="description"] { grid-column: 1 / -1; }
  .ln-total { grid-column: 3; }
}
.add-line { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.add-line select { flex: 1; min-width: 200px; }
.totals { margin: 0 0 16px auto; max-width: 280px; font-variant-numeric: tabular-nums; }
.totals > div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 2px solid var(--text); margin-top: 4px; padding-top: 8px; font-weight: 700; font-size: 1.1rem; }
.add-service { margin-top: 12px; }
.add-service summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: 8px 0; }

/* -------------------------------------------------------------- documents */
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.doc-head h2 { font-size: 1.25rem; margin: 2px 0; }
.doc-head h2 a { color: var(--text); text-decoration: none; }
.doc-head-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.big { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.lines-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.lines-table th { text-align: left; font-size: 0.8rem; color: var(--muted); border-bottom: 1px solid var(--border); padding: 6px 4px; }
.lines-table td { padding: 8px 4px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.lines-table .num { text-align: right; white-space: nowrap; }
.lines-table tfoot td { border-bottom: none; text-align: right; padding: 4px; }
.lines-table tfoot td:first-child { color: var(--muted); }
.lines-table .grand td { font-weight: 700; font-size: 1.1rem; color: var(--text); border-top: 2px solid var(--text); padding-top: 8px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); }

.todo { list-style: none; margin: 0 0 16px; padding: 0; }
.todo-item { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.todo-item h3 { margin: 6px 0 2px; }

/* printable sheet (also the customer's page) */
.sheet {
  background: #fff; color: #111; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; margin: 0 auto 16px; max-width: 800px; box-shadow: var(--shadow);
}
.sheet p { margin: 0 0 2px; }
.sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.sheet-biz { font-size: 1.3rem; color: var(--primary); }
.sheet-meta { text-align: right; }
.sheet-meta h3 { font-size: 1.4rem; letter-spacing: 0.08em; color: var(--primary); margin-bottom: 4px; }
.sheet-to { margin-bottom: 20px; }
.sheet-notes, .sheet-pay { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--border); }
.sheet-pay h4 { margin-bottom: 4px; }
.print-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.demo-note { background: var(--amber-soft); color: var(--amber); padding: 8px 12px; border-radius: 10px; margin: 0 auto 12px; max-width: 800px; font-size: 0.9rem; }
.accept { max-width: 800px; margin: 0 auto 16px; }
.bare .notice { max-width: 800px; margin: 0 auto 16px; }

/* ------------------------------------------------------- landing / auth */
.small { font-size: 0.9rem; }
.auth-card { padding: 22px; margin: 0; box-shadow: 0 10px 30px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.06); }
.auth-card h2 { font-size: 1.25rem; margin-bottom: 4px; }
.auth-card .field:first-of-type { margin-top: 12px; }
.auth-card small { font-size: 0.82rem; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.auth-tabs button {
  font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted);
  padding: 8px; border-radius: 8px; cursor: pointer; min-height: 38px;
}
.auth-tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.auth-links { display: flex; flex-direction: column; align-items: center; margin-top: 4px; }
.legal { font-size: 0.82rem; color: var(--muted); margin: 10px 0 0; text-align: center; }
.auth-simple { max-width: 420px; margin: 40px auto; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 20px; text-decoration: none; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }

#app.is-bare:has(.landing) { background: var(--surface); }
.bare:has(.landing) { max-width: none; padding: 0; }
.landing { color: var(--text); }
.landing h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); letter-spacing: -0.02em; text-align: center; margin-bottom: 24px; }
.l-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1120px; margin: 0 auto; padding: 16px;
}
.l-nav a { text-decoration: none; }
.l-nav nav { display: flex; align-items: center; gap: 18px; }
.l-nav nav a { color: var(--muted); font-weight: 600; }
.l-nav nav a:hover { color: var(--text); }
@media (max-width: 560px) { .l-nav nav a { display: none; } }

.hero {
  display: grid; gap: 32px; align-items: center;
  max-width: 1120px; margin: 0 auto; padding: 24px 16px 56px;
}
@media (min-width: 900px) { .hero { grid-template-columns: 1.15fr 0.85fr; gap: 56px; padding-top: 48px; } }
.eyebrow {
  display: inline-block; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--primary); background: var(--primary-soft); padding: 4px 10px; border-radius: 999px; margin-bottom: 14px;
}
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.08; letter-spacing: -0.03em; margin-bottom: 16px; }
.lead { font-size: 1.12rem; color: var(--muted); max-width: 36em; margin-bottom: 18px; }
.ticks { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 8px; }
.ticks li { position: relative; padding-left: 30px; font-weight: 500; }
.ticks li::before {
  content: ''; position: absolute; left: 0; top: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--good-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='%231e7a46' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.trades-line { font-size: 0.9rem; color: var(--muted); margin-bottom: 18px; }
.trade-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.steps li.done a { color: var(--muted); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--primary); padding-left: 0; }
.btn-ghost:hover { text-decoration: underline; }

.l-section { max-width: 1120px; margin: 0 auto; padding: 56px 16px; border-top: 1px solid var(--border); }
.feature-grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .feature-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 960px) { .feature-grid { grid-template-columns: 1fr 1fr 1fr; } }
.feature { background: var(--bg); border-radius: var(--radius); padding: 20px; }
.feature-icon {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 10px;
  background: var(--primary); color: #fff; margin-bottom: 12px;
}
.feature h3 { font-size: 1.05rem; margin-bottom: 4px; }
.feature p { color: var(--muted); margin: 0; }
.how-steps { counter-reset: step; list-style: none; padding: 0; margin: 0 auto; max-width: 760px; display: grid; gap: 14px; }
.how-steps li { counter-increment: step; position: relative; padding: 14px 16px 14px 64px; background: var(--bg); border-radius: var(--radius); }
.how-steps li::before {
  content: counter(step); position: absolute; left: 16px; top: 12px; width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff; font-weight: 800; display: grid; place-items: center;
}
.price-card { max-width: 440px; margin: 0 auto; text-align: center; padding: 28px; }
.price { font-size: 3rem; font-weight: 800; letter-spacing: -0.03em; margin: 4px 0 8px; }
.price small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.price-card p { color: var(--muted); }
.faq { max-width: 760px; }
.faq details { border-bottom: 1px solid var(--border); padding: 4px 0; }
.faq summary { cursor: pointer; font-weight: 600; padding: 12px 0; list-style-position: outside; }
.faq details p { color: var(--muted); margin: 0 0 12px; }
.l-footer {
  max-width: 1120px; margin: 0 auto; padding: 24px 16px 40px; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 18px; color: var(--muted); font-size: 0.9rem;
}
.l-footer a { color: var(--muted); }

/* Standalone pages (privacy, terms) */
.doc-page { max-width: 760px; margin: 0 auto; padding: 0 16px 56px; }
.doc-page h1 { font-size: 2rem; letter-spacing: -0.02em; margin: 16px 0 4px; }
.doc-page h2 { font-size: 1.2rem; margin: 28px 0 8px; }
.doc-page p, .doc-page li { color: #2d3a46; }
.doc-page table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 0.95rem; }
.doc-page th, .doc-page td { border: 1px solid var(--border); padding: 8px; text-align: left; vertical-align: top; }
.page-plain { background: var(--surface); }
.todo { background: #fff3a8; color: #6b4e00; padding: 0 4px; border-radius: 4px; font-weight: 600; }

/* ---------------------------------------------------------- modal / toast */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 32, 0.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; }
}
.modal-text { font-size: 1.05rem; margin-bottom: 8px; }
.send-buttons { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px); transform: translate(-50%, 20px);
  background: #17212b; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------------ print */
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  .no-print, .topbar, .sidebar, .tabbar, .demo-banner { display: none !important; }
  .bare { padding: 0; max-width: none; }
  .sheet { border: none; box-shadow: none; padding: 0; max-width: none; }
}
