/* ===== 1. VARIABLES + RESET ===== */
:root { /* Colors and design tokens. This section defines the primary color palette and other design tokens used throughout the application. */
    --primary:      #7c3aed;
    --primary-dark: #5b21b6; /* Darker shade of primary, used for gradients and hover states */
    --accent:       #a78bfa;
    --danger:       #ef4444;
    --success:      #10b981;
    --warning:      #f59e0b;
    --bg:           #f5f3ff;
    --sidebar-bg:   #1e1b4b;
    --card-bg:      #ffffff;
    --text:         #1e1b4b;
    --text-light:   #6b7280;
    --border:       #e5e7eb;
    --shadow:       0 4px 6px -1px rgba(0,0,0,0.1); /* Subtle shadow for cards and modals */
    --radius:       12px; /* Border radius for cards and buttons */
    --radius-sm:    8px;  /* Smaller border radius for compact elements like nav links */
    --sidebar-w:    240px; /* Fixed width of the sidebar */
    --transition:   all 0.2s ease; /* Smooth transitions for interactive elements */
}

* { /* Resetting default styles for all elements to ensure consistency across browsers. This includes removing default margins and paddings, and setting box-sizing to border-box for easier layout management. */
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body { /* Base styles for the body element. This sets the font family, background color, text color, and minimum height to ensure the layout covers the entire viewport. */
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text); /* Default text color for the application. */
    min-height: 100vh; /* Ensures the body takes up the full height of the viewport. */
}

a { text-decoration: none; color: inherit; } /* Styles for anchor tags to remove default underlines and inherit text color from the parent element. This means links will blend seamlessly with surrounding text. */


/* ===== 2. LAYOUT ===== */
.sidebar {
    position: fixed; /* The sidebar is fixed to the left side of the viewport, allowing it to remain visible as users scroll through the main content. */
    top: 0; left: 0; /* Positioning the sidebar at the top-left corner of the viewport. */
    width: var(--sidebar-w); /* The width of the sidebar is defined by a CSS variable, allowing for easy adjustments across the application. */
    height: 100vh; /* The sidebar takes up the full height of the viewport. */
    background: var(--sidebar-bg); /* The background color of the sidebar is defined by a CSS variable, providing a consistent look and feel. */
    color: #fff; /* The text color within the sidebar is set to white for better contrast against the dark background. */
    display: flex; /* The sidebar uses Flexbox for layout, allowing for easy alignment and spacing of its child elements. */
    flex-direction: column; /* The child elements of the sidebar are arranged in a column, stacking vertically. */
    padding: 2rem 1.25rem; /* Padding inside the sidebar to create space around the content. */
    z-index: 100; /* Ensures the sidebar appears above other content. */
    box-shadow: 4px 0 20px rgba(0,0,0,0.15); /* Adds a subtle shadow to the sidebar for depth. */
}

.main-content {
    margin-left: var(--sidebar-w); /* Ensures the main content is positioned to the right of the sidebar. */
    min-height: 100vh; /* Ensures the main content takes up the full height of the viewport. */
    padding: 2.5rem 2rem; /* Adds padding around the main content for spacing. */
}


