/**
 * JARVIS UI FRAMEWORK
 * Central Design System and Component Library
 *
 * Single source of truth for all color tokens.
 * Portal and Backend both inherit from this file.
 */

:root {
    color-scheme: light;
    /* === Baseline Tokens (Unified for all areas) === */
    --primary: #06319A;
    --primary-rgb: 6, 49, 154;
    --primary-soft: rgba(var(--primary-rgb), 0.05);
    --primary-glass: rgba(var(--primary-rgb), 0.15);

    --accent: #34c759;
    --accent-rgb: 52, 199, 89;
    --accent-soft: rgba(var(--accent-rgb), 0.1);

    --warning: #ff9f0a;
    --warning-rgb: 255, 159, 10;
    --warning-soft: rgba(var(--warning-rgb), 0.1);

    --danger: #ff3b30;
    --danger-rgb: 255, 59, 48;
    --danger-soft: rgba(var(--danger-rgb), 0.1);

    --bg: #f5f5f7;
    --surface: #ffffff;
    --card-bg: rgba(255, 255, 255, 0.85);
    --text: #1d1d1f;
    --text-soft: #86868b;
    --btn-primary: #06319a;
    --border: rgba(0, 0, 0, 0.08);
    --border-color: rgba(0, 0, 0, 0.08);

    --radius: 10px;
    --radius-sm: 5px;
    --glass: blur(20px) saturate(180%);

    /* === Component Aliases === */
    --color-primary: var(--primary);
    --color-primary-soft: var(--primary-soft);
    --color-primary-glass: var(--primary-glass);

    --color-success: var(--accent);
    --color-success-soft: var(--accent-soft);

    --color-warning: var(--warning);
    --color-warning-soft: var(--warning-soft);

    --color-danger: var(--danger);
    --color-danger-soft: var(--danger-soft);

    --color-bg: var(--bg);
    --color-surface: var(--surface);
    --color-text: var(--text);
    --color-text-soft: var(--text-soft);
    --color-border: var(--border-color);
    --color-border-light: var(--border);

    /* === Geometry === */
    --radius-lg: var(--radius);
    --radius-md: var(--radius-sm);
    --sidebar-width: 280px;
    --header-height: 70px;

    /* === Effects === */
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 25px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 15px 45px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 25px 60px rgba(0, 0, 0, 0.18);

    /* === Spacing === */
    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 20px;
    --space-lg: 30px;
    --space-xl: 50px;

    /* === Missing Tokens (previously caused silent failures) === */
    --primary-shadow: rgba(6, 49, 154, 0.25);
    --bg-soft-surface: rgba(0, 0, 0, 0.03);
    --font-system: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

[data-theme="dark"] {
    color-scheme: dark;
    --primary: #7eb0ff;
    --primary-soft: rgba(126, 176, 255, 0.15);
    --primary-glass: rgba(126, 176, 255, 0.25);
    --primary-shadow: rgba(0, 0, 0, 0.4);

    --bg: #0A0A0E;
    --surface: #1a1a26;
    --card-bg: rgba(26, 26, 38, 0.95);
    --text: #eaeaf4;
    --text-soft: #9898b8;
    --border: rgba(255, 255, 255, 0.1);
    --border-color: rgba(255, 255, 255, 0.1);

    /* Framework alias overrides */
    --color-primary: var(--primary);
    --color-primary-soft: var(--primary-soft);
    --color-primary-glass: var(--primary-glass);
    --color-bg: var(--bg);
    --color-surface: var(--surface);
    --color-text: var(--text);
    --color-text-soft: var(--text-soft);
    --btn-primary: #1853af;
    --color-border: var(--border-color);
    --color-border-light: var(--border);

    /* Shadow overrides for dark mode */
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 25px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 15px 45px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 25px 60px rgba(0, 0, 0, 0.6);

    --bg-soft-surface: rgba(255, 255, 255, 0.04);
}

/* --- Base Reset Enhancements --- */
/* --- Global Reset & Baseline --- */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Outfit', -apple-system, blinkmacsystemfont, 'Segoe UI', roboto, oxygen, ubuntu, cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Base resets handled globally above */

/* --- Layout Grids --- */
.ui-grid {
    display: grid;
    gap: var(--space-md);
}

.ui-grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.ui-grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.ui-grid-4 {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.ui-grid-tiles {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}

.ui-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* --- Layout System (Centralized) --- */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    margin: 0;
    padding: 0;
}

.sidebar {
    width: var(--sidebar-width, 280px);
    background: var(--color-surface);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    border-right: 1px solid var(--color-border-light);
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    z-index: 1100;
    flex-shrink: 0;
    transition: all 0.3s ease;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: var(--color-border);
    border-radius: 20px;
}

.sidebar-links a,
.nav-item {
    text-decoration: none;
    color: var(--color-text-soft);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    position: relative;
}

.sidebar-links a:hover,
.nav-item:hover {
    background: var(--color-primary-soft);
    color: var(--color-primary);
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.05);
}

