:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f3f4f6;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --card-bg: rgba(255, 255, 255, 0.8);
    --card-border: rgba(255, 255, 255, 0.8);
    --border-color: #e5e7eb;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --header-bg: rgba(255, 255, 255, 0.8);
    --input-bg: #ffffff;
    --sidebar-bg: #ffffff;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --transition-speed: 0.3s;
}

[data-theme='dark'] {
    --primary-color: #6366f1;
    --primary-hover: #818cf8;
    --bg-color: #0f172a;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --card-bg: rgba(30, 41, 59, 0.7);
    --card-border: rgba(255, 255, 255, 0.05);
    --border-color: #334155;
    --danger-color: #f87171;
    --success-color: #34d399;
    --header-bg: rgba(30, 41, 59, 0.8);
    --input-bg: #1e293b;
    --sidebar-bg: #1e293b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
    transition: background var(--transition-speed), box-shadow var(--transition-speed);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--primary-color);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.header-logo {
    height: 48px;
    width: auto;
    object-fit: contain;
}

.nav-link {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 500;
    margin-left: 20px;
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--primary-color);
}

/* Buttons */
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    transition: background 0.2s;
    border: none;
    cursor: pointer;
    font-size: 1rem;
}

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

.btn-outline {
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-color);
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-danger-icon {
    background: #fee2e2;
    color: var(--danger-color);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-danger-icon:hover {
    background: var(--danger-color);
    color: white;
}

.btn-card-delete {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 10;
}

/* Dashboard Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.student-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    border: 1px solid var(--card-border);
    position: relative;
    overflow: hidden;
}

.student-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), #818cf8);
}

.student-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Dashboard Enhancements */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-color), #818cf8);
    color: white;
    padding: 30px;
    border-radius: 16px;
    margin-bottom: 30px;
    box-shadow: 0 10px 25px -5px rgba(79, 70, 229, 0.4);
}

.dashboard-header .actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 450px;
    /* Ensure enough space for the buttons */
}


/* DB Actions Buttons */
.db-actions {
    display: flex;
    gap: 10px;
    width: 100%;
}

.btn-db-action {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    padding: 10px 0;
    border-radius: 8px;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    /* Distribute equally */
    /* Removed fixed width, controlled by flex parent */
    width: 100%;
    height: 100%;
    /* Fill container */
    max-width: 100%;
    box-sizing: border-box;
    transition: all 0.2s;
    font-family: inherit;
}

.item-flex {
    flex: 1;
    /* Each form/link takes equal space */
    display: flex;
    /* Allow button to fill it */
}

.width-full {
    width: 100%;
}

.btn-db-action:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-1px);
}

.btn-db-danger:hover {
    background: rgba(239, 68, 68, 0.8);
    border-color: rgba(239, 68, 68, 1);
}

.btn-pfi-small {
    padding: 4px 8px !important;
    font-size: 0.8rem !important;
    border-radius: 6px;
    white-space: nowrap;
    min-width: 60px;
    font-weight: 600;
    border: none !important;
    /* Remove outline border since we use background colors */
    color: white !important;
    transition: transform 0.2s, filter 0.2s;
}

.btn-pfi-small:hover {
    transform: translateY(-2px);
    filter: brightness(110%);
}

