:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #646b78;
  --border: #e2e5ea;
  --border-strong: #cdd2da;
  --accent: #4c5fd5;
  --accent-hover: #3d4fc0;
  --accent-soft: #eceffd;
  --accent-text: #ffffff;
  --danger: #c93636;
  --danger-soft: #fdeeee;
  --success: #1d8a54;
  --success-soft: #e6f5ec;
  --warning: #9a6700;
  --warning-soft: #fff4d6;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.06);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 0.18);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2a2f38;
    --border-strong: #3a404b;
    --accent: #7b8cf0;
    --accent-hover: #93a1f4;
    --accent-soft: #242a48;
    --accent-text: #0f1115;
    --danger: #f07171;
    --danger-soft: #3a1f22;
    --success: #5cc98f;
    --success-soft: #16301f;
    --warning: #f0c24f;
    --warning-soft: #352b12;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.error { color: var(--danger); margin: 0; min-height: 0; }
.error:empty { display: none; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, .menu-item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-link { height: auto; padding: 0; border: none; background: none; color: var(--accent); font-weight: 500; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger); filter: brightness(0.92); }
.btn-block { width: 100%; }
.icon-btn {
  width: 32px; height: 32px; border: none; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select {
  width: 100%; height: 38px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="number"] { font-variant-numeric: tabular-nums; }

/* ---------- Brand ---------- */

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; letter-spacing: 0.5px;
}
.brand-lg { font-size: 18px; }
.brand-lg .brand-mark { width: 36px; height: 36px; font-size: 13px; }

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px;
  padding: 32px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
}
.login-card p { margin: 0; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.nav { display: flex; gap: 4px; }

.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 8px; border-radius: 8px; }
.user-chip:hover { background: var(--surface-2); }
.user-text { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.avatar {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 13px; flex: none;
}
.role-badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
}
.menu-item {
  display: block; width: 100%; padding: 8px 10px; text-align: left;
  border: none; border-radius: 6px; background: none; cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }

/* ---------- Page ---------- */