.sidebar-links a.active,
.nav-item.active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.08);
}

/* Specific Nav Item Variants */
.nav-item--logout {
    margin-top: 10px;
}

.nav-item--logout:hover {
    background: var(--color-danger-soft) !important;
    color: var(--color-danger) !important;
}

.nav-item--soft:hover {
    background: var(--bg-soft-surface);
    color: var(--color-text);
}

.sidebar-admin-link {
    background: var(--primary-soft) !important;
    color: var(--color-primary) !important;
    margin: 15px 0 5px;
    border: 1px solid var(--color-primary) !important;
}

.sidebar-admin-link:hover {
    filter: brightness(1.1);
}

.sidebar-logo {
    display: flex;
    gap: 12px;
    padding: 0px 0px 0px;
    text-decoration: none;
    color: var(--color-primary);
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -1px;
    flex-direction: column;
}

.sidebar-logo-img {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.sidebar-logo-icon {
    width: 32px;
    height: 32px;
    color: var(--color-primary);
}

.sidebar-footer {
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sidebar-logout-btn {
    width: 100%;
    margin-top: 10px;
}

.nav-icon,
svg.nav-icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
    flex-shrink: 0;
    vertical-align: middle;
}

/* --- Hierarchical Sidebar Navigation --- */
.sidebar-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    margin-top: 15px;
}

.sidebar-links a:hover,
.sidebar-links a.active,
.nav-item:hover,
.nav-item.active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 5px;
}

.nav-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    color: var(--color-text-soft);
    font-size: 15px;
    font-weight: 600;
    transition: color 0.2s;
}

.nav-group-header:hover {
    color: var(--color-text);
}

.nav-group-chevron {
    margin-left: auto;
    width: 14px;
    height: 14px;
    transition: transform 0.3s ease;
    opacity: 0.5;
}

.nav-group.open .nav-group-chevron {
    transform: rotate(180deg);
}

.nav-group-content {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-left: 12px;
}

.nav-group.open .nav-group-content {
    max-height: 1000px;
    opacity: 1;
    margin-top: 5px;
    margin-bottom: 10px;
}

/* --- Sidebar Search System --- */
.sidebar-search {
    margin: 15px 0px;
    position: relative;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.03) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: var(--radius-sm);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0 8px;
}

[data-theme="dark"] .search-wrapper {
    background: rgba(255, 255, 255, 0.05) !important;
}

.search-wrapper:focus-within {
    background: var(--color-surface) !important;
    border-color: var(--color-primary) !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
}

.search-wrapper i {
    position: absolute;
    left: 12px;
    z-index: 2;
    color: var(--color-text-soft);
    pointer-events: none;
    transition: color 0.3s;
}

.search-wrapper:focus-within i {
    color: var(--color-primary);
}

.search-input {
    width: 100%;
    padding: 6px 10px 6px 28px !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--color-text) !important;
    font-size: 12.5px;
    outline: none !important;
    min-width: 0;
}

.search-dropdown {
    position: absolute;
    top: 100%;
    left: 10px;
    right: 10px;
    background: var(--color-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    z-index: 1200;
    margin-top: 10px;
    max-height: 450px;
    overflow-y: auto;
    padding: 8px;
    display: none;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.search-result-category {
    padding: 10px 14px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text-soft);
    letter-spacing: 0.1em;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--color-text);
    transition: all 0.2s ease;
}

.search-result-item:hover {
    background: var(--color-primary-soft);
}