/* ===== 3. SIDEBAR ===== */
.sidebar-logo {
    font-size: 1.6rem; /* The font size for the logo in the sidebar is set to 1.6rem, making it larger than regular text for emphasis. */
    font-weight: 800; /* The font weight for the logo is set to 800, making it bold and prominent. */
    margin-bottom: 2.5rem; /* Adds space below the logo to separate it from the navigation links. */
    padding-bottom: 1.5rem; /* Adds padding below the logo for visual balance. */
    border-bottom: 1px solid rgba(255,255,255,0.1); /* Adds a subtle border below the logo for separation. */
    background: linear-gradient(135deg, #a78bfa, #f9a8d4); /* Applies a gradient background to the logo text. */
    -webkit-background-clip: text; /* Clips the background to the text for the gradient effect. */
    -webkit-text-fill-color: transparent; /* Makes the text fill color transparent to show the gradient. */
    background-clip: text; /* Clips the background to the text for the gradient effect. */
}

.sidebar nav { /* Styles for the navigation section within the sidebar. This section contains the links for navigating through different parts of the admin panel. */
    display: flex; /* The navigation uses Flexbox for layout, allowing for easy alignment and spacing of the links. */
    flex-direction: column; /* The navigation links are arranged in a column, stacking vertically. */
    gap: 0.4rem; /* Adds space between each navigation link for better readability. */
    flex: 1; /* Allows the navigation section to grow and fill available space within the sidebar. */
}

.sidebar nav a { /* Styles for the individual navigation links within the sidebar. This includes padding, color, font size, and transition effects for interactivity. */
    color: rgba(255,255,255,0.7); /* Sets the text color for the navigation links with some transparency for a subtle effect. */
    padding: 0.75rem 1rem; /* Adds padding inside the navigation links for better clickability and spacing. */
    border-radius: var(--radius-sm); /* Rounds the corners of the navigation links for a softer look. */
    font-size: 0.95rem; /* Sets the font size for the navigation links. */
    font-weight: 500; /* Sets the font weight for the navigation links. */
    transition: var(--transition); /* Applies a transition effect for smooth interactions. */
}

.sidebar nav a:hover, /* Styles for the navigation links when hovered over or when they are active. This includes changes to background color, text color, and a slight movement to indicate interactivity. */
.sidebar nav a.active { /* The .active class is applied to the currently active navigation link, providing visual feedback to users about their current location within the admin panel. */
    background: rgba(167,139,250,0.2); /* Sets the background color on hover or when active. */
    color: #ffffff; /* Sets the text color on hover or when active. */
    transform: translateX(4px); /* Moves the link slightly to the right on hover or when active. */
}

.sidebar .logout { /* Styles for the logout button in the sidebar. This button is designed to stand out with a distinct color and is positioned at the bottom of the sidebar for easy access. */
    color: rgba(255,255,255,0.5); /* Sets the text color for the logout button with some transparency for a subtle effect. */
    font-size: 0.9rem; /* Sets the font size for the logout button. */
    padding: 0.75rem 1rem; /* Adds padding inside the logout button for better clickability and spacing. */
    border-radius: var(--radius-sm); /* Rounds the corners of the logout button for a softer look. */
    transition: var(--transition); /* Applies a transition effect for smooth interactions. */
    border: 1px solid rgba(255,255,255,0.1); /* Adds a subtle border around the logout button. */
    text-align: center; /* Centers the text within the logout button. */
    margin-top: auto; /* Pushes the logout button to the bottom of the sidebar. */
}

.sidebar .logout:hover {
    background: rgba(239,68,68,0.2);
    color: #fca5a5;
    border-color: rgba(239,68,68,0.3);
}


/* ===== 4. AUTH WRAPPER ===== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, #4c1d95 50%, #7c3aed 100%);
    padding: 1.5rem;
}

.auth-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}

.auth-card h2 {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 0.4rem;
}

.auth-card .auth-subtitle {
    color: var(--text-light);
    font-size: 0.95rem;
    margin-bottom: 2rem;
}

.auth-card .auth-logo {
    font-size: 1.4rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1.5rem;
    display: block;
}

.auth-link {
    display: block;
    text-align: center;
    margin-top: 1.25rem;
    color: var(--text-light);
    font-size: 0.9rem;
}

.auth-link a { color: var(--primary); font-weight: 600; }
.auth-link a:hover { text-decoration: underline; }


/* ===== 5. BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    white-space: nowrap;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(124,58,237,0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(124,58,237,0.4);
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text);
    border: 1.5px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg);
    border-color: var(--accent);
    color: var(--primary);
}

.btn-danger {
    background: #fef2f2;
    color: var(--danger);
    border: 1.5px solid #fecaca;
}

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

.btn-success {
    background: #ecfdf5;
    color: var(--success);
    border: 1.5px solid #a7f3d0;
}

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

.btn-warning {
    background: #fffbeb;
    color: #92400e;
    border: 1.5px solid #fde68a;
}

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

/* Browser default override for input[type=submit] */
input[type="submit"].btn-primary  { color: white; }
input[type="submit"].btn-secondary { color: var(--text); }
input[type="submit"].btn-danger    { color: var(--danger); }
input[type="submit"].btn-success   { color: var(--success); }
input[type="submit"].btn-warning   { color: #92400e; }

.btn-full { width: 100%; }
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8rem; }


/* ===== 6. FORMS ===== */
.form-group { margin-bottom: 1.25rem; }

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.form-control {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    color: var(--text);
    background: var(--card-bg);
    transition: var(--transition);
    outline: none;
    font-family: inherit;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(167,139,250,0.2);
}

.form-control:hover { border-color: var(--accent); }

.form-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.3rem;
    display: block;
}

.form-page { max-width: 860px; margin: 0 auto; }
.form-page h2 { font-size: 1.75rem; font-weight: 800; margin-bottom: 2rem; }

.form-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.form-section h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--bg);
}

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


