:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #667085;
  --line: #e3e7ec;
  --side: #10202b;
  --side-ink: #c9d4dc;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #e6f4f2;
  --danger: #c0352b;
  --danger-soft: #fdecea;
  --warn: #b25e09;
  --warn-soft: #fff4e5;
  --ok: #1e7f4f;
  --ok-soft: #e7f6ee;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
.boot { padding: 40px; color: var(--muted); }

/* layout */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700; font-size: 16px; }
.logo small { display: block; font-weight: 400; color: var(--side-ink); font-size: 12px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7f93a1; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 8px 10px; border-radius: 6px; margin: 1px 0; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav svg { width: 17px; height: 17px; flex: none; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 24px; position: sticky; top: 0; z-index: 5; }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.logo svg { width: 30px; height: 30px; flex: none; }
.content { padding: 22px 24px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 4px; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 13px; border-radius: 6px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f8fafb; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: #f1c4c0; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 0; }
.btn:disabled { opacity: .55; cursor: default; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafcfc; }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; margin: -18px; }

.table-wrap th:first-child, .table-wrap td:first-child { padding-left: 18px; }
.table-wrap th:last-child, .table-wrap td:last-child { padding-right: 18px; }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef1f4; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

/* forms */
form .row { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0,1fr)); margin-bottom: 14px; }
form .row.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
form .row.one { grid-template-columns: 1fr; }
label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 550; margin-bottom: 5px; }
input, select, textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #cfd6dd; border-radius: 6px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15,118,110,.25); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 220px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

.lines td { padding: 6px; vertical-align: middle; }
.lines input, .lines select { padding: 6px 8px; }
.totals { margin-left: auto; width: 320px; max-width: 100%; margin-top: 14px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 9px; font-weight: 700; font-size: 16px; }

dl.info { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; white-space: pre-line; }

