:root {
    --bg-dark: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --secondary: #ec4899;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --boy-color: #3b82f6;
    --boy-bg: rgba(59, 130, 246, 0.2);
    --girl-color: #ec4899;
    --girl-bg: rgba(236, 72, 153, 0.2);

    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
    --glow: 0 0 20px rgba(139, 92, 246, 0.4);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(139, 92, 246, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 85% 30%, rgba(236, 72, 153, 0.15) 0%, transparent 40%);
}

h1, h2, h3, h4 {
    font-family: 'Outfit', sans-serif;
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 3rem;
    color: var(--primary);
}

.logo h2 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.nav-item:hover {
    background-color: rgba(255,255,255,0.05);
    color: var(--text-main);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    box-shadow: var(--shadow);
}

.nav-item i {
    width: 20px;
    height: 20px;
}

.student-count-widget {
    background-color: rgba(0,0,0,0.2);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 1px solid var(--border-color);
}

.student-count-widget i {
    color: var(--primary);
}

.student-count-widget span {
    font-weight: 800;
    font-size: 1.2rem;
    font-family: 'Outfit';
}

.credits {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding-top: 2rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    margin-top: 1rem;
}

/* --- MAIN CONTENT --- */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 3rem;
    position: relative;
}

.tab-content {
    display: none;
    animation: fadeIn 0.4s ease forwards;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.tab-header {
    margin-bottom: 2rem;
}

.tab-header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 800;
}

.tab-header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* --- PANELS --- */
.panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.panel h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 1.5rem;
    font-size: 1.3rem;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 2.5rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    background: rgba(0,0,0,0.1);
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.05);
}

.upload-area i {
    color: var(--primary);
    width: 40px;
    height: 40px;
    margin-bottom: 1rem;
}

