:root {
  color-scheme: dark;
  --bg: #07111d;
  --panel: #101b2a;
  --panel-2: #15263a;
  --panel-3: #1a314b;
  --line: #29445f;
  --soft-line: rgba(148, 190, 231, 0.16);
  --text: #f5f9ff;
  --muted: #9fb3c9;
  --blue: #1d9bf0;
  --blue-dark: #0f5f93;
  --blue-light: #7cc8ff;
  --green: #32d583;
  --amber: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 22px 70px rgba(0, 15, 35, 0.48);
  --glow: 0 0 30px rgba(29, 155, 240, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="light"] {
  --bg: #eef4fb;
  --panel: #ffffff;
  --panel-2: #f7fbff;
  --panel-3: #eef5fd;
  --line: #c9d9ea;
  --soft-line: rgba(19, 78, 125, 0.12);
  --text: #122235;
  --muted: #63788f;
  --blue: #2386d9;
  --blue-dark: #15598f;
  --blue-light: #8bcafc;
  --green: #168f55;
  --amber: #c98205;
  --danger: #d33b3b;
  --shadow: 0 18px 45px rgba(20, 48, 78, 0.12);
  --glow: 0 0 24px rgba(35, 134, 217, 0.16);
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 0%, rgba(29, 155, 240, 0.2), transparent 32%),
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 34px 34px, 34px 34px, auto;
  color: var(--text);
}

body[data-theme="light"] {
  background:
    radial-gradient(circle at 18% 0%, rgba(35, 134, 217, 0.12), transparent 32%),
    linear-gradient(rgba(16, 37, 61, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 37, 61, 0.04) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 34px 34px, 34px 34px, auto;
}

html[dir="rtl"] body {
  text-align: right;
}

html[dir="rtl"] .app-header,
html[dir="rtl"] .brand,
html[dir="rtl"] .profile,
html[dir="rtl"] .hero-strip,
html[dir="rtl"] .toolbar,
html[dir="rtl"] .panel-header,
html[dir="rtl"] .search-results,
html[dir="rtl"] .checkbox-line,
html[dir="rtl"] .reset-options .checkbox-line,
html[dir="rtl"] .serial-counter-row,
html[dir="rtl"] .workspace,
html[dir="rtl"] .view,
html[dir="rtl"] .tabs,
html[dir="rtl"] .form-grid,
html[dir="rtl"] .invoice-line,
html[dir="rtl"] .invoice-view-grid,
html[dir="rtl"] .invoice-view-total,
html[dir="rtl"] .stats-grid,
html[dir="rtl"] .control-grid,
html[dir="rtl"] .report-grid,
html[dir="rtl"] .financial-summary-strip,
html[dir="rtl"] .backup-grid,
html[dir="rtl"] .backup-status-grid,
html[dir="rtl"] .permissions-grid,
html[dir="rtl"] .statement-date-row,
html[dir="rtl"] .table-wrap,
html[dir="rtl"] table,
html[dir="rtl"] .compact-list,
html[dir="rtl"] .bar-chart,
html[dir="rtl"] .line-list,
html[dir="rtl"] .invoice-lines,
html[dir="rtl"] .modal-card,
html[dir="rtl"] .panel {
  direction: rtl;
}

html[dir="rtl"] .system-print-page,
html[dir="rtl"] .print-preview,
html[dir="rtl"] .print-shell,
html[dir="rtl"] .print-header,
html[dir="rtl"] .print-summary-grid,
html[dir="rtl"] .print-bottom-grid,
html[dir="rtl"] .print-table,
html[dir="rtl"] .print-footer {
  direction: ltr;
}

html[dir="rtl"] .tabs {
  justify-content: flex-start;
}

html[dir="rtl"] .search-box input,
html[dir="rtl"] input,
html[dir="rtl"] textarea,
html[dir="rtl"] select,
html[dir="rtl"] th,
html[dir="rtl"] td,
html[dir="rtl"] .page-title,
html[dir="rtl"] .brand-copy,
html[dir="rtl"] .profile-copy,
html[dir="rtl"] .line-header,
html[dir="rtl"] .serial-feedback,
html[dir="rtl"] .list-row,
html[dir="rtl"] .stat-card,
html[dir="rtl"] .mini-stat,
html[dir="rtl"] .financial-section,
html[dir="rtl"] .invoice-view-cell,
html[dir="rtl"] .backup-card,
html[dir="rtl"] .backup-info-card,
html[dir="rtl"] .permission-card,
html[dir="rtl"] .empty-state,
html[dir="rtl"] .reset-panel,
html[dir="rtl"] label {
  text-align: right;
}

html[dir="rtl"] .checkbox-line,
html[dir="rtl"] .permission-card label,
html[dir="rtl"] .reset-options .checkbox-line {
  justify-content: space-between;
}

html[dir="rtl"] .invoice-view-cell strong.value-ltr,
html[dir="rtl"] .value-ltr,
html[dir="rtl"] .date-ltr {
  direction: ltr;
  unicode-bidi: plaintext;
  text-align: left;
}

html[dir="rtl"] .search-box {
  flex-direction: row-reverse;
}

html[dir="rtl"] .list-row {
  grid-template-columns: auto minmax(0, 1fr);
}

html[dir="rtl"] .bar {
  grid-template-columns: auto minmax(0, 1fr) minmax(140px, 0.9fr);
}

html[dir="rtl"] .bar-label,
html[dir="rtl"] .bar-value {
  text-align: right;
}

html[dir="rtl"] .primary-nav {
  justify-content: center;
  min-width: 0;
}

html[dir="rtl"] .stat-button,
html[dir="rtl"] .toast,
html[dir="rtl"] .panel-header > div,
html[dir="rtl"] .hero-strip > div,
html[dir="rtl"] .financial-section h3 {
  text-align: right;
}

html[dir="rtl"] .toolbar {
  justify-content: flex-end;
}

html[dir="rtl"] .compact-list .badge,
html[dir="rtl"] .search-results .badge,
html[dir="rtl"] .list-row .badge {
  justify-self: start;
}

html[dir="rtl"] .serial-counter-row {
  justify-content: flex-start;
}

html[dir="rtl"] .serial-issues-list,
html[dir="rtl"] .serial-issue,
html[dir="rtl"] .invoice-view-body table,
html[dir="rtl"] .invoice-view-body .table-wrap,
html[dir="rtl"] #invoiceRows,
html[dir="rtl"] #quotationRows,
html[dir="rtl"] #stockRows,
html[dir="rtl"] #expenseRows,
html[dir="rtl"] #backupFilesTable table,
html[dir="rtl"] #archiveTable table {
  direction: rtl;
}

