:root {
    --blue: #1e5fa8;
    --blue-dark: #164680;
    --bg: #f4f6f9;
    --border: #dde3ea;
    --text: #2b2f36;
    --text-light: #6b7280;
    --danger: #d64545;
    --danger-dark: #b53737;
    --success: #1f9d55;
    --success-dark: #187a41;
    --white: #ffffff;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Sahel", Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    direction: rtl;
}

a {
    color: inherit;
}

/* form controls don't inherit the page font automatically in all browsers,
   so Sahel has to be re-applied to them explicitly */
input,
textarea,
select,
button {
    font-family: inherit;
}

/* hides the page until the session check confirms the user is logged in,
   so an unauthenticated visit never flashes real content before redirecting to login */
body.pending-auth {
    visibility: hidden;
}

/* ---------- Simple page backgrounds ---------- */
/* very light dotted pattern behind the login page */
body.bg-login {
    background-color: var(--bg);
    background-image: radial-gradient(circle, rgba(30, 95, 168, 0.08) 1px, transparent 1px);
    background-size: 22px 22px;
}

/* very light diagonal pattern behind the main app page */
body.bg-app {
    background-color: var(--bg);
    background-image: repeating-linear-gradient( 135deg, rgba(30, 95, 168, 0.035) 0px, rgba(30, 95, 168, 0.035) 1px, transparent 1px, transparent 14px );
}

/* ---------- Login page ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
}

    /* simple soft shapes behind the login card */
    .login-wrap::before,
    .login-wrap::after {
        content: "";
        position: absolute;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(30, 95, 168, 0.16), rgba(30, 95, 168, 0) 70%);
        z-index: 0;
    }

    .login-wrap::before {
        width: 480px;
        height: 480px;
        top: -160px;
        right: -140px;
    }

    .login-wrap::after {
        width: 380px;
        height: 380px;
        bottom: -140px;
        left: -120px;
        background: radial-gradient(circle, rgba(30, 95, 168, 0.1), rgba(30, 95, 168, 0) 70%);
    }

.login-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 40px 36px;
    width: 360px;
    max-width: 100%;
    text-align: center;
    box-shadow: 0 4px 18px rgba(20, 30, 45, 0.08);
    position: relative;
    z-index: 1;
}

    .login-card img.logo {
        display: block;
        width: 196px;
        height: 196px;
        object-fit: contain;
        margin: 0 auto 12px;
    }

    .login-card h1 {
        font-size: 17px;
        line-height: 1.5;
        margin: 0 0 24px;
        color: var(--blue-dark);
    }

.field {
    text-align: right;
    margin-bottom: 14px;
}

    .field label {
        display: block;
        font-size: 13px;
        color: var(--text-light);
        margin-bottom: 6px;
    }

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--white);
    color: var(--text);
}

input:read-only, input[disabled] {
    background: #f0f2f5;
    color: var(--text-light);
}

textarea {
    resize: vertical;
    min-height: 70px;
}

.btn {
    display: inline-block;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
}

.btn-primary {
    background: var(--blue);
    color: #fff;
}

    .btn-primary:hover {
        background: var(--blue-dark);
    }

.btn-danger {
    background: var(--danger);
    color: #fff;
}

    .btn-danger:hover {
        background: var(--danger-dark);
    }

.btn-success {
    background: var(--success);
    color: #fff;
}

    .btn-success:hover {
        background: var(--success-dark);
    }

.btn-outline {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
}

    .btn-outline:hover {
        background: #f0f2f5;
    }

.btn-block {
    width: 100%;
}

.error-msg {
    color: var(--danger);
    font-size: 13px;
    margin-top: 10px;
    min-height: 16px;
}

/* ---------- Top bar ---------- */
.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 10px 24px;
    min-height: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

    .topbar .logout-btn {
        flex-shrink: 0;
        background: transparent;
        border: 1px solid var(--danger);
        color: var(--danger);
        border-radius: var(--radius);
        padding: 8px 16px;
        cursor: pointer;
        font-family: inherit;
        font-size: 13px;
        white-space: nowrap;
    }

        .topbar .logout-btn:hover {
            background: #fdeeee;
        }

    .topbar .search-box {
        flex: 1;
        min-width: 0;
        max-width: 420px;
        margin: 0 auto;
    }

    .topbar img.logo {
        flex-shrink: 0;
        width: 56px;
        height: 56px;
        object-fit: contain;
    }

/* ---------- Page content ---------- */
.page {
    max-width: 1100px;
    margin: 24px auto;
    padding: 0 20px;
}

.page-header {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 16px;
}

/* ---------- Table ---------- */
.table-wrap {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    background: #f0f4f9;
    color: var(--text-light);
    font-weight: 600;
    text-align: right;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: #fafbfd;
}

.actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.icon-btn {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}

    .icon-btn:hover {
        background: #f0f2f5;
    }

    .icon-btn.danger {
        border-color: var(--danger);
        color: var(--danger);
    }

        .icon-btn.danger:hover {
            background: #fdeeee;
        }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 18px;
    flex-wrap: wrap;
}

    .pagination button {
        border: 1px solid var(--border);
        background: #fff;
        border-radius: 6px;
        min-width: 34px;
        height: 34px;
        cursor: pointer;
        font-family: inherit;
    }

        .pagination button.active {
            background: var(--blue);
            color: #fff;
            border-color: var(--blue);
        }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20,25,35,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

    .modal-overlay.hidden {
        display: none;
    }

.modal-box {
    background: #fff;
    border-radius: var(--radius);
    width: 420px;
    max-width: 92vw;
    max-height: 88vh;
    overflow-y: auto;
    padding: 24px;
}

    .modal-box.small {
        width: 360px;
        text-align: center;
    }

.modal-title {
    font-size: 16px;
    margin: 0 0 18px;
    color: var(--blue-dark);
    text-align: right;
}

.modal-box.small .modal-title {
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 18px;
}

.modal-box.small .modal-actions {
    justify-content: center;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.details-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

    .details-row:last-child {
        border-bottom: none;
    }

    .details-row .label {
        color: var(--text-light);
    }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-light);
    cursor: pointer;
}

    .checkbox-label input[type="checkbox"] {
        width: auto;
        cursor: pointer;
    }

.remember-field {
    margin-bottom: 18px;
}
