:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e3e8ef;
  --text: #1a2433;
  --text-muted: #5a6878;
  --primary: #0a5784;
  --primary-hover: #084766;
  --secondary: #eef2f6;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --accent: #0891b2;
  --shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}
.brand {
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo { font-size: 22px; }
.topbar nav {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user {
  color: var(--text-muted);
  font-size: 13px;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* ---------- Buttons ---------- */
.btn {
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--secondary);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: #e0e7ec;
}
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

/* ---------- Actions bar ---------- */
.actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.search-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 280px;
}
#search {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  max-width: 360px;
  font-size: 14px;
  background: white;
}
#search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 87, 132, 0.1);
}
.count {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}
.actions {
  display: flex;
  gap: 10px;
}
.cache-info {
  color: var(--text-muted);
  font-size: 12px;
  margin: 0 0 16px 0;
}

/* ---------- Table ---------- */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
table {
  width: 100%;
  border-collapse: collapse;
}
thead {
  background: #f9fafb;
}
th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  user-select: none;
  white-space: nowrap;
}
th:hover { background: #f3f4f6; }
th.num { text-align: right; }

td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

td.sku {
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 13px;
  color: var(--text-muted);
}
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
td.notes {
  max-width: 280px;
  color: var(--text-muted);
  font-size: 13px;
}

.sale-badge {
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.cat-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  margin-right: 4px;
  margin-bottom: 2px;
  /* Fallback grijs als categorie geen specifieke kleur heeft */
  background: #e2e8f0;
  color: #475569;
}

.cat-badge.cat-diepvries {
  background: #dbeafe;
  color: #1e40af;
}
.cat-badge.cat-gerookt {
  background: #fed7aa;
  color: #9a3412;
}
.cat-badge.cat-verse-vis {
  background: #d1fae5;
  color: #065f46;
}
.cat-badge.cat-schaal-en-schelp {
  background: #cffafe;
  color: #155e75;
}
.cat-badge.cat-visdelicatessen {
  background: #e9d5ff;
  color: #6b21a8;
}
.cat-badge.cat-dim-sum {
  background: #fecaca;
  color: #991b1b;
}
.cat-badge.cat-salades {
  background: #ecfccb;
  color: #4d7c0f;
}
.cat-badge.cat-non-food {
  background: #f1f5f9;
  color: #475569;
}

.stock-empty {
  color: #cbd5e1;
  font-size: 12px;
  font-style: italic;
}

/* ---------- Editable cells ---------- */
td.editable {
  cursor: cell;
  position: relative;
  transition: background 0.1s;
}
td.editable:hover {
  background: #eff6ff;
}
td.editable:hover::after {
  content: "✎";
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 11px;
}
.cell-input {
  width: 100%;
  padding: 6px 8px;
  border: 2px solid var(--primary);
  border-radius: 4px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
  background: white;
  outline: none;
}
.cell-changed {
  background: #fef9c3 !important;
  position: relative;
}
.cell-changed::before {
  content: "•";
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--warning);
  font-size: 22px;
  line-height: 0;
}

/* Stock toggle button */
.stock-toggle {
  background: none;
  border: 1px solid transparent;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  width: 100%;
}
.stock-toggle:hover {
  background: #eff6ff;
  border-color: var(--border);
}
.stock-toggle.cell-changed {
  background: #fef9c3 !important;
  border-color: var(--warning);
}

/* ---------- Save bar ---------- */
.save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
  z-index: 100;
  padding: 14px 24px;
  animation: slideUp 0.2s ease-out;
}
.save-bar.hidden { display: none; }

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.save-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.save-info {
  font-size: 14px;
  color: var(--text);
}
.save-info strong {
  color: var(--warning);
  font-size: 16px;
  margin-right: 4px;
}
.save-actions {
  display: flex;
  gap: 10px;
}

.stock {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.stock-in { color: var(--success); }
.stock-out { color: var(--danger); }
.stock-back { color: var(--warning); }

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
}

/* ---------- Sync panel ---------- */
.sync-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 16px 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.sync-panel.hidden { display: none; }

.sync-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}
.sync-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;
}
.dot-running {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.dot-success { background: var(--success); }
.dot-failed { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sync-time {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: auto;
  margin-right: 12px;
}

.sync-output {
  margin: 0;
  padding: 14px 16px;
  background: #0f172a;
  color: #cbd5e1;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 12px;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

/* ---------- Flash messages ---------- */
.flash {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}
.flash-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}
.flash-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
  text-align: center;
}
.login-logo {
  font-size: 48px;
  margin-bottom: 8px;
}
.login-card h1 {
  margin: 0 0 4px 0;
  font-size: 22px;
}
.subtitle {
  color: var(--text-muted);
  margin: 0 0 28px 0;
  font-size: 14px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-form span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.login-form input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: white;
}
.login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 87, 132, 0.1);
}
.login-form button {
  margin-top: 8px;
  padding: 11px;
  font-size: 15px;
  justify-content: center;
}

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .container { padding: 16px; }
  .actions-bar { flex-direction: column; align-items: stretch; }
  .actions { justify-content: stretch; }
  .actions .btn { flex: 1; justify-content: center; }
  th, td { padding: 10px 12px; font-size: 13px; }
  td.notes { max-width: 160px; }
}