.search-result-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    opacity: 0.8;
}

.search-result-info {
    min-width: 0;
    flex: 1;
}

.search-result-title {
    font-weight: 600;
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.search-result-sub {
    font-size: 11px;
    color: var(--color-text-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    /* Verhindert das "Rausdrücken" aus dem Flex-Container */
    padding: 40px 60px 80px;
    width: 100%;
    max-width: 100%;
    /* Begrenzung auf Container, kein fixes Pixel-Maß hier */
    box-sizing: border-box;
    transition: all 0.3s ease;
}

.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height, 70px);
    background: var(--color-surface);
    backdrop-filter: var(--glass);
    z-index: 1001;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--color-border);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    z-index: 1050;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

@media (max-width: 1024px) {
    .main-content {
        padding: 30px;
    }
}

@media (max-width: 768px) {
    .app-layout {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        z-index: 2000;
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.1);
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-open .sidebar-overlay {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: calc(var(--header-height, 70px) + 20px);
    }

    .mobile-header {
        display: flex;
    }
}

/* --- Global Dashboard Components --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.stat-card {
    text-align: center;
    padding: var(--space-lg) !important;
}

.stat-card label {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-soft);
    display: block;
    margin-bottom: 10px;
}

/* --- Dashboard Filter Form --- */
.dashboard-filter-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-lg);
}

.dashboard-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-bottom: var(--space-sm);
}

.dashboard-filter-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
    align-items: flex-end;
}

.dashboard-filter-form>div {
    display: flex;
    flex-direction: column !important;
    gap: 10px;
    align-items: flex-start;
}

.dashboard-filter-form label {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-text-soft);
    margin-bottom: 2px;
}

.dashboard-filter-actions {
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
    padding-bottom: 1px;
    /* Align baseline with input bottom edge */
}

.stat-card p {
    font-size: 32px;
    font-weight: 600;
    margin: 0;
    letter-spacing: -1px;
}

.grid-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

/* --- Dashboard Chart Component --- */
.chart-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 140px;
    padding: 10px 0;
}

.chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    gap: 6px;
}

.chart-bar-inner {
    width: 100%;
    min-height: 4px;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    opacity: 0.8;
    position: relative;
    transition: opacity 0.2s;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.chart-bar-inner:hover {
    opacity: 1;
}

.chart-value {
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    padding-top: 4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.chart-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-soft);
    white-space: nowrap;
    text-align: center;
}

/* --- Dashboard Top-List Component --- */
.top-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.top-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    gap: 15px;
    transition: border-color 0.2s;
}

.top-item:hover {
    border-color: var(--primary);
}

.top-item-info {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-item-sub {
    font-size: 11px;
    color: var(--text-soft);
    font-family: monospace;
    margin-top: 2px;
}

.top-item-badge {
    flex-shrink: 0;
    background: var(--primary-soft);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}

/* --- Session Detail Container --- */
.session-detail-container {
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 400px;
    overflow-y: auto;
}

/* Fix: Section header h3 margin */
.dashboard-section-header h3 {
    margin: 0;
    font-size: 16px;
}

/* --- Form Label Utility --- */
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text-soft);
    margin-bottom: 8px;
}

.tile-card {
    text-decoration: none;
    display: flex;
    flex-direction: column;
    gap: 15px;
    transition: all 0.3s ease;
}

.tile-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}

/* --- Global Alerts & Toasts --- */
.jarvis-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    padding: 12px 25px;
    border-radius: 50px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-lg);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.toast-success {
    color: var(--color-success);
    background: var(--color-success-soft);
    border-color: var(--color-success);
}

.toast-error {
    color: var(--color-danger);
    background: var(--color-danger-soft);
    border-color: var(--color-danger);
}

.toast-animate {
    animation: toastIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* --- Admin Utilities --- */
.admin-proxy-banner {
    background: #06319A;
    color: #fff;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 9999;
    position: relative;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}


/* Base Card Alias for Legacy Compatibility */
.card {
    background: var(--color-surface);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    padding: var(--space-lg);
    border-radius: var(--radius);
    border: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    margin-bottom: var(--space-md);
    position: relative;
    overflow: hidden;
}

.card-hover:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
}

