/* ============================================================
   FND-App — Design System
   Weiß/Rot + Dark Mode
   ============================================================ */

/* ---- Google Fonts ----------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Sora:wght@500;600&display=swap');

/* ---- CSS Custom Properties -------------------------------- */
:root {
    /* Brand */
    --red:          #C8001A;
    --red-hover:    #A30015;
    --red-light:    #FFF0F2;
    --red-border:   #FFCCD3;

    /* Neutral Light */
    --white:        #FFFFFF;
    --gray-50:      #F9F9FB;
    --gray-100:     #F0EFF4;
    --gray-200:     #E2E0EA;
    --gray-300:     #C9C7D4;
    --gray-400:     #9996AB;
    --gray-500:     #6B6882;
    --gray-600:     #4A4760;
    --gray-700:     #2E2C40;
    --gray-800:     #1A1828;
    --gray-900:     #0E0D1A;

    /* Semantic */
    --success:      #16A34A;
    --success-bg:   #F0FDF4;
    --warning:      #D97706;
    --warning-bg:   #FFFBEB;
    --info:         #2563EB;
    --info-bg:      #EFF6FF;

    /* Surfaces (Light Mode) */
    --bg-body:      var(--gray-50);
    --bg-card:      var(--white);
    --bg-card-2:    var(--gray-100);
    --bg-input:     var(--white);
    --bg-nav:       var(--white);
    --bg-sidebar:   var(--white);

    /* Text (Light Mode) */
    --text-primary:   var(--gray-800);
    --text-secondary: var(--gray-500);
    --text-muted:     var(--gray-400);
    --text-on-red:    #FFFFFF;

    /* Borders */
    --border:       var(--gray-200);
    --border-focus: var(--red);

    /* Shadows */
    --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
    --shadow-md:    0 4px 12px rgba(0,0,0,.10);
    --shadow-lg:    0 8px 24px rgba(0,0,0,.12);

    /* Typography */
    --font-body:    'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Sora', 'Inter', system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', 'Fira Code', monospace;

    /* Spacing */
    --radius-sm:    6px;
    --radius-md:    10px;
    --radius-lg:    16px;
    --radius-xl:    24px;

    /* Transitions */
    --transition:   .18s ease;
}

/* ---- Dark Mode -------------------------------------------- */
[data-theme="dark"] {
    --bg-body:      #0F0F14;
    --bg-card:      #18181F;
    --bg-card-2:    #1F1F28;
    --bg-input:     #18181F;
    --bg-nav:       #14141A;
    --bg-sidebar:   #14141A;

    --text-primary:   #E8E6F4;
    --text-secondary: #8F8DA8;
    --text-muted:     #5A5870;

    --border:       #2A2840;
    --border-focus: #E8001E;

    --red:          #E8001E;
    --red-hover:    #FF1C38;
    --red-light:    #1F0A0D;
    --red-border:   #3D0D14;

    --shadow-sm:    0 1px 3px rgba(0,0,0,.3);
    --shadow-md:    0 4px 12px rgba(0,0,0,.4);
    --shadow-lg:    0 8px 24px rgba(0,0,0,.5);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family:      var(--font-body);
    background-color: var(--bg-body);
    color:            var(--text-primary);
    line-height:      1.6;
    min-height:       100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--red); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--red-hover); text-decoration: underline; }

h1,h2,h3,h4,h5,h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
}

img, svg { display: block; max-width: 100%; }

/* ============================================================
   AUTH LAYOUT (Login, DSGVO-Onboarding)
   ============================================================ */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1rem;
    background: var(--bg-body);
}

.auth-container {
    width: 100%;
    max-width: 440px;
    position: relative;
}

.auth-card {
    background:    var(--bg-card);
    border:        1px solid var(--border);
    border-radius: var(--radius-xl);
    padding:       2.5rem 2rem;
    box-shadow:    var(--shadow-lg);
}

.auth-brand {
    display:        flex;
    align-items:    center;
    gap:            10px;
    margin-bottom:  2rem;
}

