:root {
    --bg: #0e1116;
    --bg-elev: #161b22;
    --bg-elev-2: #1c2230;
    --border: #262d3a;
    --border-soft: #1e242f;
    --text: #e6edf3;
    --text-dim: #8b98a9;
    --text-faint: #616e7f;
    --accent: #3b82f6;
    --accent-hover: #2f6fdd;
    --green: #2ea043;
    --green-soft: #1d3326;
    --amber: #d29922;
    --amber-soft: #33290f;
    --red: #f85149;
    --red-soft: #3a1a1a;
    --blue-soft: #14243d;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 8px 28px rgba(0, 0, 0, .45);
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Muss die display-Regeln der Klassen unten schlagen. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: .92em; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }

/* ------------------------------------------------------------- Buttons -- */
.btn {
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #232b3a; border-color: #34405280; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-elev-2); }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

input[type=password], input[type=text], input[type=search] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #3b82f625; }
input::placeholder { color: var(--text-faint); }

.form-error {
    color: var(--red);
    background: var(--red-soft);
    border: 1px solid #5c2a2a;
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    font-size: 13px;
}

/* --------------------------------------------------------------- Login -- */
.login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: radial-gradient(900px 500px at 50% -10%, #172032 0%, var(--bg) 60%);
}
.login-card {
    width: 100%;
    max-width: 340px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 32px 28px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 12px;
    text-align: center;
}
.login-logo {
    width: 46px; height: 46px;
    margin: 0 auto 4px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    display: grid; place-items: center;
    font-weight: 700; color: #fff;
}
.login-card h1 { font-size: 20px; }
.login-card .muted { font-size: 13px; margin-bottom: 6px; }
.login-card input { text-align: center; }

/* --------------------------------------------------------------- Layout - */
.app { display: grid; grid-template-columns: 264px 1fr; height: 100vh; }

.sidebar {
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    gap: 10px;
    min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 10px; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    display: grid; place-items: center;
    font-size: 13px; font-weight: 700; color: #fff;
}
.brand-text { font-weight: 600; letter-spacing: -.01em; }

.sidebar-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
    color: var(--text-faint); padding: 0 6px;
}
/* Gleiches Problem wie bei .orders – bei vielen Konten wuerden die Eintraege
   sonst zusammengedrueckt statt zu scrollen. */
.account-list { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; min-height: 0; flex: 1; }
.account-item { flex: 0 0 auto; }