.btn-pfi-1 {
    background-color: #3b82f6 !important;
    /* Blue */
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.btn-pfi-2 {
    background-color: #10b981 !important;
    /* Emerald */
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.btn-pfi-3 {
    background-color: #f59e0b !important;
    /* Amber */
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
}

.btn-pfi-4 {
    background-color: #8b5cf6 !important;
    /* Violet */
    box-shadow: 0 2px 4px rgba(139, 92, 246, 0.3);
}

.btn-pfi-5 {
    background-color: #ec4899 !important;
    /* Pink/Rose */
    box-shadow: 0 2px 4px rgba(236, 72, 153, 0.3);
}

.header-content h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.header-content p {
    color: rgba(255, 255, 255, 0.9);
}

.search-form {
    display: flex;
    gap: 10px;
    background: rgba(255, 255, 255, 0.2);
    padding: 5px;
    border-radius: 10px;
    width: 100%;
    /* Match the width of the container */
    box-sizing: border-box;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex-grow: 1;
    /* Expand to fill space */
}

.search-wrapper i {
    position: absolute;
    left: 12px;
    color: rgba(255, 255, 255, 0.7);
}

.search-wrapper input {
    background: transparent;
    border: none;
    color: white;
    padding: 10px 10px 10px 35px;
    font-size: 1rem;
    width: 100%;
    /* Fill the wrapper */
    box-sizing: border-box;
}

.search-wrapper input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.search-wrapper input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

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

.search-form .btn-outline {
    border-color: rgba(255, 255, 255, 0.5);
    color: white;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: var(--shadow);
    border: 1px solid var(--card-border);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    background: #e0e7ff;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.avatar-placeholder {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
    color: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.student-card .card-header {
    display: flex;
    justify-content: flex-start;
    gap: 15px;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 15px;
    margin-bottom: 15px;
}

.student-info h3 {
    margin-bottom: 5px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.full-width {
    flex: 1;
    text-align: center;
}

.btn-danger-outline {
    border: 1px solid var(--danger-color);
    background: transparent;
    color: var(--danger-color);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-danger-outline:hover {
    background: #fee2e2;
}


.card-body p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 5px;
}

.card-footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px;
    color: #9ca3af;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 20px;
}

.empty-state p {
    margin-bottom: 20px;
    font-size: 1.1rem;
}

/* FORM STYLES - PFI Specific */
.pfi-form-container {
    background: var(--card-bg);
    padding: 40px;
    /* A4 padding emulation */
    border-radius: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--card-border);
    max-width: 210mm;
    /* A4 Width */
    margin: 0 auto;
}

.form-actions {
    position: sticky;
    top: 20px;
    display: flex;
    gap: 10px;
    background: var(--header-bg);
    padding: 15px;
    backdrop-filter: blur(5px);
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 100;
    margin-bottom: 20px;
    justify-content: flex-end;
}

.pfi-page-title {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--text-color);
    padding-bottom: 10px;
}

.form-section {
    margin-bottom: 30px;
    page-break-inside: avoid;
}

.form-section h3 {
    background: var(--bg-color);
    padding: 10px;
    border-left: 4px solid var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.1rem;
    text-transform: uppercase;
}

.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
}

.form-group {
    flex: 1;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition-speed), background var(--transition-speed);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.checkbox-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Radio grids for Levels (A1, A2...) */
.radio-level-grid {
    display: flex;
    gap: 15px;
    margin-top: 5px;
}

.radio-level-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.8rem;
}

/* Table-like inputs */
.input-table {
    width: 100%;
    border-collapse: collapse;
}

.input-table th,
.input-table td {
    padding: 10px;
    border: 1px solid var(--border-color);
}

.input-table th {
    background: #f9fafb;
    text-align: left;
    font-size: 0.9rem;
}

/* Print Styles Optimized */
@media print {
    @page {
        size: A4;
        margin: 1.5cm 1cm;
    }

    html,
    body {
        height: auto !important;
        overflow: visible !important;
        background: white !important;
        color: black !important;
        font-size: 11pt;
    }

    /* Layout Resets */
    .app-container,
    .content {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    .pfi-form-container,
    .page-wrapper {
        display: block !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    .no-print,
    .form-actions,
    .sidebar-sticky,
    .pfi-sidebar {
        display: none !important;
    }

    /* Headings & Page Breaks */
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        page-break-after: avoid !important;
        break-after: avoid !important;
        margin-top: 1.2em;
        margin-bottom: 0.8em;
    }

    /* Major Sections (Parts) */
    .pfi-page-title {
        page-break-before: always !important;
        break-before: page !important;
        margin-top: 0 !important;
        border-bottom: 2px solid black;
        padding-bottom: 10px;
        margin-bottom: 30px !important;
        text-align: center;
    }

    /* Avoid double break after cover page */
    .print-cover-page+.pfi-page-title,
    .print-cover-page+*+.pfi-page-title {
        page-break-before: auto !important;
        break-before: auto !important;
    }

    .form-section {
        display: block !important;
        page-break-inside: auto !important;
        break-inside: auto !important;
        margin-bottom: 25px !important;
    }

    /* Form Fields */
    .form-group input,
    .form-group textarea,
    .form-group select {
        border: none !important;
        border-bottom: 1px dotted #666 !important;
        border-radius: 0 !important;
        padding: 2px 0 !important;
        background: transparent !important;
        font-size: 11pt !important;
    }

    /* Tables */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
        page-break-inside: auto !important;
    }

    tr {
        page-break-inside: avoid !important;
        page-break-after: auto !important;
    }

    thead {
        display: table-header-group !important;
    }

    /* COVER PAGE SPECIFIC */
    .print-cover-page {
        display: block !important;
        min-height: 26cm;
        width: 100%;
        page-break-after: always !important;
        break-after: page !important;
        position: relative;
        text-align: center;
        padding-top: 4cm;
        overflow: visible !important;
    }

    .print-cover-header {
        margin-bottom: 3cm;
    }

    .print-cover-logo {
        max-width: 160px;
        max-height: 160px;
        margin-bottom: 20px;
    }

    .print-cover-school-name {
        font-size: 24pt;
        font-weight: bold;
        text-transform: uppercase;
        margin-bottom: 10px;
    }

    .print-cover-school-details {
        font-size: 12pt;
    }

    .print-cover-title {
        font-size: 32pt;
        font-weight: bold;
        margin-bottom: 2cm;
        border-top: 2px solid black;
        border-bottom: 2px solid black;
        padding: 30px 0;
        line-height: 1.2;
    }

    .print-cover-student {
        font-size: 18pt;
        border: 1px solid black;
        padding: 30px;
        display: inline-block;
        min-width: 70%;
        text-align: left;
        margin: 0 auto;
    }

    .print-cover-student p {
        margin: 10px 0;
    }

    /* Checkboxes Fix for Print */
    .checkbox-item input[type="checkbox"] {
        -webkit-appearance: none;
        appearance: none;
        width: 14px;
        height: 14px;
        border: 1px solid black;
        display: inline-block;
        position: relative;
        vertical-align: middle;
    }

    .checkbox-item input[type="checkbox"]:checked:after {
        content: '✓';
        position: absolute;
        top: -4px;
        left: 1px;
        font-size: 14px;
        font-weight: bold;
    }
}

