*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6f8;
  --card-bg: #fff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --tag-bg: #eff6ff;
  --tag-text: #1e40af;
  --tag-border: #bfdbfe;
  --success: #059669;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  /* Safe-area for iOS PWA */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.stats {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-box {
  flex: 1;
  position: relative;
}

.search-box svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 11px 38px 11px 42px;
  font-size: 16px; /* >= 16 voorkomt iOS zoom on focus */
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s;
  background: #fff;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

#search:focus { border-color: var(--primary); }
#search::placeholder { color: #9ca3af; }
#search::-webkit-search-decoration,
#search::-webkit-search-cancel-button,
#search::-webkit-search-results-button,
#search::-webkit-search-results-decoration { display: none; }

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  background: #e5e7eb;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 0 2px 0;
}

.search-clear.visible { display: flex; }
.search-clear:hover { background: #d1d5db; }

.icon-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s, color .15s;
}

.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { border-color: var(--primary); }
.icon-btn.active { border-color: var(--primary); background: var(--tag-bg); color: var(--primary); }

.icon-btn-plain {
  border: none;
  background: transparent;
  font-size: 26px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 6px;
  line-height: 1;
}
.icon-btn-plain:hover { background: var(--bg); color: var(--text); }

/* Filter panel */
.filter-panel {
  display: none;
  padding: 12px 0 0;
}

.filter-panel.open { display: block; }

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.filter-row label,
.autocomplete-wrap label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.filter-select {
  width: 100%;
  padding: 9px 12px;
  font-size: 15px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  outline: none;
  cursor: pointer;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
  padding-right: 34px;
}

.filter-select:focus { border-color: var(--primary); }

.filter-toggles {
  margin-top: 10px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.check input { width: 16px; height: 16px; cursor: pointer; }

/* Locatie autocomplete */
.autocomplete-wrap { position: relative; }

.autocomplete-input-wrap { position: relative; }

.autocomplete-input {
  width: 100%;
  padding: 9px 34px 9px 12px;
  font-size: 15px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  outline: none;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

.autocomplete-input:focus { border-color: var(--primary); }
.autocomplete-input::placeholder { color: #9ca3af; }

.autocomplete-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  background: #e5e7eb;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 0 2px 0;
}

.autocomplete-clear:hover { background: #d1d5db; }
.autocomplete-clear.visible { display: flex; }

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 200;
  background: #fff;
  border: 2px solid var(--primary);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 280px;
  overflow-y: auto;
  display: none;
  box-shadow: var(--shadow-lg);
  -webkit-overflow-scrolling: touch;
}

.autocomplete-list.open { display: block; }

.autocomplete-item {
  padding: 9px 12px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.autocomplete-item:hover,
.autocomplete-item.highlighted { background: var(--tag-bg); }

.autocomplete-item .count {
  font-size: 11px;
  color: var(--text-muted);
  background: #f3f4f6;
  padding: 1px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}

.autocomplete-selected-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 500;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--tag-border);
  border-radius: 14px;
}

.autocomplete-selected-tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--tag-text);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  opacity: .6;
}

.autocomplete-selected-tag button:hover { opacity: 1; }

/* Main results */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px 32px;
}

.item-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 14px;
  align-items: start;
  transition: box-shadow .12s;
}

.item-card:hover { box-shadow: var(--shadow-lg); }

.item-main { min-width: 0; grid-column: 1; grid-row: 1 / 3; }

.item-artnr {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

.item-desc {
  font-size: 14px;
  color: var(--text);
  line-height: 1.35;
  margin-top: 2px;
  word-break: break-word;
}

.item-side {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.loc-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: 14px;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
  transition: background .12s;
}

.loc-badge:hover { background: var(--primary-hover); }

.loc-badge.empty {
  background: #f3f4f6;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  cursor: default;
}

.loc-badge.empty:hover { background: #f3f4f6; }

.unit-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: #f3f4f6;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

/* Loading / Empty */
.loading, .empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .4; }

/* Highlight */
mark { background: #fef08a; color: inherit; padding: 0 1px; border-radius: 2px; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

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

@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 20px; }
}

.modal {
  background: #fff;
  border-radius: 14px 14px 0 0;
  padding: 20px 18px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  -webkit-overflow-scrolling: touch;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

@media (min-width: 640px) {
  .modal { border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.modal h3 { font-size: 18px; font-weight: 700; }
.modal p { font-size: 14px; color: var(--text); margin-bottom: 16px; line-height: 1.5; }

.modal-section { margin-top: 18px; }
.modal-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}

.modal-hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 10px;
}

.data-meta {
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.5;
}

.data-meta strong { color: var(--text); }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}

.btn {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  transition: all .15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }

.btn-secondary { background: var(--bg); color: var(--text); }
.btn-secondary:hover { background: #e5e7eb; }

.btn-cancel { background: var(--bg); color: var(--text); }
.btn-cancel:hover { background: #e5e7eb; }

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-row .btn { flex: 1; min-width: 0; }

.btn-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  border: none;
  transition: background .15s;
}

.btn-file:hover { background: var(--primary-hover); }
.btn-file svg { width: 16px; height: 16px; }
.btn-file input[type=file] { display: none; }

.file-status {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  min-height: 20px;
}

.file-status.error { color: var(--danger); }
.file-status.ok { color: var(--success); }

.local-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.local-banner svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Toast */
.toast {
  position: fixed;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 24px));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1f2937;
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
  z-index: 2000;
  opacity: 0;
  transition: transform .25s, opacity .25s;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error { background: var(--danger); }
.toast.ok { background: var(--success); }

/* Mobile */
@media (max-width: 640px) {
  .header-inner { padding: 10px 12px; }
  .header-top { gap: 8px; margin-bottom: 8px; }
  .logo { font-size: 16px; }
  .stats { font-size: 12px; }
  .filter-row { grid-template-columns: 1fr; }
  .item-card { padding: 10px 12px; }
  .item-artnr { font-size: 14px; }
  .item-desc { font-size: 13px; }
  .loc-badge { font-size: 13px; padding: 4px 10px; }
  .main { padding: 10px 12px 32px; }
}

/* Tap highlight + selection */
* { -webkit-tap-highlight-color: transparent; }
input, textarea { -webkit-user-select: text; user-select: text; }

/* ── Login ── */
.login { padding: 32px 16px; }
.login[hidden] { display: none; }
.login-card {
  max-width: 380px; margin: 0 auto; padding: 24px; background: var(--card-bg, #fff);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.06); display: flex; flex-direction: column; gap: 8px;
}
.login-card h2 { margin: 0 0 4px; font-size: 1.2rem; }
.login-card p { margin: 0 0 8px; color: var(--text-muted); font-size: .9rem; line-height: 1.4; }
.login-card label { font-size: .85rem; font-weight: 600; margin-top: 4px; }
.login-card input {
  font: inherit; font-size: 16px; padding: 10px 12px; border: 2px solid var(--border);
  border-radius: var(--radius); outline: none; background: #fff;
}
.login-card input:focus { border-color: var(--primary); }
.btn-login { margin-top: 12px; justify-content: center; }
.login-error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }
body.logged-out .search-row, body.logged-out .filter-panel, body.logged-out .stats { display: none; }
