/* --- Basic Setup --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    margin: 0;
    line-height: 1.6;
}
.admin-container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
h1, h2 {
    color: #004d40; /* Dark Green */
}
hr {
    border: 0;
    height: 1px;
    background-color: #e0e0e0;
    margin: 30px 0;
}
/* --- Theme Color --- */
:root {
    --theme-color: #28a745; /* Main Green */
    --theme-color-dark: #218838; /* Darker Green for hover */
    --danger-color: #dc3545; /* Red for delete */
    --danger-color-dark: #c82333; /* Darker Red for hover */
    --secondary-color: #6c757d; /* Grey for cancel */
}
/* --- Header --- */
.admin-header {
    background-color: var(--theme-color);
    color: white;
    padding: 15px 30px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.admin-header h1 {
    color: white;
    margin: 0;
}
/* --- Forms --- */
.admin-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.form-group {
    display: flex;
    flex-direction: column;
}
.form-group-row {
    display: flex;
    gap: 20px;
}
.form-group-row .form-group {
    flex: 1;
}
.admin-form label {
    font-weight: 600;
    margin-bottom: 5px;
}
.admin-form input[type="text"],
.admin-form input[type="number"],
.admin-form input[type="file"],
.admin-form textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}
.admin-form textarea {
    resize: vertical;
}
/* --- Buttons --- */
.btn-primary {
    background-color: var(--theme-color);
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
}
.btn-primary:hover {
    background-color: var(--theme-color-dark);
}
.btn-secondary, .btn-edit {
    background-color: var(--secondary-color);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
}
.btn-delete {
    background-color: var(--danger-color);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
}
.btn-delete:hover {
    background-color: var(--danger-color-dark);
}

/* --- Table --- */
.table-container {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}
table th, table td {
    border: 1px solid #e0e0e0;
    padding: 12px;
    text-align: left;
    vertical-align: middle;
}
table th {
    background-color: #f9f9f9;
    font-weight: 600;
}
table td.actions {
    display: flex;
    gap: 5px;
}
/* --- Messages --- */
.message {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 4px;
    background-color: #d4edda; /* Light green for success */
    color: #155724;
    border: 1px solid #c3e6cb;
}
/* --- Styles for Make Order Page --- */
#product-order-list {
    margin-top: 0;
}
#product-order-list th,
#product-order-list td {
    vertical-align: middle;
}
#product-order-list input[type="number"] {
    width: 100px; /* Smaller inputs for table */
    padding: 8px;
}
#product-order-list .row-total {
    font-weight: 600;
}
#product-order-list .btn-delete {
    padding: 5px 10px;
    font-size: 18px;
    line-height: 1;
}
.pricing-summary {
    background-color: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}
.pricing-summary .form-group {
    flex-grow: 1;
}
.pricing-summary input[readonly] {
    background-color: #e9ecef;
    font-weight: 600;
}

/* --- Styles for Order Management Page --- */
table th, table td {
    vertical-align: top;
}
.product-details {
    font-size: 0.9em;
    line-height: 1.5;
}
.payment-form .payment-input {
    width: 100px;
    padding: 5px;
    margin-bottom: 5px;
}
.payment-form .payment-due {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--danger-color);
}
.status-form .status-select {
    width: 120px;
    padding: 5px;
}
.status-form small {
    font-size: 0.8em;
    color: #555;
    display: inline-block;
    margin-top: 5px;
}
/* --- Modal (Pop-up) Styles --- */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgb(0,0,0); 
    background-color: rgba(0,0,0,0.4); 
}
.modal-content {
    background-color: #fefefe;
    margin: 15% auto; 
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 500px;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
}
.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}
#history-content ul {
    list-style-type: disc;
    padding-left: 20px;
}
#history-content li {
    margin-bottom: 10px;
    line-height: 1.5;
}

/* --- Styles for Review Order Page --- */
.info-box {
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    line-height: 1.8;
}

