:root {
  --color-primary: #13ad54;
  --color-background: #f5f7fa;
  --color-surface: #ffffff;
  --color-text: #111827;
  --color-muted: #667085;
  --color-border: #e5e7eb;
  --radius-card: 18px;
  --shadow-card: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #e8eaed;
  color: var(--color-text);
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-page[hidden],
.modal[hidden],
.bottom-navigation[hidden],
.ticket-modal[hidden] {
  display: none !important;
}

#caisse-app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--color-surface);
}

.app-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.app-header h1,
.app-header .page-title {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.1;
}

.current-date {
  color: var(--color-muted);
  font-size: clamp(13px, 1.8vw, 18px);
  font-weight: 600;
  text-align: right;
}

.app-content {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.app-page {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

.bottom-navigation {
  position: relative;
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  flex: 0 0 calc(72px + env(safe-area-inset-bottom));
  height: calc(72px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}
.bottom-navigation .nav-button {
  border: 0;
  background: transparent;
  color: var(--color-muted);
  font-size: 17px;
}
.bottom-navigation .nav-button.active {
  background: #f3f4f6;
  color: var(--color-text);
  font-weight: 700;
}

@media (max-width: 760px) {
  .app-header {
    padding-right: 14px;
    padding-left: 14px;
  }
  .current-date {
    max-width: 52%;
  }
}
.primary-button {
  width: 100%;
  min-height: 58px;
  margin-top: 12px;
  border: 0;
  border-radius: 12px;
  background: #16b85a;
  color: #ffffff;
  font-weight: 700;
}
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  font-size: 26px;
}

.checkout-card,
.received-card,
.recap-card {
  padding: 18px;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.ticket-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.ticket-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}
.ticket-modal__content {
  position: relative;
  z-index: 1;
  width: min(500px, 100%);
  max-height: 85dvh;
  overflow-y: auto;
  padding: 24px;
  border-radius: 18px;
  background: var(--color-surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.ticket-modal__close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #f1f5f9;
  font-size: 26px;
  line-height: 1;
}
.ticket-modal__header {
  margin-bottom: 22px;
  padding-right: 45px;
}
.ticket-modal__header h3 {
  margin: 0 0 4px;
  font-size: 24px;
}
.ticket-modal__header span {
  color: var(--color-muted);
  font-size: 14px;
}
.ticket-modal__meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}
.ticket-modal__meta div {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px;
  border-radius: 12px;
  background: #f8fafc;
}
.ticket-modal__meta span {
  color: var(--color-muted);
  font-size: 13px;
}
.ticket-modal__items {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}
.ticket-modal__item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e2e8f0;
}
.ticket-modal__item-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.ticket-modal__item-name, .ticket-modal__item-price {
  font-weight: 700;
}
.ticket-modal__item-quantity {
  color: var(--color-muted);
  font-size: 14px;
}
.ticket-modal__totals {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 2px solid #e2e8f0;
}
.ticket-modal__totals div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}
.ticket-modal__totals div:first-child {
  font-size: 20px;
}
.ticket-modal__totals span {
  color: #475569;
}
.ticket-modal__totals strong {
  white-space: nowrap;
}

@media (max-width: 600px) {
  .ticket-modal {
    align-items: flex-end;
    padding: 0;
  }
  .ticket-modal__content {
    width: 100%;
    max-height: 90dvh;
    border-radius: 20px 20px 0 0;
  }
  .ticket-modal__meta {
    grid-template-columns: 1fr;
  }
}
#salePage {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.pos-layout {
  display: flex;
  gap: 20px;
  height: 100%;
  min-height: 0;
  padding: 10px;
  overflow: hidden;
}

.catalog-column {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--color-surface);
}

.catalog-scroll {
  height: 100%;
  min-height: 0;
  padding: 0 8px 24px 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.product-category {
  margin-bottom: 22px;
}
.product-category h2 {
  position: sticky;
  top: -12px;
  z-index: 2;
  margin: 0 0 10px;
  padding: 12px 0 8px;
  background: var(--color-surface);
  font-size: 14px;
  text-transform: uppercase;
}

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

.checkout-column {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
  overflow: hidden;
  background: var(--color-surface);
  border-left: 1px solid #edf0f3;
  width: 190px;
}

.ticket-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 14px;
  overflow: hidden;
  background: var(--color-surface);
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

.ticket-heading {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
}
.ticket-heading h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
}

