* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 2.5em;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.upload-section {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    padding: 30px;
    border-radius: 15px;
    margin-bottom: 30px;
    color: white;
    text-align: center;
}

.file-input-wrapper {
    position: relative;
    display: inline-block;
    cursor: pointer;
    background: rgba(255,255,255,0.2);
    padding: 15px 30px;
    border-radius: 50px;
    border: 2px dashed rgba(255,255,255,0.5);
    transition: all 0.3s ease;
    margin: 20px 0;
}

.file-input-wrapper:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}

.file-input {
    position: absolute;
    left: -9999px;
}

.debug-info {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 15px;
    margin: 20px 0;
    font-family: monospace;
    font-size: 12px;
    max-height: 300px;
    overflow-y: auto;
}

.students-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.class-header {
    grid-column: 1 / -1; /* Sträcker sig över alla kolumner */
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 15px 20px;
    border-radius: 12px;
    margin: 10px 0 5px 0;
    text-align: center;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.class-header h3 {
    margin: 0 0 5px 0;
    font-size: 1.3em;
    font-weight: bold;
}

.class-header .source-info {
    font-size: 0.9em;
    opacity: 0.9;
    font-weight: normal;
}

.student-card {
    background: white;
    border-radius: 12px;
    padding: 4px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 3px solid transparent;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    position: relative;
}

.student-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.student-card.selected {
    border-color: #4CAF50;
    background: linear-gradient(135deg, #c8e6c9 0%, #e8f5e8 100%);
}

.student-card.selected::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    background: #4CAF50;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 12px;
}

.student-name {
    font-weight: bold;
    color: #333;
    font-size: 14px;
    margin-bottom: 5px;
}

.student-class {
    font-size: 12px;
    color: #666;
}

.student-image {
    width: 80px;
    height: 105px;
    border-radius: 8px;
    margin: 0 auto 10px auto;
    object-fit: cover;
    display: block;
}

.student-placeholder {
    width: 80px;
    height: 105px;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    color: #1976d2;
    margin: 0 auto 10px auto;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    margin: 5px;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
}

.btn-secondary {
    background: linear-gradient(45deg, #ffecd2, #fcb69f);
    color: #333;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.2);
}

.loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.error {
    background: #ff6b6b;
    color: white;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    text-align: center;
}

.success {
    background: #51cf66;
    color: white;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    text-align: center;
}

.controls {
    text-align: center;
    margin: 20px 0;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.selected-count {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    display: inline-block;
    margin: 10px 0;
    position: sticky;
    top: 20px;
    z-index: 10;
}

#preview {
    background: white;
    border-radius: 15px;
    padding: 30px;
    margin-top: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    text-align: center;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.preview-student {
    text-align: center;
    background: #f9f9f9;
    padding: 2px;
    border-radius: 10px;
}

.preview-student img {
    width: 90px;
    height: 120px;
    border-radius: 8px;
    object-fit: cover;
    margin: 0 auto 2px auto;
    display: block;
}

.text-input {
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
}

.text-input:focus {
    outline: none;
    border-color: #764ba2;
}

h2{
    margin-bottom: 10px;
}

#topBtn {
  display: none;
  position: fixed;
  bottom: 30px;
  left: 48%;
  z-index: 99;
}

@page {
    margin-top: 0.8cm;
    margin-bottom: 0cm;
    margin-left: 1.5cm;
    margin-right: 1.5cm;
}

@media print {
    html, body {
        height: auto !important;
        overflow: visible !important;
    }

    /* Dölj allt först */
    body * {
        visibility: hidden;
    }
    
    /* === DEN NYA, VIKTIGA REGELN === */
    /* Ta bort student-listan helt från utskriftens layout */
    #studentsGrid {
        display: none !important;
    }
    
    /* Visa bara förhandsvisningen och dess innehåll */
    #preview, #preview * {
        visibility: visible;
    }
    
    /* Positionera förhandsvisningen för utskrift */
    #preview {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background: white !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0px !important;
        margin: 0px auto;
        text-align: center;
    }
    
    /* Förhindra att kort delas över sidor */
    .preview-student {
        break-inside: avoid;
        page-break-inside: avoid;
        margin-bottom: 10px;
        font-size: 0.8em;
    }
    
    /* Dölj kontrollknappar vid utskrift */
    #preview .controls {
        display: none !important;
    }
    
    /* Anpassa grid för utskrift */
    .preview-grid {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)) !important;
        gap: 0px 10px !important;
    }
}