:root {
  --bg: #f4f5f7; --surface: #ffffff; --line: #e3e5ea; --line-strong: #cfd3da;
  --text: #16181d; --text-2: #555b66; --text-3: #8a909b;
  --accent: #167a7c; --accent-dark: #0f5f63; --accent-soft: #e2f3f2; --accent-bright: #3ba5a0;
  --side: #073641; --side-text: #c3dcdc;
  --red: #c62f2f; --red-soft: #fdecec; --green: #1c7c3c; --green-soft: #e6f4ea;
  --amber: #9a6200; --amber-soft: #fdf3dc; --grey-soft: #eceef1;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
a.plain { color: inherit; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 2px; font-weight: 600; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }
h3.mt { margin: 22px 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--text-2); } .small { font-size: 12px; }
.pre { white-space: pre-wrap; }
.late { color: var(--red); font-weight: 600; }
.grow { flex: 1; }
[hidden] { display: none !important; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border: 1px solid var(--line-strong);
  border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: #f1f3f6; text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--red); border-color: #e7b9b9; }
.btn.danger:hover { background: var(--red-soft); }
.btn.danger.primary, .modal-foot .btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }
.btn.block { width: 100%; height: 40px; margin-top: 6px; }
.btn:disabled { opacity: .55; cursor: default; }

