/* Colours and type of x-raysolutions.com: deep navy, warm paper, teal accents; Inter for text, Space Grotesk for headings.
   The fonts are served from /static/fonts (SIL Open Font License), as the content security policy allows no other origin. */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400 700; font-display: swap; src: url('fonts/inter-latin.woff2') format('woff2'); }
@font-face { font-family: 'Space Grotesk'; font-style: normal; font-weight: 500 700; font-display: swap; src: url('fonts/space-grotesk-latin.woff2') format('woff2'); }

:root {
  --bg: #f6f5f1;
  --surface: #fff;
  --surface-2: #faf9f6;
  --text: #26313a;
  --muted: #64707a;
  --border: #e1ded3;
  --border-strong: #cdc8b9;
  --accent: #0e7a85;
  --accent-hover: #0a5b64;
  --accent-soft: #e2f2f3;
  --accent-bright: #17b8c4;
  --side: #0b1620;
  --side-2: #132430;
  --side-text: #b7c2cb;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --ok: #1b7f3b;
  --ok-soft: #e9f7ee;
  --warn: #9a6400;
  --warn-soft: #fff5e0;
  --info-soft: #eaf3fb;
  --radius: 4px;
  --shadow: 0 1px 2px rgba(11, 22, 32, .05), 0 1px 3px rgba(11, 22, 32, .05);
  --font-display: 'Space Grotesk', 'Inter', -apple-system, 'Segoe UI', sans-serif;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; letter-spacing: -.01em; color: var(--side); margin: 0; line-height: 1.25; }