html[dir="rtl"] .invoice-view-total,
html[dir="rtl"] .invoice-view-grid {
  direction: rtl;
}

html[dir="rtl"] .app-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

html[dir="rtl"] .brand {
  grid-column: 1;
  justify-self: end;
}

html[dir="rtl"] .primary-nav {
  grid-column: 2;
}

html[dir="rtl"] .profile {
  grid-column: 3;
  justify-self: start;
}

html[dir="rtl"] .profile-copy {
  max-width: 132px;
}

html[dir="rtl"] .profile-copy strong,
html[dir="rtl"] .profile-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
}

html[dir="rtl"] .bar {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) minmax(140px, 220px);
  align-items: center;
  column-gap: 14px;
  text-align: right;
  direction: rtl;
}

html[dir="rtl"] .bar-label {
  grid-column: 1;
  min-width: 0;
  max-width: none;
  justify-self: stretch;
  text-align: right;
}

html[dir="rtl"] .bar-track {
  grid-column: 2;
  width: 100%;
  display: flex;
  justify-content: flex-end;
}

html[dir="rtl"] .bar-value {
  grid-column: 3;
  min-width: 36px;
  text-align: center;
}

html[dir="rtl"] .invoice-line {
  direction: rtl;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 42px 42px;
}

html[dir="rtl"] .invoice-line .line-product {
  grid-column: 1 / -1;
  grid-row: 1;
}

html[dir="rtl"] .invoice-line .line-brand {
  grid-column: 3;
  grid-row: 2;
}

html[dir="rtl"] .invoice-line .line-category {
  grid-column: 2;
  grid-row: 2;
}

html[dir="rtl"] .invoice-line .line-model {
  grid-column: 1;
  grid-row: 2;
}

html[dir="rtl"] .invoice-line .line-price {
  grid-column: 4;
  grid-row: 3;
}

html[dir="rtl"] .invoice-line .line-qty {
  grid-column: 3;
  grid-row: 3;
}

html[dir="rtl"] .invoice-line .line-sale-price {
  grid-column: 2;
  grid-row: 3;
}

html[dir="rtl"] .invoice-line .line-min {
  grid-column: 1;
  grid-row: 3;
}

html[dir="rtl"] .invoice-line .line-add {
  grid-column: 5;
  grid-row: 3;
  justify-self: center;
  margin-left: 0;
}

html[dir="rtl"] .invoice-line .line-remove {
  grid-column: 6;
  grid-row: 3;
  justify-self: center;
}

html[dir="rtl"] .invoice-line .line-wide {
  grid-column: 1 / -1;
  grid-row: 4;
}

html[dir="rtl"] .invoice-line .line-full {
  grid-column: 1 / -1;
  grid-row: 5;
}

html[dir="rtl"] .invoice-line:not(.purchase-line):not(.return-line) .line-full {
  grid-row: 4;
}

html[dir="rtl"] .purchase-line .line-source {
  grid-column: 1 / -1;
  grid-row: 1;
}

html[dir="rtl"] .purchase-line .line-existing {
  grid-column: 1 / -1;
  grid-row: 2;
}

html[dir="rtl"] .purchase-line .line-product {
  grid-column: 1 / -1;
  grid-row: 3;
}

html[dir="rtl"] .purchase-line .line-brand {
  grid-column: 3;
  grid-row: 4;
}

html[dir="rtl"] .purchase-line .line-category {
  grid-column: 2;
  grid-row: 4;
}

html[dir="rtl"] .purchase-line .line-model {
  grid-column: 1;
  grid-row: 4;
}

html[dir="rtl"] .purchase-line .line-price {
  grid-column: 2;
  grid-row: 5;
}

html[dir="rtl"] .purchase-line .line-qty {
  grid-column: 3;
  grid-row: 5;
}

html[dir="rtl"] .purchase-line .line-sale-price {
  grid-column: 4;
  grid-row: 5;
}

html[dir="rtl"] .purchase-line .line-min {
  grid-column: 1;
  grid-row: 5;
}

html[dir="rtl"] .purchase-line .line-add,
html[dir="rtl"] .purchase-line .line-remove {
  grid-row: 5;
}

html[dir="rtl"] .purchase-line .line-wide {
  grid-row: 6;
}

html[dir="rtl"] .purchase-line .line-full {
  grid-row: 7;
}

html[dir="rtl"] .return-line .line-product {
  grid-column: 1 / -1;
  grid-row: 1;
}

html[dir="rtl"] .return-line .line-brand {
  grid-column: 3;
  grid-row: 2;
}

html[dir="rtl"] .return-line .line-category {
  grid-column: 2;
  grid-row: 2;
}

