/* ==========================================================================
   IntelliXis – Hauptstylesheet
   Farbgebung: Dunkelblau / Weiß
   Responsive, Touch-optimiert, PWA-tauglich
   ========================================================================== */

/* --- Custom Properties --- */
:root {
    /* Primärfarben: Dunkelblau */
    --color-primary-900: #0a1628;
    --color-primary-800: #0f2240;
    --color-primary-700: #152e54;
    --color-primary-600: #1b3a68;
    --color-primary-500: #22467c;
    --color-primary-400: #3a6098;
    --color-primary-300: #5a82b4;
    --color-primary-200: #8aaed4;
    --color-primary-100: #c5d9ed;
    --color-primary-50:  #e8f0f8;

    /* Neutral */
    --color-white: #ffffff;
    --color-gray-50:  #f8f9fb;
    --color-gray-100: #f0f2f5;
    --color-gray-200: #e2e5ea;
    --color-gray-300: #c8cdd5;
    --color-gray-400: #9aa2af;
    --color-gray-500: #6b7585;
    --color-gray-600: #4b5563;
    --color-gray-700: #374151;
    --color-gray-800: #1f2937;

    /* Status */
    --color-success: #059669;
    --color-success-bg: #ecfdf5;
    --color-warning: #d97706;
    --color-warning-bg: #fffbeb;
    --color-error: #dc2626;
    --color-error-bg: #fef2f2;
    --color-info: #2563eb;
    --color-info-bg: #eff6ff;

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed: 64px;
    --header-height: 60px;
    --content-max-width: 1200px;
    --border-radius: 8px;
    --border-radius-sm: 4px;
    --border-radius-lg: 12px;

    /* Schatten */
    --shadow-sm: 0 1px 2px rgba(10, 22, 40, 0.06);
    --shadow-md: 0 4px 12px rgba(10, 22, 40, 0.1);
    --shadow-lg: 0 8px 24px rgba(10, 22, 40, 0.14);

    /* Typografie */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.8125rem;
    --font-size-base: 0.9375rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.375rem;
    --font-size-2xl: 1.75rem;

    /* Touch */
    --touch-target-min: 44px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;

    /* Safe Areas (iOS) */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--color-gray-800);
    background: var(--color-gray-50);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Layout: App Shell --- */
.app {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: linear-gradient(180deg, var(--color-primary-900) 0%, var(--color-primary-800) 100%);
    color: var(--color-white);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-base);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--safe-area-bottom);
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--header-height);
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: var(--color-white);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--color-primary-800);
    font-size: var(--font-size-lg);
    flex-shrink: 0;
}

.sidebar-logo-img {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius);
    flex-shrink: 0;
    object-fit: contain;
}

.sidebar-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-version {
    font-size: var(--font-size-xs);
    color: var(--color-primary-300);
    margin-top: 2px;
}

.sidebar-footer-logo {
    display: block;
    max-width: 140px;
    height: auto;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.sidebar-footer-logo:hover {
    opacity: 1;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.nav-section {
    margin-bottom: 8px;
}

.nav-section-title {
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-primary-400);
    padding: 8px 20px 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--color-primary-200);
    text-decoration: none;
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: all var(--transition-fast);
    min-height: var(--touch-target-min);
    border-left: 3px solid transparent;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
}

.nav-link:hover,
.nav-link:focus-visible {
    color: var(--color-white);
    background: rgba(255, 255, 255, 0.06);
}

.nav-link.active {
    color: var(--color-white);
    background: rgba(255, 255, 255, 0.1);
    border-left-color: var(--color-white);
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-link:hover .nav-icon,
.nav-link.active .nav-icon {
    opacity: 1;
}

.nav-badge {
    margin-left: auto;
    background: var(--color-error);
    color: var(--color-white);
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: calc(12px + var(--safe-area-bottom));
}

/* --- Main Content --- */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-gray-200);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    padding-top: var(--safe-area-top);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-toggle {
    display: none;
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    border: none;
    background: none;
    cursor: pointer;
    color: var(--color-gray-700);
    padding: 8px;
    border-radius: var(--border-radius-sm);
    touch-action: manipulation; /* Verhindert 300ms-Delay auf iOS */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    user-select: none;
    -webkit-user-select: none;
}

