/* ============================================================
   SHLD — Layout & Struktur
   Kein einziger Hex-Wert hier. Alles über var().
   ============================================================ */

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

html { font-size: 16px; height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 0.875rem;
    line-height: 1.5;
    background: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { opacity: 0.8; }

/* ── App-Grundstruktur ────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    min-width: 220px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow: visible;   /* Dropdown darf rausragen */
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-logo { width: 26px; height: 26px; }

.sidebar-brand-text {
    font-size: 1rem;
    font-weight: 700;
    color: var(--sidebar-brand);
    letter-spacing: 0.06em;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: visible;
    padding: 6px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.83rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    white-space: nowrap;
}

.nav-item svg { flex-shrink: 0; opacity: 0.7; }
.nav-item:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-hover); }
.nav-item:hover svg, .nav-item.active svg { opacity: 1; }
.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    border-left-color: var(--sidebar-active-text);
}

.nav-item--sub {
    padding-left: 36px;
    font-size: 0.78rem;
    font-weight: 400;
    opacity: 0.85;
}
.nav-item--sub svg { opacity: 0.5; }

/* ── Profil-Footer ───────────────────────────────────────── */
.sidebar-footer {
    flex-shrink: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--sidebar-footer-border);
    background: var(--sidebar-footer-bg);
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: visible;
    position: relative;
}

.profile-dropdown-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    overflow: visible;
}

.profile-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px 0;
    text-align: left;
    overflow: hidden;
}

.profile-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #0d2830;
    border: 1px solid rgba(255, 174, 3, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: #ffae03;
    text-transform: uppercase;
}

.profile-info { flex: 1; min-width: 0; overflow: hidden; }

.profile-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: #d0e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-role {
    font-size: 0.66rem;
    color: #6b9aaa;
    white-space: nowrap;
}

.profile-chevron {
    color: #6b9aaa;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.profile-dropdown-wrap.open .profile-chevron { transform: rotate(180deg); }

.profile-dropdown-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: -12px;
    width: 210px;
    background: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border);
    border-radius: 6px;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.55);
    overflow: hidden;
    z-index: 9999;
}

.profile-dropdown-wrap.open .profile-dropdown-menu { display: block; }

.dropdown-section { padding: 3px 0; }
.dropdown-section + .dropdown-section { border-top: 1px solid rgba(255, 255, 255, 0.07); }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 14px;
    color: var(--dropdown-text);
    text-decoration: none;
    font-size: 0.8rem;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    transition: background 0.1s, color 0.1s;
}

.dropdown-item:hover {
    background: var(--dropdown-hover-bg);
    color: var(--dropdown-hover-text);
}