html[dir="rtl"] .return-line .line-model {
  grid-column: 1;
  grid-row: 2;
}

html[dir="rtl"] .return-line .line-price {
  grid-column: 4;
  grid-row: 3;
}

html[dir="rtl"] .return-line .line-qty {
  grid-column: 3;
  grid-row: 3;
}

html[dir="rtl"] .return-line .line-wide {
  grid-column: 1 / 3;
  grid-row: 3;
}

html[dir="rtl"] .return-line .line-full {
  grid-column: 1 / -1;
  grid-row: 4;
}

html[dir="rtl"] .page-title span,
html[dir="rtl"] .panel-header p,
html[dir="rtl"] .brand-copy span,
html[dir="rtl"] .profile-copy span,
html[dir="rtl"] .list-row span,
html[dir="rtl"] .stat-card span,
html[dir="rtl"] .financial-section p,
html[dir="rtl"] .line-header,
html[dir="rtl"] .invoice-lines strong,
html[dir="rtl"] .serial-feedback,
html[dir="rtl"] th,
html[dir="rtl"] td {
  unicode-bidi: plaintext;
}

html[dir="rtl"] .home-charts,
html[dir="rtl"] .home-charts .chart-panel,
html[dir="rtl"] .home-charts .bar-chart,
html[dir="rtl"] .home-charts .compact-list {
  direction: rtl;
}

html[dir="rtl"] .home-charts .panel-header,
html[dir="rtl"] .home-charts .panel-header > div,
html[dir="rtl"] .home-charts h2,
html[dir="rtl"] .home-charts p {
  text-align: right;
}

html[dir="rtl"] .home-charts .bar {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: right;
  direction: rtl;
}

html[dir="rtl"] .home-charts .bar-value {
  flex: 0 0 52px;
  text-align: left;
  order: 3;
}

html[dir="rtl"] .home-charts .bar-label {
  flex: 0 0 180px;
  text-align: right;
  order: 1;
}

html[dir="rtl"] .home-charts .bar-track {
  flex: 1 1 auto;
  order: 2;
}

html[dir="rtl"] .home-charts .list-row {
  direction: rtl;
}

html[dir="rtl"] .home-charts .chart-row-main {
  direction: rtl;
}

html[dir="rtl"] .home-charts .chart-row-copy {
  justify-content: flex-end;
  text-align: right;
}

html[dir="rtl"] .home-charts .badge.warn {
  direction: rtl;
  gap: 4px;
}

html[dir="rtl"] .home-charts .badge.warn .badge-number {
  order: 2;
}

html[dir="rtl"] .home-charts .badge.warn .badge-text {
  order: 1;
}

html[dir="rtl"] .toast {
  left: auto;
  right: 18px;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
img { display: block; }

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 27, 42, 0.94);
  box-shadow: var(--shadow);
}

body[data-theme="light"] .login-card {
  background: rgba(255, 255, 255, 0.96);
}

.login-logo {
  width: 72px;
  height: 72px;
  border: 1px solid rgba(124, 200, 255, 0.52);
  border-radius: 8px;
  object-fit: cover;
  box-shadow: var(--glow);
}

.login-card h1, .login-card p { margin: 0; }
.login-card h1 { font-size: 28px; }
.login-card p { color: var(--muted); font-size: 12px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 74px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 17, 29, 0.92);
  backdrop-filter: blur(18px);
}

body[data-theme="light"] .app-header {
  background: rgba(255, 255, 255, 0.9);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 205px;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  overflow: hidden;
  place-items: center;
  border: 1px solid rgba(124, 200, 255, 0.52);
  border-radius: 8px;
  background: linear-gradient(145deg, var(--blue), var(--blue-dark));
  box-shadow: var(--glow);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-copy strong, .brand-copy span, .profile-copy strong, .profile-copy span {
  display: block;
}

.brand-copy strong {
  font-size: 14px;
  font-weight: 950;
}

.brand-copy span, .profile-copy span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.primary-nav {
  display: flex;
  flex: 1;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
}

.primary-nav::-webkit-scrollbar { display: none; }

.nav-button, .tab-button, .primary-button, .secondary-button, .danger-button, .icon-button, .logout-button, .avatar-button {
  border-radius: 7px;
}

.nav-button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid transparent;
  background: transparent;
  color: #c3d3e4;
  font-size: 13px;
  font-weight: 850;
}

body[data-theme="light"] .nav-button {
  color: #4f657d;
}

.nav-button:hover {
  border-color: var(--line);
  background: var(--panel);
  color: #fff;
}

body[data-theme="light"] .nav-button:hover {
  color: var(--text);
}

.nav-button.active {
  border-color: rgba(124, 200, 255, 0.55);
  background: rgba(29, 155, 240, 0.16);
  color: #fff;
}

body[data-theme="light"] .nav-button.active {
  color: var(--blue-dark);
}

.profile {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: max-content;
}

.profile-copy strong {
  font-size: 11px;
}

.avatar-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(124, 200, 255, 0.58);
  border-radius: 50%;
  background: linear-gradient(145deg, #123d61, #0b2033);
  box-shadow: 0 0 18px rgba(29, 155, 240, 0.22);
  font-weight: 900;
}

body[data-theme="light"] .avatar-button {
  background: linear-gradient(145deg, #f4fbff, #deedf9);
  color: var(--blue-dark);
  box-shadow: 0 0 14px rgba(35, 134, 217, 0.14);
}

.logout-button {
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 11px;
  font-weight: 850;
}

.workspace {
  max-width: 1580px;
  margin: 0 auto;
  padding: 16px;
}

.view { display: none; }
.view.active { display: block; }

.hero-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 88px;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(29, 155, 240, 0.14), rgba(16, 27, 42, 0.92));
  box-shadow: var(--shadow);
}