/* --- Styles for Customer Leads Page --- */
.lead-row td {
    vertical-align: top;
}
.lead-status-select {
    width: 140px;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
}
.lead-notes-textarea {
    width: 100%;
    max-width: 250px; /* Prevent it from being too wide */
    box-sizing: border-box; /* Proper width */
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    resize: vertical;
}
.update-spinner {
    font-size: 0.9em;
    color: var(--theme-color);
    margin-left: 5px;
}

/* --- Styles for View Announcement Page --- */
.read-status-list {
    flex: 1;
    min-width: 300px;
    background-color: #fdfdfd;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
}
.read-status-list h3 {
    margin-top: 0;
}
.read-status-list ul {
    list-style-type: none;
    padding-left: 0;
    max-height: 400px;
    overflow-y: auto;
}
.read-status-list li {
    border-bottom: 1px solid #f0f0f0;
    padding: 10px 0;
}
.read-status-list li:last-child {
    border-bottom: none;
}

/* --- Styles for Inbox List --- */
tbody tr[onclick]:hover {
    background-color: #f8f9fa;
    cursor: pointer;
}
/* --- Styles for Chat Conversation --- */
.chat-container {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    height: 500px;
    overflow-y: auto;
    background-color: #fdfdfd;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.chat-message {
    padding: 12px 18px;
    border-radius: 18px;
    max-width: 70%;
    line-height: 1.5;
}
.chat-message p {
    margin: 0 0 5px 0;
    white-space: pre-wrap; /* Preserves line breaks */
}
.chat-meta {
    font-size: 0.8em;
    color: #555;
}
.admin-message {
    background-color: var(--theme-color);
    color: white;
    border-radius: 18px 18px 0 18px;
    align-self: flex-end;
    margin-left: auto;
}
.admin-message .chat-meta {
    color: #f0f0f0;
}
.admin-message .read-receipt {
    font-weight: 600;
}
.admin-message .delete-msg {
    color: #ffebee;
    text-decoration: none;
    font-weight: 600;
}
.dealer-message {
    background-color: #e9ecef;
    color: #333;
    border-radius: 18px 18px 18px 0;
    align-self: flex-start;
    margin-right: auto;
}

/* --- Styles for Dealer Inbox --- */
.inbox-list tr {
    cursor: pointer;
}
.inbox-list tr:hover {
    background-color: #f8f9fa;
}
.inbox-list tr.unread {
    background-color: #fdfdfd;
    font-weight: 600;
}
.inbox-list tr.unread td:first-child {
    border-left: 4px solid var(--theme-color);
}
.unread-badge {
    background-color: var(--danger-color);
    color: white;
    font-size: 0.8em;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 5px;
    font-weight: 600;
}

/* --- Login Page Styles --- */
.login-body {
    background-color: #f4f7f6;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
.login-container {
    width: 100%;
    max-width: 400px;
}
.login-form {
    background-color: #ffffff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}
.login-form h2 {
    text-align: center;
    margin-top: 0;
    color: var(--theme-color);
}
.login-form p {
    text-align: center;
    margin-bottom: 20px;
    color: #555;
}
/* --- Navigation Bar Styles --- */
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 30px;
    flex-wrap: wrap;
}
.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.admin-nav a {
    color: white;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: 500;
}
.admin-nav a:hover, .admin-nav a.active {
    background-color: rgba(255, 255, 255, 0.2);
}

/* --- FIX: Logout Button --- */
.logout-btn,
.admin-nav .logout-btn {
    background-color: var(--danger-color);
    color: white;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: 500;
}
.logout-btn:hover,
.admin-nav .logout-btn:hover {
    background-color: var(--danger-color-dark);
}

/* --- Dealer Header --- */
.dealer-header {
    background-color: #004d40; /* Darker Green for Dealer */
}
/* --- Status Badges --- */
.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 600;
    color: white;
}
.status-pending { background-color: #ffc107; color: #333; }
.status-processing { background-color: #17a2b8; }
.status-shipped { background-color: #007bff; }
.status-delivered { background-color: var(--theme-color); }
.status-cancelled { background-color: var(--danger-color); }

/* --- Admin Dashboard Styles --- */
.welcome-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}
.welcome-header h2 {
    margin: 0;
}
.welcome-header p {
    margin: 5px 0 0 0;
    font-size: 16px;
    color: #555;
}

/* Quick Action Cards */
.quick-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}
.quick-action-card {
    display: block;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s ease-in-out;
}
.quick-action-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border-color: var(--theme-color);
}
.quick-action-card h3 {
    margin: 0 0 5px 0;
    color: var(--theme-color);
}
.quick-action-card small {
    color: #555;
}

