.sales-shell {
  --sales-accent: var(--primary, #6d5dfc);
  --sales-success: #16a34a;
  --sales-warning: #d97706;
  --sales-danger: #dc2626;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;
}

.sales-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-surface);
  scrollbar-width: thin;
}

.sales-tab {
  flex: 0 0 auto;
  border: 0;
  border-radius: 9px;
  padding: 9px 13px;
  background: transparent;
  color: var(--text-sec);
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
}

.sales-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.sales-tab.active {
  color: var(--primary-text);
  background: var(--primary-soft);
}

.sales-panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-surface);
  overflow: hidden;
}

.sales-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.sales-panel-title {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 760;
  letter-spacing: -0.025em;
}

.sales-panel-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

.sales-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sales-search {
  min-width: 220px;
  height: 36px;
  border: 1px solid var(--border-md);
  border-radius: 9px;
  padding: 0 11px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
}

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

.sales-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.sales-table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--muted);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: 9.5px;
  font-weight: 700;
  white-space: nowrap;
}

.sales-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-sec);
  font-size: 12.5px;
  vertical-align: middle;
}

.sales-table tbody tr {
  transition: background .15s ease;
}

.sales-table tbody tr:hover {
  background: var(--bg-hover);
}

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

.sales-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.sales-link:hover {
  color: var(--primary-text);
}

.sales-muted {
  color: var(--muted);
  font-size: 11px;
}

.sales-num {
  text-align: right !important;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.sales-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-sec);
  font-size: 10.5px;
  font-weight: 700;
}

.sales-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.sales-badge.issued::before,
.sales-badge.paid::before {
  background: var(--sales-success);
}

.sales-badge.draft::before,
.sales-badge.partial::before {
  background: var(--sales-warning);
}

.sales-badge.cancelled::before,
.sales-badge.overdue::before {
  background: var(--sales-danger);
}

.sales-empty {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.sales-empty-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary-text);
  font-size: 22px;
}

.sales-empty h3 {
  margin: 0 0 5px;
  color: var(--text);
  font-size: 14px;
}

.sales-empty p {
  max-width: 420px;
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
}

.sales-editor {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sales-editor-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.sales-back {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}

.sales-back:hover {
  color: var(--text);
}

.sales-editor-title {
  margin: 7px 0 0;
  color: var(--text);
  font-size: 20px;
  letter-spacing: -0.04em;
}

.sales-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
}

.sales-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-surface);
  padding: 17px;
}

.sales-card-title {
  margin: 0 0 14px;
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
}

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

.sales-field {
  grid-column: span 4;
  min-width: 0;
}

.sales-field.wide {
  grid-column: span 8;
}

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

.sales-field.half {
  grid-column: span 6;
}

.sales-field.quarter {
  grid-column: span 3;
}

.sales-field label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
}

.sales-field input,
.sales-field select,
.sales-field textarea,
.sales-line-input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border-md);
  border-radius: 9px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.sales-field textarea {
  min-height: 80px;
  resize: vertical;
}

.sales-field input:focus,
.sales-field select:focus,
.sales-field textarea:focus,
.sales-line-input:focus {
  border-color: var(--sales-accent);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.sales-field input:disabled,
.sales-field select:disabled,
.sales-field textarea:disabled,
.sales-line-input:disabled {
  opacity: .75;
  cursor: not-allowed;
  background: var(--bg-elevated);
}

.sales-line-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

.sales-line-table th,
.sales-line-table td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
}

.sales-line-table th {
  color: var(--muted);
  font-size: 9px;
  text-align: left;
  text-transform: uppercase;
}

.sales-line-table .description {
  min-width: 230px;
}

.sales-line-table .small-cell {
  width: 88px;
}

.sales-line-table .money-cell {
  width: 115px;
}

.sales-line-table .action-cell {
  width: 38px;
  text-align: center;
}

.sales-line-remove {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.sales-line-remove:hover {
  background: rgba(220, 38, 38, .1);
  color: var(--sales-danger);
}

.sales-editor-footer {
  display: grid;
  grid-template-columns: 1fr minmax(270px, 380px);
  gap: 18px;
  align-items: start;
}

.sales-totals {
  width: 100%;
  border-collapse: collapse;
}

.sales-totals td {
  padding: 6px 4px;
  color: var(--text-sec);
  font-size: 12px;
}

.sales-totals td:last-child {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.sales-totals .grand td {
  padding-top: 10px;
  border-top: 1px solid var(--border-md);
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
}

.sales-chain {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.sales-chain-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  background: var(--bg-elevated);
  color: var(--text-sec);
  font-size: 11px;
}

.sales-chain-arrow {
  color: var(--muted);
}

.sales-history {
  display: grid;
  gap: 8px;
}

.sales-history-item {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-sec);
  font-size: 11.5px;
}

.sales-history-item:last-child {
  border-bottom: 0;
}

.sales-history-time {
  color: var(--muted);
}

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

.sales-stat {
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 15px;
  background: var(--bg-surface);
}

.sales-stat-label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.sales-stat-value {
  display: block;
  margin-top: 7px;
  color: var(--text);
  font-size: 21px;
  font-weight: 780;
  letter-spacing: -0.04em;
}

.sales-alert {
  padding: 12px 14px;
  border: 1px solid rgba(217, 119, 6, .25);
  border-radius: 10px;
  background: rgba(217, 119, 6, .08);
  color: var(--text-sec);
  font-size: 11.5px;
  line-height: 1.5;
}

.sales-alert.error {
  border-color: rgba(220, 38, 38, .25);
  background: rgba(220, 38, 38, .08);
}

.sales-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 7000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .52);
}

.sales-modal {
  width: min(720px, 100%);
  max-height: min(760px, calc(100dvh - 40px));
  overflow-y: auto;
  border: 1px solid var(--border-md);
  border-radius: 16px;
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
}

.sales-modal-head,
.sales-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 17px;
  border-bottom: 1px solid var(--border);
}

.sales-modal-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  border-bottom: 0;
}

.sales-modal-body {
  padding: 17px;
}

.sales-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.sales-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sales-loading {
  display: flex;
  min-height: 320px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.sales-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-md);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: sales-spin .7s linear infinite;
}

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

@media (max-width: 980px) {
  .sales-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sales-field,
  .sales-field.quarter {
    grid-column: span 6;
  }

  .sales-field.wide {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .sales-panel-head,
  .sales-editor-head {
    flex-direction: column;
    align-items: stretch;
  }

  .sales-toolbar,
  .sales-actions {
    width: 100%;
  }

  .sales-search {
    min-width: 0;
    width: 100%;
  }

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

  .sales-field,
  .sales-field.wide,
  .sales-field.full,
  .sales-field.half,
  .sales-field.quarter {
    grid-column: 1;
  }

  .sales-editor-footer {
    grid-template-columns: 1fr;
  }

  .sales-stats {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 440px) {
  .sales-stats {
    grid-template-columns: 1fr;
  }

  .sales-card,
  .sales-panel-head {
    padding: 14px;
  }
}