.account-item {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    align-items: center;
    gap: 9px;
    padding: 8px 9px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    text-align: left;
    width: 100%;
}
.account-item:hover { background: var(--bg-elev-2); }
.account-item.active { background: var(--blue-soft); border-color: #2a4a7c; }
.account-avatar {
    width: 28px; height: 28px; border-radius: 8px;
    background: var(--bg-elev-2); border: 1px solid var(--border);
    display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.account-item.active .account-avatar { background: var(--accent); border-color: var(--accent); color: #fff; }
.account-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-meta { font-size: 11.5px; color: var(--text-dim); }
.account-badge { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--green); }
.dot.warn { background: var(--amber); }
.dot.err { background: var(--red); }
.dot.sync { background: var(--accent); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

.add-account {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-dim);
    padding: 9px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: .15s;
}
.add-account:hover { border-color: var(--accent); color: var(--text); background: var(--blue-soft); }
.add-account .plus { color: var(--accent); font-weight: 700; }

.sidebar-foot { border-top: 1px solid var(--border-soft); padding-top: 10px; display: grid; gap: 8px; }
.sys-status { font-size: 11.5px; color: var(--text-faint); display: grid; gap: 4px; }
.sys-status .row { display: flex; align-items: center; gap: 6px; }

/* ----------------------------------------------------------------- Main - */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
}
.topbar-title h2 { font-size: 17px; }
.topbar-title p { font-size: 12.5px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; }

.toolbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 22px;
    border-bottom: 1px solid var(--border-soft);
    flex-wrap: wrap;
}
.search-wrap { flex: 1; min-width: 220px; }
.filters { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
    background: transparent; border: 1px solid var(--border);
    padding: 6px 11px; border-radius: 999px; cursor: pointer;
    font-size: 12.5px; color: var(--text-dim); white-space: nowrap;
}
.chip:hover { background: var(--bg-elev-2); color: var(--text); }
.chip.active { background: var(--blue-soft); border-color: #2a4a7c; color: var(--text); }
.chip .n { color: var(--text-faint); margin-left: 5px; font-variant-numeric: tabular-nums; }

/* Bewusst flex statt grid: Als Grid-Zeilen wurden die Karten auf die
   Containerhoehe zusammengestaucht, sobald mehr Bestellungen da waren als
   hineinpassen (durch overflow:hidden auf .order ist deren Mindesthoehe 0).
   flex-shrink: 0 auf den Karten erzwingt die Inhaltshoehe und laesst scrollen. */
/* ----------------------------------------------------------- Übersicht -- */
.account-item.overall { margin-bottom: 4px; }
.account-item.overall .account-avatar { font-size: 15px; }

.overview {
    padding: 16px 22px 4px;
    border-bottom: 1px solid var(--border-soft);
    flex: 0 0 auto;
}
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 9px; }
.tile {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 11px 13px;
    display: grid; gap: 2px;
}
.tile-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile-label { font-size: 11.5px; color: var(--text-dim); }
.tile:first-child .tile-value { color: #56d364; }

.overview-detail {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px; margin-top: 14px;
}
.chart-block { grid-column: span 2; }
@media (max-width: 900px) { .chart-block { grid-column: auto; } }

.bars { display: flex; align-items: flex-end; gap: 5px; height: 96px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
.bar-track { width: 100%; height: 76px; display: flex; align-items: flex-end; }
.bar-fill {
    width: 100%; border-radius: 3px 3px 0 0;
    background: linear-gradient(180deg, var(--accent), #2f6fdd);
    transition: height .25s;
}
.bar-col:hover .bar-fill { background: linear-gradient(180deg, #60a5fa, var(--accent)); }
.bar-label { font-size: 10px; color: var(--text-faint); white-space: nowrap; }

.ranking { display: grid; gap: 7px; }
.rank-row {
    display: grid; grid-template-columns: minmax(0, 1fr) 70px auto;
    align-items: center; gap: 10px; font-size: 12.5px;
}
.rank-row[data-goto] { cursor: pointer; }
.rank-row[data-goto]:hover .rank-title { color: var(--accent); }
.rank-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.rank-bar { height: 6px; background: var(--bg-elev-2); border-radius: 3px; overflow: hidden; }
.rank-bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.rank-count { font-variant-numeric: tabular-nums; color: var(--text); }

.overview-note { font-size: 11.5px; margin-top: 14px; padding-bottom: 4px; }
.badge.account { background: var(--bg-elev-2); border-color: var(--border); }

.orders { flex: 1; overflow-y: auto; padding: 16px 22px; display: flex; flex-direction: column; gap: 9px; }
.pager { padding: 0 22px 18px; display: flex; gap: 8px; align-items: center; }

/* --------------------------------------------------------------- Karte -- */
.order {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    flex: 0 0 auto;
    transition: border-color .15s;
}
.order:hover { border-color: #34405299; }
.order.fresh { border-color: #2a5c3a; box-shadow: 0 0 0 1px #2ea04322; }

.order-head {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.6fr) minmax(0, 1.4fr) auto;
    gap: 14px;
    align-items: center;
    padding: 12px 14px;
    cursor: pointer;
}
.order-col { min-width: 0; display: grid; gap: 3px; }
.order-id { font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.order-date { font-size: 11.5px; color: var(--text-faint); }
.order-buyer { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-user { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-addr { font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-total { font-variant-numeric: tabular-nums; font-weight: 600; }
.order-right { display: flex; align-items: center; gap: 8px; justify-self: end; }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
    border: 1px solid var(--border); color: var(--text-dim); white-space: nowrap;
}
.badge.green { background: var(--green-soft); border-color: #24512f; color: #56d364; }
.badge.amber { background: var(--amber-soft); border-color: #56430f; color: #e3b341; }
.badge.blue  { background: var(--blue-soft); border-color: #2a4a7c; color: #79b8ff; }
.badge.red   { background: var(--red-soft); border-color: #5c2a2a; color: #ff7b72; }
.badge.new   { background: var(--green-soft); border-color: #24512f; color: #56d364; font-weight: 600; }

.tracking {
    font-family: var(--mono); font-size: 12px;
    display: inline-flex; align-items: center; gap: 6px;
}
.tracking .copy { cursor: pointer; color: var(--text-faint); background: none; border: 0; padding: 0 2px; }
.tracking .copy:hover { color: var(--accent); }
.tracking a, .kv a { color: inherit; text-decoration: underline; text-decoration-color: var(--text-faint); text-underline-offset: 2px; }
.tracking a:hover, .kv a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* ------------------------------------------------------------- Details -- */
.order-body { border-top: 1px solid var(--border-soft); padding: 14px; display: none; gap: 18px; }
.order.open .order-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.order.open .order-head { background: var(--bg-elev-2); }

.detail h4 {
    font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
    color: var(--text-faint); margin: 0 0 8px; font-weight: 600;
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; word-break: break-word; }

.items { display: grid; gap: 6px; font-size: 13px; }
.item-row { display: flex; justify-content: space-between; gap: 12px; }
.item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-qty { color: var(--text-faint); }

.timeline { display: grid; gap: 9px; font-size: 12.5px; }
.timeline-row { display: grid; grid-template-columns: 8px 1fr; gap: 10px; }
.timeline-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); margin-top: 6px; }
.timeline-row.first .timeline-dot { background: var(--accent); }
.timeline-when { color: var(--text-faint); font-size: 11.5px; }
.change { color: var(--text-dim); }
.change b { color: var(--text); font-weight: 500; }

.addr-block { font-size: 13px; line-height: 1.65; white-space: pre-line; }

/* --------------------------------------------------------------- Notiz -- */
.note-detail { grid-column: 1 / -1; }
.note-input {
    width: 100%;
    min-height: 76px;
    resize: vertical;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text);
    font: inherit;
    line-height: 1.55;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.note-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #3b82f625; }
.note-input::placeholder { color: var(--text-faint); }
.note-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.note-status { font-size: 12px; }
.badge.note { background: var(--amber-soft); border-color: #56430f; cursor: help; }

.empty {
    text-align: center; padding: 60px 20px; color: var(--text-dim);
    border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty h3 { margin-bottom: 6px; font-size: 15px; color: var(--text); }
.skeleton {
    height: 62px; border-radius: var(--radius);
    background: linear-gradient(90deg, var(--bg-elev) 25%, var(--bg-elev-2) 50%, var(--bg-elev) 75%);
    background-size: 200% 100%; animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { background-position: 200% 0 } to { background-position: -200% 0 } }

/* -------------------------------------------------------------- Dialog -- */
.dialog {
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text);
    border-radius: 14px;
    padding: 24px;
    max-width: 460px;
    width: calc(100% - 32px);
    box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(2px); }
.dialog h3 { font-size: 16px; margin-bottom: 6px; }
.dialog .muted { font-size: 13px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 18px; }
.callout {
    margin-top: 14px; padding: 10px 12px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 12px; color: var(--text-dim);
    word-break: break-all;
}
.callout code { color: var(--text); }
.fallback { margin-top: 16px; border-top: 1px solid var(--border-soft); padding-top: 12px; }
.fallback summary { cursor: pointer; font-size: 13px; color: var(--text-dim); }
.fallback summary:hover { color: var(--text); }
.fallback p { margin: 10px 0; }
.fallback input { margin-bottom: 8px; }
.dialog .form-error { margin-top: 12px; }

/* ------------------------------------------------------------- Sprache -- */
.lang-switch { display: flex; gap: 4px; justify-content: center; }
.lang-btn {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: var(--radius-sm);
    padding: 5px 0;
    font-size: 11.5px;
    letter-spacing: .06em;
    cursor: pointer;
    transition: .15s;
}
.lang-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.lang-btn.active { background: var(--blue-soft); border-color: #2a4a7c; color: var(--text); }
.login-card .lang-switch { margin-top: 4px; }

/* --------------------------------------------------------- Zwei-Faktor -- */
.twofa-label {
    display: block; margin: 16px 0 6px;
    font-size: 12px; color: var(--text-dim);
}
.qr {
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 12px;
    margin: 14px 0;
    display: flex; justify-content: center;
}
.qr svg { width: 190px; height: 190px; display: block; }
.recovery {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
    margin-top: 12px;
}
.recovery code {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 7px 9px;
    text-align: center; font-size: 13px; letter-spacing: .04em;
}
#code { text-align: center; letter-spacing: .3em; font-size: 18px; }

/* -------------------------------------------------------------- Toasts -- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 50; }
.toast {
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 11px 15px;
    box-shadow: var(--shadow);
    font-size: 13px;
    max-width: 340px;
    animation: slide-in .22s ease-out;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes slide-in { from { transform: translateX(16px); opacity: 0 } to { transform: none; opacity: 1 } }

/* --------------------------------------------------------------- Klein -- */
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; height: auto; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
    .account-list { max-height: 220px; }
    .order-head { grid-template-columns: 1fr; gap: 8px; }
    .order-right { justify-self: start; flex-wrap: wrap; }
}