/* Stat Cards */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}
.stat-card {
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
}
.stat-card h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #555;
}
.stat-card p {
    margin: 0 0 10px 0;
    font-size: 28px;
    font-weight: 600;
    color: #004d40;
}
.stat-card small {
    color: #6c757d;
}
.stat-card.urgent {
    border-left: 4px solid var(--danger-color);
}
.stat-card.urgent p {
    color: var(--danger-color);
}
.stat-card.urgent-alt {
    border-left: 4px solid #ffc107; /* Yellow */
}
.stat-card.urgent-alt p {
    color: #ffc107;
}
.stat-card a {
    text-decoration: none;
    font-weight: 600;
    color: var(--theme-color);
}

/* Content Grid */
.dashboard-content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.card {
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 0;
}
.card h3 {
    margin-top: 0;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 10px;
}
.card .table-container {
    padding: 0;
}
.card table {
    margin-top: 0;
}

/* Minimal Activity List */
.activity-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}
.activity-list li {
    padding: 12px 5px;
    border-bottom: 1px solid #f0f0f0;
}
.activity-list li:last-child {
    border-bottom: none;
}
.activity-list li a.activity-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
}
.activity-list .item-title {
    font-weight: 600;
    color: var(--text-color);
}
.activity-list .item-meta {
    font-size: 0.9em;
    color: #555;
    margin: 0 10px;
}
.activity-list .item-value {
    font-weight: 600;
    color: var(--theme-color);
    margin-left: auto;
}
.activity-list a.activity-link .item-value {
    font-size: 1.2em;
}

/* Low Stock List */
.low-stock-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}
.low-stock-list li {
    margin-bottom: 5px;
}
.low-stock-list li a {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    text-decoration: none;
    color: var(--text-color);
    border-radius: 4px;
}
.low-stock-list li a:hover {
    background-color: #f8f9fa;
}
.low-stock-list .stock-count {
    font-weight: 600;
    color: var(--danger-color);
}

/* --- Admin/Dealer Hamburger Menu --- */
.mobile-menu-button {
    display: none; /* Hidden by default */
    background: none;
    border: none;
    font-size: 28px;
    color: white;
    cursor: pointer;
}
.mobile-menu-container {
    display: flex;
    align-items: center;
    gap: 10px; /* Original gap */
}

/* --- Public Site Hamburger Menu --- */
.public-header .mobile-menu-button {
    color: var(--theme-color);
}
.public-header .mobile-menu-container {
    gap: 20px;
}

/* --- Outline Button Style --- */
.btn-outline {
    background-color: transparent;
    color: var(--secondary-color);
    border: 1px solid #ccc;
    padding: 10px 20px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    display: inline-block;
}
.btn-outline:hover {
    background-color: #f8f9fa;
    border-color: #aaa;
}

/* ================================================================
   MERGED RESPONSIVE (MOBILE) STYLES
================================================================
*/

