:root {
  color-scheme: dark;
  --ink: #e2ebe7;
  --heading: #f1f7f4;
  --muted: #9ba9a4;
  --faint: #73817c;
  --line: rgba(206, 224, 217, 0.14);
  --line-strong: rgba(206, 224, 217, 0.24);
  --soft: #101715;
  --paper: #17211e;
  --raised: #1d2925;
  --raised-soft: #202d29;
  --brand: #45c7b8;
  --brand-dark: #2ea99b;
  --brand-soft: rgba(69, 199, 184, 0.14);
  --accent: #d5a24f;
  --danger: #eb8b84;
  --warning: #d9a65d;
  --success: #98c977;
  --button-text: #0f1715;
  --shadow: 0 18px 42px rgba(5, 10, 9, 0.22);
  --focus: 0 0 0 3px rgba(69, 199, 184, 0.22);
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #1c2825;
  --heading: #101a18;
  --muted: #61706b;
  --faint: #7b8984;
  --line: #dbe5e1;
  --line-strong: #c7d4cf;
  --soft: #f3f6f4;
  --paper: #fbfcfb;
  --raised: #f6f9f7;
  --raised-soft: #eef4f1;
  --brand: #12766f;
  --brand-dark: #105f59;
  --brand-soft: rgba(18, 118, 111, 0.1);
  --accent: #a66d18;
  --danger: #b83a32;
  --warning: #9a6417;
  --success: #4f7f2d;
  --button-text: #f3faf7;
  --shadow: 0 16px 36px rgba(21, 35, 31, 0.08);
  --focus: 0 0 0 3px rgba(18, 118, 111, 0.18);
}

* {
  box-sizing: border-box;
}

.urgency { display: inline-flex; margin-top: 4px; padding: 3px 7px; border: 1px solid var(--line-strong); border-radius: 5px; background: transparent; color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.urgency.active { color: var(--warning); border-color: currentColor; background: var(--brand-soft); font-weight: 700; }
.urgent-field { display: flex; align-items: center; gap: 8px; }
.urgent-field input { width: auto; }
.ui-icon { width: 19px; height: 19px; flex-shrink: 0; vertical-align: middle; }
.dashboard-filters { grid-template-columns: minmax(180px, 2fr) minmax(140px, 1fr) auto auto; }
.filters[hidden], .filter-summary[hidden] { display: none; }
.filter-summary { color: var(--muted); font-size: 0.8rem; overflow-wrap: anywhere; }
.overdue-badge { display: inline-block; color: var(--danger); font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.entry-deadline-hint { color: var(--muted); margin: 0; font-size: 0.85rem; }
.dashboard-billing { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); text-align: left; }
.dashboard-billing strong { margin-left: auto; color: var(--heading); }
.dashboard-billing span:last-child { color: var(--brand); font-size: 0.8rem; }

html {
  background: var(--soft);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--soft);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.demo-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 26px;
  color: #422006;
  background: #fef3c7;
  border-bottom: 1px solid #f59e0b;
  font-size: 13px;
}

.demo-banner strong {
  flex: 0 0 auto;
  color: #92400e;
}

.sync-status[data-state="demo"]::before {
  background: #f59e0b;
}

@media (max-width: 640px) {
  .demo-banner {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
    padding: 9px 16px;
  }
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 0;
  box-shadow: var(--focus);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  background: #111c19;
  color: #e4efeb;
  border-right: 1px solid var(--line);
}

:root[data-theme="light"] .sidebar {
  background: #10201d;
  color: #edf7f4;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(228, 239, 235, 0.24);
  border-radius: 8px;
  background: var(--brand);
  color: var(--button-text);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  color: #f0f7f4;
}

.brand span,
.profile-card small {
  color: #9ab7af;
  font-size: 0.85rem;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #cadbd6;
  text-align: left;
  padding: 10px 12px;
}

.nav-button:hover,
.nav-button.active {
  border-color: rgba(69, 199, 184, 0.2);
  background: rgba(69, 199, 184, 0.12);
  color: #edf7f4;
}

.nav-button:disabled,
.primary-button:disabled,
.ghost-button:disabled,
.segment-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.profile-card {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(228, 239, 235, 0.16);
  border-radius: 8px;
  background: rgba(228, 239, 235, 0.04);
}

.profile-card label {
  color: #d3e1dd;
}

.profile-card select {
  width: 100%;
}

.main {
  min-width: 0;
  padding: 20px 24px;
}

.topbar,
.section-heading,
.panel-header,
.billing-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar {
  margin-bottom: 16px;
}

.topbar h1,
.section-heading h2,
.panel-header h3,
.registry-panel h3 {
  margin: 0;
  color: var(--heading);
}

