/**
 * styles.css - Estate Checkout
 * Mobile-first, single viewport layout, no scrolling to reach buttons
 * Target: 375x667 viewport (iPhone SE) as minimum
 */

/* === CSS Variables === */
:root {
  /* Colors */
  --color-bg: #f5f5f5;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-secondary: #666666;
  --color-primary: #2563eb;
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-border: #e5e5e5;

  /* Spacing - tighter for viewport fit */
  --space-xs: 2px;
  --space-sm: 4px;
  --space-md: 8px;
  --space-lg: 12px;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-sm: 12px;
  --font-size-base: 14px;
  --font-size-lg: 16px;
  --font-size-xl: 20px;
  --font-size-2xl: 28px;
  --font-size-price: 36px;

  /* Fixed heights for layout calculation */
  --header-height: 32px;
  --total-height: 36px;
  --input-height: 76px;
  --numpad-button-size: 52px;
  --numpad-gap: 4px;
  --add-button-height: 44px;
  --action-bar-height: 40px;

  /* Borders */
  --radius-sm: 4px;
  --radius-md: 6px;
}

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.3;
  color: var(--color-text);
  background-color: var(--color-bg);
}

/* === Screen Container === */
.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* === Checkout Pad Layout === */
/* Note: display:flex comes from .screen.active, NOT here */
.checkout-pad {
  overflow: hidden;
}

/* === Header (single line) === */
.header {
  position: relative;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: 0 var(--space-md);
  flex-shrink: 0;
}