@media (max-width: 992px) {
    /* --- Dashboard --- */
    .dashboard-content-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    /* --- Basic Admin --- */
    .form-group-row {
        flex-direction: column;
        gap: 15px;
    }
    table td.actions {
        flex-direction: column;
    }

    /* --- Admin/Dealer Header --- */
    .admin-header,
    .dealer-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
    }
    .admin-header .mobile-menu-button,
    .dealer-header .mobile-menu-button {
        display: block; /* Show hamburger */
    }
    
    .admin-header .mobile-menu-container,
    .dealer-header .mobile-menu-container {
        display: none; /* Hide the menu by default */
        flex-direction: column;
        width: 100%;
        order: 4; /* Put it at the bottom */
        background-color: #fdfdfd;
        margin-top: 15px;
        border-top: 1px solid #f0f0f0;
    }
    
    .admin-header .mobile-menu-container.is-active,
    .dealer-header .mobile-menu-container.is-active {
        display: flex; /* Show the menu when active */
    }
    
    .admin-nav {
        flex-direction: column;
        width: 100%;
        margin-top: 0;
        gap: 0;
    }
    
    /* --- FIX: White Text Bug --- */
    .admin-header .mobile-menu-container .admin-nav a,
    .dealer-header .mobile-menu-container .admin-nav a {
        color: var(--text-color); /* Dark text on light background */
        padding: 15px;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .admin-nav a:hover, .admin-nav a.active {
        background-color: #f8f9fa; /* Light hover for links */
    }
    
    /* --- FIX: Logout Button (Mobile) --- */
    .logout-btn,
    .admin-nav .logout-btn {
        margin: 15px;
        width: calc(100% - 30px);
        text-align: center;
        box-sizing: border-box;
        /* Ensure red style is applied */
        background-color: var(--danger-color);
        color: white;
    }
    .logout-btn:hover,
    .admin-nav .logout-btn:hover {
        background-color: var(--danger-color-dark);
    }
    
    /* --- Admin Dashboard --- */
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .quick-action-grid {
        grid-template-columns: 1fr;
    }

    /* --- Public Header --- */
    .public-header .nav-container {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
    .public-header .logo {
        flex-grow: 1;
    }
    .public-header .mobile-menu-button {
        display: block; /* Show hamburger */
    }
    .public-header .mobile-menu-container {
        display: none; /* Hide the menu by default */
        flex-direction: column;
        width: 100%;
        order: 4; /* Put it at the bottom */
        background-color: #fdfdfd;
        margin-top: 15px;
        border-top: 1px solid #f0f0f0;
    }
    .public-header .mobile-menu-container.is-active {
        display: flex; /* Show the menu when active */
    }
    .public-header .public-nav {
        flex-direction: column;
        width: 100%;
        gap: 0;
    }
    .public-header .public-nav a {
        padding: 15px;
        width: 100%;
        text-align: left;
        box-sizing: border-box;
        border-bottom: 1px solid #f0f0f0;
    }
    .public-header .public-nav a:first-child {
        border-top: none;
    }
    .public-header .cart-button {
        margin: 15px;
        width: calc(100% - 30px);
        text-align: center;
    }

    /* --- Public Cart Page --- */
    #cart-page-layout {
        grid-template-columns: 1fr;
    }
    .checkout-form-container {
        order: 2; 
    }
    .cart-items-list {
        order: 1;
    }
    .cart-item-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .cart-item-info {
        margin-top: 10px;
    }
    .cart-item-actions {
        margin-top: 10px;
    }
    .cart-item-actions .update-cart-form {
        display: flex;
        align-items: center;
    }
    .cart-item-total {
        margin-top: 10px;
        font-weight: 600;
        align-self: flex-end;
    }
}

/* --- FINAL FIX for Mobile Menu White Text --- */
@media (max-width: 768px) {

    .admin-header .mobile-menu-container .admin-nav a,
    .dealer-header .mobile-menu-container .admin-nav a {
        color: #333 !important; /* Force dark text */
    }
    
}

/* --- NEW: Login "Back" Link Style --- */
.back-to-home {
    text-align: center;
    margin-top: 20px;
}
.back-to-home a {
    color: var(--secondary-color);
    text-decoration: none;
    font-size: 0.9em;
}
.back-to-home a:hover {
    text-decoration: underline;
    color: var(--text-color);
}