/**
 * @file main.css
 * @description Main stylesheet for the AHR Secure Portal.
 * @version 2.0 - Refactored for improved consistency and maintainability.
 *
 * This stylesheet governs the primary user interface, including the login
 * screen and the main application dashboard. It is built with a theming system
 * using CSS variables to support both light and dark modes.
 */

/* ==========================================================================
   1. Setup & Globals
   ========================================================================== */

/* --- Google Font Import --- */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');

/* --- CSS Variables for Theming --- */
:root {
    /* Light Theme (Default) */
    --page-bg: #f7f9f8;
    --panel-bg: #ffffff;
    --text-primary: #333;
    --text-secondary: #555;
    --border-color: #e9e9e9;
    --input-bg: #f9f9f9;
    --brand-purple: #8c4c8c;
    --brand-purple-darker: #7a3d7a;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --shadow-hover-color: rgba(140, 76, 140, 0.4);
    --error-bg: #f8d7da;
    --error-border: #f5c6cb;
    --error-text: #d9534f;
    --white: #fff;
    --logo-heart-color: #559f75;
    --logo-house-color: #9551a1;
}

body.dark-mode {
    /* Dark Theme Overrides */
    --page-bg: #121212;
    --panel-bg: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #444;
    --input-bg: #2a2a2a;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --shadow-hover-color: rgba(140, 76, 140, 0.5);
    --error-bg: #4a2c2e;
    --error-border: #8b3a42;
    --error-text: #ff8a8a;
    --logo-heart-color: #8dbb9d;
    --logo-house-color: #b577b5;
}

/* --- Global Styles --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--page-bg);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==========================================================================
   2. Layout & Shared Components
   ========================================================================== */

.login-page-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.main-content {
    padding: 2rem;
}

.logo-svg {
    width: 80px;
    height: auto;
    transition: fill 0.3s ease;
}

.logo-svg .logo-horizontal-path {
    /* This was the 'heart' color (green) */
    fill: var(--logo-heart-color);
    transition: fill 0.3s ease;
}

.logo-svg .logo-vertical-path {
    /* This was the 'house' color (purple) */
    fill: var(--logo-house-color);
    transition: fill 0.3s ease;
}

/* ==========================================================================
   3. Page: Login
   ========================================================================== */

.login-container {
    background-color: var(--panel-bg);
    padding: 2.5rem 3rem;
    border-radius: 20px;
    box-shadow: 0 10px 30px var(--shadow-color);
    width: 100%;
    max-width: 420px;
    text-align: center;
    position: relative;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.login-logo {
    margin-bottom: 1.5rem;
}

.login-container h1 {
    font-weight: 600;
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.login-header {
    position: relative;
    /* Make this a positioning context for the button */
    display: flex;
    justify-content: center;
    /* Center the logo */
    align-items: center;
    width: 100%;
    margin-bottom: 1.5rem;
    box-sizing: border-box;
}


.login-header-logo a {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.login-header-theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
}


.login-header-logo .logo-svg {
    width: 90px;
    height: 90px;
}

.theme-toggle-button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    transition: background-color 0.2s ease-in-out;
}

.theme-toggle-button:hover {
    /* FIX: Changed from --background-hover to the defined --input-bg for a subtle effect */
    background-color: var(--input-bg);
}

/* Logic for showing the correct theme icon */
.moon-icon {
    display: none;
}

.sun-icon {
    display: inline-block;
}

.dark-mode .moon-icon {
    display: inline-block;
}

.dark-mode .sun-icon {
    display: none;
}

/* ==========================================================================
   4. Page: Dashboard
   ========================================================================== */

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.dashboard-header .logo-svg {
    width: 30px;
    height: 30px;
    margin-right: 0.75rem;
}

.user-management-container {
    max-width: 900px;
    margin: 2rem auto;
}

.user-management-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.user-management-header .btn-submit {
    width: auto;
    text-decoration: none;
}

.user-table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--panel-bg);
    border-radius: 8px;
    overflow: hidden;
    /* Ensures border-radius is respected by children */
    box-shadow: 0 4px 15px var(--shadow-color);
}

.user-table th,
.user-table td {
    padding: 1rem;
    text-align: left;
}

.user-table thead tr {
    border-bottom: 2px solid var(--border-color);
}

.user-table tbody tr {
    border-bottom: 1px solid var(--border-color);
}

.user-table tbody tr:last-child {
    border-bottom: none;
}