/* Inputs */
input, select, textarea { font: inherit; color: var(--text); background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 10px; width: 100%; }
input[type=checkbox] { width: 16px; height: 16px; padding: 0; margin: 0; }
input:disabled, select:disabled { background: var(--grey-soft); color: var(--text-3); }
textarea { resize: vertical; }
label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field { display: flex; flex-direction: column; gap: 4px; grid-column: span 4; min-width: 0; }
.field.half { grid-column: span 2; } .field.quarter { grid-column: span 1; }
.field.check { flex-direction: row; align-items: center; gap: 8px; padding-top: 20px; }
.field.check span, label.check { font-size: 14px; font-weight: 400; color: var(--text); }
label.check { display: inline-flex; align-items: center; gap: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 14px; }
.req { color: var(--red); }
.hint { font-size: 12px; color: var(--text-3); }
.hint.late { color: var(--red); }
.form-error { background: var(--red-soft); color: var(--red); border-radius: 6px; padding: 9px 12px; margin-top: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.notice { background: var(--accent-soft); border-radius: 6px; padding: 10px 14px; margin-bottom: 14px; }
.notice.warn { background: var(--amber-soft); color: var(--amber); }

/* Login screens */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at 50% 40%, #1a6c71, #073641 75%); }
.auth-card { width: 400px; max-width: 100%; background: var(--surface); border-radius: 12px; padding: 30px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.auth-card h2 { font-size: 19px; margin: 0 0 14px; }
.auth-card .field { margin-bottom: 12px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 16px; font-size: 13px; }
.brand { margin-bottom: 18px; }
.logo { display: block; width: 72px; height: 72px; border-radius: 14px; }
.logo.small { width: 36px; height: 36px; border-radius: 8px; flex: none; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-name { font-size: 18px; font-weight: 700; color: var(--accent-dark); }

/* Layout */
.shell { display: flex; height: 100vh; }
.side { width: 226px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 16px; }
.side-brand .company { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--side-text); margin-bottom: 2px; }
#nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
#nav a.active { background: #1f8a88; color: #fff; }
#nav .ico { width: 18px; text-align: center; opacity: .85; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #7fa9ac; padding: 14px 10px 5px; }
.side-user { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-user b { display: block; color: #fff; font-weight: 600; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user small { text-transform: capitalize; color: #7fa9ac; }
.side-user .btn { color: var(--side-text); }
.side-user .btn:hover { background: rgba(255,255,255,.1); }
#view { flex: 1; overflow-y: auto; padding: 24px 28px 48px; min-width: 0; }
.page { max-width: 1240px; margin: 0 auto; }
.back { display: inline-block; margin-bottom: 8px; font-size: 13px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-2); margin-top: 3px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.loading, .empty { padding: 36px 16px; text-align: center; color: var(--text-2); }
.empty.error { color: var(--red); }

/* Cards, tiles */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card > .sub { color: var(--text-2); font-size: 12px; margin-bottom: 10px; }
.card-foot { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.card-actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 10px; }
.card-actions:empty { display: none; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.tile-value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-value.late { color: var(--red); }
.tile-note { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* Filters */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type=search] { width: 280px; }
.filters select, .filters input[type=date] { width: auto; }
.filters label { display: inline-flex; align-items: center; gap: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
input[type=text], input[type=search], input:not([type]), textarea, h1, .pre, dd { unicode-bidi: plaintext; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f2f8f8; }
tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 0; }
td .btn { margin-left: 4px; }
#list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--grey-soft); color: var(--text-2); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); } .badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); } .badge.blue { background: var(--accent-soft); color: var(--accent-dark); }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-strong); margin-bottom: 14px; flex-wrap: wrap; }
.tab { border: 0; background: none; font: inherit; font-weight: 500; color: var(--text-2); padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.tab .count { background: var(--grey-soft); border-radius: 10px; padding: 0 7px; font-size: 12px; color: var(--text-2); margin-left: 2px; }

/* Details list, notes */
dl.details { display: grid; grid-template-columns: 170px 1fr; gap: 9px 16px; margin: 0; }
dl.details dt { color: var(--text-2); font-weight: 600; font-size: 13px; }
dl.details dd { margin: 0; text-align: left; }
.inline-form { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
.note { padding: 11px 0; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: 0; }
.note-meta { font-size: 12px; color: var(--text-3); margin-bottom: 3px; display: flex; align-items: center; gap: 8px; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(16,22,36,.5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 10px; width: 460px; max-width: 100%; box-shadow: 0 18px 50px rgba(0,0,0,.3); }
.modal.wide { width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-head h3 { font-size: 17px; }
.modal-head .x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--text-3); }
.modal-body { padding: 16px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #0d3f49; color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 380px; }
.toast.error { background: var(--red); }

/* Picker */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: calc(100% + 2px); background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 260px; overflow-y: auto; z-index: 60; min-width: 260px; }
.picker-item { padding: 7px 10px; cursor: pointer; display: flex; flex-direction: column; }
.picker-item:hover { background: var(--accent-soft); }
.picker-item small { color: var(--text-3); font-size: 12px; }
.picker-empty { padding: 10px; color: var(--text-3); }

/* Invoice editor */
table.lines { margin: 18px 0 8px; }
table.lines td { vertical-align: top; border-bottom: 0; padding: 5px 6px 5px 0; }
table.lines th:nth-child(2) { width: 150px; } table.lines th:nth-child(3), table.lines th:nth-child(4), table.lines th:nth-child(5) { width: 120px; } table.lines th:nth-child(6) { width: 40px; }
table.lines input.qty, table.lines input.price { text-align: right; }
table.lines .line-total { padding-top: 12px; }
.inv-bottom, .doc-bottom { display: flex; gap: 28px; align-items: flex-start; margin-top: 18px; }
table.totals { width: 300px; flex: none; }
table.totals td { padding: 6px 0; border: 0; }
table.totals input { width: 120px; text-align: right; }
table.totals tr.grand td { font-weight: 700; font-size: 15px; border-top: 1px solid var(--line-strong); }

/* Printable document: teal header, plain body, company details in text at the bottom */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.doc-band { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 22px 36px; color: #fff; background: #0f5f63; }
.doc-brand { display: flex; gap: 16px; align-items: center; }
.doc-brand img { width: 68px; height: 68px; border-radius: 8px; }
.doc-wordmark { font-size: 32px; line-height: 1.1; font-weight: 700; letter-spacing: .5px; color: #fff; }
.doc-title { text-align: right; font-size: 14px; }
.doc-kind { font-size: 24px; font-weight: 700; letter-spacing: 2px; line-height: 1.2; }
.doc-no { font-weight: 700; }
.doc-body { padding: 26px 36px 24px; position: relative; }
.doc-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--text-3); margin-bottom: 3px; }
.doc-to { margin-bottom: 22px; unicode-bidi: plaintext; }
.doc-customer { font-size: 17px; font-weight: 700; }
.doc-lines th { color: var(--accent-dark); border-bottom: 2px solid var(--accent-dark); padding: 8px 10px; font-size: 12px; }
.doc-lines td { padding: 10px; unicode-bidi: plaintext; }
.doc-lines tbody tr:last-child td { border-bottom: 1px solid var(--line-strong); }
.doc table.totals { width: 280px; }
.doc .totals td { padding: 5px 10px; }
.doc .totals tr.grand td { color: var(--accent-dark); border-top: 2px solid var(--accent-dark); font-size: 17px; padding-top: 8px; }
.doc .totals tr.due td { font-weight: 700; }
.doc-foot { margin-top: 26px; color: var(--text-2); font-size: 13px; text-align: center; }
.doc-policy { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.doc-company-foot { margin-top: 22px; padding-top: 14px; border-top: 2px solid var(--accent-dark); text-align: center; font-size: 13px; line-height: 1.7; color: var(--text-2); unicode-bidi: plaintext; }
.doc-company { font-size: 16px; font-weight: 700; color: var(--accent-dark); letter-spacing: .3px; }
.doc-company-foot .sep { margin: 0 12px; color: var(--line-strong); }
.doc-legal b { color: var(--text); font-weight: 600; }
.doc-stamp { position: absolute; top: 20px; left: 42%; transform: rotate(-10deg); border: 3px solid var(--red); color: var(--red); font-weight: 800; font-size: 24px; letter-spacing: 3px; padding: 4px 16px; border-radius: 6px; opacity: .75; }
.doc.cancelled .doc-lines, .doc.cancelled .totals { opacity: .55; }

/* Chart */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { font-size: 11px; fill: var(--text-3); }
.chart .bar { fill: #2c9a96; }
.chart .hit { fill: transparent; }
.chart .col:hover .hit { fill: rgba(22,122,124,.08); }
.chart .col:hover .bar { fill: var(--accent-dark); }
.chart-tip { position: absolute; background: #0d3f49; color: #fff; font-size: 12px; padding: 5px 9px; border-radius: 5px; pointer-events: none; white-space: nowrap; }

@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

@media print {
  body { background: #fff; }
  .side, .page-head, .no-print, .back, #toasts { display: none !important; }
  .shell { display: block; height: auto; }
  #view { overflow: visible; padding: 0; }
  .doc { border: 0; border-radius: 0; }
  @page { size: A4; margin: 10mm; }
  .doc a { color: inherit; text-decoration: none; }
}

/* Search */
.side-search { padding: 0 12px 10px; }
.side-search input { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.18); color: #fff; }
.side-search input::placeholder { color: #9fc4c5; }
.side-search input:focus { background: #fff; color: var(--text); }
h2 .count { background: var(--grey-soft); border-radius: 10px; padding: 0 8px; font-size: 12px; color: var(--text-2); font-weight: 600; }
.form-actions.left { justify-content: flex-start; }

/* ------------------------------------------------------------------
   Phones and small tablets
   ------------------------------------------------------------------ */
.mobile-bar, .side-backdrop { display: none; }
@media (max-width: 860px) {
  body { font-size: 15px; }
  input, select, textarea { font-size: 16px; }          /* stops iPhones zooming in on every field */
  .shell { display: block; height: auto; min-height: 100vh; }
  .mobile-bar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; height: 54px; padding: 0 8px;
    padding-top: env(safe-area-inset-top); box-sizing: content-box; background: var(--side); color: #fff; }
  .mobile-bar b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
  .mobile-bar button { width: 44px; height: 44px; border: 0; background: none; color: #fff; font-size: 24px; line-height: 1; cursor: pointer; border-radius: 8px; }
  .mobile-bar button:active { background: rgba(255,255,255,.12); }
  .side { position: fixed; top: 0; bottom: 0; left: 0; width: 280px; max-width: 86vw; z-index: 45; transform: translateX(-102%); transition: transform .2s ease;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .shell.menu-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .shell.menu-open .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(8,20,24,.5); z-index: 40; }
  #nav a { padding: 12px 10px; font-size: 16px; }
  #view { overflow: visible; padding: 16px 12px 60px; }
  h1 { font-size: 20px; }
  .page-head { margin-bottom: 14px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .btn { height: 42px; }
  .btn.small { height: 34px; padding: 0 11px; font-size: 13px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 12px; } .tile-value { font-size: 17px; overflow-wrap: anywhere; }
  .card { padding: 14px 12px; }
  .filters { gap: 8px; }
  .filters input[type=search], .filters select, .filters label, .filters input[type=date] { width: 100%; }
  .filters label { justify-content: space-between; } .filters label.check { justify-content: flex-start; }
  .filters label input[type=date], .filters label select { width: auto; flex: 1; }
  #list { padding: 4px 6px; overflow-x: auto; }
  .table-wrap, #list { -webkit-overflow-scrolling: touch; }
  th, td { padding: 9px 8px; }
  td .btn { margin: 2px 4px 2px 0; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; } .tab { white-space: nowrap; padding: 10px 12px; }
  dl.details { grid-template-columns: 1fr; gap: 2px 0; } dl.details dd { margin-bottom: 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .field, .field.half, .field.quarter { grid-column: span 1; }
  .field.check { padding-top: 4px; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { width: 100%; max-height: 94vh; overflow-y: auto; border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  #toasts { left: 12px; right: 12px; bottom: 16px; } .toast { max-width: none; }
  .auth { padding: 14px; } .auth-card { padding: 22px; }
  .picker-list { max-height: 220px; }

  /* Invoice editor: each line becomes a small card */
  table.lines thead { display: none; }
  table.lines, table.lines tbody { display: block; }
  table.lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; padding: 10px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 8px; position: relative; }
  table.lines td { display: block; padding: 0; text-align: left; }
  table.lines td:nth-child(1) { grid-column: 1 / -1; padding-right: 38px; }
  table.lines td:nth-child(2) { grid-column: 1 / -1; }
  table.lines td:nth-child(3)::before { content: "Quantity"; } table.lines td:nth-child(4)::before { content: "Unit price"; }
  table.lines td:nth-child(3)::before, table.lines td:nth-child(4)::before { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); }
  table.lines td.line-total { grid-column: 1 / -1; text-align: right; font-weight: 700; padding-top: 2px; }
  table.lines td:last-child { position: absolute; top: 8px; right: 6px; }
  table.lines input.qty, table.lines input.price { text-align: left; }
  .inv-bottom { flex-direction: column; gap: 14px; } .inv-bottom table.totals { width: 100%; }
  .form-actions .btn { flex: 1; }

  /* Invoice view: keep the document's own layout and let it scroll sideways if needed */
  .page .doc { overflow-x: auto; }
  .page .doc-band { padding: 16px; gap: 12px; } .page .doc-brand { gap: 10px; } .page .doc-brand img { width: 48px; height: 48px; }
  .page .doc-wordmark { font-size: 22px; } .page .doc-kind { font-size: 18px; letter-spacing: 1px; } .page .doc-title { font-size: 13px; }
  .page .doc-body { padding: 18px 14px; }
  .page .doc-bottom { flex-direction: column; gap: 14px; } .page .doc table.totals { width: 100%; }
  .page .doc-lines th, .page .doc-lines td { padding: 8px 6px; }
  .page .doc-company-foot .sep { margin: 0 6px; }
}
