* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f4f5f7;
  color: #1c1e21;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

:root {
  --tile-font-family: system-ui;
  --tile-font-size: 16px;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; min-height: 100dvh; }
#app.screen {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- Login ---------- */
#login-screen {
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: #fff; padding: 32px; border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  text-align: center; width: 90%; max-width: 340px;
}
.login-box h1 { margin-top: 0; }
#pin-input {
  width: 100%; font-size: 28px; text-align: center;
  padding: 14px; margin: 16px 0; border: 2px solid #ddd; border-radius: 10px;
  letter-spacing: 6px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: #1c1e21; color: #fff;
  position: sticky; top: 0; z-index: 10;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
}
.topbar-title { font-size: 18px; font-weight: 600; flex-shrink: 0; }
.topbar-spacer { flex: 1; min-width: 8px; }
.topbar .btn { flex-shrink: 0; }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #999; display: inline-block;
  flex-shrink: 0;
}
.status-dot.status-online { background: #2ecc71; }
.status-dot.status-offline { background: #e74c3c; }

/* ---------- Layout ---------- */
.main-layout {
  display: flex; flex-direction: column;
  flex: 1;
  min-height: 0; /* wichtig, damit Kind-Elemente korrekt scrollen statt zu ueberlaufen */
  overflow: hidden;
}
@media (min-width: 700px) {
  .main-layout { flex-direction: row; }
}

.product-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--tile-columns, auto-fit), minmax(clamp(72px, 9vw, 130px), 1fr));
  grid-auto-rows: minmax(var(--tile-row-height, 100px), auto);
  align-content: start;
  gap: clamp(6px, 1.2vw, 12px);
  padding: clamp(8px, 1.5vw, 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.product-tile {
  border: none;
  border-radius: 14px;
  padding: 10px 6px;
  min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  touch-action: manipulation;
  font-family: var(--tile-font-family);
  font-size: var(--tile-font-size);
  font-weight: 700; text-align: center;
  cursor: pointer;
  position: relative;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.product-tile:active { transform: scale(0.96); filter: brightness(0.94); }
.product-tile .tile-icon { font-size: 1.4em; }
.product-tile .tile-name {
  font-size: 1em;
  width: 100%;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}
.product-tile .tile-category {
  font-size: 0.7em; font-weight: 500; opacity: 0.65; margin-top: 2px;
}
.product-tile .price { font-weight: 400; opacity: 0.85; margin-top: 6px; font-size: 0.8em; }

.product-tile.sold-out { opacity: 0.45; cursor: not-allowed; }
.product-tile.sold-out:active { transform: none; filter: none; }
.sold-out-label {
  position: absolute; top: 6px; right: 8px;
  font-size: 10px; font-weight: 700; background: rgba(0,0,0,0.6); color: #fff;
  padding: 2px 6px; border-radius: 6px;
}

/* ---------- Cart panel ---------- */
.cart-panel {
  background: #fff;
  padding: clamp(10px, 2vw, 16px);
  border-top: 1px solid #e2e2e2;
  display: flex; flex-direction: column;
  max-height: clamp(35vh, 45vh, 50vh);
}
@media (min-width: 700px) {
  .cart-panel {
    width: clamp(260px, 26vw, 380px); max-height: none;
    border-top: none; border-left: 1px solid #e2e2e2;
  }
}
.cart-panel h2 { margin: 0 0 8px; font-size: 16px; }
.cart-lines { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; margin-bottom: 8px; }

.cart-line {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px; border-bottom: 1px solid #f0f0f0;
}
.cart-line-main { flex: 1; display: flex; flex-direction: column; }
.cart-line-name { font-size: 14px; }
.cart-line-attrs { font-size: 12px; color: #666; margin-top: 2px; }
.cart-line-qty { display: flex; align-items: center; gap: 6px; }
.qty-btn {
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: #eee; font-size: 18px; line-height: 1;
  touch-action: manipulation;
}
.qty-btn:active { background: #ddd; }
.cart-line-total { width: 64px; text-align: right; font-weight: 600; font-size: 14px; }
.remove-btn {
  border: none; background: none; color: #d33; font-size: 18px; margin-left: 6px;
}

.attribute-options { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.attribute-option {
  display: flex; align-items: center; gap: 10px; font-size: 16px;
  padding: 10px; background: #f7f7f7; border-radius: 8px;
}
.attribute-option input[type="checkbox"] { width: 22px; height: 22px; }
#attribute-modal-extra {
  width: 100%; padding: 10px; border-radius: 8px; border: 1px solid #ddd;
  font-size: 15px; margin-top: 6px;
}

.cart-total-row {
  display: flex; justify-content: space-between; font-size: 18px; font-weight: 700;
  padding: 10px 4px; border-top: 2px solid #eee;
}

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 10px; padding: 10px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.btn-primary { background: #2f6fed; color: #fff; }
.btn-primary:disabled { background: #b7c6ee; }
.btn-secondary { background: #eee; color: #333; margin-top: 8px; }
.btn-danger { background: #f4d4d4; color: #a11; }
.btn-small { background: #3a3d42; color: #fff; font-size: 13px; padding: 8px 12px; margin-top: 0; }
.btn-large { width: 100%; padding: 16px; font-size: 17px; margin-top: 6px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 16px;
}
.modal-box {
  background: #fff; border-radius: 16px; padding: 24px;
  width: 100%; max-width: 380px;
  max-height: 90vh; overflow-y: auto;
}
.modal-box-wide { max-width: 480px; }
.modal-box h2 { margin-top: 0; }

#cash-input {
  width: 100%; font-size: 24px; padding: 12px; border-radius: 10px;
  border: 2px solid #ddd; margin-top: 6px; text-align: right;
  background: #fafafa;
}
.quick-cash-buttons {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px;
}
.quick-cash-buttons button {
  flex: 1; min-width: 64px; padding: 10px; border-radius: 8px;
  border: 1px solid #ddd; background: #f7f7f7; font-size: 14px;
}

.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px;
}
.keypad-btn {
  padding: 16px; font-size: 20px; border-radius: 10px; border: 1px solid #ddd;
  background: #f7f7f7;
}
.keypad-btn:active { background: #e8e8e8; }
.keypad-del { background: #fde3e3; }

.change-preview { font-size: 20px; font-weight: 700; margin-top: 12px; color: #1a7a37; }
.change-preview.change-warning { color: #c0392b; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

.error-text { color: #d33; font-size: 14px; min-height: 18px; }

/* ---------- Offline-Banner ---------- */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  background: #c0392b; color: #fff; padding: 10px 16px;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  font-size: 14px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1c1e21; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 15px; z-index: 70; box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  max-width: 90%; text-align: center;
}

/* ---------- Verlauf ---------- */
.history-list { max-height: 60vh; overflow-y: auto; }
.history-entry {
  border-bottom: 1px solid #eee; padding: 10px 0;
}
.history-entry.history-voided { opacity: 0.5; }
.history-entry-head {
  display: flex; justify-content: space-between; font-weight: 600; font-size: 14px;
}
.history-entry-items { font-size: 13px; color: #555; margin-top: 2px; }
.history-entry-actions { margin-top: 6px; display: flex; gap: 8px; }

.history-entry-details { margin-top: 8px; }
.details-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.details-attrs { font-size: 11px; color: #666; }
.details-receipt-number { font-size: 12px; color: #888; margin: 0 0 8px; }
.details-table th, .details-table td { text-align: left; padding: 4px 6px; }
.details-table .num { text-align: right; }
.details-table thead th { border-bottom: 1px solid #ddd; color: #777; font-weight: 500; }
.details-payment {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid #eee;
  font-size: 14px; font-weight: 600;
}
.details-payment div { display: flex; justify-content: space-between; padding: 2px 6px; }

/* ---------- Kassensturz/Tagesauszug (Kasse) ---------- */
.reports-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.reports-tab-btn {
  flex: 1; padding: 10px; border-radius: 8px; border: 1px solid #ddd;
  background: #f7f7f7; font-size: 14px; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.reports-tab-btn.active { background: #2f6fed; color: #fff; border-color: #2f6fed; }

.report-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.checkbox-label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; margin: 8px 0 2px; }
.hint-text { color: #777; font-size: 12px; margin: 0 0 12px; }

.report-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin: 10px 0 16px;
}
.report-summary .stat-box { background: #f7f8fa; border-radius: 8px; padding: 10px 12px; }
.report-summary .stat-box .stat-label { font-size: 12px; color: #777; }
.report-summary .stat-box .stat-value { font-size: 18px; font-weight: 700; }
.report-summary .bestseller-list { grid-column: 1 / -1; }

.denomination-form {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px; margin: 12px 0;
}
.denomination-form .denom-item { background: #f7f8fa; border-radius: 8px; padding: 8px 10px; }
.denomination-form label { font-size: 12px; display: block; margin-bottom: 4px; }
.denomination-form input {
  width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px;
}

#reports-modal textarea {
  width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 6px;
  font-family: inherit; font-size: 14px;
}
#reports-modal table { width: 100%; border-collapse: collapse; font-size: 13px; }
#reports-modal th, #reports-modal td { text-align: left; padding: 6px; border-bottom: 1px solid #eee; }

/* ---------- Nachschub (Kasse) ---------- */
.restock-list { max-height: 30vh; overflow-y: auto; margin-bottom: 12px; }
.restock-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; margin-bottom: 6px;
  border-left: 4px solid #ccc;
}
.restock-row.status-voll { border-left-color: #2ecc71; background: #f2fbf5; }
.restock-row.status-ausreichend { border-left-color: #6ea8fe; background: #f2f7ff; }
.restock-row.status-knapp { border-left-color: #f0a500; background: #fff8ec; }
.restock-row.status-leer { border-left-color: #e74c3c; background: #fdf0ef; }
.restock-row.status-info { border-left-color: #6ea8fe; background: #f2f7ff; }
.restock-row.status-bald { border-left-color: #f0a500; background: #fff8ec; }
.restock-row.status-dringend { border-left-color: #e74c3c; background: #fdf0ef; }
.restock-row-name { font-size: 14px; font-weight: 600; }
.restock-row-status { padding: 6px; border-radius: 6px; border: 1px solid #ddd; font-size: 13px; }
.restock-row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.restock-row-qty {
  width: 90px; padding: 6px; border-radius: 6px; border: 1px solid #ddd; font-size: 13px;
}

.restock-add-row { display: flex; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.restock-add-row input[type="text"] {
  flex: 2; min-width: 140px; padding: 8px; border: 1px solid #ddd; border-radius: 6px;
}
.restock-add-row select {
  padding: 8px; border: 1px solid #ddd; border-radius: 6px;
}

.restock-note-row {
  background: #f7f8fa; border-radius: 8px; padding: 8px 10px; margin-bottom: 6px;
}
.restock-note-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.restock-note-time { font-size: 11px; color: #888; white-space: nowrap; }
.restock-note-status { font-size: 12px; color: #666; margin: 4px 0; }