.menu-toggle:active {
    background: var(--color-gray-100);
}

.menu-toggle:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

.page-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--color-primary-900);
}

/* Content */
.content {
    flex: 1;
    padding: 24px;
    max-width: var(--content-max-width);
    width: 100%;
    margin: 0 auto;
    padding-bottom: calc(24px + var(--safe-area-bottom));
}

/* --- Cards --- */
.card {
    background: var(--color-white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-gray-200);
    overflow: hidden;
}

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

.card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-primary-900);
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--color-gray-100);
    background: var(--color-gray-50);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: var(--touch-target-min);
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.btn:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--color-primary-700);
    color: var(--color-white);
}
.btn-primary:hover { background: var(--color-primary-600); }
.btn-primary:active { background: var(--color-primary-800); }

.btn-secondary {
    background: var(--color-white);
    color: var(--color-primary-700);
    border-color: var(--color-gray-300);
}
.btn-secondary:hover { background: var(--color-gray-50); border-color: var(--color-primary-300); }

.btn-danger {
    background: var(--color-error);
    color: var(--color-white);
}
.btn-danger:hover { background: #b91c1c; }

.btn-success {
    background: var(--color-success);
    color: var(--color-white);
}
.btn-success:hover { background: #047857; }

.btn-sm {
    padding: 6px 14px;
    font-size: var(--font-size-xs);
    min-height: 36px;
}

.btn-icon {
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    padding: 0;
    border-radius: var(--border-radius);
}

/* --- Forms --- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-gray-700);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--color-gray-300);
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--color-gray-800);
    background: var(--color-white);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    min-height: var(--touch-target-min);
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 3px rgba(34, 70, 124, 0.15);
}

.form-control:disabled {
    background: var(--color-gray-100);
    color: var(--color-gray-500);
    cursor: not-allowed;
}

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7585' d='M6 8.5L1 3.5h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

.form-hint {
    font-size: var(--font-size-xs);
    color: var(--color-gray-500);
    margin-top: 4px;
}

.form-error {
    font-size: var(--font-size-xs);
    color: var(--color-error);
    margin-top: 4px;
}

/* Checkbox / Radio – Touch-tauglich */
.form-check {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--touch-target-min);
    cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    accent-color: var(--color-primary-700);
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    min-height: var(--touch-target-min);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    width: 48px;
    height: 28px;
    background: var(--color-gray-300);
    border-radius: 14px;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.toggle-track::after {
    content: '';
    display: block;
    width: 22px;
    height: 22px;
    background: var(--color-white);
    border-radius: 50%;
    margin: 3px;
    transition: transform var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-track {
    background: var(--color-primary-600);
}

.toggle input:checked + .toggle-track::after {
    transform: translateX(20px);
}

.toggle input:focus-visible + .toggle-track {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

/* --- Tables --- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--border-radius);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.table th {
    background: var(--color-primary-50);
    color: var(--color-primary-800);
    font-weight: 600;
    text-align: left;
    padding: 12px 16px;
    white-space: nowrap;
    border-bottom: 2px solid var(--color-primary-100);
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-gray-100);
    vertical-align: middle;
}

.table tr:hover td {
    background: var(--color-gray-50);
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-error   { background: var(--color-error-bg);   color: var(--color-error);   }
.badge-info    { background: var(--color-info-bg);     color: var(--color-info);    }
.badge-neutral { background: var(--color-gray-100);    color: var(--color-gray-600);}

/* --- Flash Messages --- */
.flash-container {
    position: fixed;
    top: calc(var(--header-height) + 12px + var(--safe-area-top));
    right: 16px;
    left: calc(var(--sidebar-width) + 16px);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    font-weight: 500;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: flashIn 0.3s ease;
}

.flash-success { background: var(--color-success-bg); color: var(--color-success); border-left: 3px solid var(--color-success); }
.flash-error   { background: var(--color-error-bg);   color: var(--color-error);   border-left: 3px solid var(--color-error);   }
.flash-warning { background: var(--color-warning-bg); color: var(--color-warning); border-left: 3px solid var(--color-warning); }
.flash-info    { background: var(--color-info-bg);     color: var(--color-info);    border-left: 3px solid var(--color-info);    }

.flash-icon { font-size: 1.1em; }
.flash-text { flex: 1; }

.flash-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    opacity: 0.6;
    color: inherit;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes flashIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Stat Cards (Dashboard) --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--color-white);
    border-radius: var(--border-radius-lg);
    padding: 20px;
    border: 1px solid var(--color-gray-200);
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-gray-500);
    margin-bottom: 4px;
}

.stat-value {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--color-primary-900);
}

