/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --light-bg: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Noto Naskh Arabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--light-bg);
    cursor: default; /* ensures @click.outside works on iOS Safari */
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0 1.5rem;
    width: 100%;
}

/* Header */
.header {
    background: white;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    /* position: sticky also serves as containing block for the absolute dropdown */
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-right: 2rem;
}

.nav-wrapper {
    display: flex;
    align-items: center;
    flex: 1;
}

.nav-hamburger {
    display: none;
}

.main-nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1.5rem;
    flex: 1;
}

/* Logout link inside nav — desktop: hidden, mobile: shown in dropdown */
.nav-logout-mobile {
    display: none;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 0.5rem 0;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem 0;
}

.breadcrumb {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.breadcrumb a {
    color: var(--primary-color);
    text-decoration: none;
}

/* Flash Messages */
.flash-messages {
    margin-bottom: 1.5rem;
}

.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    border-left: 4px solid;
}

.alert-success {
    background-color: #d1fae5;
    border-color: var(--success-color);
    color: #065f46;
}

.alert-error {
    background-color: #fee2e2;
    border-color: var(--danger-color);
    color: #991b1b;
}

.alert-warning {
    background-color: #fef3c7;
    border-color: var(--warning-color);
    color: #92400e;
}

.alert-info {
    background-color: #dbeafe;
    border-color: var(--primary-color);
    color: #1e40af;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #475569;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

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

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Cards */
.card {
    background: white;
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.625rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 0.5rem;
    overflow: hidden;
}

thead {
    background-color: var(--light-bg);
}

th,
td {
    padding: 0.875rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

tbody tr:hover {
    background-color: var(--light-bg);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.25rem;
}

.badge-high {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-medium {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-low {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-primary {
    background-color: #dbeafe;
    color: #1e40af;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.pagination button {
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
    background-color: var(--light-bg);
}

.pagination button.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Footer */
.footer {
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 1.5rem 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Utilities */
.text-center {
    text-align: center;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

/* Loading Spinner */
.spinner {
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 768px) {
    /* Keep header as a single row — title | hamburger | user-info */
    .header-content {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    /* Wrapper shrinks to fit only the hamburger button */
    .nav-wrapper {
        flex: 0;
    }

    /* Show the hamburger button */
    .nav-hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1.25rem;
        background: transparent;
        border: none;
        cursor: pointer;
        color: var(--text-secondary);
        padding: 0;
        line-height: 1;
    }

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

    /* Nav hidden by default on mobile */
    .main-nav {
        display: none;
    }

    /* Dropdown: full-width, anchored to sticky header */
    .main-nav.nav-open {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: white;
        border-bottom: 1px solid var(--border-color);
        box-shadow: var(--shadow);
        padding: 1rem 1.5rem;
        z-index: 99;
    }

    /* Hide username text and logout button from header on mobile */
    .username-desktop,
    .logout-desktop {
        display: none;
    }

    /* Show logout inside the nav dropdown on mobile */
    .nav-logout-mobile {
        display: block;
        border-top: 1px solid var(--border-color);
        padding-top: 0.75rem;
        margin-top: 0.25rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .table-container {
        margin: 0 -1rem;
    }
}
