:root {
  --primary: #6d4bb5;
  --primary-dark: #4d347f;
  --primary-soft: #f0ebfa;
  --primary-border: #d7c9f1;
  --danger: #b94a48;
  --danger-soft: #fff0f0;
  --success: #247b5b;
  --text-main: #181621;
  --text-muted: #6f6a7d;
  --bg-main: #f7f6fa;
  --card-bg: #ffffff;
  --surface-soft: #fbfaff;
  --border-color: #e1deea;
  --filter-active: #e58a1f;
  --filter-active-soft: #fff8ed;
  --shadow: 0 18px 42px rgba(34, 24, 54, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

body.auth-pending .app-shell,
body.login-mode .app-shell {
  display: none;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg-main);
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
}

.login-logo {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: 1px solid var(--primary-border);
}

.login-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.user-panel {
  display: grid;
  gap: 6px;
  margin: -8px 0 18px;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
}

.user-panel:empty {
  display: none;
}

.user-panel-name {
  font-size: 13px;
  font-weight: 800;
}

.user-panel-role {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.35;
  word-break: break-word;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-field input {
  width: auto;
  min-height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--border-color);
  background: #fcfbff;
  padding: 22px 16px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.brand-logo {
  display: block;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--primary-border);
  box-shadow: 0 10px 22px rgba(109, 75, 181, 0.22);
}

.brand-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.15;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
}

.period-box {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding: 10px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--primary-soft);
}

.period-title {
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 800;
}

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

[hidden] {
  display: none !important;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  color: var(--text-main);
  padding: 8px 10px;
}

input.filter-active,
select.filter-active,
textarea.filter-active {
  border-color: var(--filter-active);
  background: var(--filter-active-soft);
  box-shadow: 0 0 0 3px rgba(229, 138, 31, 0.16);
}

textarea {
  min-height: 82px;
  resize: vertical;
}

.period-links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.period-links button {
  min-height: 28px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: #fff;
  color: var(--primary-dark);
  padding: 5px 7px;
  font-size: 11px;
  font-weight: 700;
}

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

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

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #fff;
  color: var(--text-main);
  text-align: left;
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.nav-item:hover {
  background: #fff;
  border-color: var(--primary-border);
  color: var(--primary-dark);
}

.nav-item.active {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary-dark);
  font-weight: 800;
  box-shadow: none;
}

.nav-item:focus {
  outline: none;
}

.nav-item:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109, 75, 181, 0.16);
}

.nav-icon {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  height: 24px;
  color: #676b66;
}

.nav-item.active .nav-icon {
  color: var(--primary-dark);
}

.nav-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-label {
  min-width: 0;
}

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

.topbar,
.page-head,
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.topbar {
  margin-bottom: 18px;
}

.app-statusbar {
  justify-content: flex-end;
  margin-bottom: 10px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

h3 {
  font-size: 15px;
  line-height: 1.25;
}

p {
  margin-top: 6px;
  color: var(--text-muted);
}

.topbar-actions,
.actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill {
  min-height: 34px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-muted);
  padding: 7px 11px;
  white-space: nowrap;
}

.status-pill.ok {
  color: var(--success);
  border-color: #bfe4d4;
}

.status-pill.error {
  color: var(--danger);
  border-color: #efc4c3;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

.page-head {
  margin-bottom: 14px;
}

.page-sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -8px -8px 14px;
  padding: 8px 8px 1px;
  border-bottom: 1px solid rgba(225, 222, 234, 0.78);
  background: rgba(247, 246, 250, 0.94);
  backdrop-filter: blur(12px);
}

.page-sticky .page-head,
.page-sticky .filters,
.page-sticky .report-tabs,
.page-sticky .report-period-note {
  margin-bottom: 10px;
}