.topbar h1 {
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  line-height: 1.2;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.ghost-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: var(--button-text);
}

.primary-button:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.ghost-button {
  border: 1px solid var(--line-strong);
  background: var(--raised);
  color: var(--ink);
}

.ghost-button:hover {
  border-color: rgba(69, 199, 184, 0.45);
  color: var(--heading);
}

.view {
  display: none;
  min-width: 0;
}

.view.active {
  display: grid;
  gap: 12px;
}

.section-heading p,
.panel-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  min-height: 82px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.metric-button {
  display: block;
  width: 100%;
  color: inherit;
  text-align: left;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.metric-button:hover {
  border-color: rgba(69, 199, 184, 0.5);
  background: var(--raised);
  transform: translateY(-1px);
}

.metric-button.active {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.metric-status-em-andamento {
  background: rgba(69, 199, 184, 0.1);
  border-color: rgba(69, 199, 184, 0.26);
}

.metric-status-em-aberto {
  background: rgba(110, 168, 255, 0.11);
  border-color: rgba(110, 168, 255, 0.3);
}

.metric-status-em-aprovacao {
  background: rgba(217, 166, 93, 0.11);
  border-color: rgba(217, 166, 93, 0.3);
}

.metric-status-suspenso {
  background: rgba(235, 139, 132, 0.1);
  border-color: rgba(235, 139, 132, 0.3);
}

.metric-status-concluido {
  background: rgba(152, 201, 119, 0.1);
  border-color: rgba(152, 201, 119, 0.28);
}

:root[data-theme="light"] .metric-status-em-andamento {
  background: #edf8f5;
  border-color: #b7ded6;
}

:root[data-theme="light"] .metric-status-em-aberto {
  background: #edf4ff;
  border-color: #b8d1f5;
}

:root[data-theme="light"] .metric-status-em-aprovacao {
  background: #fbf3e4;
  border-color: #e8c98f;
}

:root[data-theme="light"] .metric-status-suspenso {
  background: #fbefee;
  border-color: #e8bab6;
}

:root[data-theme="light"] .metric-status-concluido {
  background: #f0f7eb;
  border-color: #bdd7a9;
}

.metric span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 4px;
  color: var(--heading);
  font-size: 1.65rem;
}

.metric small {
  color: var(--muted);
}

.workband,
.entry-form,
.registry-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.workband,
.entry-form {
  padding: 18px;
}

.table-wrap {
  min-width: 0;
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

tfoot td {
  background: var(--raised);
  color: var(--heading);
  font-weight: 900;
}

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

th {
  color: var(--faint);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td {
  color: var(--ink);
}

tbody tr:hover td {
  background: rgba(206, 224, 217, 0.035);
}

.job-row {
  cursor: pointer;
}

.job-row:focus-visible td {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

:root[data-theme="light"] tbody tr:hover td {
  background: #f5f9f7;
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-control {
  min-width: 150px;
  border-width: 1px;
  font-weight: 800;
}

.status-em-andamento {
  background: rgba(69, 199, 184, 0.14);
  color: #8de1d7;
  border-color: rgba(69, 199, 184, 0.38);
}

.status-em-aberto {
  background: rgba(110, 168, 255, 0.14);
  color: #a9c9ff;
  border-color: rgba(110, 168, 255, 0.38);
}

.status-concluido {
  background: rgba(152, 201, 119, 0.15);
  color: #b6db9b;
  border-color: rgba(152, 201, 119, 0.38);
}

.status-em-aprovacao {
  background: rgba(217, 166, 93, 0.15);
  color: #e5bd7d;
  border-color: rgba(217, 166, 93, 0.42);
}

.status-suspenso {
  background: rgba(235, 139, 132, 0.14);
  color: #efa9a4;
  border-color: rgba(235, 139, 132, 0.4);
}

.status-cancelado {
  background: rgba(148, 163, 184, 0.14);
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.4);
}

.obs-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--raised);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  cursor: pointer;
}

.obs-button.has-obs {
  border-color: rgba(217, 166, 93, 0.58);
  background: rgba(217, 166, 93, 0.16);
  color: #e5bd7d;
}

.obs-button.empty {
  cursor: pointer;
}

:root[data-theme="light"] .status-em-andamento {
  background: #e7f6f2;
  color: #0f6c65;
  border-color: #8bcfc4;
}

:root[data-theme="light"] .status-em-aberto {
  background: #e7f0ff;
  color: #265d9e;
  border-color: #a8c7f4;
}

:root[data-theme="light"] .status-concluido {
  background: #edf7e8;
  color: #437522;
  border-color: #a8d18d;
}

:root[data-theme="light"] .status-em-aprovacao {
  background: #fbf0dc;
  color: #8d5e16;
  border-color: #e6bd73;
}

:root[data-theme="light"] .status-suspenso {
  background: #fae9e8;
  color: #aa352e;
  border-color: #e4aaa5;
}

:root[data-theme="light"] .obs-button {
  background: #f7faf8;
}

:root[data-theme="light"] .obs-button.has-obs {
  background: #fbf0dc;
  color: #8d5e16;
  border-color: #e6bd73;
}

.row-status-em-andamento td:first-child {
  box-shadow: inset 4px 0 0 var(--brand);
}

.row-status-em-aberto td:first-child {
  box-shadow: inset 4px 0 0 #6ea8ff;
}

.row-status-concluido td:first-child {
  box-shadow: inset 4px 0 0 var(--success);
}

.row-status-em-aprovacao td:first-child {
  box-shadow: inset 4px 0 0 var(--warning);
}

.row-status-suspenso td:first-child {
  box-shadow: inset 4px 0 0 var(--danger);
}

.row-status-cancelado td:first-child {
  box-shadow: inset 4px 0 0 #94a3b8;
}

.client-totals {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
}

.client-totals div {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.client-totals span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 0.84rem;
  font-weight: 800;
}

.filters,
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.dashboard-filters {
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.clear-filters {
  align-self: end;
}

.commission-input {
  max-width: 120px;
}

.commission-rate-input {
  max-width: 120px;
}

.commission-bulk-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(120px, 160px) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.commission-bulk-heading {
  display: grid;
  align-self: center;
  gap: 5px;
}

.commission-bulk-heading strong {
  color: var(--heading);
}

.commission-bulk-heading span {
  color: var(--muted);
  font-size: 0.84rem;
}

.commission-bulk-confirmation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 16px;
  padding: 12px;
  border: 1px solid rgba(69, 199, 184, 0.35);
  border-radius: 6px;
  background: var(--brand-soft);
}

.commission-bulk-confirmation[hidden] {
  display: none;
}

.commission-bulk-confirmation p {
  margin: 0;
  color: var(--ink);
}

.commission-bulk-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.commission-totals {
  margin-bottom: 14px;
}

.filters .segmented-control {
  align-self: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raised);
  color: var(--ink);
  padding: 8px 10px;
}

input::placeholder {
  color: var(--faint);
}

.line-items {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) 96px minmax(170px, 1fr) minmax(150px, 1fr) minmax(180px, 1fr) minmax(150px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
}

.commission-override-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.commission-override-toggle input {
  width: auto;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raised);
  color: var(--danger);
}

