/*
 * Lead-Scanner. Colours as roles, light and dark from the same ramps.
 * Target systems carry the first three categorical slots (validated as a
 * set, all pairs, both modes); every other system is neutral grey — the
 * leads are the point, the rest is context.
 */
:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --surface-2: #f3f2ee;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --accent: #2a78d6;
    --accent-ink: #1c5cab;
    --series-1: #2a78d6; /* Shopware */
    --series-2: #eb6834; /* OXID */
    --series-3: #1baf7a; /* Sulu */
    --neutral: #a8a69f;  /* every other system */
    --good: #0ca30c;
    --good-ink: #006300;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #d03b3b;
    --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.04);
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface: #1a1a19;
        --surface-2: #232321;
        --ink: #ffffff;
        --ink-2: #c3c2b7;
        --muted: #898781;
        --grid: #2c2c2a;
        --axis: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --accent: #3987e5;
        --accent-ink: #86b6ef;
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        --neutral: #5f5e5a;
        --good-ink: #0ca30c;
        --shadow: none;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font: 14px/1.5 var(--font);
}

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
.subtitle { color: var(--ink-2); margin: 0 0 20px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--series-1), var(--series-3)); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
    padding: 6px 12px;
    border-radius: 8px;
    color: var(--ink-2);
    font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--ink); }
.user { color: var(--muted); font-size: 13px; display: flex; gap: 12px; align-items: center; }

main { max-width: 1440px; margin: 0 auto; padding: 24px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 980px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* ---------- stat tiles ---------- */

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 980px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi .label { color: var(--ink-2); font-size: 13px; }
.kpi .value { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; margin-top: 4px; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- badges ---------- */

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); flex: none; }
.platform { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.platform-Shopware .dot, .dot.platform-Shopware { background: var(--series-1); }
.platform-OXID .dot, .dot.platform-OXID { background: var(--series-2); }
.platform-Sulu .dot, .dot.platform-Sulu { background: var(--series-3); }
.platform-none { color: var(--muted); }
.platform-none .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--axis); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--ink-2);
    white-space: nowrap;
}
.badge::before { font-size: 11px; }
.badge.good::before { content: "●"; color: var(--good); }
.badge.idle::before { content: "○"; color: var(--muted); }
.badge.warning::before { content: "▲"; color: var(--warning); }
.badge.critical::before { content: "■"; color: var(--critical); }
.badge.serious::before { content: "◆"; color: var(--serious); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; margin: 1px 2px 1px 0; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left;
    font-weight: 500;
    font-size: 12px;
    color: var(--muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--grid);
    white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.right, th.right { text-align: right; }
.cell-main { font-weight: 550; }
.cell-sub { color: var(--muted); font-size: 12px; }

/* ---------- forms ---------- */

input[type=text], input[type=search], input[type=email], input[type=password], select, textarea {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 10px;
    min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; min-height: 110px; resize: vertical; }

.button, button {
    font: inherit;
    font-weight: 550;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}
.button:hover, button:hover { background: var(--surface-2); text-decoration: none; }
.button.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover, button.primary:hover { filter: brightness(1.08); }
.button.small, button.small { padding: 3px 10px; font-size: 12px; }
form.inline { display: inline; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters .grow { flex: 1 1 220px; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; user-select: none; font-size: 13px; }
.chip input { display: none; }
.chip:has(input:checked) { background: var(--surface-2); border-color: var(--ink-2); font-weight: 550; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

details.add { margin-bottom: 16px; }
details.add summary { cursor: pointer; color: var(--accent-ink); font-weight: 550; }
details.add form { display: grid; gap: 8px; margin-top: 10px; max-width: 640px; }

.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); }
.flash.success { border-left: 4px solid var(--good); }
.flash.warning { border-left: 4px solid var(--warning); }

/* ---------- charts ---------- */

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 64px; align-items: center; gap: 10px; }
.bar-row .name { display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 18px; position: relative; }
.bar { height: 18px; max-width: 100%; border-radius: 0 4px 4px 0; background: var(--neutral); min-width: 2px; }
.bar.platform-Shopware { background: var(--series-1); }
.bar.platform-OXID { background: var(--series-2); }
.bar.platform-Sulu { background: var(--series-3); }
.bar-row .value { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.bar-row:hover .name { color: var(--ink); font-weight: 550; }

.columns { display: flex; align-items: flex-end; gap: 2px; height: 140px; border-bottom: 1px solid var(--axis); position: relative; }
.column { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; position: relative; }
.column:hover { filter: brightness(1.15); }
.column-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }

