:root {
  --color-primary: #f28a22;
  --color-primary-contrast: #ffffff;
  --color-bg: #fffaf5;
  --color-surface: rgba(255, 255, 255, 0.78);
  --color-text: #30271f;
  --color-muted: #897c70;
  --color-border: rgba(225, 157, 98, 0.2);
  --color-shadow: rgba(123, 74, 32, 0.12);
  --color-glow: rgba(255, 159, 67, 0.2);
  --color-scrollbar: #efc49e;
  --color-soft: rgba(255, 238, 220, 0.82);
  --font-sans: sans-serif;
  --font-heading: var(--font-sans);
  --font-body: var(--font-sans);
  --radius: 18px;

  --tone-slate-50: #fffdfb;
  --tone-slate-100: #fff7ef;
  --tone-slate-200: #f4e7da;
  --tone-slate-400: #b7a697;
  --tone-slate-500: #897c70;
  --tone-slate-600: #6f6258;
  --tone-slate-700: #51463e;
  --tone-slate-900: #30271f;
  --tone-orange-50: #fff6ec;
  --tone-orange-100: #ffebd6;
  --tone-orange-200: #ffd6ad;
  --tone-orange-600: #e87516;
  --tone-orange-700: #c45b0c;
  --tone-blue-50: #eff7ff;
  --tone-blue-100: #dceeff;
  --tone-blue-600: #3276b8;
  --tone-blue-700: #285f96;
  --tone-blue-800: #204b76;
  --tone-green-50: #effaf4;
  --tone-green-500: #35a873;
  --tone-green-600: #24885a;
  --tone-green-700: #1c7049;
  --tone-red-50: #fff2f0;
  --tone-red-500: #e76a58;
  --tone-red-600: #cb4e3d;
  --tone-amber-50: #fff8e8;
  --tone-amber-700: #9b6714;
  --tone-violet-50: #f7f2ff;
  --tone-violet-600: #7952b3;
}

* {
  box-sizing: border-box;
}

#appMain,
#pageContent {
  min-width: 0;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 8% 4%, var(--color-glow), transparent 34rem),
    radial-gradient(ellipse at 92% 15%, rgba(255, 219, 181, 0.28), transparent 32rem),
    linear-gradient(135deg, var(--color-bg), #fff 54%, #fff5e9);
  color: var(--color-text);
  font-family: var(--font-body);
}

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

h1,
h2,
h3,
button,
input,
select,
textarea {
  font-family: var(--font-body);
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 800;
  letter-spacing: -0.025em;
}

.terminal-shell .scan-title {
  font-family: var(--font-heading);
  font-weight: 800;
  letter-spacing: -0.035em;
}

.terminal-shell .phase-name,
.terminal-shell #feedback {
  font-family: var(--font-heading);
}

button {
  cursor: pointer;
}

.page-shell {
  min-height: 100vh;
}

.login-glow {
  background: radial-gradient(circle, var(--color-glow) 0, rgba(255, 225, 195, 0.16) 38%, transparent 72%);
  filter: blur(12px);
}

#loginScreen>section {
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-top: 3px solid var(--color-primary);
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 28px 80px var(--color-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

#sidebar,
#appScreen header {
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 30px rgba(123, 74, 32, 0.045);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

#pieceworkHistorySearch {
  border: 1px solid rgba(255, 255, 255, 0.96);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.88), rgba(255, 238, 220, 0.56));
  color: var(--color-text);
  box-shadow:
    0 8px 18px rgba(123, 74, 32, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.98),
    inset 0 -2px 4px rgba(194, 124, 66, 0.08);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

#pieceworkHistorySearch:hover {
  transform: translateY(-1px);
  box-shadow:
    0 11px 22px rgba(123, 74, 32, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 1),
    inset 0 -2px 4px rgba(194, 124, 66, 0.1);
}

