/* Business Management System: brand tokens from the PHOTOA brand guide v1.1 */
:root {
  --navy: #062C59;
  --navy-2: #0B3D78;
  --orange: #FF6B00;
  --white: #FFFFFF;
  --grey: #F3F5F7;
  --line: #DDE3EA;
  --text: #062C59;
  --muted: #4A5F78;
  --ok: #1E7A3C;
  --ok-bg: #E6F4EA;
  --warn: #8A4B00;
  --warn-bg: #FFF1E3;
  --bad: #B3261E;
  --bad-bg: #FDECEA;
  --info-bg: #E8EEF6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(6,44,89,.08), 0 2px 8px rgba(6,44,89,.06);
  --head: 'Montserrat', Arial, sans-serif;
  --body: 'Open Sans', Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--white); color: var(--text); font: 16px/1.5 var(--body); -webkit-text-size-adjust: 100%; }
h1, h2, h3 { font-family: var(--head); font-weight: 700; margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; font-weight: 600; }
a { color: var(--navy); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
[hidden] { display: none !important; }
.loading { padding: 32px 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--navy); color: var(--white); padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--white); text-decoration: none; font-family: var(--head); font-weight: 700; font-size: 17px; min-width: 0; }
.brand img { height: 36px; max-width: 150px; object-fit: contain; background: var(--white); border-radius: 6px; padding: 2px 6px; }
.brand .bar { display: inline-block; width: 6px; height: 26px; background: var(--orange); border-radius: 3px; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip { background: transparent; border: 1px solid rgba(255,255,255,.5); color: var(--white); border-radius: 999px; padding: 6px 12px; min-height: 40px; cursor: pointer; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
main { padding: 16px 16px 96px; max-width: 1100px; margin: 0 auto; outline: none; }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--white); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; min-height: 60px; font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none; }
.bottomnav a svg, .sidenav a svg { width: 24px; height: 24px; }
.bottomnav a.active { color: var(--navy); box-shadow: inset 0 3px 0 var(--orange); }
.sidenav { display: none; }
@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
  .topbar { grid-column: 1 / 3; }
  .sidenav:not([hidden]) { display: flex; flex-direction: column; gap: 2px; padding: 16px 8px; background: var(--grey); border-right: 1px solid var(--line); }
  .sidenav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--navy); text-decoration: none; font-weight: 600; }
  .sidenav a.active { background: var(--white); box-shadow: inset 4px 0 0 var(--orange); }
  .bottomnav { display: none !important; }
  main { padding: 24px 32px 48px; width: 100%; }
}

/* Page header */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-weight: 600; min-height: 40px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 8px;
  border: 1px solid var(--navy); background: var(--white); color: var(--navy); font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn-primary { background: var(--navy); color: var(--white); }
