:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #94a3b8;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-ink: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 4px 14px rgba(15,23,42,.06);
  --tb-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* CRITICAL: .view { display:flex } would otherwise override the browser's
   [hidden] rule and stack all views visibly on one long page. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }

/* ---------- connectivity bar ---------- */
.connbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; font-size: .82rem; font-weight: 600;
}
.connbar.offline { background: var(--warn); color: #fff; }
.connbar.online  { background: #dcfce7; color: #166534; }
.connbar .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- views ---------- */
.view { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--tb-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h2 { font-size: 1.15rem; margin: 0; font-weight: 700; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-spacer { flex: 1; }
.btn-ghost {
  border: none; background: transparent; color: var(--brand);
  font-size: 1.05rem; font-weight: 700; padding: 10px 12px; border-radius: 12px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn-ghost:active { background: rgba(15,118,110,.1); }
.chip {
  background: var(--brand); color: #fff; font-size: .72rem; font-weight: 700;
  border-radius: 999px; padding: 2px 8px; min-width: 20px; text-align: center;
}

/* ---------- login ---------- */
#view-login { justify-content: center; align-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--card); border-radius: 24px;
  box-shadow: var(--shadow); padding: 28px 24px;
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 14px; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 1.6rem; font-weight: 800;
  display: grid; place-items: center;
}
.brand h1 { font-size: 1.3rem; margin: 0; }
.brand .sub { margin: 2px 0 0; color: var(--ink-soft); font-size: .9rem; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; font-size: 1.05rem; padding: 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: #f8fafc; color: var(--ink);
  outline: none; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--brand-2); background: #fff; }

.btn-primary {
  width: 100%; border: none; cursor: pointer;
  background: var(--brand); color: var(--brand-ink);
  font-size: 1.05rem; font-weight: 700; padding: 15px; border-radius: 12px;
  transition: transform .05s;
}
.btn-primary:active { transform: scale(.98); background: #0d5f58; }
.btn-primary.big { font-size: 1.1rem; padding: 18px; }
.btn-primary[disabled] { background: var(--muted); }
.error { color: var(--danger); font-size: .85rem; margin: 12px 0 0; font-weight: 600; text-align: center; }
.muted { color: var(--muted); } .small { font-size: .82rem; }
.login-user { margin-top: 18px; text-align: center; font-size: .85rem; color: var(--ink-soft); }

/* ---------- category grid ---------- */
.cat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 14px 14px 24px;
}
.cat-tile {
  position: relative; border: none; cursor: pointer; text-align: left;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 16px 14px; min-height: 96px;
  display: flex; flex-direction: column; justify-content: space-between;
  transition: transform .05s;
}
.cat-tile:active { transform: scale(.97); }
.cat-tile .cat-ico { font-size: 1.7rem; }
.cat-tile .cat-name { font-size: 1.02rem; font-weight: 700; line-height: 1.25; margin-top: 10px; }
.cat-tile .cat-count { font-size: .78rem; color: var(--muted); font-weight: 600; }
.cat-tile .cat-bar { position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 4px; }

/* ---------- product list ---------- */
.product-list { padding: 10px 14px 24px; display: flex; flex-direction: column; gap: 10px; }
.prod-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 12px 14px;
}
.prod-info { flex: 1; min-width: 0; cursor: pointer; }
.prod-name { font-size: 1rem; font-weight: 600; line-height: 1.3; }
.prod-arts { font-size: .74rem; color: var(--muted); font-weight: 500; margin-top: 2px; letter-spacing: .2px; }
.qty-ctrl { display: flex; align-items: center; gap: 4px; }
.qty-btn {
  width: 44px; height: 44px; border-radius: 12px; border: none; cursor: pointer;
  background: #eef2f7; color: var(--brand); font-size: 1.4rem; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
}
.qty-btn:active { background: #dce7ef; transform: scale(.94); }
.qty-btn.plus { background: var(--brand); color: #fff; }
.qty-val { min-width: 34px; text-align: center; font-size: 1.1rem; font-weight: 800; }
.qty-val.zero { color: var(--muted); font-weight: 600; }

/* ---------- cart ---------- */
.cart-scroll { flex: 1; overflow-y: auto; padding: 14px 14px 8px; }
.cart-items { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.cart-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow);
}
.cart-item .ci-info { flex: 1; min-width: 0; }
.cart-item .ci-name { font-size: .95rem; font-weight: 600; }
.cart-item .ci-arts { font-size: .72rem; color: var(--muted); }
.cart-item .ci-qty { font-weight: 800; font-size: 1rem; color: var(--brand); min-width: 40px; text-align: right; }
.cart-item .ci-x { border: none; background: #fee2e2; color: var(--danger); width: 34px; height: 34px; border-radius: 10px; font-size: 1.1rem; cursor: pointer; }
.cart-empty { text-align: center; color: var(--muted); padding: 30px 0; font-size: .95rem; }
.cart-footer {
  position: sticky; bottom: 0; padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(241,245,249,0), var(--bg) 30%);
}
#cart-status { text-align: center; margin: 8px 0 0; }

/* ---------- order list ---------- */
.order-list { padding: 12px 14px 24px; display: flex; flex-direction: column; gap: 12px; }
.order-card { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; }
.order-head { display: flex; align-items: baseline; gap: 8px; }
.order-num { font-size: .78rem; color: var(--muted); font-weight: 700; }
.order-cust { font-size: 1.05rem; font-weight: 700; flex: 1; }
.order-when { font-size: .74rem; color: var(--muted); }
.order-items { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.oi { display: flex; gap: 8px; font-size: .88rem; }
.oi .oi-qty { color: var(--brand); font-weight: 800; min-width: 28px; }
.oi .oi-arts { color: var(--muted); font-size: .72rem; }
.order-note { margin-top: 8px; font-size: .85rem; color: var(--ink-soft); font-style: italic; }
.order-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.order-op { font-size: .78rem; color: var(--muted); flex: 1; }
.status-btn {
  border: none; cursor: pointer; font-weight: 700; font-size: .8rem;
  padding: 8px 14px; border-radius: 999px;
}
.status-neu        { background: #e0f2fe; color: #0369a1; }
.status-abgerechnet{ background: #dcfce7; color: #166534; }
.status-storno     { background: #fee2e2; color: #991b1b; }
.order-empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- floating "go to order" ---------- */
.cart-hint {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 1.05rem; font-weight: 800;
  padding: 16px 26px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(15,118,110,.4);
  white-space: nowrap;
}
.cart-hint:active { transform: translateX(-50%) scale(.97); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: .9rem; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 100; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--ok); } .toast.warn { background: var(--warn); }

@media (min-width: 560px) {
  .cat-grid { grid-template-columns: repeat(2, 1fr); max-width: 560px; margin: 0 auto; }
}