.tooltip {
    position: fixed;
    z-index: 100;
    pointer-events: none;
    background: var(--ink);
    color: var(--page);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.4;
    max-width: 320px;
    opacity: 0;
    transition: opacity 0.08s;
}
.tooltip.visible { opacity: 1; }
.tooltip strong { font-size: 13px; }

/* ---------- pipeline animation ---------- */

.pipeline {
    position: relative;
    height: 520px;
    overflow: hidden;
    border-radius: var(--radius);
    background:
        radial-gradient(ellipse at 50% 45%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 60%),
        var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.pipeline-inlets { position: absolute; top: 14px; left: 0; right: 0; display: flex; justify-content: space-around; z-index: 3; }
.inlet { text-align: center; font-size: 12px; color: var(--ink-2); width: 150px; }
.inlet strong { display: block; color: var(--ink); font-size: 13px; }
.inlet .inlet-count { font-variant-numeric: tabular-nums; }
.inlet::after { content: ""; display: block; margin: 6px auto 0; width: 2px; height: 26px; background: linear-gradient(var(--axis), transparent); }

.funnel {
    position: absolute;
    left: 50%;
    top: 112px;
    width: 76%;
    height: 120px;
    transform: translateX(-50%);
    background: linear-gradient(color-mix(in srgb, var(--accent) 10%, transparent), color-mix(in srgb, var(--accent) 22%, transparent));
    clip-path: polygon(0 0, 100% 0, 58% 100%, 42% 100%);
    z-index: 1;
}
.funnel-label { position: absolute; left: 50%; top: 186px; transform: translateX(-50%); font-size: 12px; color: var(--ink-2); z-index: 2; text-align: center; }
.funnel-label strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.machine {
    position: absolute;
    left: 50%;
    top: 236px;
    transform: translateX(-50%);
    width: min(560px, 80%);
    padding: 12px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    z-index: 2;
    display: grid;
    gap: 6px;
}
.machine-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); text-align: center; }
.worker-line { display: grid; grid-template-columns: 14px 86px 1fr; align-items: center; gap: 8px; font-size: 12px; min-height: 18px; }
.worker-line .task { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.pulse.running { background: var(--good); animation: pulse 1.2s ease-in-out infinite; }
.pulse.idle { background: transparent; box-shadow: inset 0 0 0 2px var(--good); }
.pulse.dead { background: var(--critical); }
.pulse.stopped { background: var(--axis); }
@keyframes pulse { 50% { transform: scale(1.35); opacity: 0.6; } }

.outlets { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; gap: 10px; padding: 0 16px; z-index: 3; flex-wrap: wrap; }
.bin {
    min-width: 96px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    text-align: center;
    font-size: 12px;
    color: var(--ink-2);
    transition: transform 0.25s;
}
.bin .bin-name { display: flex; align-items: center; justify-content: center; gap: 6px; }
.bin .bin-count { display: block; font-size: 18px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.bin.bump { transform: translateY(-4px) scale(1.06); }
.bin.target { border-color: var(--axis); }

.drop {
    position: absolute;
    z-index: 4;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    white-space: nowrap;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink-2);
    box-shadow: var(--shadow);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    will-change: transform, opacity;
}
.drop.result { color: var(--ink); font-weight: 550; }

.feed-list { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 320px; overflow: auto; }
.feed-list li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--grid); }
.feed-list li:last-child { border-bottom: 0; }

/* ---------- detail ---------- */

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--grid); }
.timeline li { position: relative; padding: 0 0 16px 12px; }
.timeline li::before {
    content: "";
    position: absolute;
    left: -25px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: inset 0 0 0 3px var(--axis);
}
.timeline li.found::before { box-shadow: inset 0 0 0 3px var(--accent); }
.timeline li.analysis-success::before { background: var(--good); box-shadow: none; }
.timeline li.analysis-failed::before { background: var(--critical); box-shadow: none; }
.timeline li.analysis-unreachable::before { background: var(--axis); box-shadow: none; }
.timeline .when { color: var(--muted); font-size: 12px; }
.timeline .what { font-weight: 550; }
.timeline .detail { color: var(--ink-2); overflow-wrap: anywhere; }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login h1 { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.login label { display: grid; gap: 4px; color: var(--ink-2); font-size: 13px; }
.login .error { color: var(--critical); font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
    .pulse.running { animation: none; }
    .bin { transition: none; }
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
details.more-platforms { flex-basis: 100%; }
details.more-platforms > summary { list-style: none; display: inline-flex; }
details.more-platforms > summary::-webkit-details-marker { display: none; }
details.more-platforms[open] > summary { background: var(--surface-2); }
details.more-platforms .chips { margin-top: 8px; }