body[data-theme="light"] .hero-strip {
  background: linear-gradient(135deg, rgba(35, 134, 217, 0.1), rgba(255, 255, 255, 0.96));
}

.page-title strong, .page-title span {
  display: block;
}

.page-title strong {
  font-size: 20px;
  font-weight: 950;
}

.page-title span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(500px, 100%);
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(7, 17, 29, 0.68);
}

body[data-theme="light"] .search-box {
  background: rgba(255, 255, 255, 0.86);
}

.search-box.compact {
  width: min(360px, 100%);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: 0;
  background: rgba(7, 17, 29, 0.68);
  color: var(--text);
}

body[data-theme="light"] input,
body[data-theme="light"] select,
body[data-theme="light"] textarea {
  background: #fbfdff;
  border-color: var(--line);
}

.filter-select,
.inline-input {
  min-width: 180px;
}

.stack-field {
  align-content: start;
}

.stack-field select,
.stack-field input {
  width: 100%;
}

textarea {
  min-height: 88px;
  padding: 10px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(124, 200, 255, 0.58);
  box-shadow: 0 0 0 3px rgba(29, 155, 240, 0.12);
}

input:disabled, select:disabled, textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  background: rgba(4, 12, 22, 0.7);
}

body[data-theme="light"] input:disabled,
body[data-theme="light"] select:disabled,
body[data-theme="light"] textarea:disabled {
  background: #edf3f9;
}

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

.stat-card, .panel, .search-results {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 27, 42, 0.92);
  box-shadow: var(--shadow);
}

body[data-theme="light"] .stat-card,
body[data-theme="light"] .panel,
body[data-theme="light"] .search-results {
  background: rgba(255, 255, 255, 0.95);
}

.stat-card {
  display: grid;
  gap: 12px;
  min-height: 124px;
  padding: 14px;
}

.stat-button {
  width: 100%;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.stat-button:hover {
  transform: translateY(-1px);
  border-color: rgba(56, 189, 248, 0.62);
  background: linear-gradient(135deg, rgba(41, 159, 232, 0.22), rgba(16, 27, 42, 0.92));
}

body[data-theme="light"] .stat-button:hover {
  background: linear-gradient(135deg, rgba(41, 159, 232, 0.14), rgba(255, 255, 255, 0.96));
}

.stat-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.stat-card strong {
  font-size: 25px;
  font-weight: 950;
}

.amount-positive {
  color: #45d483;
}

.amount-negative {
  color: #ff6767;
}

.panel {
  min-width: 0;
  padding: 15px;
  margin-bottom: 14px;
}

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

.home-charts .chart-panel {
  margin-bottom: 0;
}

.brand-chart-panel {
  grid-column: 1 / -1;
}

.chart-panel .panel-header {
  min-height: 46px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

h2, p { margin-top: 0; }
h2 { margin-bottom: 4px; font-size: 14px; font-weight: 900; }
.panel-header p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.45; }

.mask-icon {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  background: #d9ecff;
  mask: var(--icon) center / contain no-repeat;
  -webkit-mask: var(--icon) center / contain no-repeat;
}

body[data-theme="light"] .mask-icon {
  background: #4f6f91;
}

.primary-button, .secondary-button, .danger-button, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 11px;
  font-size: 11px;
  font-weight: 850;
}

.icon-action {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}

body[data-theme="light"] .icon-action {
  border-color: #b8cee3;
  background: #f7fbff;
}

.icon-action img {
  width: 17px;
  height: 17px;
  object-fit: contain;
  filter: invert(88%) sepia(14%) saturate(1007%) hue-rotate(176deg) brightness(105%) contrast(103%);
  pointer-events: none;
}

body[data-theme="light"] .icon-action img {
  filter: invert(44%) sepia(53%) saturate(1132%) hue-rotate(179deg) brightness(96%) contrast(91%);
}

.icon-action.danger {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.14);
}

body[data-theme="light"] .icon-action.danger {
  border-color: rgba(211, 59, 59, 0.42);
  background: rgba(211, 59, 59, 0.08);
}

.icon-action.danger img {
  filter: invert(53%) sepia(83%) saturate(2622%) hue-rotate(329deg) brightness(103%) contrast(91%);
}

.icon-action.refund {
  border-color: rgba(45, 212, 191, 0.58);
  background: rgba(20, 184, 166, 0.18);
  box-shadow: 0 0 16px rgba(20, 184, 166, 0.16);
}

.icon-action.refund img {
  filter: invert(80%) sepia(42%) saturate(760%) hue-rotate(122deg) brightness(98%) contrast(96%);
}

.icon-action:hover {
  border-color: rgba(124, 200, 255, 0.52);
  background: var(--panel-3);
}

body[data-theme="light"] .icon-action:hover {
  border-color: rgba(35, 134, 217, 0.48);
  background: #eef6ff;
}

.icon-action:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  background: rgba(7, 17, 29, 0.34);
}

.primary-button {
  border: 1px solid rgba(124, 200, 255, 0.52);
  background: linear-gradient(145deg, var(--blue), var(--blue-dark));
  box-shadow: 0 0 18px rgba(29, 155, 240, 0.22);
}

body[data-theme="light"] .primary-button {
  border-color: rgba(35, 134, 217, 0.52);
  background: linear-gradient(145deg, #3da1ee, #1d6fb0);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(35, 134, 217, 0.18);
}

body[data-theme="light"] .primary-button .mask-icon {
  background: #ffffff;
}

.secondary-button, .icon-button {
  border: 1px solid var(--line);
  background: var(--panel-2);
}

body[data-theme="light"] .secondary-button,
body[data-theme="light"] .icon-button {
  color: #27425f;
}

.danger-button {
  border: 1px solid rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.14);
  color: #ffd7d7;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.38);
}