.ticket-clear {
  border: 0;
  background: transparent;
  color: #ef4444;
}

.ticket-items {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding-top: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.ticket-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  color: #98a2b3;
  text-align: center;
}
.ticket-empty small {
  margin-top: 6px;
}

.ticket-line {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 11px 6px;
  border: 0;
  border-bottom: 1px solid #edf0f3;
  background: transparent;
  color: var(--color-text);
  text-align: left;
}
.ticket-line:active {
  background: #f6f8fa;
}
.ticket-line__quantity {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: #eafaf0;
  color: var(--color-primary);
  font-size: 13px;
  font-weight: 800;
}
.ticket-line__content {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}
.ticket-line__content strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticket-line__content small {
  color: var(--color-muted);
  font-size: 10px;
}
.ticket-line__total {
  font-size: 13px;
  white-space: nowrap;
}

.checkout-bottom {
  flex: 0 0 auto;
  padding-top: 12px;
  background: var(--color-surface);
}

.ticket-summary {
  padding-top: 12px;
}

.ticket-count {
  display: block;
  margin-bottom: 8px;
  color: var(--color-muted);
  font-size: 11px;
}

.ticket-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}
.ticket-total strong {
  font-size: 24px;
}

.checkout-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.checkout-toolbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  font-weight: 600;
}

.checkout-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  flex: 1;
  min-height: 0;
  padding: 14px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}

.checkout-card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  text-transform: uppercase;
}

.checkout-ticket-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}

.checkout-total-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.checkout-total-card strong {
  font-size: 28px;
}

.payment-method {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 82px;
  margin-bottom: 12px;
}
.payment-method--active {
  border-color: var(--color-primary);
  background: #effcf4;
}
.payment-method--active .payment-method__check {
  border: 6px solid var(--color-primary);
}
.payment-method__icon {
  font-size: 28px;
}
.payment-method__content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}
.payment-method__content small {
  color: var(--color-muted);
}
.payment-method__check {
  width: 22px;
  height: 22px;
  border: 2px solid #98a2b3;
  border-radius: 50%;
}

.received-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  text-align: left;
}
.received-card span:first-child {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.received-card strong {
  color: var(--color-primary);
  font-size: 28px;
}

.change-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.change-preview strong {
  font-size: 28px;
}

.checkout-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 14px;
  margin-bottom: 12px;
}

.payment-panel {
  min-width: 0;
  padding-bottom: 24px;
}

.checkout-summary {
  min-width: 0;
}

@media (min-width: 700px) {
  .checkout-layout {
    grid-template-columns: 1fr 1fr;
  }
}
.payment-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border);
}

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

.payment-history-item > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.payment-history-item span {
  color: var(--color-muted);
}

#historyPage {
  height: 100%;
  padding: 24px;
  overflow-y: auto;
  background: var(--color-background);
}

.history-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.history-toolbar label {
  font-size: 16px;
  font-weight: 700;
}

.history-date {
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: white;
  font-size: 16px;
}

.history-summary {
  margin-bottom: 14px;
  font-size: 15px;
  color: var(--color-muted);
}

.history-list {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 900px;
}

.history-sale {
  width: 100%;
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 90px 1fr auto;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: white;
  text-align: left;
  cursor: pointer;
}

.history-sale:hover {
  background: #f8fafc;
}

.history-sale__time {
  font-size: 16px;
  font-weight: 700;
}

.history-sale__info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-sale__payment {
  font-weight: 700;
}

.history-sale__articles {
  font-size: 14px;
  color: var(--color-muted);
}

.history-sale__total {
  font-size: 20px;
  font-weight: 800;
}

.history-empty {
  padding: 50px 20px;
  border: 1px dashed var(--color-border);
  border-radius: 14px;
  text-align: center;
  color: var(--color-muted);
  background: white;
}

@media (max-width: 640px) {
  #historyPage {
    padding: 16px;
  }
  .history-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }
  .history-sale {
    grid-template-columns: 64px 1fr auto;
    gap: 10px;
    padding: 15px;
  }
  .history-sale__total {
    font-size: 17px;
  }
}