:root {
  --brand: #0B5A75;
  --brand-dark: #084357;
  --brand-soft: #e8f1f5;
  --bg: #eef2f5;
  --panel: #ffffff;
  --line: #dae3e9;
  --line-strong: #c2d0da;
  --text: #17202a;
  --muted: #6b7c89;
  --danger: #b3261e;
  --ok: #1c7c54;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 35, 47, 0.06), 0 4px 14px rgba(16, 35, 47, 0.06);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
  font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ Topbar */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 0 18px; height: 56px;
  background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 40;
}
.topbar .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.2px; }
.topbar .logo img { height: 26px; max-width: 130px; object-fit: contain; background: #fff; border-radius: 4px; padding: 2px 5px; }
.topbar .logo .sub { font-weight: 400; opacity: 0.72; font-size: 12px; display: block; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.topbar nav a, .topbar nav button {
  color: #fff; text-decoration: none; padding: 7px 12px; border-radius: 7px;
  background: transparent; border: 0; cursor: pointer; font-size: 13px; opacity: 0.9;
}
.topbar nav a:hover, .topbar nav button:hover { background: rgba(255,255,255,0.14); opacity: 1; }
.topbar nav a.active { background: rgba(255,255,255,0.2); opacity: 1; }
.topbar .user { font-size: 12.5px; opacity: 0.8; padding-right: 4px; }

/* -------------------------------------------------------------------- Layout */
.workspace {
  display: grid; grid-template-columns: 250px minmax(0, 1fr) 400px;
  gap: 14px; padding: 14px; align-items: start;
  height: calc(100vh - 56px);
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; height: 100%;
}
.panel > header {
  padding: 11px 14px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; gap: 8px; flex-shrink: 0;
}
.panel > header h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); }
.panel > header .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.panel .scroll { overflow-y: auto; flex: 1; min-height: 0; }