body[data-theme="light"] .table-wrap {
  background: rgba(255, 255, 255, 0.96);
}

.table-wrap.table-scroll-8 {
  max-height: 520px;
  overflow-y: auto;
  overflow-x: auto;
}

.table-wrap.table-scroll-8 thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(17, 27, 42, 0.98);
  box-shadow: inset 0 -1px 0 var(--soft-line);
}

body[data-theme="light"] .table-wrap.table-scroll-8 thead th {
  background: #edf4fb;
  box-shadow: inset 0 -1px 0 rgba(115, 140, 168, 0.18);
}

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

#reports table {
  min-width: 0;
  table-layout: fixed;
}

#reports th,
#reports td {
  word-break: break-word;
  overflow-wrap: anywhere;
}

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

th {
  color: var(--muted);
  font-size: 10px;
  font-weight: 950;
}

body[data-theme="light"] th {
  color: #566d86;
}

td {
  font-size: 12px;
  font-weight: 650;
}

body[data-theme="light"] td {
  color: #1d3550;
}

body[data-theme="light"] tbody tr {
  background: rgba(255, 255, 255, 0.9);
}

body[data-theme="light"] tbody tr:nth-child(even) {
  background: rgba(247, 251, 255, 0.96);
}

.low-stock-text {
  color: #ff7a7a;
  font-weight: 950;
  text-shadow: 0 0 12px rgba(239, 68, 68, 0.22);
}

body[data-theme="light"] .low-stock-text,
body[data-theme="light"] .returned-invoice-id {
  color: #cf3d3d;
  text-shadow: none;
}

.returned-invoice-id {
  color: #ff6767;
  font-weight: 950;
  text-shadow: 0 0 12px rgba(239, 68, 68, 0.22);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  min-width: 24px;
  padding: 0 9px;
  line-height: 20px;
  border: 1px solid rgba(124, 200, 255, 0.28);
  border-radius: 999px;
  background: rgba(29, 155, 240, 0.13);
  color: #bfe5ff;
  font-size: 10px;
  font-weight: 900;
  vertical-align: middle;
  white-space: nowrap;
}

body[data-theme="light"] .badge {
  border-color: rgba(35, 134, 217, 0.28);
  background: rgba(35, 134, 217, 0.1);
  color: #245983;
}

.badge.green {
  border-color: rgba(50, 213, 131, 0.32);
  background: rgba(50, 213, 131, 0.12);
  color: #a7f3d0;
}

body[data-theme="light"] .badge.green {
  border-color: rgba(22, 143, 85, 0.3);
  background: rgba(22, 143, 85, 0.1);
  color: #177047;
}

.badge.warn {
  border-color: rgba(245, 158, 11, 0.34);
  background: rgba(245, 158, 11, 0.12);
  color: #fbd38d;
}

body[data-theme="light"] .badge.warn {
  border-color: rgba(201, 130, 5, 0.34);
  background: rgba(201, 130, 5, 0.1);
  color: #9d6100;
}

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

.header-tools {
  justify-content: flex-end;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}

.tab-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 11px;
  font-weight: 900;
}

.tab-button.active {
  border-color: rgba(124, 200, 255, 0.52);
  background: rgba(29, 155, 240, 0.16);
}

body[data-theme="light"] .tab-button.active {
  color: var(--blue-dark);
}

.bar-chart {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.38);
}

body[data-theme="light"] .bar-chart {
  background: rgba(238, 245, 253, 0.9);
}

.bar {
  display: grid;
  grid-template-columns: minmax(140px, 0.9fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(16, 27, 42, 0.82);
  color: var(--text);
  font-size: 12px;
  font-weight: 850;
  text-align: left;
}

body[data-theme="light"] .bar {
  background: rgba(255, 255, 255, 0.94);
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(124, 200, 255, 0.12);
}

body[data-theme="light"] .bar-track {
  background: rgba(35, 134, 217, 0.12);
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--blue-light));
  box-shadow: 0 0 18px rgba(29, 155, 240, 0.28);
}

.bar-value {
  color: #bfe5ff;
  font-size: 11px;
  font-weight: 950;
}

body[data-theme="light"] .bar-value {
  color: var(--blue-dark);
}

.compact-list {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.38);
}

body[data-theme="light"] .compact-list {
  background: rgba(238, 245, 253, 0.9);
}

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.38);
}

body[data-theme="light"] .list-row {
  background: rgba(255, 255, 255, 0.94);
}

.chart-list-row {
  display: block;
}

.chart-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.chart-row-copy {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.chart-row-copy strong,
.chart-row-copy span {
  margin-top: 0;
  display: inline-flex;
}

.chart-row-copy strong {
  flex: 0 1 auto;
}

.chart-row-copy span {
  flex: 0 1 auto;
  white-space: nowrap;
}

.list-row > div strong,
.list-row > div span { display: block; }
.list-row > div span { margin-top: 3px; color: var(--muted); font-size: 10px; }

.search-results {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
}

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

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

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(7, 17, 29, 0.68);
  color: var(--text);
}

body[data-theme="light"] .checkbox-line {
  background: #fbfdff;
}

.checkbox-line.disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.checkbox-line input {
  width: 16px;
  height: 16px;
  min-height: auto;
  accent-color: var(--blue);
}

.serial-feedback {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.serial-entry-note {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.5;
}

.purchase-serial-sections {
  display: grid;
  gap: 10px;
}

.purchase-serial-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.32);
}

