:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f0f4f7;
  --border: #d8e0e7;
  --text: #18212b;
  --muted: #657282;
  --primary: #0f8f65;
  --primary-dark: #0a6f50;
  --danger: #c13b35;
  --sidebar: #20262d;
  --sidebar-soft: #2c343d;
  --shadow: 0 12px 30px rgba(24, 33, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  text-align: right;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

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

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 143, 101, 0.14);
}

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

label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  background: var(--sidebar);
  color: #fff;
  padding: 20px;
}

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

.sidebar-brand span,
.eyebrow,
.panel-heading p,
.stat-card span {
  color: var(--muted);
}

.sidebar-brand span {
  display: block;
  margin-top: 2px;
  color: #aeb8c2;
  font-size: 12px;
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-mark.small {
  width: 42px;
  height: 42px;
  font-size: 13px;
}

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

.nav-item,
.ghost {
  width: 100%;
  background: transparent;
  color: #dfe6ed;
  padding: 12px;
  text-align: right;
}

.nav-item:hover,
.nav-item.active {
  background: var(--sidebar-soft);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.user-pill {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 10px 12px;
  color: #dfe6ed;
}

.ghost {
  border: 1px solid rgba(255, 255, 255, 0.14);
  text-align: center;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h2,
.panel h3,
.login-card h1 {
  margin: 0;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions,
.toolbar,
.panel-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-dot {
  min-height: 34px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 800;
}

.status-dot.ok {
  background: #e1f5ed;
  color: var(--primary-dark);
}

.status-dot.error {
  background: #fae7e5;
  color: var(--danger);
}

.pane {
  min-width: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.stat-card,
.panel,
.login-card,
.modal-content {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 16px;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.dashboard-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.dashboard-controls p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.dashboard-date-toolbar {
  margin: 0;
  flex: 0 1 520px;
}

.dashboard-date-toolbar input {
  min-width: 150px;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 14px;
  margin-bottom: 14px;
}

.chart-panel {
  min-height: 330px;
}

.chart-panel:first-child {
  grid-row: span 2;
}

.chart-box {
  min-height: 230px;
}

.line-chart {
  display: block;
  width: 100%;
  min-height: 230px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.bar-chart {
  display: grid;
  gap: 13px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(96px, 150px) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.bar-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.bar-row strong {
  font-size: 13px;
  white-space: nowrap;
}

.chart-empty {
  display: grid;
  min-height: 210px;
  place-items: center;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
}

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

.panel {
  min-width: 0;
  padding: 16px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

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

.panel-heading p {
  margin: 4px 0 0;
  font-size: 13px;
}

.compact-panel {
  align-self: start;
  display: grid;
  gap: 10px;
}

.quick-action {
  width: 100%;
  background: var(--surface-soft);
  color: var(--text);
  padding: 12px;
  text-align: right;
}

.quick-action:hover,
.secondary:hover {
  background: #e7edf2;
}

.primary,
.secondary,
.danger {
  min-height: 42px;
  padding: 0 16px;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

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

.primary:hover {
  background: var(--primary-dark);
}

.secondary {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.danger {
  background: #fae7e5;
  color: var(--danger);
}

.full {
  width: 100%;
}

.sales-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(320px, 430px);
  gap: 14px;
  align-items: start;
}

.sales-side {
  display: grid;
  gap: 14px;
}

.checkout-panel {
  min-height: calc(100vh - 112px);
}

.toolbar {
  margin-bottom: 14px;
}

.sales-toolbar {
  align-items: stretch;
}

.sales-toolbar input,
.sales-toolbar select {
  min-width: 0;
}

.sales-toolbar input {
  flex: 1.15 1 220px;
}

.sales-toolbar select {
  flex: 1 1 180px;
}

.toolbar.single {
  align-items: stretch;
}

.toolbar.single button {
  width: 120px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

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

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

tbody tr:hover td {
  background: #fbfcfd;
}

.sale-table-wrap {
  min-height: 280px;
}

#saleTable input {
  width: 82px;
}

.line-type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.line-type-badge.sale {
  background: #e4f4ec;
  color: var(--primary-dark);
}

.line-type-badge.return {
  background: #fae7e5;
  color: var(--danger);
}

.return-sale-line td {
  background: #fff9f8;
}

.muted-cell {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sale-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 210px);
  gap: 12px;
  align-items: stretch;
  margin-top: 16px;
}

.sale-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 8px;
  background: #17201c;
  color: #fff;
  padding: 16px;
}

.sale-footer .sale-summary {
  margin-top: 0;
}

.sale-footer #btnPay {
  min-height: 100%;
  font-size: 18px;
}

.sale-summary span {
  color: #b9c4be;
  font-weight: 800;
}

.sale-summary strong {
  font-size: 30px;
}

.return-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.return-meta span {
  min-height: 30px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
}

.return-items-table input {
  min-width: 96px;
}

.return-summary {
  margin-bottom: 0;
}

.return-empty {
  margin-top: 12px;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 30px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

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

.held-invoice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.held-invoice-main {
  min-width: 0;
}

.held-invoice-main strong,
.held-invoice-main span {
  display: block;
}

.held-invoice-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.held-invoice-main span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.held-invoice-total {
  font-weight: 900;
}

.held-invoice-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.held-empty {
  min-height: 96px;
}

.product-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 245px);
  overflow: auto;
  padding-left: 2px;
}

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

.product-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.product-row strong,
.product-row span {
  display: block;
}

.product-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.money {
  font-weight: 900;
  white-space: nowrap;
}

.event-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
}

.event-badge.sale {
  background: #e1f5ed;
  color: var(--primary-dark);
}

.event-badge.purchase {
  background: #e8effd;
  color: #2f6fed;
}

.muted-line {
  margin: 0 0 14px;
  color: var(--muted);
}

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

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

.report-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.report-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.report-heading h4 {
  margin: 0;
}

.report-heading span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.empty-cell {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.pagination-size,
.pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-size {
  margin: 0;
  color: var(--muted);
}

.pagination-size select {
  width: auto;
  min-width: 86px;
  min-height: 34px;
}

.pagination-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.settings-panel {
  max-width: 620px;
}

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

.form-grid label {
  margin: 0;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 14px;
  margin-bottom: 0;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.switch-row input {
  width: auto;
  min-height: auto;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px 14px;
  min-width: 420px;
}

.permission-toggle {
  font-size: 13px;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #eef3f6, #f8fafb);
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  padding: 24px;
}

.login-card p {
  margin: 8px 0 18px;
  color: var(--muted);
}

.message {
  min-height: 22px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(24, 33, 43, 0.52);
  padding: 18px;
}

.modal-content {
  width: min(460px, 100%);
  padding: 18px;
}

.modal-wide {
  width: min(760px, 100%);
}

.icon-button {
  width: 34px;
  height: 34px;
  background: var(--surface-soft);
  color: var(--text);
}

.toast {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 40;
  max-width: 360px;
  border-radius: 8px;
  background: #17201c;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

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

  .sidebar {
    padding: 14px;
  }

  .sidebar-brand div:not(.brand-mark),
  .nav-item,
  .user-pill,
  .ghost {
    font-size: 0;
  }

  .nav-item::first-letter,
  .ghost::first-letter {
    font-size: 14px;
  }

  .content-grid,
  .sales-layout,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-panel:first-child {
    grid-row: auto;
  }

  .checkout-panel {
    min-height: auto;
  }

  .product-list {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: block;
    padding: 12px;
  }

  .sidebar-brand,
  .sidebar-footer {
    display: none;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    font-size: 13px;
    white-space: nowrap;
  }

  .workspace {
    padding: 14px;
  }

  .topbar,
  .toolbar,
  .panel-heading,
  .dashboard-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-actions {
    justify-content: stretch;
  }

  .panel-actions button,
  .held-invoice-actions button {
    flex: 1 1 110px;
  }

  .sales-toolbar,
  .sale-footer {
    grid-template-columns: 1fr;
  }

  .sale-footer #btnPay {
    min-height: 48px;
  }

  .dashboard-date-toolbar {
    flex: none;
  }

  .topbar-actions {
    justify-content: stretch;
  }

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

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

  .toolbar.single button,
  .topbar-actions button,
  .dashboard-date-toolbar button {
    width: 100%;
  }

  .pagination-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-actions {
    justify-content: stretch;
  }

  .pagination-actions button {
    flex: 1 1 110px;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}