.upload-area p {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.upload-area .subtext {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.upload-area input {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 2rem 0;
    color: var(--border-color);
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}
.divider span {
    padding: 0 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

/* Manual Add */
.manual-add {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.manual-add textarea {
    width: 100%;
    padding: 1rem;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s;
    resize: vertical;
    min-height: 80px;
}

.manual-add textarea:focus {
    border-color: var(--primary);
}

.gender-selector {
    display: flex;
    gap: 1rem;
}

.gender-radio {
    cursor: pointer;
    flex: 1;
}

.gender-radio input {
    display: none;
}

.btn-gender {
    display: block;
    text-align: center;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    transition: all 0.3s;
    font-weight: 600;
}

.gender-radio input:checked + .btn-gender.g {
    background: var(--boy-bg);
    border-color: var(--boy-color);
    color: var(--boy-color);
}

.gender-radio input:checked + .btn-gender.f {
    background: var(--girl-bg);
    border-color: var(--girl-color);
    color: var(--girl-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--glow);
    transform: translateY(-2px);
}

.btn-mega {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    font-size: 1.5rem;
    padding: 1.5rem 3rem;
    border-radius: 50px;
    box-shadow: var(--glow);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-mega:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(236, 72, 153, 0.6);
}

.btn-mega:active {
    transform: scale(0.95);
}

.btn-text {
    background: transparent;
    padding: 0.5rem 1rem;
}

.btn-danger {
    color: #ef4444;
}
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* List */
.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.list-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.student-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.student-list::-webkit-scrollbar {
    width: 6px;
}
.student-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.student-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0,0,0,0.2);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.student-info {
    font-weight: 600;
}

.student-actions {
    display: flex;
    gap: 0.5rem;
}

.toggle-gender {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 800;
    transition: all 0.2s;
    color: white;
}
.toggle-gender.G {
    background: var(--boy-color);
    box-shadow: 0 0 10px var(--boy-bg);
}
.toggle-gender.F {
    background: var(--girl-color);
    box-shadow: 0 0 10px var(--girl-bg);
}

.btn-del {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.btn-del:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    background: rgba(0,0,0,0.1);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-color);
}

/* --- SINGLE DRAW --- */
.single-draw-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
}

.draw-header { margin-bottom: 3rem; }
.draw-header h1 { font-size: 3rem; margin-bottom: 0.5rem; }

.draw-machine {
    margin-bottom: 4rem;
    perspective: 1000px;
}

.draw-result-box {
    background: var(--bg-panel);
    border: 2px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: 3rem 5rem;
    min-width: 400px;
    box-shadow: var(--glow);
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.draw-result-box::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%; width: 200%; height: 200%;
    background: conic-gradient(transparent, rgba(139, 92, 246, 0.3), transparent 30%);
    animation: spin 4s linear infinite;
    opacity: 0;
    transition: opacity 0.3s;
}

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

.draw-result-box.animating::before {
    opacity: 1;
}

.draw-result-box.animating {
    transform: scale(0.95);
    border-color: var(--secondary);
    box-shadow: 0 0 40px rgba(236, 72, 153, 0.5);
}

#draw-name {
    font-size: 4rem;
    font-weight: 800;
    font-family: 'Outfit';
    position: relative;
    z-index: 1;
    display: block;
    background: linear-gradient(to right, #fff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}


/* --- GROUP DRAW --- */
.group-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.number-input {
    display: flex;
    align-items: center;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    padding: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-icon:hover { background: rgba(255,255,255,0.1); }

.number-input input {
    background: transparent;
    border: none;
    color: white;
    width: 60px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 800;
    font-family: 'Outfit';
    pointer-events: none;
}

.group-info {
    color: var(--text-muted);
    font-style: italic;
}

.groups-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.group-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
    animation: scaleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.group-header {
    background: rgba(0,0,0,0.3);
    padding: 1rem 1.5rem;
    font-family: 'Outfit';
    font-size: 1.2rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
}
.group-header .badge {
    font-size: 0.8rem;
    background: var(--primary);
    padding: 2px 8px;
    border-radius: 20px;
}

.group-members {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.member-item {
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideInRight 0.3s ease backwards;
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

.member-gender-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.member-gender-indicator.G {
    background: var(--boy-color);
    box-shadow: 0 0 8px var(--boy-color);
}
.member-gender-indicator.F {
    background: var(--girl-color);
    box-shadow: 0 0 8px var(--girl-color);
}

/* --- SHUFFLING ANIMATION --- */
.shuffle-animation {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    gap: 2rem;
}
.shuffle-animation p {
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    color: var(--primary);
    animation: pulse-color 1s infinite alternate;
}
@keyframes pulse-color {
    from { opacity: 0.6; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1.02); }
}

.shuffling-cards {
    position: relative;
    width: 60px;
    height: 90px;
}
.scard {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--primary);
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    top: 0;
    left: 0;
    animation: shuffle-card 1.5s ease-in-out infinite;
    transform-origin: bottom center;
}
.scard:nth-child(1) { animation-delay: 0s; background: var(--primary); }
.scard:nth-child(2) { animation-delay: 0.3s; background: var(--secondary); }
.scard:nth-child(3) { animation-delay: 0.6s; background: #3b82f6; }
.scard:nth-child(4) { animation-delay: 0.9s; background: #10b981; }

@keyframes shuffle-card {
    0% { transform: translateY(0) rotate(0deg) scale(1); z-index: 1; }
    25% { transform: translateY(-30px) rotate(-15deg) scale(1.1); z-index: 4; }
    50% { transform: translateY(0) rotate(0deg) scale(1); z-index: 4; }
    75% { transform: translateY(-30px) rotate(15deg) scale(1.1); z-index: 1; }
    100% { transform: translateY(0) rotate(0deg) scale(1); z-index: 1; }
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-muted);
    transition: color 0.3s;
}
.radio-label:hover {
    color: var(--text-main);
}
.radio-label input[type="radio"] {
    appearance: none;
    background-color: var(--bg-dark);
    margin: 0;
    font: inherit;
    color: currentColor;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    display: grid;
    place-content: center;
    transition: all 0.2s;
}
.radio-label input[type="radio"]::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 10px 10px var(--primary);
}
.radio-label input[type="radio"]:checked {
    border-color: var(--primary);
}
.radio-label input[type="radio"]:checked::before {
    transform: scale(1);
}
.radio-label input[type="radio"]:checked + span {
    color: var(--text-main);
    font-weight: 600;
}
.radio-label span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-light {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s;
}
.input-light:focus {
    border-color: var(--primary);
}
.activity-group {
    flex: 1;
    margin: 0 1rem;
}

/* --- PRINT STYLES --- */
#print-container {
    display: none;
}
@media print {
    body {
        background: white !important;
        color: black !important;
    }
    body > * {
        display: none !important;
    }
    #print-container {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        color: black !important;
    }
    #print-container h1 {
        text-align: center;
        font-family: 'Outfit', sans-serif;
        margin-bottom: 2rem;
        color: black !important;
        font-size: 24pt;
    }
    .print-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
    .print-card {
        border: 2px solid #aaa;
        border-radius: 8px;
        padding: 15px;
        page-break-inside: avoid;
        background: white !important;
    }
    .print-card h3 {
        margin-bottom: 10px;
        border-bottom: 1px solid #ccc;
        padding-bottom: 5px;
        font-family: 'Outfit', sans-serif;
        font-size: 14pt;
        font-weight: 600;
    }
    .print-card ul {
        list-style-type: none;
        padding: 0;
    }
    .print-card li {
        padding: 6px 0;
        font-size: 12pt;
        border-bottom: 1px dashed #eee;
    }
    .print-card li:last-child {
        border-bottom: none;
    }
}

/* Responsiveness */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1rem;
    }
    .nav-links {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 0.5rem;
    }
    .nav-item {
        white-space: nowrap;
    }
    .panels { grid-template-columns: 1fr; }
    .group-controls { flex-direction: column; gap: 1rem; align-items: flex-start; }
    .activity-group { margin: 0; width: 100%; }
}