body[data-theme="light"] .purchase-serial-panel {
  background: rgba(238, 245, 253, 0.78);
}

.purchase-serial-panel > strong {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.purchase-serial-panel textarea[readonly] {
  min-height: 88px;
  max-height: 150px;
  resize: vertical;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  opacity: 1;
  cursor: default;
}

body[data-theme="light"] .purchase-serial-panel textarea[readonly] {
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

.serial-counter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.serial-counter-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border: 1px solid rgba(124, 200, 255, 0.28);
  border-radius: 999px;
  background: rgba(29, 155, 240, 0.13);
  color: #bfe5ff;
  font-size: 10px;
  font-weight: 900;
}

body[data-theme="light"] .serial-counter-chip {
  color: var(--blue-dark);
}

.serial-counter-chip.warn {
  border-color: rgba(245, 158, 11, 0.34);
  background: rgba(245, 158, 11, 0.12);
  color: #fbd38d;
}

.serial-counter-chip.danger {
  border-color: rgba(239, 68, 68, 0.34);
  background: rgba(239, 68, 68, 0.12);
  color: #ffb4b4;
}

.serial-issues-list {
  display: grid;
  gap: 6px;
}

.serial-issue {
  min-height: 32px;
  padding: 8px 10px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.45);
  font-size: 11px;
  font-weight: 800;
}

.serial-issue.warn {
  border-color: rgba(245, 158, 11, 0.34);
  background: rgba(245, 158, 11, 0.12);
  color: #fbd38d;
}

.serial-issue.danger {
  border-color: rgba(239, 68, 68, 0.34);
  background: rgba(239, 68, 68, 0.12);
  color: #ffb4b4;
}

.small-button {
  min-height: 32px;
}

.invoice-lines {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.38);
}

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

.line-header strong {
  font-size: 12px;
}

.line-header .small-button {
  display: none;
}

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

.invoice-line {
  display: grid;
  grid-template-columns:
    minmax(0, 1.6fr)
    minmax(0, 1fr)
    minmax(0, 1fr)
    minmax(0, 1.45fr)
    34px
    34px;
  gap: 9px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(16, 27, 42, 0.72);
}

body[data-theme="light"] .invoice-line {
  background: rgba(255, 255, 255, 0.94);
}

.invoice-line > * {
  min-width: 0;
}

.invoice-line .line-product { grid-column: 1; grid-row: 1; }
.invoice-line .line-brand { grid-column: 2; grid-row: 1; }
.invoice-line .line-category { grid-column: 3; grid-row: 1; }
.invoice-line .line-model { grid-column: 4 / -1; grid-row: 1; }
.purchase-line .line-source { grid-column: 1; grid-row: 1; }
.purchase-line .line-existing { grid-column: 2 / -1; grid-row: 1; }
.purchase-line .line-product { grid-column: 1; grid-row: 2; }
.purchase-line .line-brand { grid-column: 2; grid-row: 2; }
.purchase-line .line-category { grid-column: 3; grid-row: 2; }
.purchase-line .line-model { grid-column: 4 / -1; grid-row: 2; }
.invoice-line .line-price { grid-column: 1; grid-row: 2; }
.invoice-line .line-qty { grid-column: 2; grid-row: 2; }
.invoice-line .line-sale-price { grid-column: 3; grid-row: 2; }
.invoice-line .line-min { grid-column: 4; grid-row: 2; }
.invoice-line .line-wide { grid-column: 1 / -1; grid-row: 3; }
.invoice-line .line-full { grid-column: 1 / -1; grid-row: 4; }
.invoice-line .line-wide[hidden] {
  display: none;
}
.invoice-line:not(.purchase-line) .line-full { grid-row: 3; }
.purchase-line .line-price { grid-column: 1; grid-row: 3; }
.purchase-line .line-qty { grid-column: 2; grid-row: 3; }
.purchase-line .line-sale-price { grid-column: 3; grid-row: 3; }
.purchase-line .line-min { grid-column: 4; grid-row: 3; }
.purchase-line .line-wide { grid-column: 1 / -1; grid-row: 4; }
.purchase-line .line-full { grid-column: 1 / -1; grid-row: 5; }
.invoice-line .line-add {
  grid-column: 5;
  grid-row: 2;
  align-self: end;
}
.invoice-line .line-remove {
  grid-column: 6;
  grid-row: 2;
  align-self: end;
}
.purchase-line .line-add,
.purchase-line .line-remove {
  grid-row: 3;
}

.icon-action.add-line {
  color: #dff4ff;
  border-color: rgba(56, 189, 248, 0.52);
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.3), rgba(14, 116, 144, 0.24));
  font-size: 20px;
  font-weight: 950;
  line-height: 1;
}

body[data-theme="light"] .icon-action.add-line {
  color: #ffffff;
  border-color: rgba(35, 134, 217, 0.48);
  background: linear-gradient(180deg, #5db7f4, #2a7fc0);
  box-shadow: 0 8px 18px rgba(35, 134, 217, 0.16);
}

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

.invoice-view-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.invoice-view-cell {
  min-height: 62px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.45);
}

body[data-theme="light"] .invoice-view-cell {
  background: rgba(247, 251, 255, 0.94);
}

.invoice-view-cell span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
}

.invoice-view-cell strong {
  color: var(--text);
  font-size: 13px;
}

.invoice-view-cell.full-span {
  grid-column: 1 / -1;
}

.invoice-view-total {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

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

.statement-filter-tabs {
  margin-bottom: 12px;
}

.statement-date-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.statement-date-row label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
}

.financial-summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: stretch;
}

.mini-stat {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.45);
}

.mini-stat span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
}

.mini-stat strong {
  color: var(--text);
  font-size: 18px;
  font-weight: 950;
}