.card-header {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: calc(var(--space-lg) * -1) calc(var(--space-lg) * -1) var(--space-md);
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border-light);
    gap: 15px;
}

.card-title-group h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    gap: 10px;
}

.card-title-group p {
    margin: 5px 0 0 0;
    font-size: 13px;
    color: var(--text-soft);
}

.card-body {
    padding: 0;
}

.form-subtitle {
    margin: 0 0 10px;
    display: flex;
    color: var(--text-soft);
    font-size: 14px;
}

/* --- Advanced Alerts & Info Boxes --- */
.alert {
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: var(--space-md);
    font-size: 14px;
    line-height: 1.6;
    border: 1px solid transparent;
}

.alert i {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 2px;
}

.alert-success {
    background: var(--color-success-soft);
    color: var(--color-success);
    border-color: rgba(var(--accent-rgb), 0.1);
}

.alert-danger {
    background: var(--color-danger-soft);
    color: var(--color-danger);
    border-color: rgba(var(--danger-rgb), 0.1);
}

.alert-warning {
    background: var(--color-warning-soft);
    color: var(--color-warning);
    border-color: rgba(var(--warning-rgb), 0.1);
}

.alert-info {
    background: var(--color-primary-soft);
    color: var(--color-primary);
    border-color: rgba(var(--primary-rgb), 0.1);
}

.alert-best-practice {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text-soft);
}

.alert-best-practice strong {
    color: var(--color-text);
}

.alert-best-practice i {
    color: var(--color-primary);
}

/* Forms (Standard Names) */
.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    text-transform: none;
    color: var(--color-text-soft);
    margin-bottom: 8px;
    letter-spacing: normal;
}

.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="url"],
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 14px;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px var(--color-primary-soft);
}

/* Enhancing Native Date/Time Pickers (Quiet Luxury) */
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
    font-family: inherit;
    cursor: text;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s ease, filter 0.2s ease;
    padding: 4px;
    border-radius: 4px;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
input[type="month"]::-webkit-calendar-picker-indicator:hover {
    opacity: 0.9;
    background-color: var(--color-primary-soft);
}