.panel,
.summary-card,
.placeholder,
.modal,
.deal-overlay {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

.panel {
  overflow: hidden;
  margin-bottom: 14px;
}

.panel-head {
  min-height: 54px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
}

.button {
  min-height: 34px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  color: var(--text-main);
  padding: 7px 11px;
  font-weight: 700;
}

.button:hover {
  background: var(--surface-soft);
}

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

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

.button.danger,
.button.danger-soft {
  color: var(--danger);
}

.button.danger-soft {
  background: var(--danger-soft);
  border-color: #efc4c3;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  padding: 4px 0 0;
  font-weight: 800;
  text-decoration: underline;
}

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

.history-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
  align-items: baseline;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.history-row small {
  grid-column: 2;
  color: var(--text-muted);
}

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-card {
  min-height: 86px;
  padding: 13px;
}

.summary-card span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.summary-card strong {
  display: block;
  font-size: 21px;
  line-height: 1.2;
}

.summary-card small {
  display: block;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.summary-card .summary-breakdown {
  font-weight: 600;
  line-height: 1.35;
}

.operational-balance-card strong {
  color: var(--text-main);
}

.operational-balance-card.positive strong {
  color: var(--success);
}

.operational-balance-card.negative strong {
  color: var(--danger);
}

.report-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.report-tab {
  min-height: 36px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: #fff;
  color: var(--primary-dark);
  padding: 8px 12px;
  font-weight: 800;
}

.report-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.report-period-note {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
}

.report-container {
  display: grid;
  gap: 14px;
}

.report-panel {
  margin-bottom: 0;
}

.report-panel-body {
  padding: 14px;
}

.report-summary-grid {
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  margin-bottom: 0;
}

.report-panel .table-wrap {
  margin-top: 12px;
}

.report-balance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.report-balance-column {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--surface-soft);
}

.report-balance-column h4 {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 14px;
}

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

.report-line:first-of-type {
  border-top: 0;
}

.report-line span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.report-line strong {
  white-space: nowrap;
}

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

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.8fr);
  gap: 14px;
}

.dashboard-active-panel {
  margin-top: 14px;
}

.dashboard-active-scroll {
  max-height: 285px;
  overflow: auto;
}

.dashboard-active-scroll th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.dashboard-active-table {
  min-width: 1320px;
}

.dashboard-chart-panel {
  margin-top: 14px;
}

.daily-chart-empty {
  padding: 18px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.daily-chart {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  padding: 14px 16px 16px;
  min-height: 200px;
}

.daily-chart + .daily-chart {
  border-top: 1px solid var(--border-color);
}

.daily-chart-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.daily-chart-meta span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.daily-chart-meta strong {
  color: var(--text-main);
  font-size: 18px;
  line-height: 1.2;
}

.daily-chart-bars {
  display: flex;
  align-items: end;
  gap: 5px;
  height: 160px;
  min-width: 0;
  overflow-x: auto;
  padding: 8px 0 2px;
  border-bottom: 1px solid var(--border-color);
}

.daily-chart-day {
  flex: 1 0 18px;
  min-width: 18px;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: end;
  gap: 5px;
}

.daily-chart-bar {
  display: block;
  width: 100%;
  min-height: 0;
  border-radius: 5px 5px 0 0;
  background: var(--primary);
}

.daily-chart-expense .daily-chart-bar {
  background: #c9655d;
}

.daily-chart-day small {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.cash-points-panel {
  margin-top: 14px;
}

.cash-points-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px 0;
}

.cash-points-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 14px 16px 16px;
}

.cash-point-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.cash-point-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.cash-point-head h4 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
}

.cash-point-head span {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
}

.cash-point-fact {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.cash-point-fact .field-full {
  grid-column: 1 / -1;
}

.cash-point-lines {
  display: grid;
  gap: 8px;
}

.cash-point-lines div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 8px 10px;
}

.cash-point-lines span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.cash-point-lines strong {
  color: var(--text-main);
  font-size: 13px;
  text-align: right;
}

.control-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.control-badge.balance,
.money-movement.positive,
.positive {
  color: var(--success);
}

.control-badge.surplus {
  color: #2563a8;
  background: #eaf3ff;
}

.control-badge.shortage,
.money-movement.negative,
.negative {
  color: var(--danger);
}

.control-badge.balance {
  background: #e9f7ef;
}

.control-badge.shortage {
  background: var(--danger-soft);
}

