/* Import Vazirmatn font from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');

/* --- General Reset & Variables --- */
:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --secondary-color: #6c757d;
    --secondary-hover: #5a6268;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --font-family: 'Vazirmatn', sans-serif;
    --background-color: #f4f7f9;
    --card-background: #ffffff;
    --border-color: #dee2e6;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
    --border-radius: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    direction: rtl;
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--dark-color);
    line-height: 1.6;
    font-size: 16px;
}

/* --- Container & Layout --- */
.container {
    max-width: 900px;
    margin: 30px auto;
    padding: 0 20px;
}

.card {
    background-color: var(--card-background);
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
}

/* --- Header --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.header h1 {
    color: var(--dark-color);
    font-weight: 700;
    font-size: 1.75rem;
}

.header a {
    text-decoration: none;
    background-color: var(--danger-color);
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    font-weight: 500;
    transition: background-color 0.2s;
}

.header a:hover {
    background-color: #c82333;
}

/* --- Forms & Inputs --- */
form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-family: var(--font-family);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

button,
a.button-like {
    padding: 12px 20px;
    border: none;
    background-color: var(--primary-color);
    color: white;
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-family);
    border-radius: 5px;
    cursor: pointer;
    align-self: flex-start;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

button:hover,
a.button-like:hover {
    background-color: var(--primary-hover);
}

.form-horizontal {
    flex-direction: row;
    align-items: flex-end;
}

.form-horizontal .form-group {
    flex-grow: 1;
}

.search-form {
    flex-direction: row;
    align-items: center;
}

.search-form input {
    flex-grow: 1;
}

/* --- Buttons --- */
.button-secondary {
    background-color: transparent;
    border: 1px solid var(--secondary-color);
    color: var(--secondary-color);
}

.button-secondary:hover {
    background-color: var(--secondary-color);
    color: white;
}

.button-edit {
    background-color: var(--warning-color);
    color: #212529;
    padding: 8px 12px;
    font-size: 14px;
    text-decoration: none;
    border-radius: 5px;
}

.button-edit:hover {
    background-color: #e0a800;
}

.button-edit-small {
    background-color: var(--success-color);
    padding: 5px 10px;
    font-size: 13px;
    color: white;
    text-decoration: none;
    border-radius: 4px;
}

.button-edit-small:hover {
    background-color: #218838;
}

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

th,
td {
    padding: 12px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

thead th {
    background-color: var(--light-color);
    font-weight: 700;
    color: var(--secondary-color);
    text-transform: uppercase;
    font-size: 12px;
}

tbody tr:hover {
    background-color: #fafdff;
}

/* --- Messages & Notifications --- */
.message {
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 25px;
    text-align: center;
    font-weight: 500;
    border: 1px solid transparent;
}

.message.success {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}

.message.error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

.info {
    color: var(--secondary-color);
    text-align: center;
    padding: 15px;
}

/* --- Specific Sections --- */
.search-results-list {
    list-style: none;
    padding: 0;
}

.search-results-list li {
    padding: 12px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
}

.search-results-list li:last-child {
    border-bottom: none;
}

.search-results-list li:hover {
    background-color: var(--light-color);
}

.search-results-list a {
    text-decoration: none;
    color: var(--primary-color);
    font-weight: 500;
}

.search-results-list span {
    color: var(--secondary-color);
    font-size: 14px;
    margin-right: 10px;
}

.student-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.student-details-header h3 {
    margin: 0;
}

.student-details-card h4 {
    font-weight: 500;
    color: var(--secondary-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

/* ==================================================
   ================= RESPONSIVE STYLES ================
   ================================================== */

@media screen and (max-width: 768px) {
    .container {
        margin: 20px auto;
        padding: 0 15px;
    }

    .card {
        padding: 20px;
    }

    /* Adjust header for smaller screens */
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    /* Make forms stack vertically */
    .form-horizontal {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form {
        flex-direction: column;
        align-items: stretch;
    }

    /* Make buttons full-width for easier tapping */
    button,
    a.button-like {
        width: 100%;
    }

    /* --- Responsive Table --- */
    /* Hide table headers */
    table thead {
        display: none;
    }

    /* Make table elements behave like blocks */
    table,
    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    /* Style each row like a card */
    tr {
        margin-bottom: 15px;
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius);
        padding: 10px;
    }

    tr:last-child {
        margin-bottom: 0;
    }

    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
        /* Align value to the left */
        border-bottom: 1px solid #f0f0f0;
        padding: 10px 5px;
    }

    td:last-child {
        border-bottom: none;
    }

    /* Add labels before the data */
    td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--dark-color);
        padding-left: 10px;
        /* For RTL, padding-left is correct */
        text-align: right;
    }

    .student-details-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}