/* ===== Reset & Basis ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #f1f5f9;
    --surface:    #ffffff;
    --border:     #e2e8f0;
    --text:       #1e293b;
    --text-muted: #64748b;
    --primary:    #1e40af;
    --primary-h:  #1d3a9e;
    --radius:     10px;
    --shadow:     0 1px 6px rgba(0,0,0,.08);

    --c-gruen:     #16a34a;
    --c-gelb:      #ca8a04;
    --c-orange:    #ea580c;
    --c-rot:       #dc2626;
    --c-dunkelrot: #7f1d1d;

    --bg-gruen:     #dcfce7;
    --bg-gelb:      #fef9c3;
    --bg-orange:    #ffedd5;
    --bg-rot:       #fee2e2;
    --bg-dunkelrot: #fde8e8;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: .9rem;
    line-height: 1.5;
}

/* ===== Navbar ===== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .875rem 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.navbar-brand { display: flex; align-items: center; gap: .875rem; }
.navbar-logo   { height: 36px; width: auto; filter: brightness(0) invert(1); opacity: .9; }
.navbar-title  { font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; }
.navbar-subtitle { font-size: .78rem; opacity: .75; }
.navbar-meta { display: flex; align-items: center; gap: 1.25rem; }
.navbar-updated { font-size: .8rem; opacity: .85; }
.btn-logout {
    font-size: .82rem;
    color: white;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,.4);
    border-radius: 6px;
    padding: .35rem .75rem;
    transition: background .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.15); }

/* ===== Layout ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* ===== KPI-Kacheln ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}
.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}
.kpi-card--warn { border-left-color: var(--c-rot); }
.kpi-label {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin-bottom: .35rem;
}
.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}
.kpi-sub {
    font-size: .82rem;
    color: var(--text-muted);
    margin-top: .25rem;
}

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: .9rem;
    color: var(--text);
    background: #f8fafc;
}
.card-header--flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
}
.card-body { padding: 1.25rem; }

/* ===== Charts ===== */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
.chart-container { height: 260px; position: relative; }
@media (max-width: 768px) {
    .charts-grid { grid-template-columns: 1fr; }
}

/* ===== Tabellen ===== */
.table-scroll { overflow-x: auto; padding: 0; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .86rem;
}
.data-table thead th {
    text-align: left;
    padding: .65rem 1rem;
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    color: var(--text-muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    user-select: none;
}
.data-table thead th.text-right { text-align: right; }
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table td { padding: .55rem 1rem; vertical-align: middle; }

.sortable-col:hover { color: var(--primary); background: #eff6ff; }
.sorted-asc .sort-icon, .sorted-desc .sort-icon { color: var(--primary); }
.sort-icon { font-size: .8em; margin-left: .2em; }

.kunde-cell {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Badges (Ampel) ===== */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 99px;
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge--gruen     { background: var(--bg-gruen);     color: var(--c-gruen); }
.badge--gelb      { background: var(--bg-gelb);      color: var(--c-gelb); }
.badge--orange    { background: var(--bg-orange);    color: var(--c-orange); }
.badge--rot       { background: var(--bg-rot);       color: var(--c-rot); }
.badge--dunkelrot { background: var(--bg-dunkelrot); color: var(--c-dunkelrot); }

/* ===== Tabellen-Controls ===== */
.table-controls { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.search-input, .filter-select {
    padding: .45rem .75rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: .84rem;
    outline: none;
    background: white;
    color: var(--text);
    transition: border-color .2s;
}
.search-input { width: 220px; }
.search-input:focus, .filter-select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(30,64,175,.12); }
.table-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--border); background: #f8fafc; font-size: .8rem; color: var(--text-muted); }

/* ===== Legende ===== */
.legend {
    position: fixed;
    bottom: 1rem;
    right: 1.25rem;
    display: flex;
    gap: .75rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .5rem .875rem;
    font-size: .78rem;
    box-shadow: var(--shadow);
    z-index: 50;
}
.legend-item { display: flex; align-items: center; gap: .3rem; color: var(--text-muted); }

/* ===== Filter-Banner ===== */
.filter-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    padding: .65rem 1.1rem;
    font-size: .875rem;
    color: #1e40af;
    font-weight: 500;
}
.filter-reset-btn {
    background: none;
    border: 1px solid #93c5fd;
    border-radius: 6px;
    color: #1e40af;
    padding: .25rem .65rem;
    font-size: .8rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
}
.filter-reset-btn:hover { background: #dbeafe; }

/* ===== Alerts ===== */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    font-size: .9rem;
}
.alert-error { background: #fef2f2; border: 1px solid #fca5a5; color: #dc2626; }
.alert-warn  { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }
.alert a { color: inherit; font-weight: 600; }

/* ===== Misc ===== */
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: .8rem; }
.font-mono   { font-family: 'SF Mono', 'Fira Code', monospace; }
.no-results  { padding: 2rem; text-align: center; color: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .navbar { flex-direction: column; align-items: flex-start; gap: .5rem; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .legend { display: none; }
    .search-input { width: 100%; }
    .card-header--flex { flex-direction: column; align-items: flex-start; }
}