.control-badge.muted,
.money-movement.neutral {
  color: var(--text-muted);
}

.suppliers-ledger th.money-head,
.suppliers-ledger td.amount {
  text-align: right;
}

.suppliers-page-summary .summary-card strong {
  white-space: nowrap;
}

.summary-card.debt-value strong {
  color: #b42318;
}

.summary-card.advance-value strong {
  color: #2563a8;
}

.advance-value {
  color: #2563a8;
  font-weight: 900;
}

.supplier-summary {
  margin-bottom: 14px;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.supplier-summary .summary-card strong {
  white-space: nowrap;
}

.backup-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.backup-summary {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  margin-bottom: 0;
}

.backup-table td:nth-child(3) {
  white-space: normal;
  word-break: break-all;
}

.supplier-card-meta {
  margin-bottom: 14px;
}

.supplier-reconciliation-block {
  margin-top: 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.supplier-reconciliation-block .supplier-summary {
  padding: 14px;
  margin-bottom: 0;
}

.reconciliation-scroll {
  max-height: 430px;
  overflow: auto;
}

.reconciliation-scroll table {
  min-width: 1180px;
}

.employee-reconciliation-block .reconciliation-scroll table {
  min-width: 1280px;
}

.payroll-month {
  margin-top: 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
}

.payroll-month-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border-color);
}

.payroll-month-head h4 {
  margin: 0;
  font-size: 15px;
}