.icon-button:hover {
  border-color: rgba(235, 139, 132, 0.5);
  background: rgba(235, 139, 132, 0.1);
}

.registry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
}

.registry-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.clients-panel {
  grid-column: span 2;
}

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

.client-address {
  grid-column: 1 / -1;
}

.registry-panel ul {
  display: grid;
  gap: 8px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.registry-panel li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.registry-panel small {
  color: var(--muted);
}

.registry-form-actions,
.registry-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.registry-item-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.registry-item-main span,
.registry-item-main small {
  overflow-wrap: anywhere;
}

.registry-item-actions button {
  padding: 6px 9px;
  font-size: 12px;
}

.registry-state {
  font-weight: 600;
}

.registry-state.inactive {
  color: var(--danger);
}

.danger-button {
  border: 1px solid var(--danger);
  border-radius: 6px;
  background: var(--danger);
  color: #fff;
  padding: 9px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.deletion-warning {
  display: grid;
  gap: 14px;
}

.deletion-warning strong {
  color: var(--danger);
}

.billing-summary {
  padding: 16px 18px;
  border: 1px solid rgba(217, 166, 93, 0.28);
  border-radius: 8px;
  background: rgba(217, 166, 93, 0.1);
}

:root[data-theme="light"] .billing-summary {
  background: #fbf3e4;
}

.billing-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  justify-content: flex-end;
}

.billing-selector {
  min-width: 220px;
}

.billing-pdf-hint {
  flex-basis: 100%;
  color: var(--muted);
  line-height: 1.4;
}

.billing-pdf-hint:empty {
  display: none;
}

.segmented-control {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raised);
}

.segment-button {
  min-height: 40px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: var(--raised);
  color: var(--muted);
  padding: 8px 12px;
  font-weight: 800;
}

.segment-button:last-child {
  border-right: 0;
}

.segment-button.active {
  background: var(--brand);
  color: var(--button-text);
}

.billing-summary span,
.billing-summary strong {
  display: block;
}

.billing-selector[hidden] {
  display: none;
}

.billing-summary span {
  color: var(--muted);
  font-weight: 800;
}

.billing-summary strong {
  margin-top: 4px;
  color: var(--heading);
  font-size: 1.9rem;
}