.btn-accent { background: var(--orange); color: var(--navy); border-color: var(--orange); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.fab { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 15; box-shadow: 0 4px 12px rgba(6,44,89,.25); }
@media (min-width: 900px) { .fab { position: static; box-shadow: none; } }

/* Cards and lists */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .section + .section { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.section { margin-top: 24px; }
.section > h2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (min-width: 700px) { .grid-4 { grid-template-columns: repeat(4, 1fr); } .grid-3 { grid-template-columns: repeat(3, 1fr); } .md-2 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 699px) { .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--grey); border-radius: var(--radius); padding: 12px 14px; border-left: 4px solid var(--navy); }
.stat.accent { border-left-color: var(--orange); }
.stat .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat .value { font-family: var(--head); font-size: 19px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.stat .sub { font-size: 13px; color: var(--muted); }
a.stat { text-decoration: none; color: inherit; display: block; }
.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row-link { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; color: inherit; text-decoration: none; min-height: 56px; background: var(--white); width: 100%; border: 0; text-align: left; cursor: pointer; }
.row-link:hover { background: var(--grey); }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.row-end { text-align: right; flex-shrink: 0; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); background: var(--grey); border-radius: var(--radius); }

/* Badges: status always shown as text, colour only supports it */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.b-new { background: var(--info-bg); color: var(--navy); }
.b-progress { background: var(--warn-bg); color: var(--warn); }
.b-ready { background: #FFE2CC; color: #6B3200; border-color: var(--orange); }
.b-done { background: var(--ok-bg); color: var(--ok); }
.b-cancel { background: #EEF0F2; color: #555; text-decoration: line-through; }
.b-low { background: var(--bad-bg); color: var(--bad); }
.b-due { background: var(--bad-bg); color: var(--bad); }

/* Alerts */
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 12px; border-left: 4px solid var(--navy); background: var(--info-bg); }
.alert.warn { border-left-color: var(--orange); background: var(--warn-bg); }
.alert.bad { border-left-color: var(--bad); background: var(--bad-bg); }

/* Chips / tabs */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip { flex-shrink: 0; border: 1px solid var(--line); background: var(--white); border-radius: 999px; padding: 6px 14px; min-height: 38px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--navy); text-decoration: none; display: inline-flex; align-items: center; }
.chip.on { background: var(--navy); color: var(--white); border-color: var(--navy); }

/* Forms */
.form { display: grid; gap: 14px; }
.fld { display: grid; gap: 4px; }
.fld > span { font-weight: 600; font-size: 14px; }
.fld .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
input, select, textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #9AA8B8; border-radius: 8px; background: var(--white); }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--navy); outline: 2px solid var(--orange); outline-offset: 0; }
.invalid { border-color: var(--bad) !important; background: var(--bad-bg); }
.search { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; min-height: 22px; height: 22px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg label { display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; min-height: 48px; font-weight: 600; cursor: pointer; padding: 6px; text-align: center; }
.seg input { width: auto; min-height: 0; }
.seg label:has(input:checked) { border: 2px solid var(--navy); background: var(--info-bg); }

/* Item editor */
.item-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--grey); display: grid; gap: 10px; }
.item-row .grid { gap: 8px; }
.item-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.totals { display: grid; gap: 6px; background: var(--grey); border-radius: var(--radius); padding: 12px 14px; }
.totals div { display: flex; justify-content: space-between; gap: 12px; }
.totals .grand { font-family: var(--head); font-weight: 700; font-size: 18px; border-top: 1px solid var(--line); padding-top: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--grey); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: var(--grey); }

/* Key-value detail */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* Modal (bottom sheet on phones) */
.modal-bg { position: fixed; inset: 0; background: rgba(6,44,89,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--white); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 140px; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px); }
#toast .t { background: var(--navy); color: var(--white); padding: 12px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); margin-top: 8px; border-left: 5px solid var(--orange); }
#toast .t.err { background: var(--bad); border-left-color: #fff; }

/* Sign in */
.auth { max-width: 420px; margin: 0 auto; padding: 32px 0; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand img { max-width: 240px; max-height: 90px; object-fit: contain; }
.auth-brand .name { font-family: var(--head); font-size: 26px; font-weight: 700; }
.auth-brand .rule { width: 56px; height: 5px; background: var(--orange); border-radius: 3px; margin: 8px auto 0; }
.who { display: grid; gap: 8px; }
.who button { justify-content: flex-start; min-height: 56px; font-size: 17px; }
.pin { font-size: 24px; letter-spacing: 8px; text-align: center; }

/* Chart */
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); flex-wrap: wrap; margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.up { color: var(--ok); font-weight: 600; } .down { color: var(--bad); font-weight: 600; }