#pieceworkHistorySearch:focus {
  border-color: rgba(242, 138, 34, 0.72);
  outline: none;
  box-shadow:
    0 0 0 3px rgba(242, 138, 34, 0.16),
    0 10px 20px rgba(123, 74, 32, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 1);
}

#pageContent .metric-card,
#pageContent section,
#pageContent article {
  box-shadow: 0 12px 34px rgba(123, 74, 32, 0.055), inset 0 1px 0 rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#pageContent .metric-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 42px rgba(123, 74, 32, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.summary-card-grid {
  align-items: stretch;
}

.summary-card {
  min-height: 68px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow-wrap: anywhere;
  box-shadow: 0 6px 18px rgba(123, 74, 32, 0.045), inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.summary-card-label {
  line-height: 1.25;
}

.summary-card-value {
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.purchase-metric-grid {
  align-items: stretch;
}

.purchase-metric-card {
  min-height: 68px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow-wrap: anywhere;
  box-shadow: 0 6px 18px rgba(123, 74, 32, 0.045), inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

@media (max-width: 640px) {
  .summary-card {
    min-height: 62px;
  }

  .summary-card-value {
    font-size: 1rem;
  }

  .purchase-metric-card {
    min-height: 64px;
  }
}

.sidebar {
  transition: transform 0.25s ease;
}

.sidebar.is-collapsed {
  transform: translateX(-100%);
}

.sidebar-reveal-zone {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 39;
  width: 14px;
}

.app-main {
  transition: padding-left 0.25s ease;
}

.app-main.sidebar-collapsed {
  padding-left: 0;
}

.nav-section-chevron {
  display: inline-block;
  font-size: 15px;
  line-height: 1;
  transition: transform 0.18s ease;
}

.nav-section-chevron.expanded {
  transform: rotate(180deg);
}

.nav-section {
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.88);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.68), rgba(255, 247, 237, 0.42));
  box-shadow: 0 6px 18px rgba(123, 74, 32, 0.055), inset 0 1px 0 rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.nav-section-toggle {
  min-height: 42px;
  background: rgba(255, 255, 255, 0.22);
}

.nav-section-toggle:hover {
  background: rgba(255, 255, 255, 0.62);
}

.nav-section-content {
  padding: 0.35rem;
  border-top: 1px solid rgba(225, 157, 98, 0.14);
  background: rgba(255, 255, 255, 0.24);
}

.nav-section-content > button {
  border: 1px solid transparent;
  border-radius: 10px;
}

.nav-section-content > button:hover,
.nav-section-content > button.active,
.nav-section-content > button[aria-current="page"] {
  border-color: rgba(225, 157, 98, 0.18);
  background: rgba(255, 238, 220, 0.72);
  color: var(--color-primary);
}

.auto-hide-toggle.active {
  border-color: var(--color-primary);
  background: var(--color-soft);
  color: var(--color-primary);
}

.nav-item {
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

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

.nav-item:hover {
  transform: translateX(2px);
}

.report-table-scroll,
.customer-sales-summary-table-wrap {
  max-width: 100%;
  max-height: 70vh;
  overflow-y: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.report-table-scroll thead,
.customer-sales-summary-table-wrap thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

#reportBody table th,
#reportBody table td {
  border: 1px solid rgba(123, 74, 32, 0.28);
}

#reportBody table.item-out-report-table tbody tr.item-out-transaction-start > td {
  border-top: 2px solid rgba(123, 74, 32, 0.72);
}

#reportBody table.item-out-report-table tbody tr.item-out-transaction-end > td {
  border-bottom: 2px solid rgba(123, 74, 32, 0.72);
}

.report-table th,
.report-table td {
  border: 1px solid rgba(123, 74, 32, 0.28);
}

#reportBody table thead th,
.report-table thead th {
  text-align: center;
}

.report-table.payroll-report-table {
  min-width: 0;
  table-layout: fixed;
}

