:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --line: #eceef2;
    --primary: #e91e63;
    --primary-soft: #fde7ef;
    --ok: #16a34a;
    --ok-soft: #dcfce7;
    --warn: #d97706;
    --warn-soft: #fef3c7;
    --err: #dc2626;
    --err-soft: #fee2e2;
    --info: #2563eb;
    --info-soft: #dbeafe;
    --radius: 14px;
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow-x: hidden;
}
[hidden] { display: none !important; }
h2 { font-size: 1.05rem; margin: 0 0 4px; }
code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: 0.85em; word-break: break-word; }
.muted { color: var(--muted); margin: 0 0 12px; }
small.muted { margin: 0; }
.error { color: var(--err); background: var(--err-soft); padding: 8px 12px; border-radius: 8px; margin: 8px 0; }

/* Buttons */
.btn {
    border: 1px solid transparent; border-radius: 999px; padding: 8px 18px; font: inherit; font-weight: 600;
    cursor: pointer; background: #fff; color: var(--text); text-decoration: none; display: inline-flex;
    align-items: center; justify-content: center; gap: 6px; white-space: nowrap; touch-action: manipulation;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(0.95); }
.btn.danger { background: var(--err); color: #fff; }
.btn.ghost { border-color: var(--line); background: #fff; }
.btn.ghost:hover { border-color: #d1d5db; }
.btn.small { padding: 5px 12px; font-size: 0.85rem; }
.btn.big { padding: 11px 28px; font-size: 1rem; }
.btn.block { width: 100%; }
.btn.link { border: 0; background: none; color: var(--primary); padding: 0; font-weight: 600; }
.btn.danger-text { color: var(--err); }
.btn.danger-text:hover { border-color: var(--err); background: var(--err-soft); }

/* Forms */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { margin-bottom: 4px; font-size: 1.2rem; }
label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 12px; }
input, select, textarea {
    display: block; width: 100%; margin-top: 4px; padding: 9px 12px; font: inherit; color: inherit;
    border: 1px solid #d9dce3; border-radius: 10px; background: #fff; -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, #9ca3af 50%), linear-gradient(135deg, #9ca3af 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input:disabled { background: #f9fafb; color: var(--muted); }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; cursor: pointer; }
label.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; -webkit-appearance: checkbox; appearance: auto; accent-color: var(--primary); }
label.check small { font-weight: 400; }

/* Topbar */
.topbar {
    position: sticky; top: 0; z-index: 10; background: #fff; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 16px; padding: 0 calc(20px + var(--safe-r)) 0 calc(20px + var(--safe-l)); min-height: 60px;
    padding-top: env(safe-area-inset-top, 0px);
}
.topbar-row { display: contents; }
.brand { font-weight: 500; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, #7b2ff7, #e91e63); }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; order: 2; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
    border: 0; background: none; font: inherit; color: var(--muted); padding: 19px 12px; cursor: pointer;
    border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
#logout { order: 3; }
.run-chip { order: 3; font-size: 0.75rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); white-space: nowrap; }
.run-chip.wait { background: var(--warn-soft); color: var(--warn); }
.pill { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: #f3f4f6; color: var(--muted); font-size: 0.75rem; text-align: center; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* Layout */
.container { max-width: 1280px; margin: 0 auto; padding: 20px calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04); min-width: 0; }
.card.narrow { max-width: 720px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.row { display: flex; align-items: center; }
.gap { gap: 12px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 20px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; min-width: 0; }
.kpi:hover { border-color: #d1d5db; }
.kpi .label { color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 0.75rem; color: var(--muted); }
.kpi.ok .value { color: var(--ok); }
.kpi.warn .value { color: var(--warn); }
.kpi.err .value { color: var(--err); }
.kpi.primary .value { color: var(--primary); }

/* Upload + Vorschau */
.dropzone {
    display: grid; place-items: center; text-align: center; padding: 26px 16px; border: 2px dashed #d9dce3;
    border-radius: 12px; cursor: pointer; margin-bottom: 12px; font-weight: 400; color: var(--muted); background: #fafafb; word-break: break-word;
}
.dropzone.drag, .dropzone:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.dropzone.has-file { border-style: solid; border-color: var(--primary); color: var(--text); }

.result { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.result.preview { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.result-head { padding: 12px 14px; background: #fafafb; border-bottom: 1px solid var(--line); }
.result-head b { font-size: 1rem; }
.result-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); gap: 12px; }
.result-row:last-child { border-bottom: 0; }
.result-row .n { font-weight: 700; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 10px; padding: 12px 14px; background: #fafafb; border-top: 1px solid var(--line); }
.result-actions .btn { flex: 1; }
.names { padding: 8px 14px 12px; border-top: 1px solid var(--line); font-size: 0.85rem; }
.names div { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.names s { color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; flex: none; }

/* Rate + run */
.rate-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; margin-bottom: 10px; }
.rate-grid.two { grid-template-columns: 1fr 1fr; }
.rate-grid label { margin-bottom: 0; }
.rate-sep { padding-bottom: 10px; color: var(--muted); font-weight: 600; }
.rate-hint { margin: 4px 0 14px; padding: 10px 12px; background: var(--info-soft); color: #1e3a8a; border-radius: 10px; font-size: 0.85rem; }
.run-actions { display: flex; gap: 10px; }
.run-status { margin: 12px 0 8px; font-size: 0.9rem; }
.run-status .wait { display: block; margin-top: 6px; padding: 8px 12px; background: var(--warn-soft); color: #92400e; border-radius: 10px; }
.progress { height: 8px; background: #f0f1f4; border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, #7b2ff7, #e91e63); transition: width 0.4s; }
.log {
    max-height: 260px; overflow: auto; background: #0f1117; color: #d1d5db; border-radius: 10px; padding: 10px 12px;
    font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-word; -webkit-overflow-scrolling: touch;
}
.log:empty { display: none; }
.log .ok { color: #4ade80; }
.log .skip { color: #fbbf24; }
.log .err { color: #f87171; }
.log .info { color: #93c5fd; }
.log time { color: #6b7280; margin-right: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafafb; }
.table.compact td, .table.compact th { padding: 5px 8px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .wrap { max-width: 380px; word-break: break-word; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.err { background: var(--err-soft); color: var(--err); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.mute { background: #f3f4f6; color: var(--muted); }
.was { color: var(--muted); font-size: 0.8rem; }

.list-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.list-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-tools input, .list-tools select { width: 240px; margin: 0; }
.list-tools select { width: 220px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); gap: 10px; }
.pager .btns { display: flex; gap: 6px; }

.toast { position: fixed; bottom: calc(20px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
.toast.err { background: var(--err); }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
    .kpis { grid-template-columns: repeat(3, 1fr); }
    .grid-2 { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

/* ---------- Handy (iPhone 16 Pro Max = 440 px) ---------- */
@media (max-width: 760px) {
    body { font-size: 15px; }
    /* 16 px verhindert das automatische Zoomen von iOS beim Antippen eines Feldes */
    input, select, textarea { font-size: 16px; padding: 11px 12px; }

    .topbar { flex-wrap: wrap; gap: 0 10px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); min-height: 0; padding-left: calc(16px + var(--safe-l)); padding-right: calc(16px + var(--safe-r)); }
    .topbar-row { display: flex; align-items: center; gap: 10px; width: 100%; }
    .topbar-row .brand { flex: 1; min-width: 0; }
    .tabs { order: 0; flex-basis: 100%; margin: 0 -16px; padding: 0 8px; }
    .tabs button { padding: 13px 10px; }

    .container { padding: 12px calc(12px + var(--safe-r)) calc(24px + var(--safe-b)) calc(12px + var(--safe-l)); }
    .card { padding: 16px; margin-bottom: 12px; border-radius: 16px; }
    .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
    .kpi { padding: 12px; }
    .kpi .value { font-size: 1.4rem; }

    .btn { min-height: 44px; }
    .btn.small { min-height: 38px; padding: 6px 14px; }
    .btn.big { padding: 12px 20px; }
    .run-actions .btn { flex: 1; }
    .result-row { padding: 10px 14px; }
    .result-actions { flex-direction: column-reverse; }
    .log { max-height: 220px; font-size: 11.5px; }

    .list-tools, .list-tools input, .list-tools select { width: 100%; }
    .list-tools .btn { flex: 1; }
    .pager { flex-direction: column; align-items: stretch; text-align: center; }
    .pager .btns .btn { flex: 1; }

    /* Tabellen als Karten: jede Zeile ein Block, Spaltenname links */
    .table.responsive thead { display: none; }
    .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
    .table.responsive tr { border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; background: #fff; }
    .table.responsive td { border: 0; padding: 5px 0; text-align: left !important; max-width: none; display: flex; gap: 12px; justify-content: space-between; align-items: baseline; }
    .table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; flex: none; }
    .table.responsive td[data-label=""]::before, .table.responsive td.empty::before { content: none; }
    .table.responsive td > :only-child { text-align: right; }
    .table.responsive td.primary-cell { display: block; font-size: 1rem; padding-top: 8px; }
    .table.responsive td.primary-cell::before { display: none; }
    .table.responsive td.actions-cell { justify-content: stretch; }
    .table.responsive td.actions-cell .btn { flex: 1; }
    .table.responsive tr.clickable:hover td { background: none; }
}