.brand-mark {
    width:           40px;
    height:          40px;
    background:      var(--red);
    border-radius:   var(--radius-md);
    display:         flex;
    align-items:     center;
    justify-content: center;
    font-family:     var(--font-heading);
    font-weight:     600;
    font-size:       14px;
    color:           var(--text-on-red);
    letter-spacing:  -.5px;
    flex-shrink:     0;
}

.brand-name {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size:   18px;
    color:       var(--text-primary);
}

.auth-title {
    font-size:    24px;
    font-weight:  600;
    margin-bottom: .5rem;
}

.auth-subtitle {
    color:        var(--text-secondary);
    font-size:    14px;
    margin-bottom: 1.75rem;
}

.auth-footer {
    text-align:  center;
    font-size:   13px;
    color:       var(--text-muted);
    margin-top:  1.25rem;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 1.25rem; }

.form-label {
    display:       flex;
    align-items:   center;
    justify-content: space-between;
    font-size:     13px;
    font-weight:   500;
    color:         var(--text-secondary);
    margin-bottom: .5rem;
}

.label-link {
    font-weight: 400;
    font-size:   12px;
    color:       var(--red);
}

.form-input {
    width:         100%;
    height:        44px;
    padding:       0 14px;
    background:    var(--bg-input);
    border:        1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-family:   var(--font-body);
    font-size:     15px;
    color:         var(--text-primary);
    transition:    border-color var(--transition), box-shadow var(--transition);
    outline:       none;
}

.form-input:focus {
    border-color: var(--border-focus);
    box-shadow:   0 0 0 3px rgba(200, 0, 26, .12);
}

.form-input::placeholder { color: var(--text-muted); }

.input-wrapper { position: relative; }
.input-wrapper .form-input { padding-right: 44px; }
.input-toggle {
    position:   absolute;
    right:      0;
    top:        0;
    height:     44px;
    width:      44px;
    background: none;
    border:     none;
    cursor:     pointer;
    color:      var(--text-muted);
    display:    flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition);
}
.input-toggle:hover { color: var(--text-primary); }

textarea.form-input {
    height:     auto;
    min-height: 100px;
    padding:    12px 14px;
    resize:     vertical;
    line-height: 1.6;
}

select.form-input { cursor: pointer; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    gap:             8px;
    height:          44px;
    padding:         0 20px;
    border-radius:   var(--radius-md);
    font-family:     var(--font-body);
    font-size:       15px;
    font-weight:     500;
    cursor:          pointer;
    border:          1.5px solid transparent;
    transition:      all var(--transition);
    text-decoration: none;
    white-space:     nowrap;
    user-select:     none;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background:   var(--red);
    color:        var(--text-on-red);
    border-color: var(--red);
}
.btn-primary:hover:not(:disabled) {
    background: var(--red-hover);
    border-color: var(--red-hover);
    color: var(--text-on-red);
    text-decoration: none;
}

.btn-secondary {
    background:   var(--bg-card-2);
    color:        var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--bg-card);
    border-color: var(--gray-300);
    text-decoration: none;
}

.btn-ghost {
    background:   transparent;
    color:        var(--text-secondary);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg-card-2);
    color: var(--text-primary);
    text-decoration: none;
}

.btn-danger {
    background:   #DC2626;
    color:        #fff;
    border-color: #DC2626;
}
.btn-danger:hover:not(:disabled) { background: #B91C1C; border-color: #B91C1C; }

.btn-sm   { height: 34px; padding: 0 14px; font-size: 13px; }
.btn-lg   { height: 52px; padding: 0 28px; font-size: 16px; }
.btn-full { width: 100%; }

.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 34px; }

/* ============================================================
   ALERTS / FLASH MESSAGES
   ============================================================ */
.alert {
    display:       flex;
    align-items:   flex-start;
    gap:           10px;
    padding:       12px 16px;
    border-radius: var(--radius-md);
    font-size:     14px;
    margin-bottom: 1.25rem;
    border:        1px solid;
}

.alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.alert-error   { background: var(--red-light);  border-color: var(--red-border); color: var(--red); }
.alert-success { background: var(--success-bg); border-color: #BBF7D0;           color: #166534; }
.alert-warning { background: var(--warning-bg); border-color: #FDE68A;           color: #92400E; }
.alert-info    { background: var(--info-bg);    border-color: #BFDBFE;           color: #1E40AF; }

[data-theme="dark"] .alert-error   { color: #FCA5A5; border-color: #7F1D1D; }
[data-theme="dark"] .alert-success { color: #86EFAC; border-color: #14532D; }
[data-theme="dark"] .alert-warning { color: #FCD34D; border-color: #78350F; }
[data-theme="dark"] .alert-info    { color: #93C5FD; border-color: #1E3A8A; }

/* ============================================================
   DSGVO ONBOARDING
   ============================================================ */
.dsgvo-info {
    display:       flex;
    gap:           10px;
    background:    var(--info-bg);
    border:        1px solid #BFDBFE;
    border-radius: var(--radius-md);
    padding:       12px 16px;
    font-size:     13px;
    color:         var(--info);
    margin-bottom: 1.5rem;
    line-height:   1.6;
}
[data-theme="dark"] .dsgvo-info { background: #1E2A40; border-color: #1E3A8A; color: #93C5FD; }

.dsgvo-info-icon { font-size: 16px; flex-shrink: 0; }

.consent-item {
    padding:       16px;
    border:        1.5px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    transition:    border-color var(--transition), background var(--transition);
}
.consent-item:has(.consent-check:checked) {
    border-color: var(--red);
    background:   var(--red-light);
}

.consent-label {
    display:    flex;
    gap:        14px;
    cursor:     pointer;
    align-items: flex-start;
}

.consent-check { display: none; }

.consent-box {
    width:        22px;
    height:       22px;
    border:       2px solid var(--border);
    border-radius: 6px;
    flex-shrink:  0;
    margin-top:   2px;
    transition:   all var(--transition);
    position:     relative;
    background:   var(--bg-input);
}

.consent-check:checked ~ .consent-box {
    background:   var(--red);
    border-color: var(--red);
}
.consent-check:checked ~ .consent-box::after {
    content:    '';
    position:   absolute;
    left:       5px; top: 2px;
    width:      8px; height: 12px;
    border:     2.5px solid white;
    border-top: none;
    border-left: none;
    transform:  rotate(45deg);
}

.consent-text strong {
    display:     block;
    font-size:   14px;
    font-weight: 600;
    margin-bottom: 4px;
}
.consent-text p { font-size: 13px; color: var(--text-secondary); }

.badge {
    display:       inline-block;
    padding:       1px 7px;
    border-radius: 20px;
    font-size:     11px;
    font-weight:   500;
}
.badge-required { background: var(--red-light); color: var(--red); border: 1px solid var(--red-border); }
.badge-optional { background: var(--gray-100);  color: var(--text-secondary); border: 1px solid var(--border); }

[data-theme="dark"] .badge-required { background: var(--red-light); border-color: var(--red-border); }
[data-theme="dark"] .badge-optional { background: var(--bg-card-2); border-color: var(--border); }

.consent-all {
    padding:       12px 0 4px;
    border-top:    1px solid var(--border);
    margin-top:    6px;
    margin-bottom: 12px;
}
.consent-label-small {
    display:     flex;
    align-items: center;
    gap:         8px;
    font-size:   13px;
    color:       var(--text-secondary);
    cursor:      pointer;
}

.dsgvo-links {
    display:     flex;
    align-items: center;
    gap:         8px;
    font-size:   12px;
    color:       var(--text-muted);
    margin-bottom: 1.25rem;
    justify-content: center;
}

/* ============================================================
   APP LAYOUT (nach Login)
   ============================================================ */
.app-layout {
    display:    flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width:        260px;
    flex-shrink:  0;
    background:   var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display:      flex;
    flex-direction: column;
    position:     fixed;
    top:          0;
    left:         0;
    height:       100vh;
    overflow-y:   auto;
    z-index:      100;
    transition:   transform var(--transition);
}

.sidebar-brand {
    display:     flex;
    align-items: center;
    gap:         10px;
    padding:     1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-nav { flex: 1; padding: 1rem 0; }

.nav-section-label {
    font-size:    10px;
    font-weight:  600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color:        var(--text-muted);
    padding:      .75rem 1.5rem .25rem;
}

.nav-item {
    display:       flex;
    align-items:   center;
    gap:           10px;
    padding:       10px 1.5rem;
    font-size:     14px;
    color:         var(--text-secondary);
    transition:    all var(--transition);
    border-radius: 0;
    cursor:        pointer;
    text-decoration: none;
    border-left:   3px solid transparent;
}

.nav-item:hover {
    background: var(--bg-card-2);
    color:      var(--text-primary);
    text-decoration: none;
}

.nav-item.active {
    background:   var(--red-light);
    color:        var(--red);
    border-left-color: var(--red);
    font-weight:  500;
}
[data-theme="dark"] .nav-item.active { background: rgba(200,0,26,.12); }

.nav-item .nav-icon {
    width:      18px;
    height:     18px;
    flex-shrink: 0;
    opacity:    .7;
}
.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
    padding:       1rem 1.5rem;
    border-top:    1px solid var(--border);
    font-size:     13px;
}

.user-pill {
    display:       flex;
    align-items:   center;
    gap:           10px;
    padding:       8px 10px;
    border-radius: var(--radius-md);
    background:    var(--bg-card-2);
}

.user-avatar {
    width:           32px;
    height:          32px;
    border-radius:   50%;
    background:      var(--red);
    color:           white;
    display:         flex;
    align-items:     center;
    justify-content: center;
    font-size:       12px;
    font-weight:     600;
    flex-shrink:     0;
}

.user-info .user-name { font-weight: 500; font-size: 13px; }
.user-info .user-role { font-size: 11px; color: var(--text-muted); }

/* Main Content */
.main-content {
    margin-left:  260px;
    flex:         1;
    display:      flex;
    flex-direction: column;
    min-height:   100vh;
}

/* Top Bar */
.topbar {
    height:        60px;
    background:    var(--bg-nav);
    border-bottom: 1px solid var(--border);
    display:       flex;
    align-items:   center;
    padding:       0 1.5rem;
    gap:           12px;
    position:      sticky;
    top:           0;
    z-index:       200;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.topbar-title {
    font-family: var(--font-heading);
    font-size:   18px;
    font-weight: 600;
    flex:        1;
}

.page-content { padding: 1.75rem 1.5rem; max-width: 1200px; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background:    var(--bg-card);
    border:        1px solid var(--border);
    border-radius: var(--radius-lg);
    padding:       1.5rem;
    box-shadow:    var(--shadow-sm);
}

.card-header {
    display:       flex;
    align-items:   center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.card-title {
    font-family: var(--font-heading);
    font-size:   16px;
    font-weight: 600;
}

.card-grid {
    display:               grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap:                   1rem;
}

/* Stat Cards (Dashboard) */
.stat-card {
    background:    var(--bg-card);
    border:        1px solid var(--border);
    border-radius: var(--radius-lg);
    padding:       1.25rem 1.5rem;
    display:       flex;
    flex-direction: column;
    gap:           4px;
    position:      relative;
    overflow:      hidden;
}
.stat-card::before {
    content:  '';
    position: absolute;
    top:      0; left: 0; right: 0;
    height:   3px;
    background: var(--accent-color, var(--red));
}
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 28px; font-weight: 600; font-family: var(--font-heading); }
.stat-sub   { font-size: 12px; color: var(--text-secondary); }

/* ============================================================
   BADGES & TAGS
   ============================================================ */
.tag {
    display:       inline-flex;
    align-items:   center;
    gap:           4px;
    padding:       2px 8px;
    border-radius: 20px;
    font-size:     12px;
    font-weight:   500;
}

.tag-red    { background: var(--red-light);  color: var(--red);     border: 1px solid var(--red-border); }
.tag-green  { background: var(--success-bg); color: var(--success); border: 1px solid #BBF7D0; }
.tag-gray   { background: var(--gray-100);   color: var(--gray-600); border: 1px solid var(--border); }
.tag-amber  { background: var(--warning-bg); color: var(--warning);  border: 1px solid #FDE68A; }
.tag-blue   { background: var(--info-bg);    color: var(--info);    border: 1px solid #BFDBFE; }

[data-theme="dark"] .tag-red   { background: rgba(200,0,26,.15); border-color: rgba(200,0,26,.3); }
[data-theme="dark"] .tag-green { background: rgba(22,163,74,.12); border-color: rgba(22,163,74,.3); color: #86EFAC; }
[data-theme="dark"] .tag-gray  { background: var(--bg-card-2); border-color: var(--border); color: var(--text-secondary); }
[data-theme="dark"] .tag-amber { background: rgba(217,119,6,.12); border-color: rgba(217,119,6,.3); color: #FCD34D; }
[data-theme="dark"] .tag-blue  { background: rgba(37,99,235,.12); border-color: rgba(37,99,235,.3); color: #93C5FD; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper { overflow-x: auto; }

table.fnd-table {
    width:          100%;
    border-collapse: collapse;
    font-size:      14px;
}
.fnd-table th {
    text-align:    left;
    padding:       10px 14px;
    font-size:     11px;
    font-weight:   600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color:         var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space:   nowrap;
}
.fnd-table td {
    padding:      12px 14px;
    border-bottom: 1px solid var(--border);
    color:        var(--text-primary);
    vertical-align: middle;
}
.fnd-table tr:last-child td { border-bottom: none; }
.fnd-table tbody tr:hover { background: var(--bg-card-2); }

/* ============================================================
   THEME TOGGLE (floating)
   ============================================================ */
.theme-toggle {
    position:      fixed;
    bottom:        1.5rem;
    right:         1.5rem;
    width:         40px;
    height:        40px;
    border-radius: 50%;
    background:    var(--bg-card);
    border:        1px solid var(--border);
    cursor:        pointer;
    display:       flex;
    align-items:   center;
    justify-content: center;
    color:         var(--text-secondary);
    box-shadow:    var(--shadow-md);
    transition:    all var(--transition);
    z-index:       200;
}
.theme-toggle:hover { background: var(--bg-card-2); color: var(--text-primary); }

html, body { overflow-x: hidden; max-width: 100%; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
    #mobile-menu-btn { display: flex !important; }
    .auth-card { padding: 1.5rem 1rem; }
    .page-content { padding: .875rem .75rem; overflow-x: hidden; }
    .card-grid { grid-template-columns: 1fr !important; }
    .topbar { padding: 0 .75rem; }
    .topbar-title { font-size: 15px; }
    .card { padding: .875rem; }
    .form-input, select.form-input, textarea.form-input { width: 100%; box-sizing: border-box; }
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
    [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
}
@media (max-width: 480px) {
    .page-content { padding: .75rem .5rem; }
    .card { padding: .75rem; }
    .topbar-title { font-size: 14px; }
}

    .card-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.d-flex    { display: flex; }
.d-grid    { display: grid; }
.gap-1     { gap: .5rem; }
.gap-2     { gap: 1rem; }
.gap-3     { gap: 1.5rem; }
.mt-1      { margin-top: .5rem; }
.mt-2      { margin-top: 1rem; }
.mt-3      { margin-top: 1.5rem; }
.mb-1      { margin-bottom: .5rem; }
.mb-2      { margin-bottom: 1rem; }
.mb-3      { margin-bottom: 1.5rem; }
.text-sm   { font-size: 13px; }
.text-xs   { font-size: 11px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-red  { color: var(--red); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-500    { font-weight: 500; }
.fw-600    { font-weight: 600; }
.w-100     { width: 100%; }
.flex-1    { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
