:root {
    /* Farben aus dem Knobelbox-Logo: Orange #b66a31, Dunkelbraun #493c35, Taupe #7b6a58 */
    --brand-orange: #b66a31;
    --brand-brown: #493c35;
    --brand-taupe: #7b6a58;
    --bg: #f6f4f2;
    --surface: #ffffff;
    --text: #2b2420;
    --muted: #7b6a58;
    --border: #e7e1db;
    --accent: #a85f2a;
    --accent-hover: #8f4f22;
    --accent-soft: #f7ece3;
    --ok: #137333;
    --ok-soft: #e6f4ea;
    --warn: #a15c00;
    --warn-soft: #fef3e0;
    --off: #7b6a58;
    --off-soft: #efebe7;
    --danger: #b3261e;
    --danger-soft: #fce8e6;
    --topbar: #493c35;
    --radius: 8px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.nowrap { white-space: nowrap; }

/* Kopfzeile ------------------------------------------------------------- */
.topbar {
    display: flex; align-items: center; gap: 1.5rem;
    background: var(--surface); color: var(--text); padding: 0 1.25rem; height: 60px;
    border-bottom: 3px solid var(--brand-orange);
    position: sticky; top: 0; z-index: 10;
}
.brand, .login-brand { display: flex; align-items: center; gap: .6rem; }
.brand img { display: block; height: 32px; width: auto; }
.brand span, .login-brand span {
    color: var(--brand-taupe); font-weight: 400; font-size: 1.05rem;
    padding-left: .6rem; border-left: 1px solid var(--border); line-height: 1.6;
}
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: .25rem; flex: 1; }
.topbar nav > a, .dropdown > button {
    color: var(--brand-brown); background: none; border: 0; font: inherit; cursor: pointer;
    padding: .5rem .75rem; border-radius: 6px;
}
.topbar nav > a:hover, .dropdown > button:hover { background: var(--bg); color: var(--brand-brown); text-decoration: none; }
.topbar nav > a.active, .dropdown > button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.logout { color: var(--muted); font-size: .9rem; }
.logout:hover { color: var(--accent); }