.financial-section {
  display: grid;
  gap: 8px;
}

.financial-section h3 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
}

.link-button {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: #9bd1ff;
  font: inherit;
  font-weight: 900;
  text-align: left;
  cursor: pointer;
}

.link-button:hover {
  text-decoration: underline;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(330px, 0.85fr) minmax(0, 1.35fr);
  gap: 14px;
}

.control-grid.single {
  grid-template-columns: 1fr;
}

.permissions-grid, .backup-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

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

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

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

.permission-card, .backup-card, .backup-info-card {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.38);
  text-align: left;
}

body[data-theme="light"] .permission-card,
body[data-theme="light"] .backup-card,
body[data-theme="light"] .backup-info-card {
  background: rgba(247, 251, 255, 0.94);
}

.permission-card strong, .backup-card strong, .backup-card span, .backup-info-card strong, .backup-info-card span {
  display: block;
}

.backup-card:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

html[dir="rtl"] .backup-card:disabled {
  text-align: right;
}

.permission-card label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  font-size: 11px;
}

.permission-card input {
  width: 16px;
  height: 16px;
  min-height: auto;
  accent-color: var(--blue);
}

.backup-card span {
  color: var(--muted);
  font-size: 10px;
}

.backup-info-card small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.backup-info-card strong {
  color: var(--text);
  font-size: 15px;
}

.backup-file-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.backup-file-actions .icon-action {
  width: 32px;
  height: 32px;
}

.backup-tabs {
  margin-top: 12px;
  margin-bottom: 0;
}

.reset-panel {
  border-color: rgba(239, 68, 68, 0.42);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.12), rgba(16, 27, 42, 0.9));
}

body[data-theme="light"] .reset-panel {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.08), rgba(255, 255, 255, 0.96));
}

.reset-row {
  display: grid;
  gap: 10px;
}

.reset-password {
  max-width: 360px;
}

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

.reset-options .checkbox-line {
  justify-content: flex-start;
}

.reset-options .checkbox-line.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

dialog {
  width: min(820px, calc(100vw - 26px));
  max-height: calc(100vh - 28px);
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1a28;
  color: var(--text);
  box-shadow: var(--shadow);
}

body[data-theme="light"] dialog {
  background: #ffffff;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
}

.large-modal {
  width: min(820px, calc(100vw - 26px));
}

.compact-modal {
  width: min(760px, calc(100vw - 26px));
}

#contactForm {
  align-content: start;
}

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

#saleModal .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.print-preview {
  margin-top: 14px;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  color: #102033;
  direction: ltr;
  text-align: left;
}

.print-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.print-head img {
  width: 64px;
  height: 64px;
  object-fit: cover;
}

.print-head h2 {
  margin: 0;
  font-size: 28px;
}

.print-head p {
  margin: 4px 0;
  color: #475569;
}

.print-items {
  margin-top: 18px;
  border-top: 1px solid #d7dee8;
  border-bottom: 1px solid #d7dee8;
  padding: 12px 0;
  overflow-x: auto;
}

.thanks {
  margin: 28px 0 0;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
}

.print-dialog {
  width: min(980px, calc(100vw - 24px));
  padding: 0;
  background: transparent;
  border: 0;
}

.print-shell {
  display: grid;
  gap: 12px;
}

.print-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.system-print-page {
  min-height: 1123px;
  padding: 60px 53px 45px;
  background: #ffffff;
  color: #22252a;
  border: 0;
  box-shadow: 0 18px 48px rgba(20, 25, 34, 0.18);
  font-family: Arial, Helvetica, sans-serif;
  direction: ltr;
  text-align: left;
}

.print-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 2px solid #303238;
}

.print-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.print-brand img {
  width: 70px;
  height: 70px;
  object-fit: contain;
}

.print-brand strong {
  display: block;
  margin: 0 0 6px;
  color: #303238;
  font-size: 26px;
  line-height: 1;
}

.print-brand span {
  display: block;
  color: #6b7280;
  font-size: 11px;
  line-height: 1.55;
}

.print-doc-title {
  min-width: 190px;
  text-align: right;
}

.print-doc-title p {
  margin: 0 0 8px;
  color: #6b7280;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.print-doc-title strong {
  color: #303238;
  font-size: 24px;
  line-height: 1;
}

.print-blue-rule {
  display: none;
}

.print-summary-grid {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 14px;
  align-items: start;
  margin: 18px 0 0;
}

.print-summary-card {
  padding: 14px 16px;
  border: 1px solid #d8dde5;
  background: #fff;
}

.print-summary-card span {
  display: block;
  margin-bottom: 9px;
  color: #303238;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.print-summary-card strong {
  display: block;
  color: #22252a;
  font-size: 22px;
  line-height: 1.1;
}

.print-summary-card p {
  margin: 9px 0 0;
  color: #6b7280;
  font-size: 12px;
}

.print-meta {
  padding: 0;
  border: 1px solid #d8dde5;
}

.print-meta-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 0;
  min-height: 32px;
  border-bottom: 1px solid #d8dde5;
}

.print-meta-row span {
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: #6b7280;
  font-size: 11px;
}

.print-meta-row strong {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;
  color: #22252a;
  font-size: 11px;
}

.print-table {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin-top: 18px;
  table-layout: fixed;
  border-collapse: collapse;
  border: 1px solid #d8dde5;
  font-size: 10px;
}

.print-col-item { width: 31%; }
.print-col-brand { width: 15%; }
.print-col-model { width: 23%; }
.print-col-qty { width: 7%; }
.print-col-price { width: 12%; }
.print-col-total { width: 12%; }