.billing-client-groups {
  display: grid;
  gap: 18px;
}

.billing-client-block {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.billing-client-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--raised);
}

.billing-client-header h3,
.billing-client-header p {
  margin: 0;
}

.billing-client-header p {
  margin-top: 4px;
  color: var(--muted);
}

.billing-client-header strong {
  color: var(--heading);
  font-size: 1.3rem;
}

.billing-total-stack {
  text-align: right;
}

.billing-total-stack span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.billing-empty {
  padding: 24px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raised);
  color: var(--heading);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

#cloud-message {
  position: fixed;
  z-index: 1200;
  top: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(390px, calc(100vw - 36px));
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: color-mix(in srgb, var(--raised) 94%, transparent);
  color: var(--heading);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 800;
  backdrop-filter: blur(12px);
  animation: cloud-notice-in 180ms ease-out;
}

#cloud-message[hidden] {
  display: none;
}

#cloud-message::before {
  content: "i";
  display: grid;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
}

#cloud-message[data-kind="success"] {
  border-color: color-mix(in srgb, #22c55e 55%, var(--line));
}

#cloud-message[data-kind="success"]::before {
  content: "✓";
  background: #22c55e;
  color: #fff;
}

#cloud-message[data-kind="progress"]::before {
  content: "";
  box-sizing: border-box;
  border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent);
  background: transparent;
  animation: cloud-notice-spin 700ms linear infinite;
}

@keyframes cloud-notice-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cloud-notice-spin {
  to { transform: rotate(360deg); }
}

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.sync-status::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  content: "";
}

.sync-status[data-state="synced"]::before { background: #22c55e; }
.sync-status[data-state="updating"]::before,
.sync-status[data-state="reconnecting"]::before { background: #f59e0b; }
.sync-status[data-state="offline"]::before { background: #ef4444; }

.sync-conflict {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  background: color-mix(in srgb, #f59e0b 12%, var(--panel));
  color: var(--text);
}

.sync-conflict strong,
.sync-conflict p { margin: 0; }

.sync-conflict-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

form[data-sync-state="saving"] [type="submit"] { cursor: wait; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 8, 12, 0.64);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(520px, 100%);
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.modal-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--raised);
}

.modal-header h3 {
  margin: 0;
  color: var(--heading);
}

.modal-close {
  width: 34px;
  height: 34px;
  padding: 0;
}

.modal-body {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
}

.job-editor-modal .modal-card {
  width: min(1040px, 100%);
}

.job-editor-modal .modal-body,
.job-editor-modal form,
.job-editor-modal .edit-entry-items,
.job-editor-modal .item-row,
.job-editor-modal .item-row > * {
  min-width: 0;
}

.job-editor-modal .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.observation-text {
  margin: 0;
  color: var(--heading);
  font-size: 1rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.job-detail-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px 14px;
}

.job-detail-grid span {
  color: var(--muted);
  font-weight: 800;
}

.job-detail-grid strong {
  color: var(--heading);
}

.empty-observation {
  margin: 18px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
  color: var(--muted);
  font-weight: 800;
}

.empty-state {
  color: var(--muted);
  text-align: center;
}

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

  .sidebar {
    position: static;
    top: 0;
    z-index: 5;
    padding: 16px;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(120px, 1fr));
    overflow-x: auto;
  }

  .profile-card {
    margin-top: 0;
  }

  .metric-grid,
  .filters,
  .form-grid,
  .registry-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .item-row {
    grid-template-columns: 1fr 96px;
  }

  .job-editor-modal .item-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .modal-backdrop {
    place-items: stretch;
    padding: 8px;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100dvh - 16px);
  }

  .modal-header,
  .modal-body {
    padding: 14px;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .section-heading,
  .panel-header,
  .billing-summary {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .billing-client-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .client-totals div {
    justify-content: flex-start;
  }

  .metric-grid,
  .filters,
  .form-grid,
  .registry-grid,
  .item-row {
    grid-template-columns: 1fr;
  }

  .job-editor-modal .form-grid,
  .job-editor-modal .item-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .job-editor-modal .item-row .icon-button,
  .job-editor-modal .form-actions > * {
    width: 100%;
  }

  .commission-bulk-form {
    grid-template-columns: 1fr;
  }

  .commission-bulk-form .primary-button {
    width: 100%;
  }

  .commission-bulk-confirmation {
    align-items: stretch;
    flex-direction: column;
  }

  .commission-bulk-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .clients-panel,
  .client-address {
    grid-column: auto;
  }

  .client-form-grid {
    grid-template-columns: 1fr;
  }

  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-billing { gap: 8px; }
  .dashboard-billing strong { margin-left: 0; }
  .profile-card small { overflow-wrap: anywhere; }
}