.dropdown-item.danger { color: #d07070; }
.dropdown-item.danger:hover { background: rgba(200, 30, 20, 0.12); color: #ff6b6b; }
.dropdown-item svg { flex-shrink: 0; opacity: 0.7; }

/* Theme-Toggle im Dropdown */
.theme-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    font-size: 0.8rem;
    color: var(--dropdown-text);
}

.theme-toggle-switch { position: relative; width: 34px; height: 18px; }
.theme-toggle-switch input { opacity: 0; width: 0; height: 0; }

.theme-slider {
    position: absolute;
    inset: 0;
    background: #1a4050;
    border-radius: 18px;
    cursor: pointer;
    transition: background 0.2s;
}

.theme-slider:before {
    content: '';
    position: absolute;
    width: 12px; height: 12px;
    left: 3px; top: 3px;
    background: #8ab0bc;
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.theme-toggle-switch input:checked + .theme-slider { background: rgba(255, 174, 3, 0.25); }
.theme-toggle-switch input:checked + .theme-slider:before {
    transform: translateX(16px);
    background: #ffae03;
}

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
    flex: 1;
    min-width: 0;
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
}

.page-content {
    padding: 28px 36px;
    width: 100%;
    /* Kein max-width — volle Breite nutzen */
}

/* ── Flash-Alerts ─────────────────────────────────────────── */
.alert-flash {
    position: fixed;
    top: 20px;
    right: 24px;
    z-index: 9000;
    min-width: 280px;
    max-width: 500px;
    box-shadow: var(--shadow-md);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: 2px solid var(--primary);
    border-radius: 4px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body { padding: 20px; }

/* ── Tabellen ─────────────────────────────────────────────── */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
    /* Tabelle bricht NICHT um — scrollt stattdessen */
    white-space: nowrap;
}

.table thead th {
    background: var(--bg-surface);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 9px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.table tbody tr:hover { background: var(--bg-card-hover); }

.table tbody td {
    padding: 10px 14px;
    color: var(--text-primary);
    vertical-align: middle;
    /* Zelleninhalt darf umbrechen (nur Tabellen-Header nicht) */
    white-space: normal;
}

/* Aktions-Spalte: immer rechts, nie umbrechen, immer gleich breit */
.col-actions {
    width: 1%;            /* So schmal wie nötig */
    white-space: nowrap;
    text-align: right;
    padding-right: 16px !important;
}

.action-stack {
    display: inline-flex;
    flex-direction: row;
    gap: 4px;
    align-items: center;
    justify-content: flex-end;
}

.action-stack .btn-sm,
.action-stack form { 
    width: auto;
    min-width: 100px;
 }

.action-stack .btn-sm {
    display: inline-flex;
    text-align: center;
    width: 100px;
}

/* ── Formulare ────────────────────────────────────────────── */
.form-control {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 7px 11px;
    font-size: 0.83rem;
    width: 100%;
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-input-focus);
}

.form-control::placeholder { color: var(--text-disabled); }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b9aaa'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 5px;
}

.label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-hint  { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 0.72rem; color: var(--red); margin-top: 4px; }
.is-invalid { border-color: var(--red) !important; }
.form-group { margin-bottom: 16px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.12s;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.3;
}

.btn-sm { padding: 5px 11px; font-size: 0.74rem; }

.btn-primary {
    background: var(--primary);
    color: var(--btn-primary-text, #001214);
    border-color: var(--primary);
    font-weight: 700;
}
.btn-primary:hover { background: var(--primary-light); border-color: var(--primary-light); }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-strong);
}
.btn-outline:hover { border-color: var(--text-secondary); color: var(--text-primary); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.btn-danger {
    background: transparent;
    color: var(--red);
    border-color: var(--red);
}
.btn-danger:hover { background: var(--red-bg); }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 3px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.badge-green  { background: var(--green-bg);           color: var(--green); }
.badge-red    { background: var(--red-bg);             color: var(--red); }
.badge-gold   { background: var(--primary-bg);            color: var(--primary); }
.badge-muted  { background: var(--bg-surface);         color: var(--text-muted);
                border: 1px solid var(--border); }
.badge-petrol { background: var(--badge-petrol-bg);    color: var(--badge-petrol-text); }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
    padding: 11px 15px;
    border-radius: 4px;
    font-size: 0.83rem;
    border-left: 3px solid;
    margin-bottom: 16px;
}
.alert-success { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.alert-error   { background: var(--red-bg);   border-color: var(--red);   color: var(--red); }
.alert-warning { background: var(--primary-bg);  border-color: var(--primary);  color: var(--primary); }

/* ── Typografie-Utilities ─────────────────────────────────── */
h2 { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); }
h3 { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
h4 { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }

.text-primary   { color: var(--text-primary)   !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted     { color: var(--text-muted)     !important; }
.text-sm  { font-size: 0.83rem; }
.text-xs  { font-size: 0.73rem; }

/* ── Layout-Utilities ─────────────────────────────────────── */
.d-flex    { display: flex; }
.d-grid    { display: grid; }
.d-none    { display: none; }
.align-center     { align-items: center; }
.justify-between  { justify-content: space-between; }
.justify-end      { justify-content: flex-end; }
.flex-wrap        { flex-wrap: wrap; }

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }
.mb-6 { margin-bottom: 24px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Animationen ──────────────────────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.animate-fade-in-up { animation: fadeInUp 0.18s ease-out; }

/* ── Monospace ────────────────────────────────────────────── */
.font-mono, [style*="font-mono"] {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}
