/* General Styles */
html {
    height: 100%; /* Important: Ensures HTML takes full viewport height */
}

body {
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; /* More modern font */
    margin: 0;
    padding: 0;
    background-color: #f0f2f5; /* Softer background color */
    color: #333;
    min-height: 100vh; /* Ensures body is at least viewport height */
    display: flex; /* Uses flexbox for main layout */
    flex-direction: column; /* Stacks elements vertically */
}

.container {
    max-width: 1200px; /* Max width for main content */
    width: 90%; /* Container takes 90% of viewport width, more responsive */
    margin: 20px auto; /* Centers container horizontally with top/bottom margin */
    background-color: #fff;
    padding: 30px; /* Slightly more padding for breathing room */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); /* Softer shadow */
    border-radius: 12px; /* Slightly larger border-radius */
    box-sizing: border-box;
    flex-grow: 1; /* Allows container to grow to fill available vertical space in body */
    display: flex; /* Uses flexbox inside container too */
    flex-direction: column; /* Stacks elements inside container vertically */
}

h1, h2 {
    text-align: center;
    color: #2c3e50; /* Darker heading color */
    margin-bottom: 25px; /* Larger bottom margin */
    font-weight: 600; /* Heading font weight */
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px; /* Slightly adjusted margin */
    font-weight: 500; /* Label font weight */
    color: #555; /* Label text color */
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="date"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: calc(100% - 24px); /* 100% - (left padding + right padding) */
    padding: 12px; /* Slightly more padding */
    border: 1px solid #ddd;
    border-radius: 8px; /* Larger border-radius */
    box-sizing: border-box;
    font-size: 1rem; /* Consistent font size */
    transition: border-color 0.2s ease, box-shadow 0.2s ease; /* Focus transition */
}

.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group input[type="date"]:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: #007bff; /* Border color on focus */
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25); /* Shadow on focus */
    outline: none; /* Removes default outline */
}

.form-group textarea {
    resize: vertical;
}

.form-group button {
    background-color: #007bff;
    color: white;
    padding: 12px 25px; /* Better padding */
    border: none;
    border-radius: 8px; /* Larger border-radius */
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background-color 0.2s ease, transform 0.1s ease; /* Hover/active transition */
}

.form-group button:hover {
    background-color: #0056b3;
    transform: translateY(-1px); /* Slight lift on hover */
}

.form-group button:active {
    transform: translateY(0); /* Returns to normal on press */
}

.message {
    padding: 12px;
    margin-bottom: 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.message.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Admin Specific Styles */
.admin-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap; /* Allows wrapping on toolbar items */
    gap: 15px; /* Spacing between toolbar items */
}

.print-button {
    background-color: #28a745;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.print-button:hover {
    background-color: #218838;
    transform: translateY(-1px);
}

.filter-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-form label {
    font-weight: 500;
    color: #555;
    white-space: nowrap;
}

.filter-form select, .filter-form button {
    padding: 9px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-form select {
    background-color: #f9f9f9;
}

.filter-form select:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
    outline: none;
}

.filter-form button {
    background-color: #007bff;
    color: white;
    font-weight: 500;
}

.filter-form button:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}

