:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-2: #eef4f1;
  --ink: #1f2422;
  --muted: #606966;
  --soft: #8c9692;
  --line: #d9dfdc;
  --line-strong: #aeb9b4;
  --green: #194b3b;
  --teal: #177d7b;
  --coral: #c85c43;
  --blue: #365f91;
  --amber: #9b6419;
  --red: #a33939;
  --ok-bg: #e8f5ed;
  --warn-bg: #fff5df;
  --bad-bg: #fae9e6;
  --info-bg: #e9f0fa;
  --radius: 8px;
  --shadow: 0 18px 60px rgba(22, 38, 33, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
}

.app-shell.locked {
  display: none;
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #18372e;
}

.auth-screen.hidden {
  display: none;
}

.auth-box {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  margin-bottom: 4px;
}

.auth-copy {
  color: var(--muted);
  line-height: 1.4;
}

.auth-error {
  padding: 10px 12px;
  border: 1px solid #e3aaa0;
  border-radius: var(--radius);
  color: var(--red);
  background: var(--bad-bg);
  font-size: 13px;
}

.sidebar {
  background: #18372e;
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
}

.brand-subtitle,
.mini-label {
  color: rgba(255, 255, 255, 0.66);
  font-size: 12px;
  line-height: 1.3;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.12);
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
}

.invoice-pattern {
  margin-top: 4px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  color: #fff;
  overflow-wrap: anywhere;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 78px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 16px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

#view-kicker {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions,
.form-actions,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.button,
.icon-button,
.segment {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 13px;
  font-weight: 700;
  line-height: 1.2;
}

.button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.button.secondary {
  background: var(--panel-2);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--green);
}

.button.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.button.danger {
  background: var(--bad-bg);
  color: var(--red);
  border-color: #e3aaa0;
}

.button.undo {
  background: var(--warn-bg);
  color: var(--amber);
  border-color: #e6c58a;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 18px;
}