/* ===== 7. ALERTS ===== */
.alert {
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-success  { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-danger   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-warning  { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info     { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }


/* ===== 8. DASHBOARD ===== */
.dashboard-page { max-width: 960px; margin: 0 auto; }

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.dashboard-header h2 { font-size: 1.75rem; font-weight: 800; margin: 0; }

.dashboard-section { margin-bottom: 2rem; }
.dashboard-section h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }

.page-header { margin-bottom: 2rem; }
.page-header h2 { font-size: 1.75rem; font-weight: 800; }
.page-header p  { color: var(--text-light); margin-top: 0.25rem; }

.quick-actions { display: flex; gap: 1rem; margin-bottom: 2rem; flex-wrap: wrap; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-card .stat-label { font-size: 0.85rem; color: var(--text-light); margin-top: 0.4rem; }

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; }
.card-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; flex-wrap: wrap; }


/* ===== 9. RESULTS PAGE ===== */
.results-page { max-width: 860px; margin: 0 auto; }
.results-page h2 { font-size: 1.75rem; font-weight: 800; margin-bottom: 2rem; }

.result-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.75rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.result-card h3 {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.result-positive {
    border-left: 4px solid var(--danger);
    background: linear-gradient(135deg, #fff5f5, #ffffff);
}

.result-negative {
    border-left: 4px solid var(--success);
    background: linear-gradient(135deg, #f0fdf4, #ffffff);
}

.result-label { font-size: 1.25rem !important; font-weight: 700 !important; }
.result-label.positive { color: var(--danger); }
.result-label.negative { color: var(--success); }

.result-actions { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

.recommendations h3 {
    font-size: 1.1rem !important;
    font-weight: 700 !important;
    color: var(--text) !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    margin-bottom: 1.5rem;
}

.rec-section {
    padding: 1.25rem;
    border-radius: var(--radius-sm);
    background: var(--bg);
    margin-bottom: 1rem;
    border-left: 3px solid var(--accent);
}

.rec-section.severity {
    border-left-color: var(--primary);
    background: linear-gradient(135deg, #f5f3ff, #faf5ff);
}

.rec-section.info { border-left-color: var(--text-light); background: #f9fafb; }

.rec-section h4 { font-size: 0.9rem; font-weight: 700; color: var(--primary); margin-bottom: 0.6rem; }
.rec-section p  { font-size: 0.875rem; color: #4b5563; line-height: 1.7; }

#riskChart { display: block; margin: 1rem auto 0; max-width: 200px; max-height: 200px; }


/* ===== 10. HISTORY TABLE ===== */
.history-page { max-width: 960px; margin: 0 auto; }
.history-page h2 { font-size: 1.75rem; font-weight: 800; margin-bottom: 2rem; }

.table-wrapper {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg); border-bottom: 2px solid var(--border); }

thead th {
    padding: 1rem 1.25rem;
    text-align: left;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody tr { border-bottom: 1px solid var(--border); transition: var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tbody td { padding: 1rem 1.25rem; font-size: 0.9rem; }

.badge { display: inline-block; padding: 0.25rem 0.7rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-positive { background: #fee2e2; color: #991b1b; }
.badge-negative { background: #dcfce7; color: #166534; }


/* ===== 11. PROFILE & ADMIN ===== */
.profile-page { max-width: 520px; margin: 0 auto; }
.profile-page h2 { font-size: 1.75rem; font-weight: 800; margin-bottom: 2rem; }

.admin-page { max-width: 1000px; margin: 0 auto; }
.admin-page h2 { font-size: 1.75rem; font-weight: 800; margin-bottom: 0.4rem; }

.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-light);
    margin: 2rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}

.empty-state { text-align: center; padding: 3rem; color: var(--text-light); }


/* ===== 12. RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        align-items: center;
        padding: 1rem 1.25rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .sidebar-logo { margin-bottom: 0; padding-bottom: 0; border-bottom: none; font-size: 1.2rem; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; flex: none; gap: 0.25rem; }
    .sidebar nav a { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
    .sidebar nav a:hover { transform: none; }
    .sidebar .logout { margin-top: 0; padding: 0.4rem 0.85rem; font-size: 0.85rem; }

    .main-content { margin-left: 0; padding: 1.25rem 1rem; }
    .form-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .result-actions { flex-direction: column; }
}

@media (max-width: 480px) {
    .auth-card { padding: 1.75rem 1.25rem; }
    .stats-grid { grid-template-columns: 1fr; }
    thead th:nth-child(n+4), tbody td:nth-child(n+4) { display: none; }
}