[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator {
    filter: invert(1) hue-rotate(180deg);
    opacity: 0.7;
}

[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator:hover,
[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator:hover,
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.1);
}


/* Color Input Styling */
input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 44px;
    height: 44px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

input[type="color"]::-moz-color-swatch {
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

/* Modal System */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    /* Hidden by default */
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-card {
    width: 90%;
    max-width: 500px;
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: var(--space-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--color-border);
}

.modal-header {
    margin-bottom: var(--space-lg);
    font-size: 18px;
    font-weight: 700;
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-soft);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-close:hover {
    background: var(--bg-soft-surface);
    color: var(--text);
}

/* File Upload Previews */
.branding-upload-preview {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    background: var(--color-bg);
    padding: var(--space-sm);
    border-radius: var(--radius);
    border: 1px dashed var(--color-border);
}

.branding-upload-preview input[type="text"] {
    border: none !important;
    background: transparent !important;
    flex: 1;
    box-shadow: none !important;
}

.hidden-input {
    display: none !important;
}

/* Chat History Bubbles Enhancements */
.chat-bubble-item {
    margin-bottom: 25px;
    padding: 24px;
    border-radius: var(--radius);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    position: relative;
    max-width: 100%;
    box-shadow: var(--shadow-sm);
}

.chat-bubble-item:hover {
    box-shadow: var(--shadow-md);
}

.chat-bubble-time {
    font-size: 11px;
    color: var(--color-text-soft);
    margin-bottom: 18px;
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
    opacity: 0.7;
}

.chat-bubble-msg {
    font-weight: 500;
    margin-bottom: 22px;
    padding: 14px 18px;
    background: var(--color-bg);
    border-radius: 12px;
    font-size: 14px;
    position: relative;
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

.chat-bubble-msg::before {
    content: "USER";
    font-size: 10px;
    font-weight: 800;
    position: absolute;
    top: -20px;
    left: 4px;
    color: var(--color-text-soft);
    letter-spacing: 0.5px;
}

.chat-bubble-bot {
    font-weight: 400;
    padding: 14px 18px;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    border-radius: 12px;
    border-left: 4px solid var(--color-primary);
    font-size: 14px;
    position: relative;
}

.chat-bubble-bot::before {
    content: "JARVIS";
    font-size: 10px;
    font-weight: 800;
    position: absolute;
    top: -20px;
    left: 4px;
    color: var(--color-primary);
    letter-spacing: 0.5px;
}

/* --- Utilities & Resets --- */
.ui-align-left {
    text-align: left !important;
    justify-content: flex-start !important;
    align-items: flex-start !important;
}

.text-left {
    text-align: left !important;
}

.text-right {
    text-align: right !important;
}

.text-center {
    text-align: center !important;
}

/* Typografie & Page Headers */
.page-title {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
    margin: 0;
    color: var(--color-text);
}

.page-subtitle {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--color-text-soft);
    margin: 0 0 8px 0;
}

/* Margin & Padding Utilities (Legacy Compatibility) */
.me-1 {
    margin-right: 0.25rem !important;
}

.me-2 {
    margin-right: 0.5rem !important;
}

.me-3 {
    margin-right: 1rem !important;
}

.ms-1 {
    margin-left: 0.25rem !important;
}

.ms-2 {
    margin-left: 0.5rem !important;
}

.ms-3 {
    margin-left: 1rem !important;
}

.mt-1 {
    margin-top: 0.25rem !important;
}

.mt-2 {
    margin-top: 0.5rem !important;
}

.mt-3 {
    margin-top: 1rem !important;
}

.mb-1 {
    margin-bottom: 0.25rem !important;
}

.mb-2 {
    margin-bottom: 0.5rem !important;
}

.mb-3 {
    margin-bottom: 1rem !important;
}

.mb-4 {
    margin-bottom: 1.5rem !important;
}

.p-1 {
    padding: 0.25rem !important;
}

.p-2 {
    padding: 0.5rem !important;
}

.p-3 {
    padding: 1rem !important;
}

.px-1 {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
}

.px-2 {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
}

.px-3 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
}

.py-1 {
    padding-top: 0.25rem !important;
    padding-bottom: 0.25rem !important;
}

.py-2 {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
}

.py-3 {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
}

.w-100 {
    width: 100% !important;
}

.h-100 {
    height: 100% !important;
}

.d-flex {
    display: flex !important;
}

.justify-content-center {
    justify-content: center !important;
}

.align-items-center {
    align-items: center !important;
}

.gap-1 {
    gap: 0.25rem !important;
}

.gap-2 {
    gap: 0.5rem !important;
}

.gap-3 {
    gap: 1rem !important;
}

/* Font Size Utilities */
.fs-xs {
    font-size: 11px !important;
}

.fs-sm {
    font-size: 13px !important;
}

.fs-md {
    font-size: 15px !important;
}

.fs-lg {
    font-size: 18px !important;
}

.fs-xl {
    font-size: 24px !important;
}

.text-primary {
    color: var(--primary) !important;
}

.text-success {
    color: #16a34a !important;
}

.text-warning {
    color: #d97706 !important;
}

.text-danger {
    color: #dc2626 !important;
}

.text-soft {
    color: var(--text-soft) !important;
}

.w-full {
    width: 100% !important;
}

/* Flex & Grid Utilities */
.flex-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--space-sm);
}

.flex-column {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flex-start {
    display: flex;
    align-items: flex-start;
}

.flex-end {
    display: flex;
    justify-content: flex-end;
}

.flex-wrap {
    flex-wrap: wrap;
}

.flex-1 {
    flex: 1;
}

.align-items-end {
    align-items: flex-end !important;
}

.gap-lg {
    gap: 20px !important;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
}

.span-2 {
    grid-column: span 2;
}

.span-3 {
    grid-column: span 3;
}

@media (max-width: 1200px) {
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .span-2,
    .span-3 {
        grid-column: span 1;
    }
}

@media (max-width: 768px) {

    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr !important;
    }

    .span-2,
    .span-3 {
        grid-column: span 1 !important;
    }
}

.gap-xs {
    gap: var(--space-xs) !important;
}

.gap-sm {
    gap: var(--space-sm) !important;
}

.gap-md {
    gap: var(--space-md) !important;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
}

/* Spacing Utilities */
.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mb-0,
.mb-none {
    margin-bottom: 0 !important;
}

