/* ===== Theme: change these colours to restyle the whole app ===== */
:root {
  --brand: #0d8ddb;
  --brand-dark: #0a6fae;
  --accent: #b8862b;          /* GENXCON gold */
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1d2733;
  --muted: #6b7785;
  --border: #dde3ea;
  --danger: #d64545;
  --ok: #2e9d5b;
  --warn: #d98e04;
  --radius: 8px;
  --nav-w: 220px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 12px; }

/* ===== Layout ===== */
.topbar { display: none; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--nav-w);
  background: #17212c; color: #fff; padding: 16px 10px; overflow-y: auto; z-index: 20;
}
.brand-side { font-weight: 700; font-size: 16px; padding: 6px 10px 18px; color: #fff; letter-spacing: .5px; }
.brand-side small { display: block; color: var(--accent); font-weight: 500; font-size: 11px; letter-spacing: 2px; }
.sidebar a { display: block; color: #c9d3dd; padding: 10px 12px; border-radius: 6px; margin-bottom: 2px; }
.sidebar a:hover { background: #22303e; text-decoration: none; color: #fff; }
.sidebar a.active { background: var(--brand); color: #fff; }
.nav-sep { height: 1px; background: #2c3a48; margin: 12px 6px; }
.nav-backdrop { display: none; }
main { margin-left: var(--nav-w); padding: 24px 28px 60px; max-width: 1300px; }

.saved { position: fixed; right: 16px; bottom: 16px; background: var(--ok); color: #fff;
  padding: 6px 12px; border-radius: 20px; font-size: 12px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 50; }
.saved.show { opacity: 1; }

/* ===== Building blocks ===== */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 10px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.card-head > div { display: flex; flex-wrap: wrap; gap: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 140px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* ===== Forms ===== */
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=tel], input:not([type]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font: inherit; color: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9fd2f5; border-color: var(--brand); }
textarea { resize: vertical; }
input.num { text-align: right; }
input.small { font-size: 12px; padding: 5px 8px; margin-top: 4px; color: var(--muted); }
.with-btn { display: flex; gap: 6px; }
.with-btn > :first-child { flex: 1; }
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filters .grow { flex: 1 1 240px; }
.filters select, .filters input[type=date] { width: auto; }
.filters label.inline { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f3f6; text-decoration: none; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #f0c4c4; }
.btn.danger:hover { background: #fdf0f0; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.icon { border: none; background: none; cursor: pointer; color: var(--muted); padding: 4px 6px; font-size: 14px; border-radius: 4px; }
.icon:hover { background: #eef1f4; color: var(--text); }
.icon.del:hover { color: var(--danger); }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 16px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 600; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid #eef1f4; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover { background: #f6f9fc; }
.table .r, .table th.r { text-align: right; }
.table .c, .table th.c { text-align: center; }
.table.lines td { padding: 6px 6px; vertical-align: top; }
.table.lines td.r { padding-top: 14px; white-space: nowrap; font-weight: 600; }
.table.lines td.c { padding-top: 14px; }
.table.lines .w-type { width: 110px; }
.table.lines .w-num { width: 95px; }
.table.lines .w-act { width: 70px; white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); }

.totals { width: 100%; border-collapse: collapse; }
.totals td { padding: 6px 0; }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-size: 18px; font-weight: 700; border-top: 2px solid var(--text); padding-top: 10px; }
.totals tr.bal td { font-weight: 700; color: var(--brand-dark); }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 11px; font-weight: 600; background: #e8edf2; color: #45525f; white-space: nowrap; }
.badge.blue { background: #dff0fc; color: #0a6fae; }
.badge.green { background: #dcf3e5; color: #1f7a45; }
.badge.orange { background: #fdf0d5; color: #9a6400; }
.badge.red { background: #fbe1e1; color: #b03030; }
.badge.gray { background: #eceff2; color: #6b7785; }

/* ===== Validation bar (quotes / invoices) ===== */
.vbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; border: 1px solid; }
.vbar div div { font-size: 13px; margin-top: 2px; }
.vbar.draft { background: #fff8e6; border-color: #f2d48a; color: #6b4d00; }
.vbar.ok { background: #eaf6ef; border-color: #b7e0c6; color: #1f6b3f; }
.vbar.warn { background: #fdecec; border-color: #f0b8b8; color: #8f2626; }
/* cost / profit columns on quotes (internal) */
.table.lines th.cost-col, .table.lines td.cost-col { background: #fbf6ea; }
.unit-profit { font-size: 11px; color: var(--ok); text-align: right; margin-top: 3px; white-space: nowrap; }
.unit-profit.neg, .neg { color: var(--danger) !important; }
input.bad { border-color: var(--danger); background: #fdf0f0; }
.profit-h { margin-top: 18px; padding-top: 12px; border-top: 1px dashed var(--border); color: var(--accent); }
/* progress billing */
.table.progress tr.group td { background: #f3f6f9; font-weight: 700; padding-top: 8px; }
.table.progress td.r { padding-top: 12px; }
.pct-quick { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.pct-quick input { width: 80px; }
.contract-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.contract-row .label { color: var(--muted); font-size: 12px; }
.contract-row .value { font-size: 18px; font-weight: 700; margin-top: 2px; }
.docno { font-family: ui-monospace, Consolas, monospace; font-weight: 700; padding: 8px 0; }
input:disabled, select:disabled, textarea:disabled { background: #f6f8fa; color: var(--text); cursor: not-allowed; }
.doc { position: relative; }
.watermark { position: absolute; top: 260px; left: 0; right: 0; text-align: center; font-size: 140px; font-weight: 900;
  color: rgba(214, 69, 69, .13); transform: rotate(-24deg); letter-spacing: 12px; pointer-events: none; z-index: 5; }

/* ===== Calendar ===== */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--border); gap: 1px;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-h { background: var(--brand); color: #fff; text-align: center; padding: 7px 0; font-weight: 600; font-size: 12px; }
.cal-day { background: #fff; min-height: 104px; padding: 4px 5px; cursor: pointer; min-width: 0; }
.cal-day:hover { background: #f6f9fc; }
.cal-day.other { background: #fafbfc; }
.cal-day.other .dnum { color: #b6c0ca; }
.cal-day.today { background: #fff8e1; }
.cal-day.sel { box-shadow: inset 0 0 0 2px var(--brand); }
.dnum { text-align: right; font-size: 12px; color: var(--brand-dark); margin-bottom: 2px; }
.chip { font-size: 11px; padding: 2px 6px; border-radius: 4px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.event { background: var(--brand); color: #fff; }
.chip.event.sel { background: var(--brand-dark); outline: 2px solid #9fd2f5; }
.chip.job { background: #fdf0d5; color: #7a5000; border-left: 3px solid var(--accent); }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.day-item { padding: 8px 0; border-bottom: 1px solid #eef1f4; }
.day-item:last-of-type { border-bottom: none; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); margin-right: 6px; }
.dot.job { background: var(--accent); }
input[type=time] { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.btn[disabled] { opacity: .5; cursor: default; }
@media (max-width: 860px) {
  .cal-day { min-height: 64px; }
  .chip { font-size: 0; height: 6px; padding: 0; }   /* on phones, chips become coloured bars; tap the day to see details */
  .chip b { display: none; }
}

.contact-card { background: #f7f9fb; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; line-height: 1.6; }
.logo-preview { max-width: 240px; max-height: 120px; display: block; margin-bottom: 8px; border: 1px solid var(--border); padding: 6px; background: #fff; }

/* ===== Mobile ===== */
@media (max-width: 860px) {
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 15;
    background: #17212c; color: #fff; padding: 10px 14px; }
  .menu-btn { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }
  .brand-top { font-weight: 700; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 19; }
  main { margin-left: 0; padding: 16px 16px 60px; }
  .grid2, .stats { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid2 > *, .stats > * { min-width: 0; }   /* wide tables scroll inside their card instead of widening the page */
  /* job tabs scroll sideways instead of stacking into many lines */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs a { white-space: nowrap; padding: 9px 12px; }
  /* bigger touch targets and no zoom-in when typing on iPhone */
  input, select, textarea { font-size: 16px; }
  .btn { min-height: 38px; }
  .filters { gap: 8px; }
  .filters > * { flex: 1 1 140px; }
  .page-head { flex-wrap: wrap; gap: 8px; }
}

/* ===== Print (quotes & invoices) ===== */
#print-area { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
}
.doc { font-size: 12px; color: #111; line-height: 1.45; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; border-bottom: 3px solid var(--accent); padding-bottom: 14px; margin-bottom: 14px; }
.doc-head .logo { max-width: 220px; max-height: 110px; display: block; margin-bottom: 8px; }
.doc-head .logo-text { font-size: 24px; font-weight: 800; letter-spacing: 2px; margin-bottom: 6px; }
.doc-meta { text-align: right; }
.doc-meta h1 { font-size: 26px; letter-spacing: 3px; color: var(--accent); margin: 0 0 8px; }
.doc-meta table { margin-left: auto; border-collapse: collapse; }
.doc-meta td { padding: 1px 0 1px 12px; }
.doc-meta td:first-child { color: #666; }
.taxnos { margin-top: 8px; color: #666; font-size: 11px; }
.parties { display: flex; gap: 24px; margin-bottom: 14px; }
.parties > div { flex: 1; background: #f6f6f6; padding: 10px 12px; border-radius: 4px; }
.doc h4 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #666; }
.doc h3 { margin: 16px 0 6px; font-size: 13px; }
.doc table.items { width: 100%; border-collapse: collapse; }
.doc table.items th { background: #222; color: #fff; text-align: left; padding: 6px 8px; font-size: 11px; }
.doc table.items td { padding: 6px 8px; border-bottom: 1px solid #ddd; vertical-align: top; }
.doc table.items .r { text-align: right; }
.doc table.items th:first-child { width: 52%; }
.doc table.items th:not(:first-child) { width: 12%; text-align: right; }
.doc table.items .note { color: #666; font-size: 11px; }
.doc table.items.prog th:first-child { width: 34%; }
.doc table.items.prog th:not(:first-child) { width: 13.2%; }
.doc .doc-totals { width: 280px; margin: 14px 0 0 auto; border-collapse: collapse; }
.doc .doc-totals td { padding: 4px 0; }
.doc .doc-totals td:last-child { text-align: right; }
.doc .doc-totals .grand td { font-weight: 800; font-size: 15px; border-top: 2px solid #111; padding-top: 6px; }
.doc .block { margin-top: 16px; white-space: pre-wrap; }
.doc .sign { margin-top: 28px; display: flex; gap: 24px; }
.doc .sign div { flex: 1; border-top: 1px solid #111; padding-top: 4px; color: #666; font-size: 11px; }
.doc .accept { margin-top: 22px; font-style: italic; }
.doc .sign.signed div { border-top: none; padding-top: 0; flex: none; }
.doc .sign.signed > div { flex: 1; }
.doc .sign.signed .v { min-height: 50px; display: flex; align-items: flex-end; color: #111; font-size: 13px; }
.doc .sign.signed .v img { max-height: 56px; max-width: 100%; }
.doc .sign.signed .l { border-top: 1px solid #111; padding-top: 4px; }

.doc.att-page { break-before: page; page-break-before: always; text-align: center; }
.doc.att-page img { max-width: 100%; max-height: 225mm; object-fit: contain; }
.doc.att-page .att-head { text-align: left; color: #666; font-size: 11px; border-bottom: 1px solid #ddd; padding-bottom: 4px; margin-bottom: 10px; }
.doc.att-page .att-cap { margin-top: 8px; font-size: 13px; }

.doc .applies-box { margin: 10px 0; padding: 8px 12px; border-left: 4px solid var(--accent); background: #faf6ee; }
/* online mode: sign-in screen and sync status */
body.auth-open > *:not(#auth) { display: none !important; }
#auth { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: linear-gradient(160deg, #18232e, #2c3a48); overflow: auto; }
.auth-box { width: 100%; max-width: 400px; background: var(--card); border-radius: 12px; padding: 26px 24px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.auth-brand { font-weight: 800; letter-spacing: 3px; font-size: 20px; margin-bottom: 14px; color: var(--text); }
.auth-brand small { display: block; letter-spacing: 2px; font-size: 11px; color: var(--accent); font-weight: 600; }
.auth-box h2 { margin: 0 0 12px; font-size: 18px; }
.auth-box label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.auth-box input[type=email], .auth-box input[type=password] { display: block; width: 100%; margin-top: 4px; font-size: 16px; padding: 10px 12px; }
.auth-box button[type=submit] { width: 100%; margin: 6px 0 12px; padding: 11px; font-size: 15px; }
.auth-choices { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.auth-choices .btn { text-align: center; }
.auth-msg { margin-top: 10px; font-size: 13px; min-height: 18px; }
.auth-msg.bad { color: var(--danger); }
.auth-msg.good { color: var(--ok); }
.nav-foot { margin-top: auto; padding: 12px 10px 4px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.nav-foot a { padding: 0 !important; color: #9fb0c0 !important; }
.sync { font-size: 12px; white-space: nowrap; }
.sync:empty { display: none; }
.sync.ok { color: #7fd6a0; }
.sync.saving { color: #9fb0c0; }
.sync.off { color: #ffb38a; font-weight: 600; }
.topbar .sync { margin-left: auto; }

/* payments: entered (yellow) → confirmed & locked */
tr.pay-draft td { background: #fff8e6; }
tr.pay-locked td { background: #f3faf5; }
/* credit notes: shown under their invoice */
tr.credit-row td { background: #fdf6f6; }
tr.credit-row td:first-child { padding-left: 22px; }
.sub-arrow { color: var(--danger); margin-right: 6px; }
.small-line { font-size: 12px; }
.vbar.credit { background: #fdf3f3; border-color: #f0c9c9; }

/* ===== Pictures, files, attachments, history ===== */
.dropzone { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 80px; padding: 14px; margin-bottom: 14px;
  border: 2px dashed var(--border); border-radius: var(--radius); background: #fafbfd; color: var(--muted); cursor: pointer; }
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: #eef6fd; color: var(--brand-dark); }
.dropzone input[type=file] { display: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.photo-grid .ph { position: relative; margin: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; }
.photo-grid .ph img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #eef1f4; }
.photo-grid .ph input { border: none; border-top: 1px solid var(--border); border-radius: 0; width: 100%; }
.photo-grid .ph figcaption { padding: 4px 8px 8px; font-size: 12px; }
.photo-grid .ph .del { position: absolute; top: 6px; right: 6px; background: rgba(255,255,255,.9); border-radius: 50%; }
img.missing { visibility: hidden; }
.table td img[data-fid] { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; display: block; }
.ficon { font-size: 22px; }
.nowrap { white-space: nowrap; }
.attach-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.attach-list .att { display: flex; align-items: center; gap: 10px; }
.attach-list .att img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; }
.attach-list .att a { flex: 1; }
.attach-add { align-items: stretch; }
.attach-add .dropzone { min-height: 56px; margin: 0; flex: 1; font-size: 13px; }
.table.history td { vertical-align: top; }
.table.history tr.group td { background: var(--bg); font-weight: 600; font-size: 12px; }
.table.history .w-time { width: 60px; color: var(--muted); }

/* ===== Client approval / signature ===== */
.card.approval.wait { border-left: 4px solid var(--warn, #e09a1a); }
.card.approval.ok { border-left: 4px solid var(--ok); }
.card.approval.refused { border-left: 4px solid var(--danger); }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.approval-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.approval-row img.sig { height: 60px; background: #fff; border: 1px solid var(--line, #ddd); border-radius: 4px; }
.sign-pad { display: block; width: 100%; max-width: 600px; aspect-ratio: 10 / 3; height: auto; background: #fff; border: 2px dashed #bbb; border-radius: 6px; touch-action: none; cursor: crosshair; }
.chk-line { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; }