.page { max-width: 1440px; margin: 0 auto; padding: 28px 24px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; font-weight: 650; }
.period { margin: 4px 0 0; color: var(--muted); display: flex; gap: 12px; align-items: center; }
.head-actions { display: flex; gap: 8px; }
.notice {
  margin: 0 0 20px; padding: 10px 14px; border-radius: 8px;
  background: var(--accent-soft); color: var(--text);
}
.footnote { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat {
  padding: 16px 18px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: 12px; color: var(--muted); }
.stat-value.negative { color: var(--danger); }

/* Filters */
.filters { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; flex-wrap: wrap; }
.tab {
  height: 32px; padding: 0 12px; border: none; border-radius: 7px; background: none;
  color: var(--muted); font-weight: 500; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab .count { margin-left: 6px; font-size: 12px; color: var(--muted); }
.filter-controls { display: flex; gap: 8px; flex: 1; justify-content: flex-end; min-width: 260px; }
.filter-controls input { max-width: 320px; }
.filter-controls select { width: auto; }

/* Technician sections */
.tech-section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden;
}
.tech-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.tech-head h2 { font-size: 16px; font-weight: 650; }
.tech-meta { font-size: 13px; color: var(--muted); }
.tech-summary { margin-left: auto; text-align: right; font-size: 13px; color: var(--muted); }
.tech-summary strong { display: block; font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; }
.tech-summary strong.negative { color: var(--danger); }
.print-title { display: none; }

.table-wrap { overflow-x: auto; }
table.report { width: 100%; border-collapse: collapse; font-size: 13px; }
.report th {
  position: sticky; top: 0;
  padding: 10px 12px; text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.report td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.report tbody tr:hover td { background: var(--surface-2); }
.report th.num, .report td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.report td.negative { color: var(--danger); }
.report td.strong { font-weight: 600; }
.report .job-code { font-weight: 600; }
.report .sub { display: block; color: var(--muted); font-size: 12px; }
.report tbody tr.job-unsettled td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.report tfoot td { font-weight: 650; border-bottom: none; background: var(--surface); }
.report td.row-actions { white-space: nowrap; text-align: right; }
.report th.business, .report td.business { background: var(--accent-soft); }
.report tbody tr:hover td.business { background: var(--accent-soft); }
.report td.row-actions .btn { margin-left: 4px; }

.pill { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill-warning { background: var(--warning-soft); color: var(--warning); }
.pill-success { background: var(--success-soft); color: var(--success); }

.empty-state {
  padding: 48px 24px; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty-state strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* ---------- Dialogs ---------- */

dialog {
  width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.wide { width: min(780px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(15 17 21 / 0.45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.dialog-body { display: flex; flex-direction: column; gap: 16px; padding: 22px 24px 24px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { font-size: 18px; font-weight: 650; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
fieldset { border: none; margin: 0; padding: 0; }
legend { padding: 0; margin-bottom: 10px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid .span2 { grid-column: span 2; }
.preview { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); }
.preview div { display: flex; flex-direction: column; font-size: 12px; }
.preview strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.preview strong.negative { color: var(--danger); }

.list-table { border: 1px solid var(--border); border-radius: 10px; overflow: auto; }
.list-table table { width: 100%; border-collapse: collapse; }
.list-table th { padding: 8px 12px; text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.list-table td { padding: 10px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
.list-table td:last-child { text-align: right; white-space: nowrap; }
.list-table td:last-child .btn { margin-left: 4px; }
.list-table select { width: auto; height: 32px; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell strong { font-weight: 600; }
.user-cell .sub { display: block; font-size: 12px; color: var(--muted); }
.check-field { flex-direction: row; align-items: center; gap: 8px; color: var(--text); align-self: end; min-height: 38px; }
.check-field input { width: 18px; height: 18px; accent-color: var(--accent); }
.list-table th.num, .list-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.list-table tfoot td { font-weight: 650; }

/* Navigation between views */
.nav-view[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.nav-sep { width: 1px; height: 20px; background: var(--border); align-self: center; margin: 0 4px; }

/* Owners' split */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.card-title { font-size: 15px; font-weight: 650; }
.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.split-grid > .card { margin-bottom: 20px; }
.ledger { margin: 0; display: flex; flex-direction: column; }
.ledger div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.ledger dt { color: var(--muted); }
.ledger dd { margin: 0; font-variant-numeric: tabular-nums; }
.ledger dd.negative { color: var(--danger); }
.ledger .subtotal { border-bottom: 2px solid var(--border-strong); }
.ledger .subtotal dt, .ledger .subtotal dd { color: var(--text); font-weight: 650; }
.ledger .total { border-bottom: none; padding-top: 12px; }
.ledger .total dt, .ledger .total dd { color: var(--text); font-weight: 700; font-size: 16px; }
.owner-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.owner-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: var(--surface-2); }
.owner-card header { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-bottom: 10px; }
.owner-card .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 2px 0; font-variant-numeric: tabular-nums; }
.owner-card .payout { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border-strong); font-weight: 600; }
.owner-card .payout strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.owner-card .payout strong.negative { color: var(--danger); }
.owner-card .row.strong { color: var(--text); font-weight: 600; }
.owner-card .owner-pay { width: 100%; margin-top: 12px; }
.empty-row td { text-align: center !important; color: var(--muted); padding: 18px; }

.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.hint:empty { display: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--border-strong); }
.dot.on { background: var(--success); }

.audit { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.audit li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.audit li:last-child { border-bottom: none; }
.audit .when { font-size: 12px; color: var(--muted); }
.audit .changes { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-word; }

/* ---------- Toasts ---------- */

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg);
  box-shadow: var(--shadow-lg); font-weight: 500; animation: toast-in 0.2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Small screens ---------- */

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .split-grid { grid-template-columns: 1fr; gap: 0; }
}
@media (max-width: 600px) {
  .topbar { padding: 0 16px; gap: 8px; }
  .topbar .brand span:last-child, .user-text { display: none; }
  .page { padding: 20px 16px 40px; }
  .stat-value { font-size: 20px; }
  .filter-controls { min-width: 0; width: 100%; }
  .filter-controls input { max-width: none; }
  .grid, .grid-3 { grid-template-columns: 1fr; }
  .grid .span2 { grid-column: auto; }
  .tech-head { flex-wrap: wrap; }
}

/* ---------- Print: reproduce the original report, one per technician ---------- */

@media print {
  body { background: #fff; color: #000; }
  .no-print, .topbar, .row-actions, .tech-head { display: none !important; }
  .page { padding: 0; max-width: none; }
  .tech-section { border: none; box-shadow: none; border-radius: 0; margin: 0; break-after: page; }
  .tech-section:last-child { break-after: auto; }
  .print-title { display: block; text-align: center; font: bold 16px "Times New Roman", Times, serif; margin: 0 0 1em; }
  .table-wrap { overflow: visible; }
  table.report { font: normal 12px "Times New Roman", Times, serif; color: #000; }
  .report th, .report td { padding: 4px; border: 1px solid #000; background: none !important; color: #000; position: static; }
  .report th { border-bottom: 3px solid #000; }
  .report td.negative { color: red; }
  .report tbody tr.job-unsettled td { background: #ffff99 !important; box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .report tfoot td { border-style: none; font-weight: bold; }
  .report .sub { color: #000; font-size: inherit; }
  .pill { display: none; }
  .card, .owner-card { box-shadow: none; break-inside: avoid; }
  .stat { box-shadow: none; }
}