.mb-xs {
    margin-bottom: var(--space-xs);
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.pt-lg {
    padding-top: var(--space-lg);
}

.p-sm {
    padding: var(--space-sm);
}

.p-md {
    padding: var(--space-md);
}

.p-lg {
    padding: var(--space-lg);
}

.p-xl {
    padding: var(--space-xl);
}

.ml-auto {
    margin-left: auto !important;
}

.mr-auto {
    margin-right: auto !important;
}

.mt-auto {
    margin-top: auto !important;
}

.mb-auto {
    margin-bottom: auto !important;
}

/* Components & Backgrounds */
.bg-primary-soft {
    background: var(--primary-soft) !important;
}

/* Badge color variants — canonical definitions are in the Badge System section below */

/* .btn-sm canonical definition is in the Standard Buttons section below */

/* Sidebar & Navigation Overlays
   (canonical definition is at the top of this file near .sidebar)
   The .sidebar-open state toggling is handled below */
.sidebar-open .sidebar-overlay {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* --- Global Icons --- */
/* Target both the original placeholder and the rendered SVG */
i[data-lucide], 
svg.lucide {
    width: 20px;
    height: 20px;
    display: inline-block;
    vertical-align: middle;
    stroke-width: 2px;
    flex-shrink: 0;
    /* Optional: ensures color inheritance */
    stroke: currentColor;
    fill: none;
}

/* Explicit Size Helpers (with high specificity to override defaults) */
svg.lucide.icon-xs, i[data-lucide].icon-xs {
    width: 14px !important;
    height: 14px !important;
    stroke-width: 2.5px; /* Slightly thicker for very small icons */
}

svg.lucide.icon-sm, i[data-lucide].icon-sm {
    width: 16px !important;
    height: 16px !important;
}

svg.lucide.icon-md, i[data-lucide].icon-md {
    width: 22px !important;
    height: 22px !important;
}

svg.lucide.icon-lg, i[data-lucide].icon-lg {
    width: 28px !important;
    height: 28px !important;
}

.icon-lg {
    width: 28px !important;
    height: 28px !important;
}

/* --- Special Component Utilities --- */
.card--flush {
    padding: 0 !important;
    overflow: hidden;
}

/* --- Standard Form Actions (Sticky Footer) --- */

.form-actions--end {
    justify-content: flex-end;
}

.form-actions-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* --- Dashboard & Credit Components --- */
.balance-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 40px 24px !important;
    text-align: center;
}

.balance-value {
    font-size: 40px;
    font-weight: 900;
    line-height: 1.1;
    margin: 0;
    color: var(--primary);
}

.icon-box-circle {
    width: 64px;
    height: 64px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Pricing & Wallet Specifics --- */
.wallet-card {
    background: var(--surface);
    border: 1px solid var(--border-color) !important;
    position: relative;
    overflow: hidden;
    padding: 2.5rem 1.5rem !important;
    box-shadow: var(--shadow-md);
}

.wallet-card .balance-value {
    color: var(--primary) !important;
    font-size: 52px;
    letter-spacing: -1px;
}

[data-theme="dark"] .wallet-card {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1) !important;
}

.wallet-card::after {
    content: '';
    position: absolute;
    top: -20%;
    right: -10%;
    width: 200px;
    height: 200px;
    background: var(--primary-soft);
    border-radius: 50%;
    filter: blur(40px);
    pointer-events: none;
    opacity: 0.5;
}

.price-tag {
    font-size: 32px;
    font-weight: 800;
    color: var(--text);
    margin: 5px 0;
}

.pack-card {
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.pack-card:hover {
    border-color: var(--primary);
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}

.pack-card.popular {
    border: 2px solid var(--primary);
    transform: scale(1.02);
    box-shadow: 0 15px 45px var(--primary-shadow);
    z-index: 2;
}

.usage-step {
    display: flex;
    gap: 15px;
    padding: 18px;
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.usage-step i {
    color: var(--primary);
    flex-shrink: 0;
}

/* Supplemental Alerts */
.alert-soft-success {
    background: rgba(22, 163, 74, 0.05);
    border: 1px solid rgba(22, 163, 74, 0.2);
    color: #16a34a;
}

/* Robustness Patch for Forms/Labels */
.ui-stack label:not(.jarvis-switch):not(.toggle-switch),
.ui-stack-lg label:not(.jarvis-switch):not(.toggle-switch),
.ui-grid label:not(.jarvis-switch):not(.toggle-switch) {
    text-align: left !important;
    display: block;
    width: 100%;
}

.ui-card-feature input[type="checkbox"] {
    margin: 0;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Support for both .ui-badge and .badge */
.ui-badge,
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}

/* ============================================================
   PHASE 2 — UNIFIED COMPONENT LIBRARY
   Badge colors now canonical in Badge System section.
   ============================================================ */

/* --- Toggle Switch Component --- */
.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.toggle-switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.toggle-switch .slider {
    width: 44px;
    height: 26px;
    background: rgba(0, 0, 0, 0.12);
    border-radius: var(--radius-sm);
    position: relative;
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.toggle-switch .slider::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.slider {
    background: transparent;
    box-shadow: inset 0 0 0 2px var(--primary);
}

/* --- Theme Toggle Group (3-Way) --- */
.theme-switch-group {
    display: flex;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px;
    border-radius: var(--radius-sm);
    gap: 4px;
    margin-bottom: 10px;
}

[data-theme="dark"] .theme-switch-group {
    background: rgba(255, 255, 255, 0.05);
}

.theme-switch-btn {
    flex: 1;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-soft);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-switch-btn i {
    width: 16px;
    height: 16px;
}

.theme-switch-btn:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text);
}

.theme-switch-btn.active {
    background: var(--bg);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .theme-switch-btn.active {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.toggle-switch input:checked+.slider::after {
    transform: translateX(18px);
    background: var(--primary);
}

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

/* Toggle item row layout */
.toggle-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    margin-bottom: 10px;
    gap: 16px;
}

.toggle-item label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
    margin: 0;
}

.toggle-item label i {
    width: 16px;
    color: var(--text-soft);
}

/* --- Unified Form Controls --- */
.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
textarea {
    width: 100%;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    outline: none;
    font-size: 14px;
    color: var(--text);
    transition: all 0.2s ease;
    font-family: inherit;
    box-sizing: border-box;
}

.form-control:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
textarea:focus {
    border-color: var(--primary);
    background: var(--color-surface);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

/* --- Global Search Box --- */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
}

.search-box i,
.search-box svg {
    position: absolute !important;
    left: 16px;
    z-index: 10;
    color: var(--color-text-soft);
    pointer-events: none;
    width: 16px;
    height: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.search-box input {
    padding-left: 44px !important;
}

select.form-control,
select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 42px;
    cursor: pointer;
}

/* --- Standard Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    font-family: inherit;
    line-height: 1;
    white-space: nowrap;
    gap: 8px;
}

/* Small variant */
.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
    gap: 6px;
}

/* Icon-only variant */
.btn-icon {
    padding: 10px;
    aspect-ratio: 1;
}

.btn-primary {
    background: var(--btn-primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.2);
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(var(--primary-rgb), 0.3);
}

.btn-soft {
    background: var(--primary-soft);
    color: var(--primary);
}

.btn-soft:hover {
    background: var(--primary-glass);
}

.btn-ghost {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text-soft);
}

