* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f7;
  color: #222;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: #1f2937;
  color: #fff;
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.store-logo img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
}

.store-name {
  margin: 0;
}

.store-address,
.store-contact {
  margin: 0;
  font-size: 0.85rem;
}

.app-nav a {
  color: #e5e7eb;
  margin-left: 1rem;
  text-decoration: none;
  font-weight: 500;
}

.app-nav a:hover {
  text-decoration: underline;
}

.app-main {
  max-width: 980px;
  margin: 1.5rem auto;
  padding: 0 1rem 2rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.page-header h2 {
  margin: 0;
}

.page {
  background: #fff;
  padding: 1.25rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
}

.table th,
.table td {
  border: 1px solid #e5e7eb;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
}

.table th {
  background: #f3f4f6;
  text-align: left;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.8rem;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #111827;
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.btn.small {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
}

.btn.danger {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.btn:hover {
  filter: brightness(0.96);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.form input,
.form textarea,
.form select {
  padding: 0.4rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
}

.flash-container {
  margin-bottom: 0.75rem;
}

.flash {
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.flash-success {
  background: #ecfdf3;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.flash-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.items-table input[type='number'] {
  width: 100%;
}

.line-total {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.totals-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  margin-top: 1.25rem;
}

.totals-box {
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  padding: 0.75rem 0.9rem;
  background: #f9fafb;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.totals-row.grand-total {
  margin-top: 0.5rem;
  font-weight: 600;
  border-top: 1px solid #e5e7eb;
  padding-top: 0.4rem;
}

.invoice-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.invoice-footer {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.9rem;
  color: #6b7280;
}

/* Table row hover state for better scanability */
.table tbody tr:hover {
  background: #f9fafb;
}

/* Utility alignment */
.text-right {
  text-align: right;
}

/* Badges (used for payment mode, statuses, etc.) */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-payment-cash {
  background: #ecfdf3;
  color: #166534;
}

.badge-payment-upi {
  background: #eff6ff;
  color: #1d4ed8;
}

.badge-payment-credit {
  background: #fef3c7;
  color: #92400e;
}

.badge-payment-other {
  background: #e5e7eb;
  color: #374151;
}

/* Invoice view tweaks */
.page.invoice-view h3 {
  margin-top: 1.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #e5e7eb;
}

.invoice-meta>div {
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  padding: 0.75rem 0.9rem;
  background: #f9fafb;
}

.page-header>div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
  }

  .app-header-left {
    width: 100%;
    justify-content: flex-start;
  }

  .app-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.25rem;
  }

  .app-nav a {
    margin-left: 0;
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
  }

  .app-main {
    margin: 0.75rem auto;
    padding: 0 0.5rem 1.5rem;
  }

  .page {
    padding: 0.9rem;
    border-radius: 6px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .page-header>div {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .page-header>div .btn {
    flex: 1 1 120px;
    justify-content: center;
  }

  .form-grid,
  .totals-grid,
  .invoice-meta {
    grid-template-columns: 1fr;
  }

  .form-actions {
    flex-wrap: wrap;
  }

  .form-actions .btn {
    flex: 1 1 140px;
    justify-content: center;
  }

  .table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table thead,
  .table tbody,
  .table tr,
  .table th,
  .table td {
    white-space: nowrap;
  }
}

.invoice-search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-right: 0.5rem;
}

.invoice-search-form input[type="text"],
.invoice-search-form input[type="date"] {
  padding: 0.3rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  font-size: 0.85rem;
}

/* Powered by BillKaro footer style */
.powered-by {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: #9ca3af;
  font-style: italic;
}

@media print {
  @page {
    margin: 1cm;
    size: auto;
  }

  body {
    background: #fff;
    font-size: 12pt;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .app-header,
  .app-nav,
  .flash-container,
  .page-header>div,
  /* Hide buttons in page header */
  .invoice-view .btn,
  .invoice-view button {
    display: none !important;
  }

  .app-main {
    margin: 0;
    padding: 0;
    max-width: none;
    width: 100%;
  }

  .page {
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    border: none;
  }

  /* Invoice print layout improvements */
  .store-header {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 1rem;
  }

  .store-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
  }

  .store-header-text h3 {
    margin-top: 0;
    font-size: 1.5rem;
    color: #111;
  }

  .invoice-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 1.5rem;
  }

  .invoice-meta>div {
    border: none;
    background: transparent;
    padding: 0;
  }

  .table th {
    background: #f3f4f6 !important;
    color: #000;
    font-weight: bold;
    border-color: #ddd;
  }

  .table td {
    border-color: #ddd;
  }

  .totals-grid {
    grid-template-columns: 1fr 1fr;
    page-break-inside: avoid;
  }

  .totals-box {
    border: none;
    background: transparent;
    padding: 0;
  }

  .totals-row.grand-total {
    font-size: 1.1em;
    border-top: 2px solid #000;
  }

  .invoice-footer {
    margin-top: 2rem;
    margin-bottom: 0;
    padding-top: 1rem;
    border-top: 1px solid #eee;
    page-break-inside: avoid;
  }

  .powered-by {
    color: #d1d5db;
    /* Lighter for print */
  }
}

/* Simple modal (used for barcode scanning) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 9999;
}

.modal {
  width: min(720px, 100%);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: #f3f4f6;
  border-bottom: 1px solid #e5e7eb;
}

.modal-body {
  padding: 1rem;
}

.barcode-reader {
  width: 100%;
}

.barcode-scan-status {
  margin-top: 0.6rem;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  font-size: 0.9rem;
}

.barcode-scan-status.is-info {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.barcode-scan-status.is-ok {
  background: #ecfdf3;
  color: #166534;
  border-color: #bbf7d0;
}

.barcode-scan-status.is-error {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

/* Logo Placeholder Styles */
.logo-placeholder {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

/* Cash Receipt Styles */
.receipt-container {
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
  background: #f0f0f0;
  min-height: 60vh;
}

.receipt-paper {
  background: #fff;
  width: 100%;
  max-width: 340px;
  padding: 1.5rem 1.25rem;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.1),
    0 8px 16px rgba(0, 0, 0, 0.1);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  position: relative;
}

/* Ragged edge effect at top */
.receipt-paper::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 10px;
  background: linear-gradient(135deg, transparent 33.33%, #fff 33.33%, #fff 66.66%, transparent 66.66%),
    linear-gradient(225deg, transparent 33.33%, #fff 33.33%, #fff 66.66%, transparent 66.66%);
  background-size: 12px 20px;
}

.receipt-header {
  text-align: center;
  margin-bottom: 1rem;
}

.receipt-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 0.75rem;
  border-bottom: 2px solid #333;
  padding-bottom: 0.5rem;
}

.receipt-logo-area {
  margin: 0.75rem auto;
  display: flex;
  justify-content: center;
}

.receipt-logo {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: 4px;
}

.receipt-logo-placeholder {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: white;
}

.receipt-store-name {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.receipt-info {
  margin: 1rem 0;
}

.receipt-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.receipt-label {
  color: #555;
}

.receipt-value {
  font-weight: 500;
  text-align: right;
  max-width: 60%;
}

.receipt-separator {
  text-align: center;
  color: #999;
  letter-spacing: 2px;
  margin: 0.75rem 0;
  font-size: 0.75rem;
}

.receipt-separator-double {
  text-align: center;
  color: #666;
  letter-spacing: 2px;
  margin: 0.75rem 0;
  font-size: 0.75rem;
  font-weight: 600;
}

.receipt-items {
  margin: 0.5rem 0;
}

.receipt-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.item-name {
  flex: 1;
  padding-right: 1rem;
  word-break: break-word;
}

.item-price {
  font-weight: 600;
  white-space: nowrap;
}

.receipt-item-detail {
  font-size: 0.75rem;
  color: #777;
  margin-left: 1rem;
  margin-bottom: 0.35rem;
}

.receipt-totals {
  margin: 0.5rem 0;
}

.receipt-grand-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.75rem 0;
}

.grand-total-value {
  font-size: 1.3rem;
}

.receipt-payment-mode {
  text-align: center;
  margin: 0.75rem 0;
}

.receipt-reference {
  font-size: 0.75rem;
  color: #666;
  margin-top: 0.25rem;
}

.receipt-convert-form {
  text-align: center;
  margin: 0.5rem 0;
}

.receipt-notes {
  text-align: center;
  font-size: 0.8rem;
  color: #666;
  margin: 0.75rem 0;
  padding: 0.5rem;
  background: #f9f9f9;
  border-radius: 4px;
}

.receipt-thank-you {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 3px;
  margin: 1.25rem 0;
  padding: 0.75rem 0;
}

.receipt-barcode {
  text-align: center;
  margin: 1rem 0;
}

.barcode-lines {
  height: 45px;
  background: repeating-linear-gradient(90deg,
      #000 0px,
      #000 2px,
      #fff 2px,
      #fff 4px,
      #000 4px,
      #000 5px,
      #fff 5px,
      #fff 8px,
      #000 8px,
      #000 10px,
      #fff 10px,
      #fff 12px,
      #000 12px,
      #000 15px,
      #fff 15px,
      #fff 17px,
      #000 17px,
      #000 18px,
      #fff 18px,
      #fff 22px,
      #000 22px,
      #000 24px,
      #fff 24px,
      #fff 26px,
      #000 26px,
      #000 29px,
      #fff 29px,
      #fff 31px);
  margin: 0 auto;
  max-width: 200px;
}

.receipt-invoice-number {
  font-size: 0.75rem;
  margin-top: 0.35rem;
  letter-spacing: 1px;
}

.receipt-footer {
  text-align: center;
  margin-top: 1rem;
  padding-top: 0.5rem;
  border-top: 1px dashed #ddd;
}

.receipt-footer p {
  margin: 0.25rem 0;
  font-size: 0.75rem;
  color: #888;
}

/* Print styles for receipt */
@media print {
  .receipt-container {
    background: transparent;
    padding: 0;
  }

  .receipt-paper {
    box-shadow: none;
    max-width: none;
    width: 80mm;
    /* Standard thermal receipt width */
    padding: 5mm;
    margin: 0 auto;
  }

  .receipt-paper::before {
    display: none;
  }

  .receipt-barcode {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Hide toggle buttons when printing */
  .view-toggle {
    display: none !important;
  }
}

/* View Toggle Button Styles */
.view-toggle {
  background: #f3f4f6;
  padding: 0.5rem;
  border-radius: 8px;
  display: inline-flex;
}

.view-toggle-btn {
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  background: transparent;
  color: #6b7280;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.view-toggle-btn:hover {
  background: #e5e7eb;
  color: #374151;
}

.view-toggle-btn.active {
  background: #fff;
  color: #1f2937;
  border-color: #d1d5db;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Store header styling for normal view */
.store-header {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.store-header .store-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: 8px;
}

.store-header-text h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.5rem;
  color: #1f2937;
}

.store-header-text p {
  margin: 0.25rem 0;
  color: #6b7280;
  font-size: 0.9rem;
}

/* Base modal styles */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 1rem 0;
  color: #1f2937;
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-description {
  color: #4b5563;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.modal-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1.1rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  transition: border-color 0.2s;
}

.modal-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.modal-actions {
  display: flex;
  gap: 1rem;
}

.modal-btn {
  flex: 1;
  padding: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  border: none;
}

.modal-btn-secondary {
  background: #f3f4f6;
  color: #4b5563;
  border: 1px solid #e5e7eb;
}

.modal-btn-secondary:hover {
  background: #e5e7eb;
  color: #1f2937;
}

.modal-btn-primary {
  background: #1f2937;
  color: white;
}

.modal-btn-primary:hover {
  background: #111827;
  transform: translateY(-1px);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Error shake animation */
.shake {
  animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }

  10%,
  90% {
    transform: translate3d(-1px, 0, 0);
  }

  20%,
  80% {
    transform: translate3d(2px, 0, 0);
  }

  30%,
  50%,
  70% {
    transform: translate3d(-4px, 0, 0);
  }

  40%,
  60% {
    transform: translate3d(4px, 0, 0);
  }
}

/* Global print styles */
@media print {

  .btn,
  .app-header,
  .app-nav,
  .page-header>div {
    display: none !important;
  }
}