.header__name {
  font-size: var(--font-size-base);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.header__separator {
  color: var(--color-border);
  font-size: var(--font-size-sm);
}

.header__day {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.header__discount {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-success);
  white-space: nowrap;
}

.header__discount--none {
  color: var(--color-text-secondary);
}

.header__end {
  position: absolute;
  right: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.header__end:active {
  background: var(--color-bg);
}

/* === Running Total === */
.running-total {
  height: var(--total-height);
  background: var(--color-text);
  color: white;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 0 var(--space-lg);
  flex-shrink: 0;
}

.running-total__label {
  font-size: var(--font-size-base);
  font-weight: 500;
}

.running-total__amount {
  font-size: var(--font-size-xl);
  font-weight: 700;
}

.running-total__savings {
  margin-left: auto;
  font-size: var(--font-size-sm);
  color: var(--color-success);
  font-weight: 600;
}

/* === Item List (scrollable, flex-grow) === */
.item-list-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.item-list {
  list-style: none;
}

.item-list__empty {
  text-align: center;
  color: var(--color-text-secondary);
  padding: var(--space-lg);
  font-size: var(--font-size-base);
}

.item-row {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-md);
  min-height: 36px;
}

.item-row:last-child {
  border-bottom: none;
}

.item-row__desc {
  flex: 1;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-row__prices {
  text-align: right;
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
}

.item-row__prices--full {
  flex: 1;
  justify-content: flex-end;
}

.item-row__original {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  text-decoration: line-through;
}

.item-row__final {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.item-row__remove {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--color-danger);
  font-size: var(--font-size-xl);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* === Input Area (compact) === */
.input-area {
  height: var(--input-height);
  background: var(--color-surface);
  padding: var(--space-sm) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.description-input {
  height: 28px;
  width: 100%;
  padding: 0 var(--space-md);
  font-size: var(--font-size-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.description-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.price-display {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 1;
}

.price-display__value {
  flex: 1;
  font-size: var(--font-size-price);
  font-weight: 700;
  text-align: right;
  padding: 0 var(--space-md);
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.mic-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--color-text-secondary);
  color: white;
  font-size: var(--font-size-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mic-button:active,
.mic-button.listening {
  background: var(--color-danger);
}

/* === Numpad Container === */
.numpad-container {
  background: var(--color-surface);
  padding: var(--space-sm);
  flex-shrink: 0;
}

/* === Number Pad === */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--numpad-gap);
}

.numpad__button {
  height: var(--numpad-button-size);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--font-size-2xl);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.numpad__button:active {
  background: var(--color-bg);
}

.numpad__button--backspace {
  font-size: var(--font-size-xl);
}

/* === ADD Button === */
.add-button {
  width: 100%;
  height: var(--add-button-height);
  margin-top: var(--numpad-gap);
  background: var(--color-success);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-lg);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.add-button:active {
  background: #15803d;
}

/* === Action Bar === */
.action-bar {
  height: var(--action-bar-height);
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.action-bar__button {
  flex: 1;
  height: 100%;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
}

.action-bar__button--done {
  background: var(--color-primary);
  color: white;
}

.action-bar__button--done:disabled {
  background: var(--color-text-secondary);
  cursor: not-allowed;
}

.action-bar__button--clear {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

/* === Feedback Flash === */
.flash {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: var(--space-lg) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: white;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1000;
}

.flash--success {
  background: var(--color-success);
}

.flash--error {
  background: var(--color-danger);
}

.flash.visible {
  opacity: 1;
}

/* === Confirmation Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  z-index: 100;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  max-width: 280px;
  width: 100%;
  text-align: center;
}

.modal__title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--space-lg);
}

.modal__buttons {
  display: flex;
  gap: var(--space-sm);
}

.modal__button {
  flex: 1;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
}

.modal__button--cancel {
  background: var(--color-bg);
  color: var(--color-text);
}

.modal__button--confirm {
  background: var(--color-danger);
  color: white;
}

/* === Sale Setup Screen === */
.setup-screen {
  background: var(--color-bg);
  padding: 0;
}

.setup-header {
  height: 48px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.setup-header__title {
  font-size: var(--font-size-xl);
  font-weight: 600;
}

.setup-form {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
}

.setup-field {
  margin-bottom: var(--space-lg);
}

.setup-field__label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setup-field__input {
  width: 100%;
  height: 48px;
  padding: 0 var(--space-lg);
  font-size: var(--font-size-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.setup-field__input:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Discount List */
.discount-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.discount-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: var(--color-surface);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.discount-row__label {
  font-size: var(--font-size-base);
  font-weight: 500;
  min-width: 50px;
}

.discount-row__input {
  width: 64px;
  height: 40px;
  padding: 0 var(--space-md);
  font-size: var(--font-size-lg);
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.discount-row__input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.discount-row__suffix {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
}

.discount-row__remove {
  width: 32px;
  height: 32px;
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--color-danger);
  font-size: var(--font-size-xl);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.add-day-button {
  width: 100%;
  height: 40px;
  margin-top: var(--space-sm);
  background: transparent;
  color: var(--color-primary);
  border: 1px dashed var(--color-primary);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
}

.add-day-button:active {
  background: rgba(37, 99, 235, 0.1);
}

/* Setup Actions */
.setup-actions {
  padding: var(--space-lg);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.start-sale-button {
  width: 100%;
  height: 52px;
  background: var(--color-success);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-lg);
  font-weight: 700;
  cursor: pointer;
}

.start-sale-button:active {
  background: #15803d;
}

.start-sale-button:disabled {
  background: var(--color-text-secondary);
  cursor: not-allowed;
}

/* === QR Handoff Screen === */
.qr-screen {
  background: var(--color-bg);
}

.qr-code-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  background: var(--color-surface);
  flex-shrink: 0;
}

.qr-code {
  background: white;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.qr-summary {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  min-height: 0;
}

.qr-items {
  list-style: none;
  margin-bottom: var(--space-lg);
}

.qr-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border);
}

.qr-item__desc {
  font-size: var(--font-size-base);
  color: var(--color-text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: var(--space-md);
}

.qr-item__price {
  font-size: var(--font-size-base);
  font-weight: 600;
  white-space: nowrap;
}

.qr-item__original {
  text-decoration: line-through;
  color: var(--color-text-secondary);
  font-weight: 400;
  margin-right: var(--space-sm);
}

.qr-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) 0;
  border-top: 2px solid var(--color-text);
}

.qr-total__label {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.qr-total__amount {
  font-size: var(--font-size-xl);
  font-weight: 700;
}

.qr-actions {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.qr-action {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
}

.qr-action--back {
  background: var(--color-border);
  color: var(--color-text);
}

.qr-action--back:active {
  background: #d4d4d4;
}

.qr-action--new {
  background: var(--color-success);
  color: white;
}

.qr-action--new:active {
  background: #15803d;
}

/* === Utility Classes === */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