.btn-ghost:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}

[data-theme="dark"] .btn-ghost {
    border-color: transparent;
    color: var(--text-soft);
}

[data-theme="dark"] .btn-ghost:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}



.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

/* --- Form Actions (Architectural) --- */
.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 30px;
    margin-top: 40px;
    border-top: 1px solid var(--color-border);
    gap: 15px;
}


.form-actions-group {
    display: flex;
    gap: 12px;
}



/* --- Table Responsive Wrapper --- */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

/* ============================================================
   .jarvis-switch — Alias for .toggle-switch
   Used in settings-general.php, settings-models.php, etc.
   ===========================================================*/
.jarvis-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    width: 44px !important;
    height: 24px !important;
    flex-shrink: 0;
}

.jarvis-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.jarvis-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 44px;
    background-color: var(--border-color);
    transition: .3s;
    border-radius: 24px;
}

.jarvis-switch .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.jarvis-switch input:checked+.slider {
    background-color: var(--primary);
}

.jarvis-switch input:checked+.slider:before {
    transform: translateX(20px);
}

.jarvis-switch input:focus-visible+.slider {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* --- Architectural Modal System --- */
.modal-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9000;
    padding: 20px;
}

.modal-card {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--card-bg);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 30px;
}

.modal-card-lg {
    max-width: 650px;
}

