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

:root {
  --primary: #1e40af;
  --primary-dark: #1e3a8a;
  --primary-light: #3b82f6;
  --success: #059669;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 1rem 1.25rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header h1 {
  font-size: 1.35rem;
  font-weight: 700;
}
.header-actions { display: flex; gap: 0.5rem; }
.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.icon-btn:hover, .icon-btn:active { background: rgba(255,255,255,0.3); }
.subtitle {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-top: 0.25rem;
}
.date-badge {
  display: inline-block;
  margin-top: 0.75rem;
  background: rgba(255,255,255,0.2);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
}

/* ===== Views ===== */
.view { display: none; padding: 1rem 1rem 6rem; }
.view.active { display: block; }

/* ===== Search ===== */
.search-bar {
  margin-bottom: 1rem;
}
.search-bar input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 1rem;
  background: white;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,64,175,0.15);
}

/* ===== Categories ===== */
.category {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1rem;
  cursor: pointer;
  user-select: none;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.category-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.category-header .chevron {
  transition: transform 0.25s;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.category.open .chevron { transform: rotate(180deg); }
.category-body {
  display: none;
  padding: 0.5rem 0;
}
.category.open .category-body { display: block; }

/* ===== Product Row ===== */
.product-row {
  display: flex;
  align-items: center;
  padding: 0.65rem 1rem;
  gap: 0.75rem;
  border-bottom: 1px solid #f1f5f9;
}
.product-row:last-child { border-bottom: none; }
.product-info {
  flex: 1;
  min-width: 0;
}
.product-name {
  font-weight: 500;
  font-size: 0.95rem;
}
.product-unit {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.qty-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.qty-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
  transition: background 0.15s;
}
.qty-btn:active { background: #e0e7ff; }
.qty-input {
  width: 48px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem;
  font-size: 1rem;
  font-weight: 600;
  -moz-appearance: textfield;
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ===== Cart Bar ===== */
.cart-bar {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  background: white;
  border-top: 1px solid var(--border);
  padding: 0.85rem 1.25rem calc(0.85rem + var(--safe-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  z-index: 40;
}
.cart-info { font-size: 0.95rem; }
.cart-info strong { color: var(--primary); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-dark); }
.btn.primary:disabled {
  background: #94a3b8;
  border-color: #94a3b8;
  cursor: not-allowed;
  opacity: 0.7;
}
.btn.danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}
.btn.full { width: 100%; padding: 0.9rem; font-size: 1.05rem; }
.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 1rem;
  padding: 0.25rem 0;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
}
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,64,175,0.12);
}
.summary-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1.25rem 0;
}
.summary-box h3 {
  font-size: 0.95rem;
  margin-bottom: 0.6rem;
  color: var(--text-muted);
}
.summary-box ul {
  list-style: none;
}
.summary-box li {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.95rem;
  border-bottom: 1px dashed #e2e8f0;
}
.summary-box li:last-child { border-bottom: none; }
.summary-box .qty { font-weight: 700; color: var(--primary); }

/* ===== Success ===== */
.success-card {
  text-align: center;
  padding: 1rem 0;
}
.success-icon {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
}
.success-card h2 { margin-bottom: 0.5rem; }
.success-card > p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.print-area {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: left;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.print-area h3 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 0.4rem;
}
.print-meta {
  font-size: 0.9rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}
.print-meta strong { display: inline-block; min-width: 110px; }
.print-items {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.print-items th,
.print-items td {
  padding: 0.45rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.print-items th {
  background: #f1f5f9;
  font-weight: 600;
}
.print-items .num { text-align: right; font-weight: 600; }
.success-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
}
.success-actions .btn { flex: 1 1 40%; min-width: 140px; }

/* ===== History ===== */
.history-item {
  background: white;
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
}
.history-item:active { transform: scale(0.98); }
.history-item h4 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}
.history-item .meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.history-item .count {
  display: inline-block;
  background: #e0e7ff;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-top: 0.4rem;
}
.hint {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
  font-size: 0.95rem;
}

/* ===== Admin ===== */
.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.admin-cat {
  background: white;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.admin-cat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.admin-cat-header h3 { font-size: 1rem; }
.admin-products { padding: 0.5rem 0; }
.admin-product {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.95rem;
}
.admin-product:last-child { border-bottom: none; }
.admin-product .actions { display: flex; gap: 0.35rem; }
.admin-product button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem;
  opacity: 0.7;
}
.admin-product button:hover { opacity: 1; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.modal h3 {
  margin-bottom: 1rem;
  font-size: 1.15rem;
}
.modal .form-group { margin-bottom: 0.9rem; }
.modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.25rem;
  justify-content: flex-end;
}

/* ===== Print styles ===== */
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .success-actions, .header, .back-btn { display: none !important; }
}

/* ===== Responsive ===== */
@media (min-width: 640px) {
  #app { max-width: 640px; margin: 0 auto; }
  .view { padding-bottom: 5rem; }
}

