:root[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-secondary: #f1f5f9;
    --text-main: #1e293b;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --accent-primary: #10b981;
    --primary-color: #10b981;
    --accent-danger: #ef4444;
    --accent-warning: #f59e0b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

:root[data-theme="dark"] {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #1e293b;
    --bg-secondary: #334155;
    --text-main: #f8fafc;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --accent-primary: #10b981;
    --primary-color: #10b981;
    --accent-danger: #f87171;
    --accent-warning: #fbbf24;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
    overflow-y: auto;
}

.main-content {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Typography & Helpers */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.me-2 { margin-right: 0.5rem; }
.mb-4 { margin-bottom: 1.5rem; }
.d-none { display: none !important; }
.d-md-none { display: none; }

/* Components */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.card-body {
    padding: 1.5rem;
}

/* Grid */
.grid {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.grid-cols-1 { grid-template-columns: 1fr; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }

@media (min-width: 768px) {
    .md-grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
    .lg-grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 0.875rem;
    text-decoration: none;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}
.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-main);
}
.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-outline-danger {
    background: transparent;
    border: 1px solid var(--accent-danger);
    color: var(--accent-danger);
}
.btn-outline-danger:hover {
    background: var(--accent-danger);
    color: white;
}

.btn-outline-primary {
    background: transparent;
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
}
.btn-outline-primary:hover {
    background: var(--accent-primary);
    color: white;
}

.btn-outline-warning {
    background: transparent;
    border: 1px solid var(--accent-warning);
    color: var(--accent-warning);
}
.btn-outline-warning:hover {
    background: var(--accent-warning);
    color: white;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
}

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.form-control, .form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 1rem;
    transition: border-color 0.2s;
}
.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Nav */
.nav-list { list-style: none; }
.nav-item { margin-bottom: 0.5rem; }
.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    gap: 0.75rem;
}
.nav-link:hover, .nav-link.active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-primary);
}
.nav-link.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-danger);
}

/* Stats */
.stat-card {
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.stat-card.danger { background: linear-gradient(135deg, #ef4444, #b91c1c); color: white; }
.stat-card.secondary { background: linear-gradient(135deg, #64748b, #334155); color: white; }

/* Table */
.table-container { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
th {
    text-align: left;
    padding: 1rem 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}
td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.cell-member {
    font-weight: 600;
}

/* Desktop Highlight */
tr.row-highlightable.user-self {
    background-color: rgba(16, 185, 129, 0.05);
}

/* Badges */
.badge {
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-warning { background: rgba(245, 158, 11, 0.1); color: #d97706; }
.badge-success { background: rgba(16, 185, 129, 0.1); color: #059669; }

/* Theme Toggle */
.theme-toggle {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}

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

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

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

/* Mobile Header */
.mobile-header {
    display: none;
    padding: 1rem 1.5rem;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    justify-content: space-between;
    align-items: center;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        z-index: 1000;
        transition: transform 0.3s ease;
        top: 0;
        bottom: 0;
        height: 100dvh; /* Use dynamic viewport height for mobile browsers */
    }
    
    .sidebar.open {
        transform: translateX(280px);
    }

    .mobile-header { display: flex; }
    .main-content { padding: 1rem; }
    /* .grid-cols-2 { grid-template-columns: 1fr; }  Handled by md-grid-cols now */
    .d-md-none { display: block; }
    
    .flex-between {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    /* Mobile Table to Cards */
    thead { display: none; }
    
    tr {
        display: block;
        border-bottom: 2px solid var(--border-color);
        padding: 1rem 0;
    }

    /* Disable alternating background on mobile */
    tr.row-highlightable.user-self {
        background-color: transparent;
    }

    td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 1.5rem;
        border: none;
        text-align: right;
    }
    td::before {
        content: attr(data-label);
        font-weight: 700;
        text-align: left;
    }

    /* Highlighting members in the lists for better scannability on mobile */
    .table-container tr {
        border-bottom: 3px solid var(--border-color);
        padding: 1.25rem 0;
        display: flex;
        flex-direction: column;
    }

    .table-container .cell-member {
        order: -2; /* Move to very top */
        display: block;
        text-align: left;
        font-size: 1.125rem;
        background: var(--bg-secondary);
        margin: -1.25rem 0 0.5rem 0; 
        padding: 1rem 1.5rem;
        border-bottom: 1px solid var(--border-color);
        color: var(--accent-primary);
    }

    /* Left Green Bar for self-penalties in global list on mobile */
    tr.user-self .cell-member {
        border-left: 6px solid var(--accent-primary);
        text-align: left;
        padding-left: calc(1.5rem - 6px);
        color: var(--accent-primary);
        font-weight: 800;
    }

    /* Left Green Bar for self-penalties on desktop */
    @media (min-width: 769px) {
        tr.user-self .cell-member {
            border-left: 4px solid var(--accent-primary);
            padding-left: 1rem;
        }
    }

    .table-container .cell-member::before {
        display: none;
    }

    /* Specific fix for the date row in mobile - making it a floating badge or integrated info */
    .table-container td[data-label="Datum"] {
        order: -1; /* Place right after member name */
        display: flex;
        justify-content: center;
        width: auto;
        padding: 0.25rem 0.75rem;
        margin: 0 auto 1rem auto;
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--text-muted);
        background: var(--bg-main);
        border: 1px solid var(--border-color);
        border-radius: 9999px;
    }
    
    .table-container td[data-label="Datum"]::before {
        content: "\F26C"; /* Bootstrap icon calendar */
        font-family: "bootstrap-icons";
        font-weight: normal;
        margin-right: 0.5rem;
        text-align: left;
    }
}

/* Additional Utilities */
.w-100 { width: 100%; }
.mt-3 { margin-top: 1rem; }

/* Input Groups (used in Login) */
.input-group {
    position: relative;
    display: flex;
    align-items: center;
}
.input-group i {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
}
.input-group .form-control {
    padding-left: 2.75rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}
.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-danger);
    border: 1px solid var(--accent-danger);
}
.alert-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
}