/* --- Toggle & Permission Rows --- */
.toggle-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    gap: 20px;
    border-bottom: 1px solid var(--border-color);
}

.toggle-item-row:last-child {
    border-bottom: none;
}

.toggle-item-row label:not(.jarvis-switch) {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    flex: 1;
    white-space: normal;
    overflow: visible;
}

body.modal-open {
    overflow: hidden !important;
}

/* --- Data Tables & Lists (Restored) --- */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

/* --- Badge System --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.badge-active,
.badge-paid {
    background: var(--accent-soft);
    color: #15803d;
}

/* WCAG: #15803d on accent-soft = 5.2:1 */
.badge-pending,
.badge-draft {
    background: var(--primary-soft);
    color: #1e3a8a;
}

.badge-danger,
.badge-cancelled,
.badge-inactive {
    background: var(--danger-soft);
    color: #b91c1c;
}

.badge-warning,
.badge-sent {
    background: var(--warning-soft);
    color: #92400e;
}

.badge-muted {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-soft);
}

.badge-primary {
    background: var(--primary-soft);
    color: var(--primary);
}

.data-table thead th {
    padding: 15px 20px;
    font-size: 13px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
    color: var(--color-text-soft);
    border-bottom: 2px solid var(--border);
    background: var(--color-surface);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 15px 20px;
    border-bottom: 1px solid var(--color-bg);
    vertical-align: middle;
    color: var(--color-text);
}

.data-table tbody tr:hover {
    background: var(--color-primary-soft);
}

/* List Components */
.list-container {
    display: flex;
    flex-direction: column;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--color-bg);
    transition: background 0.2s;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background: var(--color-primary-soft);
}


/* ============================================================
   THEME TOGGLE BUTTON (for header)
   ============================================================ */
.theme-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.2s, color 0.2s;
}

.theme-toggle-btn:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.theme-toggle-btn .icon-moon {
    display: block;
}

.theme-toggle-btn .icon-sun {
    display: none;
}

[data-theme="dark"] .theme-toggle-btn .icon-moon {
    display: none;
}

[data-theme="dark"] .theme-toggle-btn .icon-sun {
    display: block;
}

/* ============================================================
   SYSTEM FONT STACK (GDPR — kein Google Fonts)
   ============================================================ */
:root {
    --font-system: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue',
        Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji';
}

body,
input,
textarea,
select,
button {
    font-family: var(--font-system) !important;
}

/* --- Feature Item Component (Settings/Packages) --- */
.feature-item {
    background: var(--bg);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    box-sizing: border-box;
}

.feature-item:hover {
    border-color: var(--primary);
    background: var(--surface);
    transform: translateY(-1px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.06);
}

.feature-info {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    min-width: 0;
}

.feature-icon {
    width: 28px;
    /* Slightly larger */
    height: 28px;
    color: var(--primary);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feature-icon i,
.feature-icon svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5px;
}

.feature-title-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.feature-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.feature-desc {
    font-size: 11.5px;
    color: var(--text-soft);
    line-height: 1.4;
    margin: 0;
}

.feature-item .jarvis-switch {
    margin: 0;
    flex-shrink: 0;
}

.feature-action {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* --- Phase 1 Polish: Loading & Animations --- */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.8 !important;
}

.btn-loading * {
    visibility: hidden;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    top: calc(50% - 9px);
    left: calc(50% - 9px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: jarvis-spin 0.6s linear infinite;
    visibility: visible !important;
}

.btn-soft.btn-loading::after,
.btn-outline.btn-loading::after {
    border-color: var(--primary-soft);
    border-top-color: var(--primary);
}

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

.animate-spin {
    animation: jarvis-spin 1.5s linear infinite;
}

.animate-pulse-subtle {
    animation: jarvis-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes jarvis-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .6;
    }
}

/* Page Transitions */
.page-fade-in {
    animation: page-appear 0.3s ease-out;
}

@keyframes page-appear {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}