/* Product images */
.product-img {
  width: 56px;
  height: 40px;
  object-fit: contain;
  border-radius: 6px;
  background: #f8fafc;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.product-img-placeholder {
  width: 56px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  border-radius: 6px;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.product-row {
  gap: 0.6rem;
}
.product-name {
  font-size: 0.88rem;
  line-height: 1.3;
}

/* WhatsApp button */
.btn.whatsapp {
  background: #25D366;
  color: white;
  border-color: #25D366;
}
.btn.whatsapp:hover, .btn.whatsapp:active {
  background: #1da851;
  border-color: #1da851;
}

/* ===== Formular-Look (kompakt, Wiedenig) ===== */
.form-sheet {
  background: #fff;
  border: 2px solid #222;
  border-radius: 2px;
  padding: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: #111;
  max-width: 720px;
  margin: 0 auto 0.8rem;
  box-shadow: none;
  overflow: hidden;
}
.form-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.4rem 0.6rem;
  border-bottom: 2px solid #222;
  background: #f7f7f7;
}
.form-logo {
  font-weight: 800;
  font-size: 0.95rem;
  color: #1e40af;
  line-height: 1.2;
}
.form-logo small {
  display: block;
  font-weight: 600;
  font-size: 0.7rem;
  color: #333;
}
.form-company {
  text-align: right;
  font-size: 0.68rem;
  line-height: 1.25;
}
.form-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  border-bottom: 1px solid #222;
  font-size: 0.75rem;
}
.form-field {
  padding: 0.3rem 0.4rem;
  border-right: 1px solid #222;
}
.form-field:last-child { border-right: none; }
.form-field label {
  display: block;
  font-size: 0.65rem;
  color: #555;
  margin-bottom: 0.1rem;
}
.form-field .value {
  font-weight: 600;
  min-height: 1.1em;
}
.form-baustelle {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid #222;
  font-size: 0.78rem;
}
.form-baustelle label {
  font-size: 0.65rem;
  color: #555;
}
.form-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}
.form-table th {
  background: #e8e8e8;
  border: 1px solid #222;
  padding: 0.25rem 0.25rem;
  text-align: left;
  font-weight: 700;
  line-height: 1.15;
}
.form-table td {
  border: 1px solid #999;
  padding: 0.22rem 0.25rem;
  vertical-align: top;
}
.form-table .col-qty {
  width: 58px;
  text-align: center;
  font-weight: 700;
}
.form-table .col-empty {
  width: 58px;
  background: #fffde7;
}
.form-table .col-code {
  width: 88px;
  font-size: 0.65rem;
  color: #444;
}

@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .success-actions, .header, .back-btn { display: none !important; }
}

/* ===== Responsive ===== */
@media (min-width: 640px) {
  #app { max-width: 640px; margin: 0 auto; }
  .view { padding-bottom: 5rem; }
}

/* Product images */
.product-img {
  width: 56px;
  height: 40px;
  object-fit: contain;
  border-radius: 6px;
  background: #f8fafc;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.product-img-placeholder {
  width: 56px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  border-radius: 6px;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.product-row {
  gap: 0.6rem;
}
.product-name {
  font-size: 0.88rem;
  line-height: 1.3;
}

/* WhatsApp button */
.btn.whatsapp {
  background: #25D366;
  color: white;
  border-color: #25D366;
}
.btn.whatsapp:hover, .btn.whatsapp:active {
  background: #1da851;
  border-color: #1da851;
}

/* ===== Formular-Look (ähnlich eurem Materialschein) ===== */
.form-sheet {
  background: #fff;
  border: 2px solid #333;
  border-radius: 4px;
  padding: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: #111;
  max-width: 800px;
  margin: 0 auto 1rem;
  box-shadow: none;
  overflow: hidden;
}
.form-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.6rem 0.8rem;
  border-bottom: 2px solid #333;
  background: #f8f8f8;
}
.form-logo {
  font-weight: 800;
  font-size: 1.1rem;
  color: #1e40af;
}
.form-logo small {
  display: block;
  font-weight: 600;
  font-size: 0.75rem;
  color: #333;
}
.form-company {
  text-align: right;
  font-size: 0.75rem;
  line-height: 1.3;
}
.form-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  border-bottom: 1px solid #333;
  font-size: 0.8rem;
}
.form-field {
  padding: 0.4rem 0.5rem;
  border-right: 1px solid #333;
}
.form-field:last-child { border-right: none; }
.form-field label {
  display: block;
  font-size: 0.7rem;
  color: #555;
  margin-bottom: 0.15rem;
}
.form-field .value {
  font-weight: 600;
  min-height: 1.2em;
}
.form-baustelle {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid #333;
  font-size: 0.85rem;
}
.form-baustelle label {
  font-size: 0.75rem;
  color: #555;
}
.form-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.form-table th {
  background: #e8e8e8;
  border: 1px solid #333;
  padding: 0.35rem 0.3rem;
  text-align: left;
  font-weight: 700;
}
.form-table td {
  border: 1px solid #999;
  padding: 0.3rem 0.3rem;
  vertical-align: top;
}
.form-table .col-qty {
  width: 70px;
  text-align: center;
  font-weight: 700;
}
.form-table .col-empty {
  width: 70px;
  background: #fffde7;
}
.form-table .col-code {
  width: 100px;
  font-size: 0.72rem;
  color: #444;
}
.form-footer {
  padding: 0.6rem 0.8rem;
  font-size: 0.8rem;
  border-top: 1px solid #333;
  display: flex;
  justify-content: space-between;
}
.form-footer .sig {
  border-bottom: 1px solid #333;
  min-width: 180px;
  display: inline-block;
  margin-left: 0.4rem;
}

@media print {
  .success-card > .success-icon,
  .success-card > h2,
  .success-card > p,
  .success-actions,
  .header,
  .back-btn { display: none !important; }
  .form-sheet {
    border: 1.5px solid #000;
    box-shadow: none;
    max-width: 100%;
  }
  body { background: white; }
}