.dropdown { position: relative; }
.caret { font-size: .8em; }
.dropdown-menu {
    display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 260px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: .375rem;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu ul { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.dropdown-menu a { display: block; padding: .45rem .65rem; border-radius: 6px; color: var(--text); }
.dropdown-menu a:hover { background: var(--bg); text-decoration: none; }
.dropdown-menu a.active { background: var(--accent-soft); color: var(--accent); }
.dropdown-menu input { width: 100%; margin-bottom: .375rem; }
.dropdown-menu a.dropdown-refresh { border-top: 1px solid var(--border); border-radius: 0; margin-top: .375rem; padding-top: .55rem; color: var(--muted); font-size: .85rem; }
.dropdown-menu .empty { padding: .45rem .65rem; color: var(--muted); }
/* Lieferanten: drei Spalten, von oben nach unten alphabetisch */
.dropdown-menu.dropdown-wide { width: min(720px, calc(100vw - 2rem)); }
.dropdown-scroll { max-height: 60vh; overflow-y: auto; }
.dropdown-menu ul.dropdown-columns { columns: 3; column-gap: .375rem; max-height: none; overflow: visible; }
.dropdown-columns li { break-inside: avoid; }
.dropdown-columns a { overflow-wrap: anywhere; }
@media (max-width: 700px) {
    .dropdown-menu ul.dropdown-columns { columns: 1; }
    .dropdown-menu.dropdown-wide { position: fixed; top: 60px; left: .75rem; right: .75rem; width: auto; }
}

/* Inhalt ---------------------------------------------------------------- */
main { padding: 1.5rem 1.25rem 3rem; max-width: 1400px; margin: 0 auto; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 1.25rem 1.5rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head p { margin: 0; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: .85rem; margin: 0 0 .5rem; }

input[type=search], input[type=text], input[type=number], input[type=date], input[type=password], input:not([type]) {
    font: inherit; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
.check { display: inline-flex; gap: .35rem; align-items: center; color: var(--muted); font-size: .9rem; }

.btn {
    display: inline-block; font: inherit; font-size: .9rem; padding: .45rem .9rem; cursor: pointer;
    border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text);
}
.btn:hover { text-decoration: none; border-color: #cfc5bb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.small { font-size: .8rem; padding: .25rem .6rem; }
.btn[disabled] { opacity: .5; cursor: wait; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card form { margin-top: 1rem; }

.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.success { background: var(--ok-soft); color: var(--ok); }

.empty-state { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 3rem; text-align: center; color: var(--muted); }

/* Tabellen -------------------------------------------------------------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: .6rem .75rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #faf8f6; position: sticky; top: 0; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #faf8f6; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.compact { margin-top: .5rem; }
.card table.data { border: 1px solid var(--border); border-radius: var(--radius); }

/* Sortierung und Spaltenfilter */
.sort-button {
    all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: .3rem;
    font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit;
}
.sort-button:hover, .sort-button:focus-visible { color: var(--text); }
.sort-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.sort-icon::after { content: "↕"; opacity: .35; font-size: .9em; }
th[aria-sort=ascending] .sort-icon::after { content: "▲"; opacity: 1; color: var(--accent); }
th[aria-sort=descending] .sort-icon::after { content: "▼"; opacity: 1; color: var(--accent); }
th[aria-sort=ascending], th[aria-sort=descending] { color: var(--text); }
table.data tr.filter-row th { padding-top: 0; padding-bottom: .5rem; position: static; text-transform: none; letter-spacing: 0; }
.filter-row select { font: inherit; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.filter-row input, .filter-row select { width: 100%; min-width: 4.5rem; font-size: .82rem; padding: .25rem .4rem; font-weight: 400; }
.filter-row th.num input { text-align: right; }

.address { line-height: 1.4; font-size: .92rem; }
.items { list-style: none; padding: 0; margin: 0; font-size: .92rem; }
.items li + li { margin-top: .2rem; }
.items .qty { font-weight: 600; font-variant-numeric: tabular-nums; }
.items .muted { font-size: .85em; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; margin-top: .2rem; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: var(--off-soft); color: var(--off); }
.title-badge { font-size: .85rem; vertical-align: middle; margin: 0 0 0 .4rem; }
.badge.progress { background: #e8f0fe; color: #1a5fb4; }

/* Direktbearbeitung ----------------------------------------------------- */
td.editable { cursor: pointer; position: relative; }
td.editable:hover, td.editable:focus { background: var(--accent-soft); outline: none; }
td.editable.low, td.num.low { color: var(--danger); font-weight: 600; }
td.editable.saving { opacity: .5; }
td.editable.saved { animation: flash 1.2s ease-out; }
td.editable input { width: 100%; min-width: 5.5rem; padding: .2rem .4rem; text-align: inherit; }
td.editable input[type=date] { min-width: 9.5rem; }
@keyframes flash { from { background: var(--ok-soft); } to { background: transparent; } }

.toast {
    position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(150%);
    background: var(--topbar); color: #fff; padding: .7rem 1.1rem; border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,.2); transition: transform .2s, opacity .2s; max-width: 90vw;
    opacity: 0; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: var(--danger); }

/* Anmeldung ------------------------------------------------------------- */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--brand-orange); border-radius: var(--radius); padding: 2rem; width: min(360px, 92vw); display: grid; gap: 1rem; }
.login-box h1 { margin-bottom: .5rem; }
.login-brand img { display: block; height: 40px; width: auto; max-width: 100%; }
.login-box label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }

@media (max-width: 700px) {
    .topbar { gap: .5rem; padding: 0 .75rem; }
    .brand span, .logout { display: none; }
    .brand img { height: 24px; }
    main { padding: 1rem .75rem 2rem; }
}
.btn.busy { opacity: .7; cursor: progress; }

/* Bestellungen ---------------------------------------------------------- */
table.data tr.clickable { cursor: pointer; }
table.data tfoot td { border-bottom: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0 1rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.card .address { margin: 0; }
.card .address + .facts { margin-top: .8rem; }
.facts dd { overflow-wrap: anywhere; }

/* Reiter für die Bestelllisten ------------------------------------------ */
.tabs { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs > a { padding: .5rem .85rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs > a:hover { color: var(--text); text-decoration: none; }
.tabs > a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs-search { margin-left: auto; padding-bottom: .35rem; }
.tabs-search input { width: 240px; }
.tracking-input { width: 13rem; max-width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.form-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1rem 0 1.5rem; }
.upload-card form { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.pagination { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }
.per-page { margin-left: auto; }
.per-page label { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--muted); }
.per-page select { width: auto; }
@media (max-width: 700px) { .tabs-search { margin-left: 0; width: 100%; } .tabs-search input { width: 100%; } }
.tracking + .tracking { margin-top: .4rem; }

/* Kennzahlen auf der Startseite ---------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpis > .alert, .kpi-stamp { grid-column: 1 / -1; margin: -.5rem 0 0; font-size: .85rem; text-align: right; }
.kpis > .alert { margin: 0; text-align: left; }
.kpi-box { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--brand-orange); border-radius: var(--radius); padding: .9rem 1rem; }
.kpi-box h2 { color: var(--brand-brown); }
.kpi-box dl { display: grid; grid-template-columns: 1fr auto; gap: .35rem 1rem; margin: 0; }
.kpi-box dt { color: var(--muted); }
.kpi-box dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi-sub { font-weight: 400; color: var(--muted); margin-left: .25rem; }
.kpi-note { margin: .6rem 0 0; font-size: .8rem; color: var(--muted); }
@media (max-width: 1000px) { .kpis { grid-template-columns: minmax(0, 1fr); } }
.kpi-box dt a { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
.kpi-box dt a:hover { color: var(--accent); }
.kpi-box.loading { opacity: .6; }
.kpi-box.loading p { margin: .5rem 0 0; }

/* Rücksendung ---------------------------------------------------------- */
.return-input { width: 5rem; text-align: right; }
.returns-title { font-size: 1rem; margin: 1.2rem 0 0; }
.returns-log { margin: .4rem 0 0; padding-left: 1.2rem; }

/* Verlauf einer Bestellung ------------------------------------------------ */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 9.5rem 7rem 1fr; gap: .6rem; padding: .45rem 0; border-top: 1px solid var(--border); font-size: .92rem; }
.timeline li:first-child { border-top: 0; }
.timeline-date { color: var(--muted); }
.timeline-area { font-weight: 600; }
@media (max-width: 600px) { .timeline li { grid-template-columns: 1fr; gap: .1rem; } }

/* Produkt-Import --------------------------------------------------------- */
.import-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: .75rem 1rem; }
.import-head h2 { margin: 0 0 .25rem; overflow-wrap: anywhere; }
.import-head p { margin: 0; }
.import-head .alert, .import-message { flex-basis: 100%; margin: 0; }
.progress { height: .9rem; background: var(--off-soft); border-radius: 99px; overflow: hidden; margin: .75rem 0 .5rem; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.import-counts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin: 1rem 0 0; }
.import-counts > div { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; }
.import-counts dt { color: var(--muted); font-size: .85rem; }
.import-counts dd { margin: .2rem 0 0; font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.import-counts .has-errors { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.import-counts .has-errors dt { color: inherit; }
.import-notes { margin: .5rem 0 0; padding-left: 1.2rem; }
.import-notes li + li { margin-top: .35rem; }
.import-notes li.warn { color: var(--warn); }
.import-messages { max-height: 24rem; overflow-y: auto; margin-top: .5rem; }
.import-messages.errors td:first-child { color: var(--danger); font-weight: 600; }
.import-skus { overflow-wrap: anywhere; line-height: 1.6; }
@media (max-width: 700px) { .import-counts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Auswahl für den Versand-Export ----------------------------------------- */
.check-col { width: 1.5rem; text-align: center; }
.check-col input { width: 1rem; height: 1rem; cursor: pointer; }
tr.deferred td { background: var(--warn-soft); }
.muted.small { font-size: .82rem; }

/* Verkaufskanäle ---------------------------------------------------------- */
.badge.ch-brown { background: #f3e6da; color: #8a4b1f; }
.badge.ch-yellow { background: #fff3c4; color: #8a6a00; }
.badge.ch-red { background: #fde4e1; color: #b3261e; }
.badge.ch-grey { background: #e6e6e6; color: #4a4a4a; }
.badge.ch-blue { background: #e1ecfb; color: #1a5fb4; }
.badge.ch-black { background: #222; color: #fff; }
.badge.ch-other { background: var(--off-soft); color: var(--off); }