/* Logo slot */
.logo-slot { border: 2px dashed #9AA8B8; border-radius: var(--radius); padding: 16px; text-align: center; color: var(--muted); }
.logo-slot img { max-width: 260px; max-height: 100px; object-fit: contain; }

/* ===== Printable documents (proforma, receipt, delivery note) ===== */
.doc-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.doc { background: var(--white); color: #111; max-width: 820px; margin: 0 auto; border: 1px solid var(--line); box-shadow: var(--shadow); padding: 28px; font-size: 13px; }
@media (max-width: 600px) { .doc { padding: 16px; font-size: 12px; } .doc-biz, .doc-meta { text-align: left; } .doc-meta div { justify-content: flex-start; } .doc-parties { grid-template-columns: 1fr; } }
.doc-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; border-bottom: 4px solid var(--navy); padding-bottom: 14px; flex-wrap: wrap; }
.doc-logo img { max-height: 70px; max-width: 230px; object-fit: contain; }
.doc-logo .ph { border: 1.5px dashed #9AA8B8; color: var(--muted); padding: 14px 16px; font-size: 12px; border-radius: 6px; }
.doc-biz { text-align: right; font-size: 12px; line-height: 1.5; color: var(--navy); }
.doc-biz strong { font-family: var(--head); font-size: 16px; display: block; }
.doc-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin: 18px 0 14px; flex-wrap: wrap; }
.doc-title h1 { font-size: 24px; letter-spacing: 1px; margin: 0; color: var(--navy); }
.doc-title .accent { width: 64px; height: 5px; background: var(--orange); border-radius: 3px; margin-top: 6px; }
.doc-meta { font-size: 12px; text-align: right; }
.doc-meta div { display: flex; gap: 10px; justify-content: flex-end; }
.doc-meta b { color: var(--navy); }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.doc-box { background: var(--grey); border-radius: 6px; padding: 10px 12px; }
.doc-box .lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.doc table { font-size: 12.5px; }
.doc th { background: var(--navy); color: var(--white); }
.doc-totals { margin-left: auto; width: min(320px, 100%); margin-top: 12px; }
.doc-totals div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }
.doc-totals .big { font-family: var(--head); font-weight: 700; font-size: 15px; border-bottom: 2px solid var(--navy); color: var(--navy); }
.doc-totals .due { background: #FFE2CC; padding: 6px 8px; border-radius: 4px; border: 0; font-weight: 700; color: var(--navy); }
.doc-notes { margin-top: 16px; font-size: 12px; }
.doc-notes h3 { font-size: 13px; margin: 10px 0 4px; }
.doc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 32px; font-size: 12px; }
.doc-sign div { border-top: 1px solid #333; padding-top: 4px; }
.doc-foot { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 11px; color: var(--muted); text-align: center; }
.doc-amount { font-family: var(--head); font-size: 26px; font-weight: 700; color: var(--navy); background: var(--grey); border-left: 5px solid var(--orange); padding: 10px 14px; margin: 8px 0 14px; }
.ph-text { background: #FFF1E3; color: var(--warn); padding: 0 3px; border-radius: 3px; }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .no-print, .topbar, .bottomnav, .sidenav, .doc-toolbar, .fab, #toast, #modalRoot { display: none !important; }
  #app { display: block !important; }
  main { padding: 0 !important; max-width: none; }
  .doc { border: 0; box-shadow: none; padding: 0; max-width: none; font-size: 12px; }
  .ph-text { background: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .section { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Cloud sync status */
.sync { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.12); color: var(--white); white-space: nowrap; }
.sync::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #7BD88F; vertical-align: 0; }
.sync-saving::before { background: var(--orange); }
.sync-offline::before { background: #FFD27A; }
.sync-blocked::before { background: #FF8A80; }
@media (max-width: 420px) { .sync { font-size: 0; padding: 6px; } .sync::before { margin: 0; } .user-chip { max-width: 120px; } }

/* Invoice payment stamp */
.doc-stamp { display: inline-block; margin-top: 8px; padding: 3px 10px; border: 2px solid var(--warn); color: var(--warn); border-radius: 6px; font: 700 12px/1.4 Montserrat, sans-serif; letter-spacing: .06em; }
.doc-stamp.ok { border-color: var(--ok); color: var(--ok); }
.doc-stamp.bad { border-color: var(--bad); color: var(--bad); }

.print-only { display: none; }
@media print { .print-only { display: block; } }
#branchChip { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* v1.8.3: More-page icons were huge on phones */
.list .row-main > svg { width:24px; height:24px; flex:none; }
.auth-brand .welcome-sw { margin:4px 0 0; font-weight:600; color:#062C59; }