/* login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #10202b 0%, #0f3a3a 100%); }
.auth .card { width: 380px; max-width: 100%; padding: 28px; }
.auth h1 { margin-bottom: 4px; }
.auth p { color: var(--muted); margin: 0 0 20px; }
.auth form .row { grid-template-columns: 1fr; }
.auth .btn { width: 100%; justify-content: center; padding: 10px; }
.error { background: var(--danger-soft); color: var(--danger); padding: 9px 12px; border-radius: 6px; margin-bottom: 14px; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(16,32,43,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border-radius: 10px; width: 480px; max-width: 100%; max-height: 90vh; overflow-y: auto; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h2 { font-size: 17px; }
#toast { position: fixed; bottom: 20px; right: 20px; z-index: 60; display: grid; gap: 8px; }
#toast .t { background: var(--side); color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: var(--shadow); max-width: 360px; }
#toast .t.err { background: var(--danger); }

/* chart */
.bars { display: flex; align-items: flex-end; gap: 14px; height: 170px; padding-top: 10px; }
.bars .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.bars .stack { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.bars .b { width: 40%; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .b.s { background: var(--brand); }
.bars .b.p { background: #9fb3c2; }
.bars .lbl { font-size: 11.5px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; background: var(--brand); }
.legend span.p::before { background: #9fb3c2; }

/* invoice print */
.doc { background: #fff; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.doc-head .title { font-size: 26px; font-weight: 700; letter-spacing: .02em; color: var(--brand); text-align: right; }
.doc-meta { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 22px; }

@media print {
  .side, .topbar, .page-head .actions, .no-print, #toast { display: none !important; }
  .layout { display: block; }
  body, .content { background: #fff; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
/* ---------- app shell pieces hidden on desktop ---------- */
.tabbar, .app-title { display: none; }
.btn.block { width: 100%; justify-content: center; margin-top: 10px; padding: 12px; }
.center { text-align: center; }

/* ---------- phone & small tablet: behave like a native app ---------- */
@media (max-width: 900px) {
  :root { --tabbar-h: 62px; }
  html, body { overscroll-behavior-y: none; }
  body { -webkit-tap-highlight-color: transparent; background: var(--bg); }
  .layout { display: block; }
  .side { display: none; }

  /* top app bar */
  .topbar { padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--side); border-bottom: 0; color: #fff; }
  .app-title { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; min-width: 0; }
  .app-title span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); flex: none; }
  .app-logo svg { width: 18px; height: 18px; color: #fff; }
  .topbar .user { display: none; }

  /* bottom tab bar */
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(255,255,255,.96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--tabbar-h);
    color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; }
  .tabbar a svg { width: 23px; height: 23px; }
  .tabbar a.active { color: var(--brand); }
  .tabbar a.active svg { stroke-width: 2.3; }

  .content { padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px); max-width: none; }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 22px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; justify-content: center; padding: 10px 12px; }
  /* main action becomes a floating button above the tab bar */
  .page-head .actions .btn.primary { position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
    z-index: 25; flex: none; border-radius: 99px; padding: 14px 20px; font-size: 15px; box-shadow: 0 6px 18px rgba(15,118,110,.35); }

  /* touch-friendly controls; 16px stops iPhone from zooming into fields */
  input, select, textarea { font-size: 16px; padding: 11px 12px; border-radius: 10px; }
  .btn { padding: 10px 14px; border-radius: 10px; }
  .btn.small { padding: 7px 11px; }
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { min-width: 0; width: 100%; }
  .toolbar label { display: none; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs a { white-space: nowrap; }

  .grid.g4 { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
  .g3, .g2 { grid-template-columns: 1fr; }
  .grid { gap: 12px; }
  .card { border-radius: 14px; padding: 15px; }
  .stat .value { font-size: 20px; }
  form .row, form .row.three { grid-template-columns: 1fr; gap: 12px; }
  form.card { padding-bottom: 90px; }
  .form-actions { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 26; margin: 0;
    padding: 10px 14px; background: rgba(255,255,255,.97); border-top: 1px solid var(--line); }
  .form-actions .btn { flex: 1; justify-content: center; padding: 13px; }
  .modal .form-actions { position: static; padding: 0; border: 0; background: none; margin-top: 16px; }

  /* tables turn into tappable cards */
  .table-wrap { margin: -15px; overflow: visible; }
  .table-wrap[style] { margin: 0 -15px -15px !important; }
  .table-wrap table, .table-wrap table.lines { min-width: 0; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr { padding: 12px 15px; border-bottom: 1px solid var(--line); position: relative; }
  tbody tr:last-child { border-bottom: 0; }
  tbody tr.clickable::after { content: "›"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: #b7c0c9; font-size: 22px; }
  tbody tr.clickable { padding-right: 32px; }
  tbody tr.clickable:active { background: #eef4f3; }
  th, td { border: 0; padding: 0; }
  td { display: block; padding: 3px 0; text-align: right; font-size: 14px; overflow: hidden; }
  td.num { text-align: right; }
  td[data-label]::before { content: attr(data-label); float: left; margin-right: 12px; color: var(--muted); font-size: 12.5px; line-height: 20px; }
  td:first-child { display: block; text-align: left; font-size: 15px; padding-bottom: 5px; }
  td:first-child::before { display: none; }
  td:empty { display: none; }
  .no-head td { text-align: left; }
  .no-head td.num { text-align: right; }
  .table-wrap th:first-child, .table-wrap td:first-child, .table-wrap th:last-child, .table-wrap td:last-child { padding-left: 0; padding-right: 0; }

  td.idx { display: none; }
  td.idx + td { display: block; text-align: left; font-size: 15px; padding-bottom: 5px; }
  td.idx + td::before { display: none; }

  /* order lines on the order form */
  table.lines tbody tr { background: #f8fafb; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; padding: 12px; }
  table.lines td { padding: 4px 0; }
  table.lines td input { max-width: 60%; text-align: right; }
  table.lines td[data-label]::before { line-height: 44px; }
  table.lines td.amt { font-weight: 650; }
  table.lines td.amt::before { line-height: 20px; }
  table.lines td:first-child select { width: 100%; }
  .totals { width: 100%; }

  /* invoice view */
  .doc-head, .doc-meta { flex-direction: column; gap: 12px; }
  .doc-head .title { text-align: left; font-size: 22px; }
  .doc-head .title + div { text-align: left !important; }
  dl.info { grid-template-columns: 110px 1fr; }

  /* chart */
  .bars { gap: 8px; height: 140px; }

  /* modals slide up from the bottom like a native sheet */
  .modal-bg { place-items: end stretch; padding: 0; animation: fade .18s ease; }
  .modal { width: 100%; max-width: none; border-radius: 18px 18px 0 0; max-height: 88vh;
    padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .22s ease; }
  .sheet-handle { width: 40px; height: 5px; border-radius: 9px; background: #d6dce1; margin: 4px auto 14px; }
  #toast { left: 14px; right: 14px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 80px); }
  #toast .t { max-width: none; text-align: center; border-radius: 12px; }

  .auth { padding: 0; align-items: end; }
  .auth .card { width: 100%; border-radius: 22px 22px 0 0; padding: 26px 20px calc(26px + env(safe-area-inset-bottom)); }
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* "More" sheet */
.more-user { margin-bottom: 12px; }
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 6px; }
.more-item { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 14px 6px; border-radius: 14px; background: #f3f6f7;
  color: var(--ink); font-size: 12.5px; font-weight: 600; text-align: center; }
.more-item:hover { text-decoration: none; background: var(--brand-soft); }
.more-item svg { width: 24px; height: 24px; color: var(--brand); }

/* installed app: no browser chrome, keep it snappy */
@media (display-mode: standalone) {
  body { user-select: none; -webkit-user-select: none; }
  input, textarea, td, dd, .doc { user-select: text; -webkit-user-select: text; }
}
@media print { .tabbar { display: none !important; } }