.payroll-report-table th,
.payroll-report-table td {
  vertical-align: middle;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.report-table.report-sales-detail-table {
  min-width: 1360px;
  table-layout: fixed;
}

.report-sales-detail-table th:nth-child(1),
.report-sales-detail-table td:nth-child(1) {
  width: 9%;
}

.report-sales-detail-table th:nth-child(2),
.report-sales-detail-table td:nth-child(2),
.report-sales-detail-table th:nth-child(3),
.report-sales-detail-table td:nth-child(3) {
  width: 10%;
}

.report-sales-detail-table th:nth-child(4),
.report-sales-detail-table td:nth-child(4) {
  width: 8%;
}

.report-sales-detail-table th:nth-child(5),
.report-sales-detail-table td:nth-child(5) {
  width: 9%;
}

.report-sales-detail-table th:nth-child(6),
.report-sales-detail-table td:nth-child(6) {
  width: 23%;
}

.report-sales-detail-table th:nth-child(7),
.report-sales-detail-table td:nth-child(7) {
  width: 9%;
}

.report-sales-detail-table th:nth-child(8),
.report-sales-detail-table td:nth-child(8) {
  width: 7%;
}

.report-sales-detail-table th:nth-child(9),
.report-sales-detail-table td:nth-child(9) {
  width: 8%;
}

.report-sales-detail-table th:nth-child(10),
.report-sales-detail-table td:nth-child(10) {
  width: 7%;
}

.report-sales-detail-table td:nth-child(6) {
  overflow-wrap: anywhere;
}

.report-sales-detail-table tbody td {
  border-right: 1px solid rgba(123, 74, 32, 0.14);
  border-bottom: 2px solid rgba(123, 74, 32, 0.32);
  vertical-align: top !important;
}

.report-sales-detail-table tbody td:last-child {
  border-right: 0;
}

.report-sales-detail-table thead th {
  border-bottom: 2px solid rgba(123, 74, 32, 0.42);
}

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

.customer-sales-summary .sale-items-table {
  min-width: 640px;
}

.report-column-resize-handle {
  position: absolute;
  top: 0;
  right: -6px;
  z-index: 2;
  width: 12px;
  height: 100%;
  min-height: 28px;
  cursor: col-resize;
  touch-action: none;
}

.report-column-resize-cell {
  position: relative;
}

.report-column-resize-handle::after {
  position: absolute;
  top: 50%;
  left: 50%;
  color: var(--color-muted);
  content: "↔";
  font-size: 0.75rem;
  line-height: 1;
  opacity: 0.6;
  transform: translate(-50%, -50%);
}

.report-column-resize-handle:hover::after,
.report-column-resize-handle:focus-visible::after {
  color: var(--color-primary);
  opacity: 1;
}

.sale-items-table .sale-item-number {
  white-space: nowrap;
  text-align: right;
}

.sale-items-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: 0.75rem;
  line-height: 1.35;
}

.sale-items-inline {
  min-width: 0;
  font-size: 0.7rem;
  line-height: 1.3;
}

.sale-items-table th,
.sale-items-table td {
  padding: 0.35rem 0.45rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.sale-items-table th {
  color: var(--color-muted);
  font-size: 0.625rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.sale-items-table th:first-child {
  width: 40%;
}

.sale-items-table th:not(:first-child) {
  width: 20%;
  text-align: right;
}

.customer-sales-summary .sale-items-table th:not(:first-child) {
  width: 20%;
}

.sale-item-code {
  display: block;
  color: var(--color-muted);
  font-size: 0.625rem;
}

.sale-item-entry {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--color-border);
}

.sale-item-entry:first-child {
  padding-top: 0;
}

.sale-item-entry:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.sale-item-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.sale-item-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.sale-item-total {
  flex: none;
  white-space: nowrap;
  text-align: right;
}

.sale-item-meta {
  margin-top: 0.15rem;
  color: var(--color-muted);
  font-size: 0.625rem;
}

.customer-sales-summary {
  margin-top: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.customer-sales-summary h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 700;
}

.customer-sales-summary-note,
.customer-sales-summary-entry > p {
  margin: 0 0 0.5rem;
  color: var(--color-muted);
  font-size: 0.75rem;
}

.customer-sales-summary-entry {
  margin-top: 0.85rem;
}

.customer-sales-summary-entry h4 {
  margin: 0 0 0.25rem;
  font-size: 0.875rem;
  font-weight: 700;
}

.metric-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--color-scrollbar);
  border-radius: var(--radius);
}

