:root {
  color-scheme: light;
  --bg: #f5f5f5;
  --panel: #ffffff;
  --ink: #0a0a0a;
  --muted: #737373;
  --soft: #fafafa;
  --line: #e5e5e5;
  --brand: #f87171;
  --danger: #ef4444;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 24px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  touch-action: manipulation;
}
body { margin: 0; width: 100%; max-width: 100%; min-height: 100vh; overflow-x: hidden; touch-action: manipulation; background: var(--bg); color: var(--ink); letter-spacing: 0; }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px 14px;
  background: var(--soft);
  color: var(--ink);
  outline: none;
}
textarea { min-height: 128px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: #0a0a0a;
  background: white;
  box-shadow: 0 0 0 4px rgba(10,10,10,.06);
}
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
a { color: inherit; }

.app-shell { width: 100%; max-width: 100vw; min-height: 100vh; display: flex; overflow-x: hidden; }
.sidebar {
  width: 288px;
  flex: 0 0 288px;
  background: #0a0a0a;
  color: white;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.brand { font-size: 25px; font-weight: 700; line-height: 1; padding: 8px 6px; }
.brand span { color: var(--brand); }
.nav { display: grid; gap: 8px; }
.nav button, .mobile-nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 18px;
  padding: 13px 15px;
  text-align: left;
  white-space: nowrap;
}
.nav button { color: rgba(255,255,255,.62); background: transparent; }
.nav button:hover { background: rgba(255,255,255,.08); color: white; }
.nav button.active { background: white; color: black; }
.sidebar-footer {
  margin-top: auto;
  color: rgba(255,255,255,.48);
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 18px;
  font-size: 13px;
}
.pwa-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.pwa-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: rgba(255,255,255,.76);
  background: rgba(255,255,255,.1);
}
.pwa-status.online { color: #bbf7d0; background: rgba(22,163,74,.18); }
.pwa-status.offline { color: #fecaca; background: rgba(239,68,68,.18); }
.pwa-status.installed { color: white; background: rgba(255,255,255,.16); }
.pwa-install {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 999px;
}
.mobile-pwa-actions { display: none; }
.offline-banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #fecaca;
  border-radius: 16px;
  color: #991b1b;
  background: #fef2f2;
  font-size: 14px;
}
.content { flex: 1; width: 100%; max-width: 100%; min-width: 0; padding: 32px; overflow-x: hidden; }
.mobile-nav-row { display: none; width: 100%; max-width: 100%; min-width: 0; gap: 8px; align-items: center; margin-bottom: 8px; }
.mobile-nav { display: none; flex: 1 1 auto; width: 100%; max-width: 100%; min-width: 0; gap: 7px; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.mobile-nav button { background: white; color: var(--muted); }
.mobile-nav button.active { background: var(--ink); color: white; }
.mobile-nav-logout {
  display: none;
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
  overflow: hidden;
}
.accountant-shell {
  display: block;
}
.accountant-content {
  max-width: 1180px;
  margin: 0 auto;
}
.accountant-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.accountant-topbar h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1.04;
}
.accountant-topbar p {
  margin: 7px 0 0;
}
.settings-tabs {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 7px;
  margin-bottom: 22px;
}
.settings-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.color-field {
  display: grid;
  grid-template-columns: 1fr 52px;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  font-size: 13px;
}
.color-field input {
  width: 46px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
}
.header h1 { margin: 0; font-size: clamp(28px, 4vw, 34px); line-height: 1.05; font-weight: 650; }
.page-company {
  display: inline-flex;
  align-items: center;
  max-width: min(360px, 100%);
  margin-left: 10px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  vertical-align: .16em;
  color: var(--muted);
  background: white;
  font-size: .38em;
  font-weight: 650;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header p { margin: 9px 0 0; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 12px; min-width: min(540px, 100%); justify-content: flex-end; }
.search-box { position: relative; width: min(320px, 100%); }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: #a3a3a3; pointer-events: none; }
.search-box input { padding-left: 42px; background: white; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.services-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr);
  gap: 20px;
}
.service-rules-note {
  margin: -6px 0 16px;
  color: var(--muted);
  font-size: 13px;
}
.clients-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
  gap: 20px;
  align-items: start;
  min-width: 0;
}
.documents-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
  gap: 20px;
  align-items: start;
  min-width: 0;
}
.expenses-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
  gap: 20px;
  align-items: start;
  min-width: 0;
}
.client-side,
.document-side,
.expense-side {
  display: grid;
  gap: 20px;
}
.client-list-card,
.document-list-card,
.expense-list-card {
  padding: 14px;
  min-width: 0;
  max-width: 100%;
}
.client-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 4px 12px;
  border-bottom: 1px solid var(--line);
}
.client-list-head h2 {
  margin: 0 0 2px;
}
.client-list-head p {
  margin: 0;
}
.client-list {
  display: grid;
}
.expense-list {
  display: grid;
}
.service-list {
  display: grid;
}
.client-row,
.document-row,
.expense-row,
.service-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) minmax(120px, .8fr) auto auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  max-width: 100%;
}
.document-row {
  grid-template-columns: minmax(0, 1fr) minmax(110px, max-content) auto;
  border-radius: 14px;
  padding-left: 10px;
  padding-right: 10px;
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.document-row.is-selected {
  background: #f5f5f5;
  box-shadow: inset 3px 0 0 var(--ink);
}
.document-row.status-paid {
  background: #f0fdf4;
  border-bottom-color: #bbf7d0;
}
.document-row.status-paid .document-main strong,
.document-row.status-paid .document-amount {
  color: #047857;
}
.document-row.status-partial {
  background: #fffbeb;
  border-bottom-color: #fde68a;
}
.document-row.status-partial .document-main strong,
.document-row.status-partial .document-amount {
  color: #b45309;
}
.document-row.status-overdue {
  background: #fef2f2;
  border-bottom-color: #fecaca;
}
.document-row.status-overdue .document-main strong,
.document-row.status-overdue .document-amount {
  color: #b91c1c;
}
.document-row.status-sent {
  background: #fffdf4;
}
.expense-row {
  grid-template-columns: minmax(190px, 1.4fr) minmax(90px, .45fr) minmax(96px, .45fr) auto auto;
}
.service-row {
  grid-template-columns: minmax(190px, 1.5fr) minmax(96px, .45fr) auto auto;
}
.client-row:last-child,
.document-row:last-child,
.expense-row:last-child,
.service-row:last-child {
  border-bottom: 0;
}
.client-main,
.document-main,
.expense-main,
.service-main {
  min-width: 0;
}
.client-main strong,
.document-main strong,
.expense-main strong,
.service-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  line-height: 1.2;
}
.client-main span,
.client-tax,
.document-main span,
.expense-main span,
.service-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}
.document-amount {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  text-align: right;
  white-space: nowrap;
}
.expense-amount {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  text-align: right;
  white-space: nowrap;
}
.service-price {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  text-align: right;
  white-space: nowrap;
}
.expense-bar {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #eeeeee;
}
.expense-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--ink);
}
.client-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.document-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-wrap: wrap;
  grid-column: 1 / -1;
}
.expense-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
.service-list-card {
  padding: 14px;
}
.client-action {
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
}
.client-edit {
  width: 32px;
  min-height: 32px;
  border-radius: 10px;
}
.doc-icon {
  width: 30px;
  min-height: 30px;
  border-radius: 10px;
}
.compact-metrics {
  display: grid;
  gap: 10px;
}
.compact-metrics div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.compact-metrics div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.compact-metrics span {
  color: var(--muted);
  font-size: 12px;
}
.compact-metrics strong {
  font-size: 13px;
  text-align: right;
}
.settings-panel .card {
  padding: 14px;
  border-radius: 18px;
}
.settings-panel .card h2 {
  margin-bottom: 10px;
  font-size: 15px;
}
.settings-panel input,
.settings-panel select,
.settings-panel textarea {
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
}
.settings-panel textarea {
  min-height: 88px;
}
.settings-panel .stack {
  gap: 8px;
}
.setting-field {
  display: grid;
  gap: 6px;
}
.setting-field span,
.color-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.card form,
.modal form {
  min-width: 0;
}
.card form.stack,
.modal form.stack {
  gap: 12px;
}
.card form label,
.modal form label {
  min-width: 0;
}
.card form input,
.card form select,
.card form textarea,
.modal form input,
.modal form select,
.modal form textarea {
  min-height: 48px;
  border-radius: 16px;
  background: #f7f7f7;
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.card form textarea,
.modal form textarea {
  line-height: 1.35;
}
.expense-preview {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafafa;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.declaration-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
}
.declaration-head .setting-field {
  width: min(260px, 100%);
}
.fiscal-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(4, max-content);
  align-items: end;
  gap: 10px;
}
.tax-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.tax-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 12px;
}
.tax-table th,
.tax-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.tax-table th {
  color: var(--muted);
  font-weight: 700;
}
.tax-table td:nth-child(n+4),
.tax-table th:nth-child(n+4) {
  text-align: right;
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.settings-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.import-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.import-layout-wide {
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr);
}
.export-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.backup-row:last-child {
  border-bottom: 0;
}
.backup-row div {
  min-width: 0;
}
.backup-row strong,
.backup-row span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.backup-row strong {
  font-size: 13px;
}
.backup-row span {
  color: var(--muted);
  font-size: 11px;
}
.compact-drop {
  padding: 18px;
  border-radius: 16px;
}
.quick-service-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--soft);
}
.quick-service-form button {
  grid-column: 1 / -1;
}
.quick-service-form input {
  min-height: 38px;
  border-radius: 12px;
  padding: 9px 11px;
  font-size: 13px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  max-width: 100%;
}
.card.dark { background: #0a0a0a; color: white; border-color: #0a0a0a; }
.card h2 { margin: 0 0 16px; font-size: 17px; font-weight: 650; }
.card p { color: var(--muted); }
.dark p, .dark .muted { color: rgba(255,255,255,.56); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.spaced { margin-top: 20px; }
.stack { display: grid; gap: 12px; }
.inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.right { text-align: right; }

.account-layout {
  display: grid;
  gap: 20px;
  max-width: 780px;
}
.profile-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}
.profile-actions .btn {
  width: 100%;
}
.session-note {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.session-note strong {
  display: block;
  margin-bottom: 6px;
}
.session-note p {
  margin: 0;
}
.expense-tax-box {
  display: grid;
  gap: 8px;
}
.expense-tax-box > span {
  font-weight: 650;
  color: var(--muted);
}
.expense-tax-lines {
  display: grid;
  gap: 8px;
}
.expense-tax-line {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(82px, .55fr);
  gap: 8px;
  align-items: center;
}
.expense-tax-line strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  border-radius: 14px;
  background: var(--soft);
  color: var(--muted);
}
.expense-tax-line input {
  min-height: 42px;
  border-radius: 14px;
  padding: 9px 11px;
  font-size: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 12px 15px;
  min-height: 44px;
  border-radius: 16px;
  background: #f5f5f5;
  color: var(--ink);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.btn.primary { background: var(--ink); color: white; border-color: var(--ink); }
.btn.white { background: white; color: black; border-color: white; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.icon-btn { width: 42px; padding: 0; }

.filters { display: flex; width: 100%; max-width: 100%; min-width: 0; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; padding-bottom: 7px; margin-bottom: 22px; }
.filter {
  flex: 0 0 auto;
  padding: 11px 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
}
.filter.active { background: var(--ink); color: white; border-color: var(--ink); }
.year-filter {
  display: flex;
  justify-content: flex-start;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: -8px 0 18px;
}
.year-select-field {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 8px 6px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .03);
}
.year-select-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}
.year-select-field select {
  min-width: 180px;
  min-height: 36px;
  padding: 7px 34px 7px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  outline: none;
}
.dashboard-month-picker {
  width: min(260px, 100%);
  margin: -10px 0 22px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
}
.month-picker {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 8px;
  width: 100%;
}
.month-picker button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fafafa;
  color: var(--ink);
}
.month-step,
.month-year-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.month-current {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 0;
  padding: 0 12px;
  font-weight: 720;
}
.month-current span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.month-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 12;
  width: min(330px, calc(100vw - 40px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: white;
  box-shadow: 0 18px 50px rgba(0,0,0,.16);
}
.month-yearbar {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.month-yearbar strong {
  text-align: center;
  font-size: 16px;
}
.month-yearbar .month-year-btn {
  min-height: 38px;
  border-radius: 14px;
}
.month-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.month-grid button {
  min-height: 42px;
  padding: 0 8px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  text-transform: capitalize;
}
.month-grid button.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 17px;
  background: var(--ink);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.stat-value { margin: 4px 0 0; font-size: 26px; line-height: 1.1; font-weight: 650; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--soft);
  min-width: 0;
  max-width: 100%;
}
.dark .row {
  background: white;
  color: var(--ink);
}
.dark .row .muted {
  color: var(--muted);
}
.row + .row { margin-top: 10px; }
.document-amount small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.doc-pay {
  min-height: 32px;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
}
.doc-pay.active {
  background: var(--ink);
  border-color: var(--ink);
  color: white;
}
.doc-pay.settled {
  background: #ecfdf5;
  border-color: #bbf7d0;
  color: #047857;
}
.invoice-payment-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, .8fr) minmax(260px, .8fr);
  gap: 20px;
  align-items: start;
}
.payment-document-picker {
  margin-top: 14px;
}
.payment-document-picker label {
  display: grid;
  gap: 6px;
}
.payment-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.payment-summary-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--soft);
}
.payment-summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}
.payment-summary-grid strong {
  font-size: 15px;
}
.danger-text { color: var(--danger); }
.ok-text { color: #047857; }
.payment-progress {
  height: 8px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--soft);
}
.payment-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--ink);
}
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  background: white;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.dark { background: var(--ink); border-color: var(--ink); color: white; }
.badge.green { background: #ecfdf5; color: #047857; border-color: #bbf7d0; }
.badge.red { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badge.amber { background: #fffbeb; color: #b45309; border-color: #fde68a; }

.bars { width: 100%; max-width: 100%; min-width: 0; height: 224px; display: flex; align-items: end; gap: 13px; border-bottom: 1px solid var(--line); padding-top: 24px; overflow: hidden; }
.bar-wrap { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 8px; }
.bar-pair { width: 100%; height: 176px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.bar { width: min(18px, 45%); min-height: 5px; border-radius: 14px 14px 0 0; background: var(--ink); }
.bar.expense { background: #a3a3a3; }
.progress { height: 12px; background: #f0f0f0; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ink); border-radius: inherit; }
.dark .progress { background: rgba(255,255,255,.12); }
.dark .progress > span { background: white; }

.document-form-shell {
  display: grid;
  gap: 14px;
}
.document-form {
  display: grid;
  gap: 14px;
}
.doc-form-section {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(180deg, #fff, #fcfcfc);
  padding: 18px;
  box-shadow: 0 12px 28px rgba(17, 24, 39, .04), inset 0 1px 0 rgba(255,255,255,.9);
  scroll-margin-top: 112px;
}
.doc-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.doc-section-head h3 {
  margin: 4px 0 0;
  font-size: 16px;
  line-height: 1.2;
  font-weight: 720;
}
.doc-section-head span {
  color: var(--muted);
  font-size: 12px;
}
.doc-step-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: #f4f4f5;
  font-size: 11px;
  font-weight: 760;
  line-height: 1;
}
.doc-meta-grid,
.doc-status-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
}
.doc-status-grid {
  grid-template-columns: repeat(12, minmax(0, 1fr));
}
.doc-meta-grid label,
.doc-status-grid label {
  display: grid;
  gap: 7px;
  min-width: 0;
}
.doc-meta-grid label span,
.doc-status-grid label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}
.doc-meta-grid label {
  grid-column: span 3;
}
.doc-meta-grid label.wide {
  grid-column: span 4;
}
.doc-meta-grid label:nth-child(4),
.doc-meta-grid label:nth-child(5) {
  grid-column: span 2;
}
.doc-status-grid label {
  grid-column: span 2;
}
.doc-status-grid label:nth-child(3),
.doc-status-grid label:nth-child(4) {
  grid-column: span 2;
}
.doc-meta-grid .wide,
.doc-status-grid .wide {
  grid-column: span 4;
}
.doc-status-grid .wide {
  grid-column: span 4;
}
.doc-form-section input,
.doc-form-section select,
.doc-form-section textarea {
  min-height: 48px;
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 14px;
  background: #f7f7f7;
}
.doc-form-section textarea {
  min-height: 96px;
}
.line-number {
  display: none;
}
.line-table {
  overflow-x: visible;
}
.line-head,
.line-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.15fr) minmax(220px, 1.5fr) 74px 112px 44px;
  gap: 10px;
  align-items: center;
  min-width: 0;
}
.line-head {
  padding: 0 4px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}
.line-list {
  display: grid;
  gap: 8px;
}
.line-grid {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: white;
  box-shadow: 0 8px 20px rgba(17, 24, 39, .035);
}
.line-grid:last-child {
  border-bottom: 1px solid var(--line);
}
.line-grid input,
.line-grid select {
  min-height: 42px;
  padding: 9px 11px;
  border-radius: 14px;
  font-size: 13px;
}
.line-remove {
  min-width: 0;
  min-height: 42px;
  padding: 0;
  border-radius: 14px;
}
@media (min-width: 921px) {
  .line-remove span { display: none; }
  .line-remove { width: 42px; justify-self: end; }
}
.doc-footer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 16px;
  align-items: stretch;
}
.modal-payment-card {
  margin-top: 12px;
}
.modal-payment-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}
.modal-payment-form .btn {
  min-height: 40px;
}
.total-box {
  border-radius: 26px;
  background: var(--ink);
  color: white;
  padding: 20px;
  box-shadow: 0 18px 42px rgba(10,10,10,.18), inset 0 1px 0 rgba(255,255,255,.08);
  scroll-margin-top: 112px;
}
.total-box .between { padding: 5px 0; }
.total-box .grand { font-size: 20px; font-weight: 760; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.14); margin-top: 6px; }
.compact-total {
  align-self: stretch;
  display: grid;
  align-content: center;
  position: sticky;
  top: 86px;
}
.document-submit-bar {
  position: sticky;
  bottom: -18px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 0 0;
  background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,.96) 34%, white);
}
.document-submit-bar .btn {
  min-height: 46px;
}
.inline.tight {
  gap: 6px;
}
.btn.slim {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 12px;
  font-size: 13px;
}
.drop-zone {
  border: 2px dashed #d4d4d4;
  border-radius: 24px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: #fafafa;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.42);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
  backdrop-filter: blur(10px);
}
.modal {
  width: min(760px, 100%);
  max-height: min(820px, 92vh);
  overflow: auto;
  background: white;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 32px;
  padding: 24px;
  box-shadow: 0 28px 90px rgba(0,0,0,.24);
}
.document-modal {
  width: min(1120px, 100%);
  padding: 16px;
  border-radius: 32px;
}
.modal-titlebar {
  position: sticky;
  top: -18px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -18px -18px 16px;
  padding: 18px 18px 14px;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(20px);
}
.modal-titlebar h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}
.modal-titlebar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.modal-titlebar .icon-btn {
  width: 44px;
  min-height: 44px;
  border-radius: 999px;
}
.document-titlebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 14px;
  top: -16px;
  margin: -16px -16px 16px;
  padding: 16px;
}
.document-title-main {
  min-width: 0;
}
.document-type-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--ink);
  background: #f3f4f6;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
}
.doc-step-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #f7f7f7;
}
.doc-step-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 13px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.doc-step-nav a:hover {
  color: var(--ink);
  background: white;
}
.document-save-btn {
  color: white;
  background: #34a853;
  border-color: #34a853;
  box-shadow: 0 12px 28px rgba(52, 168, 83, .22);
}
.document-save-btn:hover {
  background: #2f9a4c;
}
.modal > .between.keep:first-child {
  position: sticky;
  top: -24px;
  z-index: 4;
  margin: -24px -24px 18px;
  padding: 18px 24px 14px;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(20px);
}
.modal > .between.keep:first-child h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}
.modal > .between.keep:first-child .icon-btn {
  width: 44px;
  min-height: 44px;
  border-radius: 999px;
}
.quick-create-modal {
  width: min(560px, 100%);
  padding: 0;
  overflow: hidden;
}
.quick-create-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
}
.quick-create-head h2 {
  margin: 6px 0 4px;
  font-size: clamp(27px, 4vw, 36px);
  line-height: 1;
  letter-spacing: 0;
}
.quick-create-head p {
  margin: 0;
  color: var(--muted);
}
.quick-create-head .icon-btn {
  width: 46px;
  min-width: 46px;
  height: 46px;
  border-radius: 16px;
}
.quick-create-kicker {
  display: inline-flex;
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: white;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quick-create-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}
.quick-create-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 94px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  text-align: left;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 10px 26px rgba(17, 24, 39, .05);
}
.quick-create-card:hover {
  border-color: #d4d4d4;
  box-shadow: 0 16px 34px rgba(17, 24, 39, .08);
}
.quick-create-card.primary {
  grid-column: 1 / -1;
  min-height: 112px;
  color: white;
  background: var(--ink);
  border-color: var(--ink);
}
.quick-create-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  border-radius: 18px;
  color: var(--ink);
  background: #f5f5f5;
}
.quick-create-card.primary .quick-create-icon {
  color: var(--ink);
  background: white;
}
.quick-create-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}
.quick-create-copy strong {
  font-size: 16px;
  line-height: 1.08;
}
.quick-create-copy small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}
.quick-create-card.primary .quick-create-copy small {
  color: rgba(255, 255, 255, .7);
}
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #0a0a0a;
  color: white;
  padding: 13px 16px;
  border-radius: 16px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 44px));
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(248,113,113,.14), transparent 42%),
    #f5f5f5;
}
.login-card { width: min(440px, 100%); }
.login-card .brand { color: #0a0a0a; padding: 0; margin-bottom: 6px; }
.app-version {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8f8f8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 20px;
}
.app-loader {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #ececec;
  margin-top: 18px;
}
.app-loader span {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: inherit;
  background: var(--ink);
  animation: appLoading 1.1s ease-in-out infinite;
}
@keyframes appLoading {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(280%); }
}
.login-card .pwa-actions {
  margin-bottom: 0;
}
.login-card .pwa-status {
  color: var(--muted);
  background: #f5f5f5;
  border: 1px solid var(--line);
}
.login-card .pwa-status.online { color: #047857; background: #ecfdf5; border-color: #bbf7d0; }
.login-card .pwa-status.offline { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.offline-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f5f5f5;
}
.offline-panel {
  width: min(460px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.offline-panel .brand { color: #0a0a0a; padding: 0; margin-bottom: 24px; }
.offline-panel h1 { margin: 0 0 10px; }
.offline-panel p { color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); background: var(--soft); border-radius: 18px; border: 1px solid var(--line); }

@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .invoice-payment-workspace { grid-template-columns: 1fr 1fr; }
  .invoice-payment-workspace > .card:first-child { grid-column: 1 / -1; }
}

@media (max-width: 920px) {
  .sidebar { display: none; }
  .mobile-nav-row {
    display: flex;
    align-items: center;
    min-height: 60px;
    padding: 6px;
    border: 1px solid rgba(229, 231, 235, .9);
    border-radius: 24px;
    background: rgba(255, 255, 255, .72);
    box-shadow: 0 14px 34px rgba(17, 24, 39, .08);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }
  .mobile-nav {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 0;
  }
  .mobile-pwa-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
  }
  .mobile-pwa-actions .pwa-status {
    color: var(--muted);
    background: white;
    border: 1px solid var(--line);
  }
  .mobile-pwa-actions .pwa-status.online { color: #047857; background: #ecfdf5; border-color: #bbf7d0; }
  .mobile-pwa-actions .pwa-status.offline { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
  .mobile-pwa-actions .pwa-status.installed { color: var(--ink); }
  .mobile-pwa-actions .btn.white { border-color: var(--line); }
  .mobile-nav button,
  .mobile-nav-logout {
    display: flex;
    align-items: center;
    width: 48px;
    min-width: 48px;
    height: 48px;
    justify-content: center;
    padding: 0;
    border-radius: 16px;
  }
  .mobile-nav-logout {
    flex: 0 0 48px;
    box-shadow: 0 10px 22px rgba(185, 28, 28, .14);
  }
  .mobile-nav .nav-label,
  .mobile-nav-logout .nav-label { display: none; }
  .settings-tabs button {
    width: 48px;
    min-width: 48px;
    height: 48px;
    justify-content: center;
    padding: 0;
    border-radius: 16px;
  }
  .settings-tabs button span { display: none; }
  .content {
    padding: max(26px, calc(env(safe-area-inset-top, 0px) + 14px)) 18px 18px;
  }
  .header { flex-direction: column; }
  .header-actions { width: 100%; justify-content: stretch; }
  .search-box { width: 100%; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .services-layout { grid-template-columns: 1fr; }
  .services-layout > .card:first-child { order: 2; }
  .services-layout > .card:nth-child(2) { order: 1; }
  .clients-layout,
  .documents-layout,
  .expenses-layout,
  .settings-grid,
  .settings-grid-2,
  .import-layout,
  .import-layout-wide { grid-template-columns: 1fr; }
  .quick-service-form { grid-template-columns: 1fr 1fr; }
  .doc-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .doc-meta-grid .wide { grid-column: span 2; }
  .doc-status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .doc-status-grid .wide { grid-column: span 2; }
  .doc-footer-grid { grid-template-columns: 1fr; }
  .modal-payment-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal-payment-form .btn { grid-column: 1 / -1; }
  .invoice-payment-workspace { grid-template-columns: 1fr; }
  .invoice-payment-workspace > .card:first-child { grid-column: auto; }
  .payment-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fiscal-actions { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 620px) {
  .app-shell,
  .content,
  main,
  section,
  .grid,
  .stack,
  .card,
  .row,
  .between,
  .inline,
  .settings-panel {
    min-width: 0;
    max-width: 100%;
  }
  .content {
    padding-top: max(64px, calc(env(safe-area-inset-top, 0px) + 18px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
    padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
    padding-left: max(14px, env(safe-area-inset-left, 0px));
  }
  .mobile-nav-row { margin-bottom: 20px; }
  .mobile-nav,
  .filters,
  .settings-tabs,
  .year-filter {
    scrollbar-width: none;
  }
  .mobile-nav::-webkit-scrollbar,
  .filters::-webkit-scrollbar,
  .settings-tabs::-webkit-scrollbar,
  .year-filter::-webkit-scrollbar {
    display: none;
  }
  .header h1 {
    font-size: clamp(32px, 10vw, 44px);
    line-height: 1.03;
    overflow-wrap: anywhere;
  }
  .page-company {
    max-width: 100%;
    margin: 8px 0 0;
    padding: 7px 10px;
    font-size: 14px;
    vertical-align: baseline;
  }
  .header p {
    font-size: 18px;
    line-height: 1.28;
  }
  .filters {
    flex-wrap: wrap;
    overflow-x: visible;
    margin-right: 0;
    padding-right: 0;
  }
  .filter {
    flex: 1 1 auto;
    text-align: center;
    padding: 10px 14px;
  }
  .card {
    padding: 16px;
    border-radius: 22px;
    overflow: hidden;
  }
  .card h2 {
    font-size: clamp(25px, 7.4vw, 34px);
    line-height: 1.08;
    overflow-wrap: anywhere;
  }
  .stat-value {
    font-size: clamp(31px, 9vw, 40px);
    overflow-wrap: anywhere;
  }
  .card p,
  .row p,
  .row strong,
  .row span,
  .badge,
  .empty {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  .client-list-card,
  .document-list-card,
  .expense-list-card,
  .service-list-card { padding: 10px; }
  .client-row,
  .document-row,
  .expense-row,
  .service-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 48px;
    padding: 7px 2px;
  }
  .document-row {
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
  }
  .client-tax,
  .document-amount,
  .expense-bar,
  .expense-amount,
  .service-price {
    display: none;
  }
  .client-row .badge,
  .document-row .badge,
  .expense-row .badge,
  .service-row .badge {
    display: none;
  }
  .client-main strong,
  .document-main strong,
  .expense-main strong,
  .service-main strong {
    font-size: 13px;
  }
  .client-main span,
  .document-main span,
  .expense-main span,
  .service-main span {
    font-size: 11px;
  }
  .client-actions,
  .document-actions,
  .expense-actions {
    gap: 4px;
  }
  .document-actions {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .document-actions::-webkit-scrollbar {
    display: none;
  }
  .document-actions .btn {
    flex: 0 0 auto;
  }
  .client-action {
    min-height: 28px;
    padding: 5px 8px;
    font-size: 11px;
  }
  .client-edit {
    width: 30px;
    min-height: 30px;
  }
  .doc-icon {
    width: 28px;
    min-height: 28px;
  }
  .doc-pay {
    min-height: 28px;
    padding: 5px 8px;
    font-size: 11px;
  }
  .payment-summary-grid { grid-template-columns: 1fr; }
  .dashboard-month-picker,
  .declaration-head .setting-field,
  .declaration-head .month-picker {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .declaration-head,
  .fiscal-actions {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .declaration-head {
    display: grid;
  }
  .declaration-head .setting-field {
    width: 100%;
  }
  .fiscal-actions .btn {
    width: 100%;
    white-space: normal;
    text-align: center;
  }
  .tax-table-wrap {
    max-width: 100%;
    border-radius: 14px;
    scrollbar-width: none;
  }
  .tax-table-wrap::-webkit-scrollbar {
    display: none;
  }
  .tax-table {
    min-width: 560px;
    font-size: 11px;
  }
  .tax-table th,
  .tax-table td {
    padding: 8px 9px;
  }
  .tax-table td:nth-child(3),
  .tax-table th:nth-child(3) {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .empty {
    padding: 18px;
    white-space: normal;
  }
  .bars {
    height: 210px;
    gap: 6px;
    padding-top: 18px;
  }
  .bar-pair {
    min-width: 0;
    gap: 2px;
  }
  .bar {
    width: min(9px, 44%);
  }
  .bar-wrap span {
    font-size: 11px;
    line-height: 1;
  }
  .document-modal {
    width: 100%;
    max-height: calc(100dvh - 16px);
    padding: 12px;
    border-radius: 26px 26px 0 0;
  }
  .modal-backdrop {
    align-items: end;
    place-items: end center;
    padding: 8px 8px 0;
  }
  .modal {
    width: 100%;
    max-height: calc(100dvh - 16px);
    border-radius: 26px 26px 0 0;
    padding: 16px;
  }
  .quick-create-modal {
    padding: 0;
    border-radius: 28px 28px 0 0;
  }
  .quick-create-head {
    padding: 18px 18px 14px;
    gap: 12px;
  }
  .quick-create-head h2 {
    font-size: clamp(28px, 8vw, 34px);
  }
  .quick-create-head p {
    font-size: 14px;
    line-height: 1.25;
  }
  .quick-create-head .icon-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }
  .quick-create-kicker {
    max-width: 230px;
  }
  .quick-create-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px;
  }
  .quick-create-card,
  .quick-create-card.primary {
    min-height: 82px;
    padding: 13px;
    border-radius: 20px;
  }
  .quick-create-icon {
    flex-basis: 48px;
    width: 48px;
    height: 48px;
    border-radius: 16px;
  }
  .quick-create-copy strong {
    font-size: 16px;
  }
  .quick-create-copy small {
    font-size: 12px;
  }
  .modal-titlebar {
    top: -14px;
    margin: -14px -14px 14px;
    padding: 15px 14px 12px;
  }
  .document-titlebar {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 12px;
    top: -12px;
    margin: -12px -12px 12px;
    padding: 14px 12px 12px;
  }
  .document-title-main {
    grid-column: 1;
  }
  .document-titlebar .icon-btn {
    grid-column: 2;
    grid-row: 1;
    width: 44px;
    min-width: 44px;
    height: 44px;
    border-radius: 16px;
  }
  .doc-step-nav {
    grid-column: 1 / -1;
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
  }
  .doc-step-nav::-webkit-scrollbar {
    display: none;
  }
  .doc-step-nav a {
    flex: 1 0 auto;
    min-height: 38px;
    padding: 9px 12px;
  }
  .modal > .between.keep:first-child {
    top: -16px;
    margin: -16px -16px 16px;
    padding: 15px 16px 12px;
  }
  .modal-titlebar h2,
  .modal > .between.keep:first-child h2 {
    font-size: 22px;
  }
  .doc-meta-grid,
  .doc-status-grid,
  .quick-service-form,
  .modal-payment-form {
    grid-template-columns: 1fr;
  }
  .quick-service-form,
  .modal-payment-form {
    grid-template-columns: 1fr;
  }
  .doc-meta-grid > label,
  .doc-status-grid > label,
  .doc-meta-grid > label.wide,
  .doc-status-grid > label.wide,
  .doc-meta-grid > label:nth-child(4),
  .doc-meta-grid > label:nth-child(5) {
    grid-column: 1 / -1;
  }
  .doc-meta-grid > label:nth-child(1),
  .doc-meta-grid > label:nth-child(2),
  .doc-meta-grid > label:nth-child(3),
  .doc-status-grid > label.wide {
    grid-column: 1 / -1;
  }
  .doc-form-section {
    padding: 14px;
    border-radius: 22px;
    scroll-margin-top: 154px;
  }
  .doc-section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
  .doc-section-head .inline.tight {
    width: 100%;
  }
  .doc-section-head .inline.tight .btn {
    flex: 1 1 0;
  }
  .doc-footer-grid {
    gap: 12px;
  }
  .compact-total {
    position: static;
  }
  .total-box {
    border-radius: 22px;
    padding: 16px;
    scroll-margin-top: 154px;
  }
  .line-table { overflow: visible; }
  .line-head { display: none; }
  .line-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px;
    min-width: 0;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: white;
  }
  .line-number {
    display: inline-flex;
    grid-column: 1 / 3;
    align-items: center;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
  }
  .line-grid select,
  .line-grid input[data-line-field="description"] {
    grid-column: 1 / -1;
  }
  .line-grid input[data-line-field="quantity"] {
    grid-column: 1;
  }
  .line-grid input[data-line-field="unit_price"] {
    grid-column: 2;
  }
  .line-grid .line-remove {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }
  .line-grid input,
  .line-grid select {
    font-size: 16px;
    background: #f7f7f7;
  }
  input,
  select,
  textarea,
  .doc-form-section input,
  .doc-form-section select,
  .doc-form-section textarea,
  .quick-service-form input {
    font-size: 16px;
  }
  .line-remove span,
  .mobile-icon-label span {
    display: none;
  }
  .line-remove,
  .mobile-icon-label {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 14px;
  }
  .document-submit-bar {
    bottom: -14px;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }
  .document-submit-bar .btn.primary {
    flex: 1 1 100%;
  }
  .document-submit-bar .mobile-icon-label {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
  }
  .document-submit-bar .mobile-icon-label span {
    display: inline;
  }
  .modal-backdrop:has(.document-modal) {
    padding: 0;
    background: rgba(0,0,0,.26);
  }
  .document-modal {
    max-height: 100dvh;
    min-height: 100dvh;
    border-radius: 30px 30px 0 0;
    padding: 0 14px max(18px, env(safe-area-inset-bottom, 0px));
    background: #f2f2f7;
    border: 0;
  }
  .document-titlebar {
    grid-template-columns: 66px minmax(0, 1fr) 66px;
    position: sticky;
    top: 0;
    z-index: 8;
    min-height: 118px;
    margin: 0 -14px 22px;
    padding: max(22px, calc(env(safe-area-inset-top, 0px) + 14px)) 24px 18px;
    border-bottom: 0;
    background: rgba(242,242,247,.86);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
  }
  .document-title-main {
    grid-column: 2;
    text-align: center;
  }
  .document-title-main h2 {
    font-size: 24px;
    font-weight: 760;
    line-height: 1.05;
  }
  .document-title-main p,
  .document-type-pill,
  .doc-step-nav {
    display: none;
  }
  .document-titlebar .document-close-btn,
  .document-titlebar .document-save-btn {
    grid-row: 1;
    width: 58px;
    min-width: 58px;
    height: 58px;
    border-radius: 999px;
    box-shadow: 0 12px 28px rgba(17, 24, 39, .1);
  }
  .document-titlebar .document-close-btn {
    grid-column: 1;
    color: #0a0a0a;
    background: white;
    border-color: rgba(255,255,255,.78);
  }
  .document-titlebar .document-save-btn {
    grid-column: 3;
    color: white;
    background: #34a853;
    border-color: #34a853;
    box-shadow: 0 16px 34px rgba(52,168,83,.26);
  }
  .document-form,
  .document-form-shell {
    gap: 22px;
  }
  .doc-form-section {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  .doc-section-head {
    margin: 0 18px 10px;
  }
  .doc-step-kicker {
    display: none;
  }
  .doc-section-head h3 {
    margin: 0;
    color: #8e8e93;
    font-size: 22px;
    font-weight: 760;
    line-height: 1.1;
  }
  .doc-section-head > span {
    display: none;
  }
  .doc-meta-grid,
  .doc-status-grid {
    gap: 0;
    overflow: hidden;
    border-radius: 24px;
    background: white;
  }
  .doc-meta-grid label,
  .doc-status-grid label {
    grid-template-columns: minmax(104px, auto) minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    min-height: 72px;
    padding: 0 24px;
    border-bottom: 1px solid #e5e5ea;
  }
  .doc-meta-grid label:last-child,
  .doc-status-grid label:last-child {
    border-bottom: 0;
  }
  .doc-meta-grid label span,
  .doc-status-grid label span {
    color: #0a0a0a;
    font-size: 22px;
    font-weight: 520;
  }
  .doc-form-section input,
  .doc-form-section select,
  .doc-form-section textarea {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 58px;
    padding: 0;
    border: 0;
    border-radius: 0;
    text-align: right;
    color: #8e8e93;
    background: transparent;
    box-shadow: none;
  }
  .doc-form-section input,
  .doc-form-section textarea {
    -webkit-appearance: none;
    appearance: none;
  }
  .doc-form-section textarea {
    min-height: 150px;
    padding: 18px 0;
    text-align: left;
    line-height: 1.32;
  }
  .doc-section-head .inline.tight {
    display: grid;
    gap: 0;
    overflow: hidden;
    border-radius: 24px;
    background: white;
  }
  .doc-section-head .inline.tight .btn {
    justify-content: flex-start;
    min-height: 64px;
    padding: 0 24px;
    border: 0;
    border-bottom: 1px solid #e5e5ea;
    border-radius: 0;
    color: #34a853;
    background: white;
    font-size: 22px;
    font-weight: 520;
  }
  .doc-section-head .inline.tight .btn:last-child {
    border-bottom: 0;
  }
  .line-list {
    overflow: hidden;
    border-radius: 24px;
    background: white;
  }
  .line-grid {
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 10px 12px;
    padding: 18px 18px 16px;
    border: 0;
    border-bottom: 1px solid #e5e5ea;
    border-radius: 0;
    box-shadow: none;
  }
  .line-grid:last-child {
    border-bottom: 0;
  }
  .line-number {
    grid-column: 1;
    color: #8e8e93;
    font-size: 13px;
    line-height: 1;
  }
  .line-grid select,
  .line-grid input[data-line-field="description"],
  .line-grid input[data-line-field="quantity"],
  .line-grid input[data-line-field="unit_price"] {
    box-sizing: border-box;
    grid-column: 1 / -1;
    width: 100%;
    max-width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border-radius: 16px;
    text-align: left;
    background: #f7f7f8;
    overflow: hidden;
  }
  .line-grid select {
    color: #0a0a0a;
    font-weight: 700;
    background: white;
    padding-left: 0;
  }
  .line-grid .line-remove {
    grid-column: 2;
    grid-row: 1;
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 16px;
  }
  .line-highlight {
    animation: linePulse 1.4s ease;
  }
  @keyframes linePulse {
    0% { background: #ecfdf3; }
    100% { background: white; }
  }
  .total-box {
    border-radius: 24px;
    padding: 20px 24px;
  }
  .document-submit-bar {
    position: static;
    padding: 0 0 max(12px, env(safe-area-inset-bottom, 0px));
    background: transparent;
  }
  .document-submit-bar .btn.primary {
    display: none;
  }
  .header-actions { flex-wrap: wrap; }
  .header-actions .btn.primary { width: 100%; }
  .row { align-items: flex-start; flex-direction: column; }
  .row > * {
    min-width: 0;
    max-width: 100%;
  }
  .row .inline,
  .row .inline.right {
    width: 100%;
    justify-content: flex-start;
    overflow: hidden;
  }
  .row .inline .btn,
  .row .inline.right .btn {
    flex: 0 0 auto;
  }
  .between { align-items: flex-start; flex-direction: column; }
  .between.keep { align-items: center; flex-direction: row; }
  .right { text-align: left; }
}

@media (max-width: 620px) {
  .modal-backdrop:has(.document-modal) {
    align-items: end;
    place-items: end center;
    padding: 0;
    background: rgba(0,0,0,.24);
  }

  .document-modal {
    width: 100%;
    max-height: 100dvh;
    min-height: 100dvh;
    overflow: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: 26px 26px 0 0;
    padding: 0 16px max(18px, env(safe-area-inset-bottom, 0px));
    background: #f3f3f6;
    box-shadow: none;
  }

  .document-titlebar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) 46px;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 11px 12px;
    min-height: auto;
    margin: 0 -16px 18px;
    padding: max(12px, calc(env(safe-area-inset-top, 0px) + 8px)) 16px 12px;
    border-bottom: 0;
    background: rgba(243,243,246,.92);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
  }

  .document-title-main {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    text-align: center;
  }

  .document-title-main h2 {
    margin: 0;
    font-size: 21px;
    font-weight: 760;
    line-height: 1.12;
    letter-spacing: 0;
  }

  .document-title-main p,
  .document-type-pill {
    display: none;
  }

  .document-titlebar .document-close-btn,
  .document-titlebar .document-save-btn {
    grid-row: 1;
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 0;
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(17, 24, 39, .09);
  }

  .document-titlebar .document-close-btn {
    grid-column: 1;
    color: #111;
    background: rgba(255,255,255,.95);
    border-color: rgba(255,255,255,.9);
  }

  .document-titlebar .document-save-btn {
    grid-column: 3;
    color: white;
    background: #34a853;
    border-color: #34a853;
    box-shadow: 0 12px 26px rgba(52,168,83,.24);
  }

  .doc-step-nav {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    width: 100%;
    overflow: visible;
    padding: 4px;
    border: 0;
    border-radius: 15px;
    background: #e5e5ea;
  }

  .doc-step-nav a {
    min-width: 0;
    min-height: 34px;
    padding: 8px 6px;
    border-radius: 12px;
    color: #6e6e73;
    font-size: 13px;
    font-weight: 720;
    line-height: 1;
    text-align: center;
  }

  .doc-step-nav a:hover,
  .doc-step-nav a:focus {
    color: #111;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
  }

  .document-form-shell,
  .document-form {
    gap: 18px;
  }

  .document-form-shell {
    padding-bottom: 8px;
  }

  .doc-form-section {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    scroll-margin-top: 116px;
  }

  .doc-section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-direction: row;
    gap: 10px;
    margin: 0 6px 9px;
  }

  .doc-section-head h3 {
    margin: 0;
    color: #8e8e93;
    font-size: 17px;
    font-weight: 760;
    line-height: 1.18;
  }

  .doc-step-kicker,
  .doc-section-head > span {
    display: none;
  }

  #doc-lines .doc-section-head {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    margin-bottom: 10px;
  }

  .doc-section-head .inline.tight {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    width: 100%;
    overflow: hidden;
    border-radius: 18px;
    background: white;
    box-shadow: 0 1px 0 rgba(0,0,0,.04);
  }

  .doc-section-head .inline.tight .btn {
    justify-content: flex-start;
    width: 100%;
    min-height: 52px;
    padding: 0 16px;
    border: 0;
    border-bottom: 1px solid #e5e5ea;
    border-radius: 0;
    color: #34a853;
    background: white;
    font-size: 16px;
    font-weight: 680;
  }

  .doc-section-head .inline.tight .btn:last-child {
    border-bottom: 0;
  }

  .doc-meta-grid,
  .doc-status-grid,
  .line-list {
    gap: 0;
    overflow: hidden;
    border-radius: 22px;
    background: white;
    box-shadow: 0 1px 0 rgba(0,0,0,.04);
  }

  .doc-meta-grid,
  .doc-status-grid,
  .quick-service-form,
  .modal-payment-form {
    grid-template-columns: 1fr;
  }

  .doc-meta-grid > label,
  .doc-status-grid > label,
  .doc-meta-grid > label.wide,
  .doc-status-grid > label.wide,
  .doc-meta-grid > label:nth-child(4),
  .doc-meta-grid > label:nth-child(5) {
    grid-column: 1 / -1;
  }

  .doc-meta-grid label,
  .doc-status-grid label {
    display: grid;
    grid-template-columns: minmax(88px, 36%) minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    min-height: 58px;
    padding: 7px 16px;
    border-bottom: 1px solid #e5e5ea;
  }

  .doc-meta-grid label:last-child,
  .doc-status-grid label:last-child {
    border-bottom: 0;
  }

  .doc-meta-grid label span,
  .doc-status-grid label span {
    min-width: 0;
    color: #111;
    font-size: 16px;
    font-weight: 560;
    line-height: 1.2;
  }

  .doc-form-section input,
  .doc-form-section select,
  .doc-form-section textarea {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: 0;
    color: #6e6e73;
    background: transparent;
    box-shadow: none;
    font-size: 16px;
    line-height: 1.25;
    text-align: right;
  }

  .doc-form-section input,
  .doc-form-section select,
  .doc-form-section textarea {
    -webkit-appearance: none;
    appearance: none;
  }

  .doc-form-section textarea {
    min-height: 112px;
    padding: 12px 0;
    text-align: left;
    resize: vertical;
  }

  .line-table {
    overflow: visible;
  }

  .line-head {
    display: none;
  }

  .line-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px;
    gap: 8px;
    min-width: 0;
    padding: 14px;
    border: 0;
    border-bottom: 1px solid #e5e5ea;
    border-radius: 0;
    background: white;
    box-shadow: none;
  }

  .line-grid:last-child {
    border-bottom: 0;
  }

  .line-number {
    display: inline-flex;
    grid-column: 1 / 3;
    grid-row: 1;
    align-items: center;
    color: #8e8e93;
    font-size: 12px;
    font-weight: 760;
    line-height: 1;
  }

  .line-grid .line-remove {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 14px;
  }

  .line-grid select,
  .line-grid input[data-line-field="description"] {
    grid-column: 1 / -1;
  }

  .line-grid input[data-line-field="quantity"] {
    grid-column: 1 / 2;
  }

  .line-grid input[data-line-field="unit_price"] {
    grid-column: 2 / -1;
  }

  .line-grid select,
  .line-grid input[data-line-field="description"],
  .line-grid input[data-line-field="quantity"],
  .line-grid input[data-line-field="unit_price"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 0 13px;
    border-radius: 15px;
    text-align: left;
    background: #f4f4f6;
  }

  .line-grid select {
    color: #111;
    font-weight: 700;
    background: white;
    box-shadow: inset 0 0 0 1px #e5e5ea;
  }

  .quick-service-form {
    gap: 8px;
    margin: 0 0 18px;
    padding: 12px;
    border: 0;
    border-radius: 22px;
    background: white;
    box-shadow: 0 1px 0 rgba(0,0,0,.04);
  }

  .quick-service-form input {
    min-height: 46px;
    border-radius: 15px;
    background: #f4f4f6;
  }

  .doc-footer-grid {
    gap: 18px;
  }

  .compact-total,
  .total-box {
    position: static;
    border-radius: 22px;
    padding: 18px;
    scroll-margin-top: 116px;
  }

  .total-box .between.keep {
    flex-direction: row;
    align-items: center;
  }

  .document-submit-bar {
    position: static;
    gap: 8px;
    padding: 0 0 max(12px, env(safe-area-inset-bottom, 0px));
    background: transparent;
  }

  .document-submit-bar .btn.primary {
    display: none;
  }

  .document-submit-bar .mobile-icon-label {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 46px;
    border-radius: 16px;
  }

  .document-submit-bar .mobile-icon-label span {
    display: inline;
  }
}

@media (max-width: 620px) {
  .doc-form-section input[name="project"] {
    text-align: left;
  }

  .doc-form-section input[name="project"]::placeholder {
    text-align: left;
  }

  #doc-lines .doc-section-head .inline.tight {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #doc-lines .doc-section-head .inline.tight .btn {
    justify-content: center;
    min-height: 50px;
    padding: 0 9px;
    border-bottom: 0;
    font-size: 14px;
    white-space: nowrap;
  }

  #doc-lines .doc-section-head .inline.tight .btn:first-child {
    border-right: 1px solid #e5e5ea;
  }

  .line-grid input[data-line-field="description"] {
    min-height: 42px;
    color: #6e6e73;
    font-size: 14px;
    line-height: 1.25;
  }

  .line-grid select {
    min-height: 48px;
    font-size: 16px;
  }
}