h2 { font-family: var(--font-display); font-size: 1.08rem; font-weight: 600; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .85rem; }
.hint { display: block; color: var(--muted); font-size: .82rem; font-weight: normal; margin-top: .25rem; }
.pre { white-space: pre-line; }
.right { text-align: right; }
.neg { color: var(--danger); }
.cur { color: var(--muted); font-size: .85em; }
.spacer { flex: 1; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 99; background: #fff; padding: .5rem; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex: none; background: var(--side); color: var(--side-text); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; padding: .4rem .5rem 1.1rem; }
.brand img { width: 185px; height: auto; display: block; }
.brand:hover { text-decoration: none; }
.sidebar nav a { display: block; color: var(--side-text); padding: .42rem .6rem; border-radius: 6px; font-size: .92rem; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(23, 184, 196, .14); color: #fff; box-shadow: inset 3px 0 0 var(--accent-bright); }
.nav-group { font-family: var(--font-display); text-transform: uppercase; font-size: .7rem; font-weight: 600; letter-spacing: .1em; color: var(--accent-bright); opacity: .8; padding: 1rem .6rem .3rem; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.menu-btn { display: none; background: none; border: 0; font-size: 1.3rem; cursor: pointer; }
.content { padding: 1.25rem 1.5rem 3rem; max-width: 1400px; width: 100%; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; display: flex; gap: .4rem; flex-wrap: wrap; }
.crumbs .sep { color: var(--border-strong); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head p { margin: .25rem 0 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- dropdowns ---------- */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; cursor: pointer; }
.dropdown > summary::-webkit-details-marker { display: none; }
.user-menu > summary { padding: .4rem .6rem; border-radius: 6px; }
.user-menu > summary:hover { background: var(--surface-2); }
.menu { position: absolute; top: calc(100% + 4px); left: 0; min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(15, 28, 36, .14); padding: .35rem; z-index: 30; }
.menu-right { left: auto; right: 0; }
.menu a, .menu .linklike { display: block; width: 100%; text-align: left; padding: .45rem .7rem; color: var(--text); border-radius: 5px; font-size: .92rem; }
.menu a:hover, .menu .linklike:hover { background: var(--surface-2); text-decoration: none; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: .3rem 0; }
.menu form { margin: 0; }
.linklike { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; color: inherit; }
.linklike.danger { color: var(--danger); }

/* ---------- cards, stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 640px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-head.pad { padding: .85rem 1.25rem; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary h2 { display: inline; margin: 0; }
details.card[open] > summary { margin-bottom: .75rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.report-card { color: inherit; }
.report-card:hover { border-color: var(--accent); text-decoration: none; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.1rem; box-shadow: var(--shadow); color: inherit; display: flex; flex-direction: column; gap: .2rem; }
a.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat strong { font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats.big .stat strong { font-size: 1.45rem; }
.stat em { font-style: normal; font-size: .85rem; color: var(--muted); }
.stat em.neg { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem !important; }

/* ---------- buttons, badges ---------- */
.btn { font-family: var(--font-display); letter-spacing: .01em; display: inline-flex; align-items: center; gap: .35rem; padding: .48rem .95rem; border-radius: 2px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: .9rem; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1.25; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: #f0b4b4; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(15, 28, 36, .05); }
.btn-sm { padding: .25rem .6rem; font-size: .82rem; }
.new-menu > summary { padding: .45rem .95rem; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge-paid, .badge-accepted { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cb; }
.badge-overdue, .badge-expired { background: var(--danger-soft); color: var(--danger); border-color: #f4c2c2; }
.badge-partial, .badge-pending { background: var(--warn-soft); color: var(--warn); border-color: #f2d9a6; }
.badge-open { background: var(--info-soft); color: #1d5f99; border-color: #c4dcf2; }
.badge-void, .badge-rejected, .badge-closed { text-decoration: none; }
.badge-cancelled { text-decoration: line-through; }
/* Quote status picker in the quotes list, coloured like the badges. */
select.status-select { width: auto; font-size: .78rem; font-weight: 600; padding: .15rem 1.6rem .15rem .5rem; border-radius: 999px; cursor: pointer; }
.status-select.status-pending { background-color: var(--warn-soft); color: var(--warn); border-color: #f2d9a6; }
.status-select.status-accepted { background-color: var(--ok-soft); color: var(--ok); border-color: #bfe5cb; }
.status-select.status-rejected { background-color: var(--danger-soft); color: var(--danger); border-color: #f4c2c2; }
.status-select.status-cancelled, .status-select.status-closed { background-color: var(--surface-2); color: var(--muted); }
.leave-dialog .actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- forms ---------- */
form { margin: 0; }
form.inline { display: inline; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.inline-form input:not([type=checkbox]):not([type=file]) { width: auto; flex: 1 1 200px; }
.stack { display: flex; flex-direction: column; gap: .85rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .88rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: normal; }
input, select, textarea { font: inherit; font-size: .93rem; font-weight: normal; padding: .45rem .6rem; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff; color: var(--text); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=file] { padding: .3rem; background: var(--surface-2); }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.row2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .85rem 1rem; }
.row3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .85rem 1rem; }
.form-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters label { font-size: .8rem; }
.filters input, .filters select { width: auto; }
.filters input[type=search] { min-width: 240px; flex: 1 1 240px; max-width: 380px; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; background: #fff; }
.segmented a { padding: .42rem .8rem; color: var(--text); font-size: .88rem; border-right: 1px solid var(--border); }
.segmented a:last-child { border-right: 0; }
.segmented a.active { background: var(--accent); color: #fff; }
.segmented a:hover { text-decoration: none; }

/* ---------- document form ---------- */
.doc-head { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .85rem 1rem; }
.doc-head .span2 { grid-column: span 2; }
.addresses { margin-top: .85rem; }
.addresses summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .9rem; margin-bottom: .6rem; }
.lines-table td { vertical-align: top; padding: .35rem .4rem; }
.lines-table select, .lines-table input, .lines-table textarea { font-size: .88rem; padding: .35rem .45rem; }
.lines-table td:nth-child(2) { min-width: 150px; }
.lines-table td:nth-child(3) { min-width: 220px; width: 32%; }
.lines-table td:nth-child(7) { min-width: 150px; }
.lines-table .x-export, .lines-table .x-progress { display: none; }
.lines-table.show-export .x-export, .lines-table.show-progress .x-progress { display: table-cell; }
.lines-table .x-export input { min-width: 6rem; }
.lines-table .drag { color: var(--border-strong); width: 1rem; padding-top: .55rem; }
.lines-table td[data-amount] { padding-top: .55rem; white-space: nowrap; }
input.qty { width: 5.5rem; text-align: right; }
input.price { width: 8rem; text-align: right; }
.lines-foot { display: flex; justify-content: space-between; gap: 1rem; padding: .85rem 1.25rem; border-top: 1px solid var(--border); align-items: flex-start; flex-wrap: wrap; }
.totals { display: grid; grid-template-columns: auto auto; gap: .3rem 1.5rem; margin: 0; min-width: 260px; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; color: var(--text); font-size: 1.08rem; }
.doc-summary { display: flex; flex-wrap: wrap; gap: 1rem 2.2rem; }
.doc-summary .label { display: block; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .15rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
.grid th, .grid td { padding: .55rem .8rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.grid th { background: var(--surface-2); color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; white-space: nowrap; }
.grid.compact th, .grid.compact td { padding: .4rem .7rem; }
.grid .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.grid tbody tr[data-href] { cursor: pointer; }
.grid tbody tr[data-href]:hover { background: var(--accent-soft); }
.grid tfoot td { background: var(--surface-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.grid tr.grand td { font-weight: 700; border-top: 2px solid var(--border-strong); }
.grid tr.inactive td { color: var(--muted); }
.grid .group-row td { background: var(--surface-2); font-weight: 600; }
.clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.report-title { padding: 0 0 .5rem; }
.report-table td { padding: .4rem .8rem; }
.report-table .section td { font-weight: 700; padding-top: 1rem; border-bottom: 0; }
.report-table .indent { padding-left: 1.8rem; }
.report-table .subtotal td { font-weight: 600; }
.report-table .total td { font-weight: 700; background: var(--surface-2); }
.report-table .grand td { font-size: 1.02rem; }
.report-table a { color: var(--text); }
.report-table a:hover { color: var(--accent); }
.files { list-style: none; margin: 0 0 .5rem; padding: 0; }
.files li { padding: .35rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* ---------- ERP screens ---------- */
.pos { color: var(--ok); }
.grow { flex: 1 1 260px; }
.stack-sm { display: flex; flex-direction: column; gap: .45rem; }
h2.pad { padding: .85rem 1.25rem 0; }
.span-all { flex-basis: 100%; }
.sidebar .count { float: right; background: rgba(255, 255, 255, .14); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .45rem; line-height: 1.5; margin-top: .1rem; }
.sidebar nav a.active .count { background: rgba(255, 255, 255, .3); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-size: .92rem; }
.tabs a.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
code.secret { font-size: 1.05rem; letter-spacing: .06em; background: var(--surface-2); padding: .3rem .6rem; border-radius: 6px; user-select: all; }
tr.late td, li.late { color: var(--danger); }
.tasks { list-style: none; padding: 0; margin: 0 0 .75rem; }
.tasks li { display: flex; gap: .5rem; align-items: center; padding: .3rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tasks li.done span:first-of-type { text-decoration: line-through; color: var(--muted); }
.check-btn { background: none; border: 0; font-size: 1.15rem; cursor: pointer; line-height: 1; padding: 0 .2rem; color: var(--accent); }
.note { border-left: 3px solid var(--accent-soft); padding: .2rem 0 .1rem .75rem; margin-bottom: .6rem; }
.note p { margin: 0 0 .2rem; }
.dropzone { border: 2px dashed var(--border-strong); background: var(--surface-2); display: flex; flex-direction: column; gap: .6rem; }
.dropzone.drag, label.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-text { display: flex; flex-direction: column; gap: .15rem; }
.camera { position: relative; }
.inbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.inbox-item { display: flex; flex-direction: column; gap: .7rem; margin: 0; }
.inbox-item .thumb { display: flex; align-items: center; justify-content: center; height: 150px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.inbox-item .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.file-icon { font-weight: 700; color: var(--muted); font-size: 1.3rem; letter-spacing: .05em; }
.inbox-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.with-preview { display: grid; grid-template-columns: minmax(280px, 38%) 1fr; gap: 1rem; align-items: start; }
.receipt-preview { position: sticky; top: 4.5rem; }
.receipt-preview img { max-width: 100%; border-radius: 6px; }
.receipt-preview iframe { width: 100%; height: 75vh; border: 0; }
.sig-field { display: flex; flex-direction: column; gap: .35rem; }
.sig-field .label { font-weight: 600; font-size: .88rem; }
.sig-pad { width: 100%; max-width: 600px; aspect-ratio: 10 / 3; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff; touch-action: none; cursor: crosshair; }
.sig-current { max-height: 70px; max-width: 260px; background: #fff; border: 1px solid var(--border); border-radius: 4px; }

/* ---------- flash ---------- */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash-ok { background: var(--ok-soft); border-color: #bfe5cb; color: #134d26; }
.flash-error { background: var(--danger-soft); border-color: #f4c2c2; color: #7a1717; }
.flash-info { background: var(--info-soft); border-color: #c4dcf2; color: #1d4467; }

/* ---------- dashboard chart ---------- */
.chart { display: flex; gap: .4rem; align-items: flex-end; height: 180px; padding-top: .5rem; }
.month { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .3rem; height: 100%; }
.bars { flex: 1; width: 100%; display: flex; gap: 3px; align-items: flex-end; justify-content: center; }
.bar { width: 42%; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar.income, .key.income { background: var(--accent); }
.bar.expense, .key.expense { background: #f0a35e; }
.month .m { font-size: .75rem; color: var(--muted); }
.legend { font-size: .82rem; color: var(--muted); margin: .6rem 0 0; display: flex; gap: .4rem; align-items: center; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.key.expense { margin-left: .8rem; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 10px; padding: 1.4rem; width: min(520px, 94vw); box-shadow: 0 20px 50px rgba(15, 28, 36, .3); }
dialog::backdrop { background: rgba(15, 28, 36, .45); }
dialog h2 { margin: 0; }

/* ---------- sign-in ---------- */
body.bare { background: radial-gradient(ellipse at top, var(--side-2), var(--side) 70%); min-height: 100vh; }
.bare-main { max-width: 460px; margin: 0 auto; padding: 4rem 1rem; }
.bare-brand { display: flex; justify-content: center; margin-bottom: 1.5rem; }
.bare-brand img { width: 240px; height: auto; }
.auth h1 { margin-bottom: 1rem; }
.auth.wide { max-width: 560px; }
.logo-preview { max-height: 40px; vertical-align: middle; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; box-shadow: 0 0 30px rgba(0, 0, 0, .3); }
  body.sidebar-open .sidebar { left: 0; }
  .menu-btn { display: block; }
  .content { padding: 1rem; }
  .topbar { padding: .5rem 1rem; }
  .doc-head .span2 { grid-column: auto; }
  .with-preview { grid-template-columns: 1fr; }
  .receipt-preview { position: static; }
  .receipt-preview iframe { height: 50vh; }
}

@media print {
  .sidebar, .topbar, .no-print, .actions, .filters, .crumbs, .form-actions { display: none !important; }
  body, .content { background: #fff; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