.pos-receipt-modal {
  align-items: flex-start;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pos-receipt {
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.receipt-jpg-viewer {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  overflow: auto;
  padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  background: #f3f4f6;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.receipt-jpg-viewer-close {
  position: sticky;
  top: 0;
  z-index: 1;
  align-self: flex-end;
  flex: none;
  min-height: 2.75rem;
  padding: 0.65rem 1rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 700;
}

.receipt-jpg-viewer img {
  display: block;
  flex: none;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  background: #fff;
  object-fit: contain;
}

@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.is-collapsed {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-reveal-zone {
    display: none;
  }

  .app-main.sidebar-collapsed {
    padding-left: 0;
  }
}

@media (prefers-reduced-transparency: reduce) {
  :root {
    --color-surface: #ffffff;
  }

  #loginScreen>section,
  #sidebar,
  #appScreen header,
  #pageContent .metric-card,
  #pageContent section,
  #pageContent article {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media print {
  @page {
    size: auto;
    margin: 0;
  }

  html,
  body {
    width: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body > :not(.pos-receipt-modal) {
    display: none !important;
  }

  .pos-receipt-modal {
    position: static !important;
    display: block !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important;
    background: transparent !important;
  }

  .pos-receipt {
    position: relative !important;
    width: var(--receipt-width, 58mm) !important;
    max-width: var(--receipt-width, 58mm) !important;
    max-height: none !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: var(--receipt-padding, 3mm) !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    font-family: Arial, sans-serif !important;
    font-size: var(--receipt-font-size, 12px) !important;
    line-height: var(--receipt-line-height, 1.25) !important;
    backdrop-filter: none !important;
  }

  .pos-receipt .receipt-meta,
  .pos-receipt .receipt-items,
  .pos-receipt .receipt-totals {
    font-size: inherit !important;
    line-height: inherit !important;
  }

  .receipt-actions,
  .receipt-jpg-status,
  .receipt-jpg-preview {
    display: none !important;
  }

  .receipt-meta > div,
  .receipt-item,
  .receipt-totals > div {
    display: flex;
    justify-content: space-between;
    gap: 2mm;
    margin-block: 1.5mm;
  }

  .receipt-destination strong {
    max-width: 65%;
    text-align: right;
    overflow-wrap: anywhere;
  }

  .receipt-items {
    display: block;
  }

  .receipt-item {
    display: block;
    margin-block: 2mm;
  }

  .receipt-item-name {
    display: block;
  }

  .receipt-item-details {
    display: block;
    text-align: left;
    font-size: 0.9em;
  }

  .receipt-item-calculation {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2mm;
    width: 100%;
    text-align: left;
    overflow-wrap: anywhere;
  }

  .receipt-item-unit-calculation {
    min-width: 0;
  }

  .receipt-item-line-total {
    flex: 0 0 auto;
    white-space: nowrap;
    text-align: right;
  }

  .receipt-total,
  .receipt-balance {
    border-top: 1px dashed #000;
    padding-top: 2mm;
    font-size: 1.1em;
  }

  .receipt-footer {
    border-top: 1px dashed #000;
    padding-top: 3mm;
  }
}

.receipt-logo {
  display: block;
  max-width: 30mm;
  max-height: 18mm;
  margin: 0 auto 2mm;
  object-fit: contain;
}

.receipt-details {
  margin-top: 1mm;
  white-space: normal;
  overflow-wrap: anywhere;
}