/* Table wrapper for horizontal scroll */
.table-responsive-horizontal {
    width: 100%;
    overflow-x: auto; /* Enables horizontal scroll if table is too wide */
    margin-bottom: 20px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

table {
    width: 100%;
    border-collapse: collapse; /* Crucial: This collapses borders between cells */
    white-space: nowrap; /* Prevents cell content from wrapping by default */
}

table thead {
    position: sticky;
    top: 0;
    background-color: #2c3e50;
    color: white;
    z-index: 1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Main Change Here: Apply border to all th and td elements */
th, td {
    padding: 15px 20px;
    text-align: left;
    border: 1px solid #ddd; /* This adds a border to every cell */
}

th {
    font-weight: 600;
    font-size: 0.95rem;
    text-transform: uppercase;
}

table tbody tr:hover {
    background-color: #f5f5f5;
}

/* Remove specific border overrides if they were preventing full borders */
/*
table th:first-child,
table td:first-child {
    border-left: 1px solid #ddd;
}

table th:last-child,
table td:last-child {
    border-right: 1px solid #ddd;
}
*/

/* Column Width Optimization for Desktop */
table th:nth-child(1), /* ID */
table td:nth-child(1) {
    width: 50px;
    min-width: 50px;
}
table th:nth-child(2), /* Nama Lengkap */
table td:nth-child(2) {
    width: 200px;
    min-width: 180px;
}
table th:nth-child(3), /* NISN */
table td:nth-child(3) {
    width: 120px;
    min-width: 110px;
}
table th:nth-child(4), /* Jurusan */
table td:nth-child(4) {
    width: 200px;
    min-width: 180px;
}
table th:nth-child(5), /* Tempat/Tanggal Lahir */
table td:nth-child(5) {
    width: 180px;
    min-width: 160px;
}
table th:nth-child(6), /* Jenis Kelamin */
table td:nth-child(6) {
    width: 100px;
    min-width: 90px;
}
table th:nth-child(7), /* Email */
table td:nth-child(7) {
    width: 180px;
    min-width: 160px;
    white-space: normal;
    word-break: break-word;
}
table th:nth-child(8), /* Telepon */
table td:nth-child(8) {
    width: 120px;
    min-width: 110px;
}
table th:nth-child(9), /* Berkas */
table td:nth-child(9) {
    width: 150px;
    min-width: 130px;
    white-space: normal;
}
table th:nth-child(10), /* Tanggal Daftar */
table td:nth-child(10) {
    width: 120px;
    min-width: 110px;
}
table th:nth-child(11), /* Aksi */
table td:nth-child(11) {
    width: 200px;
    min-width: 180px;
    text-align: center;
}


.actions a {
    text-decoration: none;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 5px;
    margin: 0 3px;
    transition: background-color 0.2s ease;
    display: inline-block;
}

.actions a.view-link {
    color: #007bff;
    background-color: #e6f2ff;
}
.actions a.view-link:hover {
    background-color: #cce0ff;
}

.actions a.edit-link {
    color: #ffc107;
    background-color: #fff8e6;
}
.actions a.edit-link:hover {
    background-color: #ffe082;
}

.actions a.delete-link {
    color: #dc3545;
    background-color: #ffe6e6;
}
.actions a.delete-link:hover {
    background-color: #ffcccc;
}

.print-button {
    background-color: #28a745;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.print-button:hover {
    background-color: #218838;
    transform: translateY(-1px);
}

.filter-form {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.filter-form label {
    font-weight: 500;
    color: #555;
    margin-right: 0;
    white-space: nowrap;
}
.filter-form select, .filter-form button {
    padding: 9px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    margin-left: 0;
    transition: all 0.2s ease;
}
.filter-form button {
    background-color: #007bff;
    color: white;
    font-weight: 500;
}
.filter-form button:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}
.filter-form button:nth-of-type(2) {
    background-color: #6c757d;
}
.filter-form button:nth-of-type(2):hover {
    background-color: #5a6268;
}

/* No data message */
.no-data-message {
    text-align: center;
    padding: 30px;
    font-style: italic;
    color: #777;
}

/* Logout link */
.logout-link {
    text-align: center;
    margin-top: 30px;
    font-size: 1rem;
}
.logout-link a {
    color: #007bff;
    text-decoration: none;
    font-weight: 500;
}
.logout-link a:hover {
    text-decoration: underline;
}

/* Detail toggle button (for mobile) */
.detail-toggle {
    /* DEFAULT STATE: Hidden on desktop */
    display: none;
}

/* --- Media Queries for Responsiveness --- */

/* For small screens (e.g., phones) */
@media screen and (max-width: 768px) {
    .container {
        width: 100%;
        margin: 0;
        padding: 15px;
        border-radius: 0;
        box-shadow: none;
    }

    h1 {
        font-size: 22px;
        margin-bottom: 20px;
    }

    .admin-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .print-button {
        width: 100%;
        text-align: center;
    }

    .filter-form {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .filter-form select, .filter-form button {
        width: 100%;
        margin-left: 0;
    }

    /* Hide traditional table headers */
    table thead {
        display: none;
    }

    /* Change table rows to block elements (card-like) */
    table, table tbody, table tr, table td {
        display: block;
        width: 100%;
    }

    /* Card-like styling for each row (tr) */
    table tr {
        margin-bottom: 20px;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        padding: 15px;
        background-color: #fff;
        position: relative;
    }

    table tbody tr:hover {
        background-color: #fff;
    }

    /* Styling for individual cells (td) in mobile */
    table td {
        border: none; /* Keep this 'none' for card view on mobile */
        padding: 8px 0;
        position: relative;
        padding-left: 120px;
        font-size: 0.9rem;
    }

    table td:before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 110px;
        padding-right: 10px;
        white-space: nowrap;
        text-align: right;
        font-weight: bold;
        color: #555;
    }

    /* Hide longer columns by default in card view */
    table td[data-label="ID"],
    table td[data-label="NISN"],
    table td[data-label="Tempat/Tanggal Lahir"],
    table td[data-label="Jenis Kelamin"],
    table td[data-label="Email"],
    table td[data-label="Telepon"],
    table td[data-label="Berkas"],
    table td[data-label="Tanggal Daftar"] {
        display: none;
    }

    /* Always show key identification info */
    table td[data-label="Nama Lengkap"],
    table td[data-label="Jurusan"],
    table td[data-label="Aksi"] {
        display: block;
        padding-left: 0;
        text-align: left;
        padding-bottom: 5px;
        border-bottom: 1px dashed #eee;
        font-size: 1rem;
        font-weight: 600;
        color: #2c3e50;
    }
    table td[data-label="Jurusan"] {
        font-weight: 500;
        color: #666;
        font-size: 0.9rem;
    }

    /* Actions in card view */
    .actions {
        text-align: center;
        padding-left: 0;
        border-top: 1px dashed #eee;
        margin-top: 10px;
        padding-top: 10px;
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }
    .actions a {
        flex: 1 1 auto;
        max-width: 100px;
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    /* Detail toggle button (show only on mobile) */
    .detail-toggle {
        display: flex;
        position: absolute;
        top: 10px;
        right: 10px;
        background: #f0f2f5;
        border: 1px solid #ccc;
        border-radius: 50%;
        width: 30px;
        height: 30px;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 1.2rem;
        font-weight: bold;
        color: #555;
        transition: background-color 0.2s ease, transform 0.2s ease;
        z-index: 10;
    }
    .detail-toggle:hover {
        background-color: #e0e2e5;
        transform: rotate(90deg);
    }
    table tr.expanded .detail-toggle {
        transform: rotate(45deg);
    }

    /* Show hidden columns when row is expanded */
    table tr.expanded td[data-label="ID"],
    table tr.expanded td[data-label="NISN"],
    table tr.expanded td[data-label="Tempat/Tanggal Lahir"],
    table tr.expanded td[data-label="Jenis Kelamin"],
    table tr.expanded td[data-label="Email"],
    table tr.expanded td[data-label="Telepon"],
    table tr.expanded td[data-label="Berkas"],
    table tr.expanded td[data-label="Tanggal Daftar"] {
        display: block;
    }
}

/* Adjustments for very small screens */
@media screen and (max-width: 480px) {
    .container {
        padding: 10px;
    }
    table td {
        padding-left: 100px;
    }
    table td:before {
        width: 90px;
    }
    .actions a {
        padding: 6px 8px;
        font-size: 0.8rem;
    }
}

/* Print Styles */
@media print {
    .print-button, .actions, .filter-form, .detail-toggle {
        display: none !important;
    }
    .container {
        box-shadow: none !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: none !important;
    }
    .table-responsive-horizontal {
        overflow-x: visible !important;
        border: none !important;
        box-shadow: none !important;
    }
    table {
        white-space: normal !important;
        min-width: unset !important;
    }
    table thead {
        position: static !important;
        box-shadow: none !important;
    }
    table th, table td {
        border: 1px solid #000 !important; /* Ensure borders are visible when printing */
        padding: 8px 10px !important;
    }
    table td[data-label]:before {
        content: none !important;
    }
    table tr, table td {
        display: table-row !important;
        width: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background-color: transparent !important;
    }
    table td {
        padding-left: 10px !important;
    }
    .actions {
        display: none !important;
    }
    .document-preview img {
        max-width: 100% !important;
        height: auto !important;
    }
}