.content {
  padding: 22px;
  overflow: auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card,
.panel,
.mini-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat-card {
  min-height: 108px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  font-size: 25px;
  line-height: 1.1;
  font-weight: 800;
}

.stat-note {
  color: var(--soft);
  font-size: 12px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.panel-wide {
  grid-column: 1 / -1;
}

.panel {
  padding: 14px;
}

.panel-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.stack {
  display: grid;
  gap: 10px;
}

.mini-card {
  padding: 12px;
  display: grid;
  gap: 7px;
}

.worker-owed-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.owed-row {
  min-height: 92px;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.owed-row.settled {
  background: var(--ok-bg);
}

.owed-main,
.owed-breakdown {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.owed-amount {
  font-weight: 800;
  font-size: 18px;
  color: var(--green);
  white-space: nowrap;
}

.owed-breakdown {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  flex-wrap: wrap;
}

.mini-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.mini-title {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.mini-meta,
.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
  background: var(--panel-2);
}

.segment {
  border: 0;
  min-height: 34px;
  padding: 7px 11px;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: var(--panel);
  color: var(--green);
  box-shadow: 0 1px 3px rgba(20, 34, 30, 0.12);
}

.filters {
  display: grid;
  grid-template-columns: minmax(140px, 190px) minmax(150px, 190px) minmax(200px, 1fr);
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 9px 11px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(23, 125, 123, 0.22);
  outline-offset: 2px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.invoice-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  font-size: 12px;
  color: var(--muted);
  background: #f1f5f3;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.cell-main {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.invoice-actions {
  min-width: 205px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(82px, 1fr));
  gap: 5px;
}

.status-toggle {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  border: 1px solid #b3c7e3;
  border-radius: 999px;
  background: var(--info-bg);
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.status-toggle:hover {
  filter: brightness(0.98);
}

.status-toggle.is-paid {
  background: var(--ok-bg);
  border-color: #9bd3b1;
  color: #246138;
}

.status-toggle.is-unpaid {
  background: var(--info-bg);
  border-color: #b3c7e3;
  color: var(--blue);
}

.action-menu {
  position: relative;
  justify-self: end;
}

.action-menu summary {
  list-style: none;
}

.action-menu summary::-webkit-details-marker {
  display: none;
}

.menu-trigger {
  width: 32px;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.menu-trigger:hover {
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--green);
}

.action-menu-list {
  display: grid;
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 5;
  min-width: 150px;
  gap: 2px;
  margin-top: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(22, 38, 33, 0.12);
}

.menu-action {
  width: 100%;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 7px 9px;
  font-weight: 700;
  text-align: left;
}

.menu-action:hover,
.menu-action:focus-visible {
  background: var(--panel-2);
}

.menu-action.danger {
  color: var(--red);
}

.status-badge {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-paid {
  color: #246138;
  background: var(--ok-bg);
  border-color: #a6d7b9;
}

.status-unpaid {
  color: var(--blue);
  background: var(--info-bg);
  border-color: #b3c7e3;
}

.status-partial {
  color: var(--amber);
  background: var(--warn-bg);
  border-color: #e4c58e;
}

.status-overdue {
  color: var(--red);
  background: var(--bad-bg);
  border-color: #e3aaa0;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
}

.worker-list {
  display: grid;
  gap: 10px;
}

.worker-row,
.payment-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.worker-prefix {
  display: inline-flex;
  min-width: 54px;
  justify-content: center;
  padding: 5px 9px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--teal);
  font-weight: 800;
}

.form-grid,
.invoice-form {
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.form-row.with-action {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check-line input {
  width: 18px;
  min-height: 18px;
}

.modal-layer {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  background: rgba(14, 24, 22, 0.48);
  z-index: 20;
  overflow: auto;
}

.modal {
  width: min(760px, 100%);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.payment-list {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.payment-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfb;
}

.payment-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.2;
}

.upload-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.upload-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.empty-state {
  padding: 22px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.6);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   Invoice cards — two-track layout (replaces the invoice table)
   ============================================================ */
.invoice-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.invoice-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 14px 15px;
  display: grid;
  gap: 12px;
}

.invoice-card.status-paid { border-left-color: #9bd3b1; }
.invoice-card.status-unpaid { border-left-color: #b3c7e3; }
.invoice-card.status-partial { border-left-color: #e4c58e; }
.invoice-card.status-overdue { border-left-color: #e3aaa0; }

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-no {
  font-family: Consolas, "Courier New", monospace;
  font-weight: 800;
  font-size: 13px;
  color: var(--green);
  overflow-wrap: anywhere;
}

.card-head .card-recip {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.card-head .card-ref {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.lab-tag {
  color: var(--teal);
  font-weight: 800;
}

.card-tracks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.card-track {
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
}

.track-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 800;
}

.track-value {
  margin: 5px 0 3px;
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.track-meta {
  color: var(--soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.track-bar {
  height: 5px;
  margin-top: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.track-bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--teal);
}

.track-bar > i.is-done {
  background: var(--green);
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: 11px;
}

.card-dates {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.card-foot .invoice-actions.card-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  width: auto;
  min-width: auto;
  grid-template-columns: none;
}

.filechip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filechip:hover {
  border-color: var(--line-strong);
  color: var(--green);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 10px 12px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
  }

  .brand {
    border-bottom: 0;
    padding: 0;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .nav {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    overflow-x: auto;
  }

  .nav-button {
    width: auto;
    min-width: 112px;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid,
  .dashboard-grid,
  .settings-layout,
  .toolbar,
  .filters {
    grid-template-columns: 1fr;
  }

  .invoice-card-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  body {
    font-size: 14px;
  }

  .content,
  .topbar,
  .modal-layer {
    padding: 14px;
  }

  .topbar-actions,
  .modal-actions,
  .form-actions {
    width: 100%;
    justify-content: stretch;
  }

  .button {
    flex: 1;
  }

  .form-row,
  .form-row.with-action {
    grid-template-columns: 1fr;
  }

  .modal {
    padding: 14px;
  }

  .card-foot .invoice-actions.card-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* ============================================================
   Refined ledger table — money columns, balances, status
   ============================================================ */
.invoice-table td {
  vertical-align: top;
}

.invoice-table .num-col,
.invoice-table .num-cell {
  text-align: right;
}

.invoice-table .num-cell .track-bar {
  margin-top: 7px;
  margin-left: auto;
  max-width: 160px;
}

.money-main {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.money-sub {
  margin-top: 2px;
  color: var(--soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.invoice-table .actions-cell {
  text-align: right;
  white-space: nowrap;
}

.invoice-table .action-menu {
  display: inline-block;
}

.invoice-table .filechip {
  margin-top: 2px;
}