/* End @media print */

/* Screen only styles for cover (hidden or preview) */
@media screen {
    .print-cover-page {
        display: none !important;
    }
}

/* Radio Group Vertical Box Style */
.radio-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.radio-item-box {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.radio-item-box:hover {
    background: rgba(255, 255, 255, 0.8);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.radio-item-box input[type="radio"] {
    margin-top: 5px;
    /* Align with text top */
}

/* SIDEBAR LAYOUT STYLES */
.page-wrapper {
    display: flex;
    /* align-items: stretch; Default behavior ensures sidebar stretches */
    gap: 20px;
    max-width: 1400px;
    /* Slightly wider */
    margin: 0 auto;
    padding: 20px;
}

.pfi-sidebar {
    width: 250px;
    flex-shrink: 0;
}

.sidebar-sticky {
    position: sticky;
    top: 20px;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    max-height: 90vh;
    overflow-y: auto;
}

.sidebar-sticky h4 {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1.1rem;
    border-bottom: 2px solid #eef2ff;
    padding-bottom: 10px;
}

.sidebar-sticky ul {
    list-style: none;
    padding: 0;
}

.sidebar-sticky li {
    margin-bottom: 10px;
}

.sidebar-sticky a {
    text-decoration: none;
    color: #4b5563;
    font-size: 0.95rem;
    display: block;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.sidebar-sticky a:hover {
    background: #eef2ff;
    color: var(--primary-color);
    transform: translateX(5px);
}

/* Adjust PFI Container to fit */
.pfi-form-container {
    flex: 1;
    margin: 0;
    /* Let wrapper handle margins */
    max-width: 210mm;
    /* Keep A4 constraint */
}

/* Ensure smooth scrolling */
html {
    scroll-behavior: smooth;
    scroll-padding-top: 100px;
    /* Offset for sticky header/actions */
}

/* Custom Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    animation: fadeIn 0.2s forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(0.95);
    animation: scaleIn 0.2s forwards;
}

@keyframes scaleIn {
    to {
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h3 {
    margin: 0;
    color: var(--danger-color);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: #6b7280;
    cursor: pointer;
}

.btn-close:hover {
    color: #1f2937;
}

.modal-body {
    padding: 20px;
    color: #374151;
    font-size: 1rem;
    line-height: 1.5;
}

.modal-footer {
    padding: 15px 20px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}
/* Success Modal Specifics */
#success-modal .modal-body {
    text-align: center;
}

#success-modal .student-data-summary {
    background-color: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    text-align: left;
    border: 1px solid var(--border-color);
}

#success-modal .student-data-summary p {
    margin-bottom: 5px;
    font-size: 0.95rem;
}

#success-modal .student-data-summary strong {
    color: var(--primary-color);
}