.user-group-row td {
    background-color: var(--input-bg);
    padding: 0.5rem 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.user-role-badge {
    background-color: var(--input-bg);
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
    display: inline-block;
}

.user-actions {
    display: flex;
    gap: 0.5rem;
}

.user-actions .btn-submit,
.user-actions input[type="submit"] {
    width: auto;
    padding: 8px 12px;
    text-decoration: none;
}

.user-actions .btn-delete {
    background-color: var(--error-text);
}

.header-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.1rem;
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

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

.app-card {
    display: block;
    background-color: var(--panel-bg);
    padding: 1.5rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    text-decoration: none;
    transition: all 0.2s ease-in-out;
}

.app-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px var(--shadow-color);
    border-color: var(--brand-purple);
}

.app-card-icon {
    width: 96px;
    height: 96px;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--input-bg);
    border-radius: 21px;
    border: 1px solid var(--border-color);
}

.app-card-icon img,
.app-card-icon svg {
    width: 64px;
    height: 64px;
    color: var(--text-secondary);
    object-fit: contain;
}

.app-card-title {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.app-card-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ==========================================================================
   5. Components: Forms & Inputs
   ========================================================================== */

.form-group {
    position: relative;
    margin-bottom: 1.5rem;
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    font-size: 1rem;
    font-family: 'Poppins', sans-serif;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    transition: border-color 0.2s ease, background-color 0.3s ease, color 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--brand-purple);
}

/* Floating label effect for text inputs */
.form-group .form-control+label {
    position: absolute;
    top: 50%;
    left: 15px;
    transform: translateY(-50%);
    color: var(--text-secondary);
    background-color: var(--input-bg);
    padding: 0 5px;
    transition: all 0.2s ease-in-out;
    pointer-events: none;
}

.form-control:focus+label,
.form-control:not(:placeholder-shown)+label {
    top: 0;
    font-size: 0.8rem;
    color: var(--brand-purple);
}

.search-bar input {
    width: 400px;
    padding: 0.6rem 1rem;
    font-size: 1rem;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--brand-purple);
    background-color: var(--panel-bg);
}

/* Static label for dropdowns, checkboxes etc. */
.form-label-static {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    display: block;
}

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

.form-container {
    max-width: 600px;
    margin: 2rem auto;
    padding: 2rem;
    background-color: var(--panel-bg);
    border-radius: 16px;
    box-shadow: 0 4px 15px var(--shadow-color);
    /* Added a subtle shadow for consistency */
}

/* ==========================================================================
   6. Components: Buttons
   ========================================================================== */

.btn-submit {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--white);
    background-color: var(--brand-purple);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.btn-submit:hover {
    background-color: var(--brand-purple-darker);
    box-shadow: 0 4px 15px var(--shadow-hover-color);
}


/* ==========================================================================
   7. Components: Dropdown Menu
   ========================================================================== */

.user-menu-container {
    position: relative;
    display: inline-block;
}

.user-menu-trigger {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Poppins', sans-serif;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.user-menu-trigger svg {
    width: 16px;
    height: 16px;
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 5px);
    background-color: var(--panel-bg);
    min-width: 200px;
    box-shadow: 0 8px 16px var(--shadow-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    z-index: 100;
    overflow: hidden;
}

.user-menu-dropdown.is-active {
    display: block;
}

.dropdown-item {
    color: var(--text-primary);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
    width: 100%;
    background: none;
    border: none;
    font-size: 0.9rem;
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
}

.dropdown-item:hover {
    background-color: var(--input-bg);
}

.dropdown-item-logout {
    color: var(--error-text);
    border-top: 1px solid var(--border-color);
}

/* ==========================================================================
   8. Components: Modals & Alerts
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: none;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--panel-bg);
    color: var(--text-primary);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1001;
    width: 90%;
    max-width: 500px;
    display: none;
}

.modal-content h2 {
    margin-top: 0;
}

.flash-message {
    position: relative;
    padding: 1rem 2.5rem 1rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--error-border);
    border-radius: 8px;
    color: var(--error-text);
    background-color: var(--error-bg);
}

.flash-close-btn {
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.5rem;
    font-weight: bold;
    color: inherit;
    opacity: 0.7;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.flash-close-btn:hover {
    opacity: 1;
}

/* ==========================================================================
   9. Responsive Design
   ========================================================================== */
/* @media (max-width: 768px) {
    .dashboard-header {
        flex-direction: column;
        gap: 1rem;
    }
} */