.payroll-month-total {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.payroll-scroll {
  max-height: 360px;
}

.reconciliation-scroll th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.table-wrap {
  overflow-x: auto;
}

.synced-table {
  display: grid;
  gap: 4px;
}

.table-scroll-top {
  overflow-x: auto;
  overflow-y: hidden;
  height: 14px;
}

.table-scroll-top div {
  height: 1px;
}

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

.compact-table table {
  min-width: 1080px;
}

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

th {
  background: #fbfaff;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  font-size: 13px;
}

.compact-table th,
.compact-table td {
  padding: 7px 8px;
  font-size: 12px;
}

.compact-table th {
  white-space: normal;
  line-height: 1.15;
}

.deal-lines-table-wrap {
  overflow-x: auto;
}

.deal-lines-table {
  min-width: 980px;
  table-layout: fixed;
}

.deal-lines-table th,
.deal-lines-table td {
  padding: 4px 7px;
  height: 30px;
  line-height: 1.15;
  vertical-align: middle;
}

.deal-lines-table th:nth-child(1),
.deal-lines-table td:nth-child(1) {
  width: 105px;
}

.deal-lines-table th:nth-child(2),
.deal-lines-table td:nth-child(2) {
  width: 260px;
}

.deal-lines-table th:nth-child(3),
.deal-lines-table td:nth-child(3),
.deal-lines-table th:nth-child(4),
.deal-lines-table td:nth-child(4) {
  width: 78px;
}

.deal-lines-table th:nth-child(5),
.deal-lines-table td:nth-child(5),
.deal-lines-table th:nth-child(6),
.deal-lines-table td:nth-child(6) {
  width: 118px;
}

.deal-lines-table th:nth-child(7),
.deal-lines-table td:nth-child(7) {
  width: 170px;
}

.deal-line-row:hover td {
  background: #fbf7ff;
}

.deal-line-text {
  max-width: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deal-line-actions-head,
.deal-line-actions-cell {
  width: 78px;
  text-align: right;
}

.deal-line-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  white-space: nowrap;
}

.line-action-pill {
  min-height: 22px;
  border: 1px solid #d9c8f5;
  border-radius: 7px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  cursor: pointer;
}

.line-icon-button {
  width: 22px;
  height: 22px;
  min-height: 22px;
  border-radius: 7px;
  font-size: 15px;
  cursor: pointer;
}

.payment-lines-table {
  min-width: 980px;
  table-layout: fixed;
}

.payment-lines-table th,
.payment-lines-table td {
  padding: 4px 7px;
  height: 30px;
  line-height: 1.15;
  vertical-align: middle;
}

.payment-client-table th:nth-child(1),
.payment-client-table td:nth-child(1),
.payment-supplier-table th:nth-child(1),
.payment-supplier-table td:nth-child(1) {
  width: 82px;
}

.payment-client-table th:nth-child(2),
.payment-client-table td:nth-child(2),
.payment-client-table th:nth-child(3),
.payment-client-table td:nth-child(3),
.payment-client-table th:nth-child(4),
.payment-client-table td:nth-child(4),
.payment-supplier-table th:nth-child(3),
.payment-supplier-table td:nth-child(3),
.payment-supplier-table th:nth-child(4),
.payment-supplier-table td:nth-child(4),
.payment-supplier-table th:nth-child(5),
.payment-supplier-table td:nth-child(5) {
  width: 126px;
}

.payment-supplier-table th:nth-child(2),
.payment-supplier-table td:nth-child(2) {
  width: 150px;
}

.payment-client-table th:nth-child(5),
.payment-client-table td:nth-child(5),
.payment-supplier-table th:nth-child(6),
.payment-supplier-table td:nth-child(6) {
  width: 160px;
}

.payment-client-table th:nth-child(6),
.payment-client-table td:nth-child(6),
.payment-supplier-table th:nth-child(7),
.payment-supplier-table td:nth-child(7) {
  width: 180px;
}

.payment-client-table th:nth-child(7),
.payment-client-table td:nth-child(7),
.payment-supplier-table th:nth-child(8),
.payment-supplier-table td:nth-child(8) {
  width: 78px;
}

.payment-note-cell {
  max-width: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deals-ledger {
  table-layout: fixed;
  min-width: 1610px;
}

.deals-ledger .col-deal-no {
  width: 58px;
}

.deals-ledger .col-author {
  width: 96px;
}

.deals-ledger .col-date {
  width: 88px;
}

.deals-ledger .col-client {
  width: 138px;
}

.deals-ledger .col-title {
  width: 140px;
}

.deals-ledger .col-type {
  width: 84px;
}

.deals-ledger .col-status {
  width: 116px;
}

.deals-ledger .col-currency {
  width: 62px;
}

.deals-ledger .col-money {
  width: 102px;
}

.deals-ledger .col-percent {
  width: 66px;
}

.deals-ledger .col-actions {
  width: 42px;
}

.deals-ledger th.money-head,
.deals-ledger td.amount {
  text-align: right;
}

.deals-ledger th,
.deals-ledger td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.deals-ledger .badge {
  max-width: 100%;
}

.deal-number-cell {
  display: inline-block;
  min-width: 34px;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.1;
}

.deal-number-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.deal-number-short {
  color: var(--primary-dark);
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
}

.deal-number-full {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.deal-number-meta {
  align-items: flex-start;
}

.operation-deal-number {
  min-width: 0;
}

.operation-deal-number .deal-number-short {
  font-size: 22px;
}

.operation-deal-number .deal-number-full {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.clickable-row:hover {
  background: var(--primary-soft);
}

.clickable-row.cancelled-row {
  background: #fff7f7;
}

.clickable-row.request-row {
  background: #f3f8ff;
}

.clickable-row.voided-row {
  background: #fff7f7;
  color: #7d6f75;
}

.clickable-row.archived-row {
  background: #fff7f7;
  color: #7d6f75;
}

.clickable-row.cancelled-row:hover {
  background: #ffecec;
}

.clickable-row.request-row:hover {
  background: #e8f3ff;
}

.clickable-row.voided-row:hover {
  background: #ffecec;
}

.clickable-row.archived-row:hover {
  background: #ffecec;
}

.cancelled-row td {
  color: #7d6f75;
}

.voided-row td {
  color: #7d6f75;
}

.archived-row td {
  color: #7d6f75;
}

.clickable-row {
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  color: var(--text-muted);
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.icon-button.danger-soft {
  background: var(--danger-soft);
  border-color: #efc4c3;
  color: var(--danger);
}

.icon-button.restore-soft {
  background: #edf8f1;
  border-color: #b9dfc8;
  color: #247b5b;
}

.amount {
  font-variant-numeric: tabular-nums;
}

.deal-table-sale-value,
.deal-table-cost-value {
  font-weight: 850;
}

.debt-value,
.low-margin-value {
  color: var(--danger);
  font-weight: 850;
}

.negative {
  color: var(--danger);
}

.muted {
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 8px;
  padding: 3px 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.badge.muted {
  color: var(--text-muted);
  background: #f1eff5;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  max-width: 100%;
  border-radius: 8px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.15;
  white-space: nowrap;
}

.status-potential {
  background: #fdebf3;
  color: #9f3d67;
}

.status-request {
  background: #e8f3ff;
  color: #2f5f88;
}

.status-active {
  background: #e8f6ef;
  color: #247b5b;
}

.status-waiting {
  background: #fff6d8;
  color: #8a6400;
}

.status-completed {
  background: #4c4854;
  color: #fff;
}

.status-cancelled {
  background: #fff0e7;
  color: #b45309;
}

.status-unknown {
  background: #f1eff5;
  color: var(--text-muted);
}

.request-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid #b9d9ff;
  border-radius: 8px;
  background: #f3f8ff;
  color: #2f5f88;
}

.request-notice strong,
.request-notice span {
  display: block;
}

.request-notice span {
  margin-top: 3px;
  color: #55718b;
  font-size: 12px;
}

.weekly-range {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 14px;
  font-weight: 850;
}

.weekly-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(180px, 1fr));
  gap: 10px;
  align-items: stretch;
  overflow-x: auto;
  padding-bottom: 4px;
}

.weekly-day {
  min-width: 180px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
  overflow: hidden;
}

.weekly-day.today {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109, 75, 181, 0.12);
}

.weekly-day-head {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-bottom: 1px solid var(--border-color);
  background: var(--surface-soft);
}

.weekly-day-head strong {
  font-size: 13px;
}

.weekly-day-head span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.weekly-day-body {
  display: grid;
  gap: 8px;
  min-height: 360px;
  align-content: start;
  padding: 10px;
}

.weekly-empty {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 750;
}

.weekly-task-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.weekly-task-card:hover,
.weekly-task-card:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 6px 18px rgba(59, 47, 92, 0.12);
  outline: none;
  transform: translateY(-1px);
}

.weekly-task-card.deadline {
  border-color: #e4c06c;
  background: #fffaf0;
}

.weekly-task-card.overdue {
  border-color: #ef9a9a;
  background: var(--danger-soft);
}

.weekly-task-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.weekly-task-top > span:first-child {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 850;
}

.weekly-task-card h3 {
  font-size: 13px;
  line-height: 1.25;
}

.weekly-task-card p {
  margin-top: 0;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 11px;
  line-height: 1.3;
}

.weekly-task-meta {
  display: grid;
  gap: 5px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 750;
}

.weekly-task-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.weekly-task-actions .button {
  min-height: 28px;
  padding: 4px 7px;
  font-size: 12px;
}

.weekly-event-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  padding: 6px 7px;
  border: 1px solid #d8e5ef;
  border-left: 3px solid #6a93b8;
  border-radius: 6px;
  background: #f7fbff;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.weekly-event-row:hover,
.weekly-event-row:focus-visible {
  border-color: #9bbdd8;
  box-shadow: 0 5px 14px rgba(47, 95, 136, 0.12);
  outline: none;
  transform: translateY(-1px);
}

.weekly-event-main {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.weekly-event-main > div {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.weekly-event-main strong,
.weekly-event-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weekly-event-main strong {
  color: var(--text-main);
  font-size: 12px;
  line-height: 1.2;
}

.weekly-event-main span {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 750;
}

.weekly-event-time {
  flex: 0 0 auto;
  color: #426983;
  font-size: 10px;
  font-weight: 900;
}

.weekly-event-label {
  flex: 0 0 auto;
  color: #426983;
  font-size: 9px;
  font-weight: 900;
  text-transform: uppercase;
}

.weekly-event-request_created {
  border-left-color: #8a79c7;
  background: #f8f6ff;
}

.weekly-event-client_payment_received {
  border-left-color: #3b9b73;
  background: #f2fbf7;
}

.weekly-event-deal_status_changed {
  border-left-color: #d89a2b;
  background: #fff9ec;
}

.weekly-delete-row {
  display: flex;
  justify-content: flex-start;
  padding-top: 2px;
}

.weekly-event-modal {
  width: min(640px, 100%);
}

.weekly-event-card {
  display: grid;
  gap: 14px;
}

.weekly-status-new {
  background: #e8f3ff;
  color: #2f5f88;
}

.weekly-status-in_progress {
  background: #fff6d8;
  color: #8a6400;
}

.weekly-status-done {
  background: #e8f6ef;
  color: #247b5b;
}

.weekly-status-cancelled {
  background: #fff0e7;
  color: #b45309;
}

.confirm-message {
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
}

.placeholder {
  padding: 22px;
}

.panel-note {
  margin: 0;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--surface-soft);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.modal-backdrop,
.deal-overlay-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 16, 31, 0.42);
  padding: 20px;
}

.modal-backdrop {
  z-index: 40;
}

.period-notice {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  width: min(560px, calc(100vw - 40px));
  padding: 14px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

.period-notice strong {
  display: block;
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.35;
}

.period-notice span {
  display: block;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.period-notice-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.nested-modal-backdrop {
  z-index: 70;
}

.modal {
  width: min(820px, 100%);
  max-height: min(86vh, 900px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.modal-small {
  width: min(520px, 100%);
}

.supplier-modal {
  width: min(1320px, 90vw);
}

.invoice-modal {
  width: min(1180px, 92vw);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.modal-body {
  overflow-y: auto;
  padding: 16px;
}

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

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

.invoice-lines-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.invoice-lines-head h3 {
  margin: 0;
}

.invoice-lines-head span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.invoice-items-wrap {
  overflow-x: auto;
}

.invoice-items-table {
  min-width: 980px;
  table-layout: fixed;
}

.invoice-items-table th,
.invoice-items-table td {
  padding: 5px 6px;
  vertical-align: middle;
}

.invoice-items-table th:nth-child(1),
.invoice-items-table td:nth-child(1) {
  width: 54px;
}

.invoice-items-table th:nth-child(2),
.invoice-items-table td:nth-child(2) {
  width: 360px;
}

.invoice-items-table th:nth-child(3),
.invoice-items-table td:nth-child(3) {
  width: 105px;
}

.invoice-items-table th:nth-child(4),
.invoice-items-table td:nth-child(4),
.invoice-items-table th:nth-child(5),
.invoice-items-table td:nth-child(5),
.invoice-items-table th:nth-child(6),
.invoice-items-table td:nth-child(6) {
  width: 120px;
}

.invoice-items-table input,
.invoice-items-table textarea {
  min-height: 28px;
  padding: 4px 6px;
  font-size: 13px;
}

.invoice-items-table textarea.invoice-item-name-input {
  min-height: 54px;
  resize: vertical;
  line-height: 1.25;
  white-space: normal;
}

.invoice-total-box {
  display: grid;
  grid-template-columns: minmax(180px, 0.35fr) minmax(0, 1fr);
  gap: 10px;
}

.invoice-total-box div {
  padding: 10px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.invoice-total-box span {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.invoice-total-box strong {
  display: block;
  font-size: 16px;
  line-height: 1.25;
}

.deal-form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-full {
  grid-column: 1 / -1;
}

.field-note {
  display: block;
  min-height: 16px;
  margin-top: 4px;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
}

.price-calc-button {
  align-self: flex-start;
  margin-top: 6px;
  padding: 0;
}

.line-calc-card,
.line-margin-card,
.payment-context,
.calculator-result {
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--primary-soft);
  padding: 10px 12px;
}

.line-calc-card span,
.payment-context span,
.calculator-result span,
.line-margin-card span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.line-calc-card strong,
.payment-context strong,
.calculator-result strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.payment-warning {
  border: 1px solid #efc4c3;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
}

.line-margin-card h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

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

.line-margin-grid div {
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.line-margin-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 15px;
}

.sale-price-note {
  color: var(--primary-dark);
}

.price-formula-note {
  color: var(--text-muted);
}

.cost-item-form-grid {
  align-items: start;
}

.cost-item-quantity-stack {
  display: grid;
  grid-column: 2;
  gap: 12px;
  align-self: start;
}

.cost-item-quantity-stack [data-field-name="quantity"],
.cost-item-quantity-stack [data-field-name="unit"] {
  align-self: start;
}

.cost-item-quantity-stack [data-field-name="quantity"] input,
.cost-item-quantity-stack [data-field-name="unit"] select {
  height: 36px;
  min-height: 36px;
}

.required-rule select,
.required-rule input {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.form-error {
  grid-column: 1 / -1;
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

.modal-wide {
  width: min(1180px, calc(100vw - 32px));
}

.request-recognition-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: -4px;
}

.request-photo-box {
  display: grid;
  gap: 10px;
  min-height: 76px;
  border: 1px dashed var(--primary-border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
}

.request-photo-box.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.request-photo-empty,
.request-photo-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.request-photo-empty span,
.request-photo-meta span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
}

.request-photo-preview img {
  width: 72px;
  height: 54px;
  flex: 0 0 auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  object-fit: cover;
}

.request-photo-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.request-photo-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.request-photo-preview .icon-button {
  margin-left: auto;
  flex: 0 0 auto;
}

.request-recognition-result:empty {
  display: none;
}

.assistant-warnings,
.assistant-recognized {
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.assistant-warnings {
  border-color: rgba(245, 158, 11, 0.45);
  background: #fff7ed;
  color: #92400e;
}

.assistant-warnings strong,
.assistant-recognized h3 {
  display: block;
  margin: 0 0 8px;
  font-size: 13px;
}

.assistant-warnings p {
  margin: 4px 0 0;
  font-size: 13px;
}

.assistant-recognized {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
}

.assistant-recognized h3 {
  grid-column: 1 / -1;
  color: var(--primary-dark);
}

.assistant-recognized span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.assistant-recognized strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

.checkbox-label {
  align-items: center;
  grid-template-columns: auto 1fr;
}

.checkbox-label input {
  width: auto;
  margin-right: 8px;
}

.deal-overlay-backdrop {
  z-index: 30;
  align-items: stretch;
  justify-items: stretch;
}

.deal-overlay {
  width: min(1320px, 100%);
  max-height: calc(100vh - 40px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  margin: auto;
}

.deal-overlay-body {
  overflow-y: auto;
  padding: 16px;
}

.deal-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.deal-audit-meta {
  display: grid;
  grid-column: span 2;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.deal-inline-form {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--primary-soft);
}

.meta-cell {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
}

.meta-cell span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 5px;
}

.meta-cell strong {
  display: block;
  font-size: 14px;
}

.meta-cell .deal-number-short {
  font-size: 26px;
}

.meta-cell .deal-number-full {
  margin-bottom: 0;
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-color);
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .filters,
  .summary-grid,
  .dashboard-grid,
  .cash-points-summary,
  .cash-points-grid,
  .deal-meta,
  .line-margin-grid,
  .report-summary-grid,
  .report-balance-grid,
  .backup-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .page-head,
  .panel-head {
    flex-direction: column;
  }

  .topbar-actions,
  .actions,
  .row-actions {
    width: 100%;
  }

  .button {
    flex: 1;
  }

  .nav,
  .filters,
  .summary-grid,
  .cash-points-summary,
  .cash-points-grid,
  .deal-meta,
  .deal-audit-meta,
  .line-margin-grid,
  .report-summary-grid,
  .report-balance-grid,
  .backup-summary,
  .invoice-total-box,
  .form-grid,
  .deal-form-grid {
    grid-template-columns: 1fr;
  }

  .daily-chart {
    grid-template-columns: 1fr;
  }

  .cash-point-fact {
    grid-template-columns: 1fr;
  }

  .period-notice {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
    grid-template-columns: 1fr;
  }

  .period-notice-actions {
    justify-content: stretch;
  }

  .cost-item-quantity-stack {
    grid-column: auto;
  }
}