/* ------------------------------------------------------------------- Filter */
.filter-group { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.filter-group:last-child { border-bottom: 0; }
.filter-group h3 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
}
.chip-list { display: flex; flex-direction: column; gap: 2px; }
#vendor-list { margin-top: 8px; }
.chip {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  padding: 6px 8px; border-radius: 7px; border: 0; background: transparent; cursor: pointer;
  font-size: 13px; color: var(--text);
}
.chip:hover { background: var(--brand-soft); }
.chip.active { background: var(--brand); color: #fff; font-weight: 600; }
.chip .n { margin-left: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.active .n { color: rgba(255,255,255,0.8); }

/* ------------------------------------------------------------------ Controls */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
input[type="text"], input[type="search"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: #fff; outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(11, 90, 117, 0.13);
}
textarea { resize: vertical; min-height: 56px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 13px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: #f5f8fa; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fdeceb; }
.btn.small { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; }

.searchbar { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; flex-shrink: 0; }
.searchbar input { flex: 1; }
.searchbar select { width: auto; flex-shrink: 0; }

/* --------------------------------------------------------------- Ergebnisse */
.result {
  display: grid; grid-template-columns: 42px minmax(0,1fr) auto auto;
  gap: 10px; align-items: center; padding: 8px 14px; border-bottom: 1px solid #eef2f5;
}
.result:hover { background: #f8fbfc; }
.result .thumb {
  width: 42px; height: 42px; border-radius: 7px; border: 1px solid var(--line);
  object-fit: contain; background: #fff; flex-shrink: 0;
}
.result .thumb.placeholder { display: flex; align-items: center; justify-content: center; color: #b8c6d0; font-size: 15px; }
.result .name { font-weight: 550; line-height: 1.3; }
.result .meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; }
.result .meta .sku { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 11.5px; }
.result .price { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.result .price .old { display: block; font-size: 11px; color: var(--muted); text-decoration: line-through; font-weight: 400; }
.result.in-form { background: #f2f8f5; }
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 20px; font-size: 10.5px;
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.badge.ok { background: #e3f3ec; color: var(--ok); }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ------------------------------------------------------------------ Formular */
.form-section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.form-grid .full { grid-column: 1 / -1; }
details.form-section > summary {
  list-style: none; cursor: pointer; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--muted); display: flex; align-items: center; gap: 6px; user-select: none;
}
details.form-section > summary::-webkit-details-marker { display: none; }
details.form-section > summary::before { content: "▸"; font-size: 10px; transition: transform .15s; }
details.form-section[open] > summary::before { transform: rotate(90deg); }
details.form-section > summary + * { margin-top: 10px; }

.pos {
  display: grid; grid-template-columns: 20px minmax(0,1fr) auto; gap: 8px; align-items: start;
  padding: 8px 14px; border-bottom: 1px solid #eef2f5; background: #fff;
}
.pos.dragging { opacity: 0.4; }
.pos.drop-target { box-shadow: inset 0 2px 0 var(--brand); }
.pos .handle { cursor: grab; color: #b8c6d0; text-align: center; font-size: 13px; padding-top: 2px; user-select: none; }
.pos .pos-main { min-width: 0; cursor: pointer; }
.pos .name { font-weight: 550; font-size: 13px; line-height: 1.3; }
.pos .meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.pos .actions { display: flex; gap: 2px; }
.pos .icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  padding: 3px 5px; border-radius: 6px; font-size: 13px; line-height: 1;
}
.pos .icon-btn:hover { background: var(--brand-soft); color: var(--brand); }
.pos .icon-btn.remove:hover { background: #fdeceb; color: var(--danger); }
.pos .editor { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 8px 0 3px; }
.pos .editor .full { grid-column: 1 / -1; }
.pos .editor input { padding: 6px 8px; font-size: 12.5px; }
.pos .editor label { font-size: 10px; }

.group-label {
  padding: 6px 14px; background: #f0f5f8; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--brand);
}

.form-footer {
  padding: 12px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column;
  gap: 8px; background: #fafcfd; flex-shrink: 0;
}
.form-footer .row { display: flex; gap: 8px; }
.form-footer .row .btn { flex: 1; }
.discount-row { display: flex; align-items: center; gap: 8px; }
.discount-row label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.discount-row select { flex: 1; }
.discount-row input { width: 72px; flex-shrink: 0; }
.opts { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.opts label { display: flex; align-items: center; gap: 5px; font-size: 12.5px; cursor: pointer; }
.opts input[type="checkbox"] { accent-color: var(--brand); width: 15px; height: 15px; }

/* -------------------------------------------------------------------- Dialog */
dialog {
  border: 0; border-radius: 12px; padding: 0; box-shadow: 0 20px 60px rgba(16, 35, 47, 0.28);
  max-width: 560px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(16, 35, 47, 0.45); }
dialog.wide { max-width: 760px; }
dialog header { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 650; }
dialog .tabs { display: flex; gap: 4px; padding: 10px 18px 0; border-bottom: 1px solid var(--line); }
dialog .tab {
  border: 0; background: transparent; cursor: pointer; padding: 8px 12px; border-radius: 8px 8px 0 0;
  font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
dialog .tab:hover { background: var(--brand-soft); }
dialog .tab.active { color: var(--brand); font-weight: 650; border-bottom-color: var(--brand); }
dialog .dlg-note { margin-right: auto; font-size: 12px; color: var(--muted); align-self: center; }
dialog .body { padding: 18px; display: flex; flex-direction: column; gap: 12px; max-height: 65vh; overflow-y: auto; }
dialog footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafcfd; }

/* --------------------------------------------------------------- Archiv */
.arc-row { padding: 11px 0; border-bottom: 1px solid var(--line); }
.arc-row:last-child { border-bottom: 0; }
.arc-head { display: flex; align-items: baseline; gap: 8px; }
.arc-head .name { font-weight: 650; }
.arc-head .sub { color: var(--muted); font-size: 12.5px; }
.arc-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.arc-meta .who { color: var(--brand); font-weight: 600; }
.arc-cats { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.arc-actions { display: flex; gap: 6px; margin-top: 8px; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px;
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.pill.discount { background: #fdeceb; color: var(--danger); }

.tpl-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.tpl-row:last-child { border-bottom: 0; }
.tpl-row .info { flex: 1; min-width: 0; }
.tpl-row .info .name { font-weight: 600; }
.tpl-row .info .meta { font-size: 12px; color: var(--muted); }

/* --------------------------------------------------------------------- Toast */
.toasts { position: fixed; right: 16px; top: 68px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: #17202a; color: #fff; padding: 10px 14px; border-radius: 9px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.22); max-width: 380px; animation: slide-in .18s ease-out;
}
.toast.error { background: var(--danger); }
.toast.hide { opacity: 0; transition: opacity .25s; }
.toast.ok { background: var(--ok); }
@keyframes slide-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
.btn:not(.primary) .spinner { border-color: rgba(11,90,117,0.25); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------- Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(150deg, var(--brand) 0%, #06344a 100%); }
.login-card { background: #fff; border-radius: 14px; padding: 30px; width: 100%; max-width: 380px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.25); }
.login-card h1 { margin: 0 0 4px; font-size: 20px; color: var(--brand); }
.login-card p.lead { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 13px; }
.login-error { background: #fdeceb; color: var(--danger); padding: 9px 12px; border-radius: 8px; font-size: 13px; }

/* --------------------------------------------------------------------- Admin */
.admin-wrap { max-width: 880px; margin: 0 auto; padding: 22px 16px 60px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 4px; font-size: 15px; }
.card p.hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: 190px 1fr; gap: 7px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.ok { background: var(--ok); }
.status-dot.err { background: var(--danger); }
.status-dot.idle { background: #b8c6d0; }
.btn-row { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.logo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
#logo-preview { max-height: 56px; max-width: 220px; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; background: #fff; }
pre.log {
  background: #0f1b23; color: #d6e4ec; padding: 12px; border-radius: 9px; font-size: 11.5px;
  max-height: 260px; overflow: auto; margin: 12px 0 0; line-height: 1.5;
}
.warn-box { background: #fff6e5; border: 1px solid #f0d9a8; color: #7a5a12; padding: 10px 12px;
  border-radius: 8px; font-size: 13px; margin-bottom: 12px; }

/* ---------------------------------------------------------------- Responsive */
.mobile-tabs { display: none; }
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 220px minmax(0,1fr) 350px; }
}
@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; height: auto; padding: 10px; }
  .panel { height: auto; max-height: 72vh; }
  .mobile-tabs { display: flex; gap: 6px; padding: 10px 10px 0; }
  .mobile-tabs .btn { flex: 1; }
  body.tab-filter .panel-results, body.tab-filter .panel-form,
  body.tab-results .panel-filter, body.tab-results .panel-form,
  body.tab-form .panel-filter, body.tab-form .panel-results { display: none; }
}