.stat-change {
    font-size: var(--font-size-xs);
    margin-top: 4px;
}

.stat-change.positive { color: var(--color-success); }
.stat-change.negative { color: var(--color-error); }

/* --- Overlay (für mobile Sidebar) --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 22, 40, 0.5);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--color-white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-primary-900);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--color-gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Loading / Spinner --- */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-gray-200);
    border-top-color: var(--color-primary-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--color-gray-500);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-gray-700);
    margin-bottom: 8px;
}

/* --- Utilities --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--color-gray-500); }
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }
.text-warning { color: var(--color-warning); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
.font-mono { font-family: var(--font-mono); }

/* --- Responsive --- */

/* Tablet */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.active {
        display: block;
    }
    .main {
        margin-left: 0;
    }
    .menu-toggle {
        display: flex;
    }
    .flash-container {
        left: 16px;
    }
    .content {
        padding: 16px;
    }
}

/* Smartphone */
@media (max-width: 640px) {
    :root {
        --header-height: 56px;
    }
    .page-title {
        font-size: var(--font-size-lg);
    }
    .card-header {
        padding: 12px 16px;
    }
    .card-body {
        padding: 16px;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .stat-card {
        padding: 14px;
    }
    .stat-value {
        font-size: var(--font-size-xl);
    }
    .content {
        padding: 12px;
    }
    .table th,
    .table td {
        padding: 10px 12px;
    }

    /* Mobile: Card-Ansicht für Tabellen */
    .table-mobile .table thead {
        display: none;
    }
    .table-mobile .table tr {
        display: block;
        margin-bottom: 12px;
        border: 1px solid var(--color-gray-200);
        border-radius: var(--border-radius);
        background: var(--color-white);
    }
    .table-mobile .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 14px;
        border-bottom: 1px solid var(--color-gray-100);
    }
    .table-mobile .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--color-gray-600);
        font-size: var(--font-size-xs);
        flex-shrink: 0;
        margin-right: 12px;
    }
    .table-mobile .table td:last-child {
        border-bottom: none;
    }
}

/* --- App Footer --- */
.app-footer {
    padding: 16px 24px;
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--color-gray-400);
    border-top: 1px solid var(--color-gray-200);
    margin-top: 32px;
    padding-bottom: calc(16px + var(--safe-area-bottom));
}

.app-footer-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
}

.app-footer a {
    color: var(--color-gray-500);
    text-decoration: none;
    padding: 4px 2px;
}

.app-footer a:hover {
    color: var(--color-primary-600);
    text-decoration: underline;
}

.app-footer-sep {
    color: var(--color-gray-300);
}

/* --- Print --- */
@media print {
    .sidebar, .header, .menu-toggle, .sidebar-overlay { display: none !important; }
    .main { margin-left: 0; }
    .content { padding: 0; max-width: 100%; }
    .card { box-shadow: none; border: 1px solid #ccc; }
}