.print-table th {
  padding: 8px 7px;
  border-bottom: 0;
  background: #303238;
  color: #ffffff;
  text-align: left;
  font-size: 9px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.print-table td {
  padding: 9px 7px;
  border-bottom: 0;
  border-left: 1px solid #d8dde5;
  border-top: 1px solid #d8dde5;
  color: #22252a;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: normal;
}

.print-table td:first-child,
.print-table th:first-child {
  border-left: 0;
}

.print-table small {
  display: block;
  margin-top: 4px;
  color: #6b7280;
  font-size: 9px;
  line-height: 1.35;
}

.print-num {
  text-align: right;
  white-space: normal;
}

.print-table .print-num {
  overflow-wrap: normal;
  word-break: keep-all;
}

.print-bottom-grid {
  display: block;
  margin-top: 16px;
}

.print-totals-box {
  display: grid;
  align-content: start;
  width: 100%;
  border: 1px solid #d8dde5;
  background: #fff;
}

.print-totals-box div {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 0;
  align-items: center;
  min-height: 34px;
  padding: 0;
  border-bottom: 1px solid #d8dde5;
}

.print-totals-box div:last-child {
  border-bottom: 0;
}

.print-totals-box span {
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: #303238;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.print-totals-box strong {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 14px;
  border-left: 1px solid #d8dde5;
  color: #22252a;
  font-size: 11px;
  font-weight: 900;
}

.print-totals-box .important {
  min-height: 48px;
  border-left: 0;
  background: #f4f5f7;
}

.print-totals-box .important strong {
  font-size: 22px;
}

.print-footer {
  display: grid;
  gap: 5px;
  margin-top: 22px;
  padding-top: 12px;
  border-top: 1px solid #d8dde5;
  color: #303238;
  text-align: center;
  font-size: 13px;
  font-weight: 900;
}

.print-footer span {
  color: #6b7280;
  font-size: 12px;
  font-weight: 700;
}

.print-only-page {
  position: fixed;
  top: 0;
  left: -12000px;
  width: 794px;
  pointer-events: none;
  visibility: hidden;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 0;
    background: #fff;
  }

  body * {
    visibility: hidden;
  }
  .print-actions {
    display: none;
  }
  #printOnlyPreview,
  #printOnlyPreview * {
    visibility: visible;
  }
  #printOnlyPreview {
    position: absolute;
    inset: 0 auto auto 0;
    width: 210mm;
    min-height: 297mm;
    pointer-events: auto;
  }
  .system-print-page {
    min-height: 297mm;
    width: 210mm;
    padding: 16mm 14mm 12mm;
    border: 0;
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .print-table {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }
}

.empty-state {
  min-height: 220px;
  display: grid;
  align-content: center;
}

.danger-badge {
  color: #ffb4b4;
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.5);
}

body[data-theme="light"] .danger-badge {
  color: #9f2f2f;
  background: rgba(211, 59, 59, 0.1);
  border-color: rgba(211, 59, 59, 0.34);
}

.danger-text {
  color: #ff7373;
}

body[data-theme="light"] .danger-text {
  color: #c23838;
}

.report-total-row td {
  color: var(--text);
  background: rgba(41, 159, 232, 0.12);
  font-weight: 900;
}

.toast {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 40;
  transform: translateY(16px);
  opacity: 0;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1a28;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  font-weight: 850;
  pointer-events: none;
  transition: 180ms ease;
}

body[data-theme="light"] .toast {
  border-color: #c0d5e8;
  background: rgba(255, 255, 255, 0.98);
  color: #20364f;
  box-shadow: 0 18px 40px rgba(20, 48, 78, 0.16);
}

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

@media (max-width: 1180px) {
  .stats-grid, .control-grid, .permissions-grid, .backup-grid, .backup-status-grid {
    grid-template-columns: 1fr 1fr;
  }
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .app-header {
    flex-wrap: wrap;
    gap: 8px;
    min-height: auto;
    padding: 10px;
  }
  .brand-copy, .profile-copy {
    display: none;
  }
  .primary-nav {
    order: 3;
    width: 100%;
  }
  .nav-button {
    min-height: 35px;
    padding: 0 10px;
    font-size: 11px;
  }
  .workspace {
    padding: 10px;
  }
  .hero-strip, .stats-grid, .control-grid, .permissions-grid, .backup-grid, .backup-status-grid, .form-grid, .report-grid, .financial-summary-strip {
    display: grid;
    grid-template-columns: 1fr;
  }
  .home-charts {
    grid-template-columns: 1fr;
  }
  dialog .form-grid,
  #saleModal .form-grid {
    grid-template-columns: 1fr;
  }
  .invoice-line {
    grid-template-columns: 1fr 34px;
  }
  .invoice-line .line-product,
  .invoice-line .line-source,
  .invoice-line .line-existing,
  .invoice-line .line-brand,
  .invoice-line .line-category,
  .invoice-line .line-model,
  .invoice-line .line-price,
  .invoice-line .line-qty,
  .invoice-line .line-sale-price,
  .invoice-line .line-min,
  .invoice-line .line-wide,
  .invoice-line .line-full {
    grid-column: 1 / -2;
    grid-row: auto;
  }
  .invoice-line .line-add {
    grid-column: 2;
    grid-row: auto;
  }
  .invoice-line .line-remove {
    grid-column: 2;
    grid-row: auto;
  }
  .search-box, .search-box.compact {
    width: 100%;
  }
  .bar-chart {
    grid-template-columns: 1fr;
  }
  .bar {
    grid-template-columns: 1fr;
    min-height: 58px;
  }
  .reset-row {
    display: grid;
  }
  .reset-options {
    grid-template-columns: 1fr;
  }
}
