:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --receivables-color: #4f46e5;
    /* Blue/Indigo */
    --receivables-light: #e0e7ff;
    --payables-color: #10b981;
    /* Emerald/Green */
    --payables-light: #d1fae5;

    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.main-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Global Chat Fullscreen */
#chatModal .modal-content {
    width: 100% !important;
    height: 100dvh !important;
    max-width: none !important;
    margin: 0 !important;
    border-radius: 0 !important;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.main-nav {
    display: flex;
    gap: 2rem;
}

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

.nav-item:hover {
    color: var(--text-main);
}

/* Specific Navigation Active States */
.nav-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Image Styles */
.logo-img {
    height: 32px;
    width: auto;
    display: block;
}

.landing-logo .logo-img {
    height: 40px;
}

.hero-content-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4rem;
    max-width: 1000px;
    margin: 0 auto;
    text-align: left;
}

.hero-text {
    flex: 1;
    max-width: 500px;
}

.hero-image-container {
    flex: 1;
    display: flex;
    justify-content: center;
}

.hero-image {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.feature-icon-img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .hero-content-wrapper {
        flex-direction: column;
        text-align: center;
        gap: 2rem;
    }

    .hero-text {
        max-width: 100%;
    }
}

/* --- UI Components Restoration --- */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    /* Increased weight */
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    text-decoration: none;
    line-height: 1.25;
    border: 1px solid transparent;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #4338ca 100%);
    /* Gradient */
    color: white;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #4338ca 0%, #3730a3 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 10px -1px rgba(79, 70, 229, 0.3);
}

.btn-outline {
    background-color: white;
    border-color: var(--border);
    color: var(--text-muted);
}

.btn-outline:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    color: var(--text-main);
    transform: translateY(-1px);
}

.btn-lg {
    padding: 0.75rem 2rem;
    font-size: 1rem;
}

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

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

label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea,
.form-control {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-main);
    background-color: white;
    transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--receivables-light);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    overflow-y: auto;
}

.modal-content {
    background-color: white;
    margin: 3rem auto;
    padding: 0;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    max-width: 500px;
    width: 90%;
    position: relative;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.close {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: var(--text-main);
}

/* Dashboard Elements */
.main-content {
    padding: 2rem 0;
}

.page-section {
    animation: fadeIn 0.3s ease-out;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.dashboard-header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-main);
}

/* User Profile Dropdown */
.user-profile {
    position: relative;
    cursor: pointer;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.5rem;
    width: 200px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 50;
    padding: 0.5rem 0;
}

/* .user-profile:hover .dropdown-menu, */
/* .dropdown-menu:hover {
    display: block;
} */

.dropdown-menu.show {
    display: block;
}

.dropdown-header {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
}

.dropdown-item {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background-color: #f1f5f9;
}

/* Stat Box (Admin) */
.stat-box {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    min-width: 150px;
    flex: 1;
}

.stat-box h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

/* Utilities */
.text-muted {
    color: var(--text-muted);
}

.text-danger {
    color: var(--danger);
}

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

/* Invoices specific */
.invoice-item {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: white;
    transition: all 0.2s;
}

.invoice-item:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.invoice-list.loading {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

/* Responsive */
@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .hero-content-wrapper {
        flex-direction: column;
    }

    .header-content {
        height: 60px;
        padding: 0;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .main-nav {
        display: none;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Back Link Style */
/* Back Link Style */
.back-link {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    text-decoration: none;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.6rem 1.25rem;
    border-radius: 99px;
    background: white;
    border: 1px solid var(--border);
    transition: all 0.2s ease-in-out;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.back-link:hover {
    color: white;
    background: var(--primary);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 6px 10px -2px rgba(79, 70, 229, 0.3);
}

.back-link svg {
    transition: transform 0.2s;
}

.back-link:hover svg {
    transform: translateX(-3px);
}

/* Mobile Bottom Navigation */
.mobile-bottom-nav {
    display: none;
    /* Hidden by default on desktop */
}

@media (max-width: 640px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: white;
        border-top: 1px solid var(--border);
        padding: 0.5rem 0;
        justify-content: space-around;
        z-index: 1000;
        box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        font-size: 0.75rem;
        color: var(--text-muted);
        gap: 0.2rem;
    }

    .mobile-nav-item .nav-icon {
        font-size: 1.25rem;
    }

    .mobile-nav-item.active {
        color: var(--primary);
        font-weight: 600;
    }

    /* Ensure content doesn't get hidden behind the nav */
    body {
        padding-bottom: 80px;
    }

    .desktop-only-text {
        display: none !important;
    }

    .hero-banner {
        display: none !important;
    }

    /* Mobile Text & Layout Fixes */
    h1 {
        font-size: 1.5rem !important;
        /* Smaller Page Titles */
        margin-bottom: 1rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
        /* Smaller Card Titles */
    }

    .dashboard-header {
        margin-bottom: 1rem !important;
    }

    .card {
        margin-bottom: 1rem !important;
        padding: 0 !important;
        border-radius: 8px !important;
    }

    .card-header,
    .card-body {
        padding: 1rem !important;
    }

    /* Force Grid to Single Column */
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Input and Select Mobile Fixes */
    input,
    select,
    .form-control {
        font-size: 16px !important;
        /* Prevent iOS Zoom */
        max-width: 100% !important;
    }

    /* Stats Container Wrap */
    .actions,
    .stats-container {
        width: 100%;
        margin-top: 0.5rem;
    }

    /* Buttons Full Width on Mobile */
    .dashboard-header .actions button,
    .dashboard-header button {
        width: 100%;
        margin-bottom: 0.5rem;
        display: block;
    }

    /* Chart Container Height Fix */
    .card-body[style*="height: 250px"] {
        height: auto !important;
        min-height: 250px;
    }

    /* Fix table or list overflow */
    .invoice-list {
        overflow-x: auto;
    }

    /* Reduce Padding on Container */
    .container {
        padding: 0 1rem;
    }

    /* Fix Team Member Layout overflow */
    .invoice-item[style*="display:flex"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .invoice-item[style*="display:flex"]>div {
        width: 100%;
    }
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.status-paid {
    background-color: #dcfce7;
    color: #166534;
}

.status-unpaid {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-partially_paid {
    background-color: #ffedd5;
    color: #9a3412;
}

.status-pending {
    background-color: #f1f5f9;
    color: #475569;
}

.status-declared_by_buyer {
    background-color: #e0f2fe;
    color: #0369a1;
}

.status-under_verification {
    background-color: #fce7f3;
    color: #be185d;
}

/* Global Modal Content Fix */
.modal-content>form,
.modal-content>.modal-body,
#invoiceModal .modal-content>form,
#relationshipModal .modal-content>form,
#detailsModal .modal-content>div:not(.modal-header),
#paymentDeclarationModal .modal-content>form,
#verifyPaymentModal .modal-content>div:not(.modal-header),
#changePasswordModal .modal-content>form,
#editRoleModal .modal-content>form {
    padding: 1.5rem;
}

/* --- Mobile Modal Fixes --- */
@media (max-width: 640px) {

    /* Make modals full screen on mobile */
    .modal-content {
        margin: 0 !important;
        width: 100% !important;
        height: 100dvh !important;
        max-width: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        display: flex;
        flex-direction: column;
        border: none !important;
    }

    /* Ensure header stays at top */
    .modal-header {
        flex-shrink: 0;
        border-bottom: 1px solid var(--border);
        background: white;
        z-index: 10;
    }

    /* Make the content body scrollable */
    /* Target common containers inside modals */
    #invoiceModal .modal-content>form,
    #relationshipModal .modal-content>form,
    #detailsModal .modal-content>div:not(.modal-header),
    #subscriptionModal .modal-content>.modal-body,
    #paymentDeclarationModal .modal-content>form,
    #verifyPaymentModal .modal-content>div:not(.modal-header),
    #changePasswordModal .modal-content>form,
    #editRoleModal .modal-content>form {
        flex: 1;
        overflow-y: auto;
        padding: 1.5rem !important;
        /* Ensure visible padding */
        padding-bottom: 80px !important;
        /* Space for bottom nav or scrolling */
        -webkit-overflow-scrolling: touch;
    }

    /* Ensure form actions have space at bottom */
    .form-actions {
        margin-top: 1.5rem;
        padding-bottom: 1rem;
    }
}

@media (max-width: 768px) {
    #admin-dashboard-view>div:first-child {
        grid-template-columns: 1fr !important;
    }

    .stat-box {
        min-width: 45%;
        margin-bottom: 1rem;
    }

    /* Adjust list view for mobile */
    #admin-users-list .card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    #admin-users-list .card-header>div {
        width: 100%;
        justify-content: space-between;
    }

    /* Hide table headers on mobile */
    #admin-users-header {
        display: none !important;
    }

    #admin-users-list .card-body>div {
        grid-template-columns: 1fr !important;
        gap: 0.5rem !important;
        padding: 1rem !important;
        border-bottom: 1px solid #e2e8f0;
    }

    #admin-users-list .card-body>div>div {
        display: flex;
        justify-content: space-between;
    }

    #admin-users-list .card-body>div>div::before {
        content: attr(data-label);
        /* requires updating JS to add data-label */
        font-weight: 600;
        color: #64748b;
    }

    /* Mobile Invoice Item Fixes */
    .invoice-item>div {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .invoice-item>div>div {
        width: 100% !important;
    }

    /* Make buttons stack vertically on mobile */
    .invoice-item div[style*="display: flex; gap: 0.5rem"] {
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.5rem !important;
    }

    .invoice-item .btn {
        width: 100% !important;
        justify-content: center !important;
    }

    .invoice-item .btn-sm {
        padding: 0.5rem 1rem !important;
        font-size: 0.875rem !important;
    }

    /* Ensure status badge stays inline on mobile */
    .invoice-item>div:first-child {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
    }
}

@media (max-width: 640px) {

    /* Fix chat type area visibility on mobile */
    #chatForm {
        padding-bottom: 5.5rem !important;
        /* Ensure it's not hidden by gesture bars */
        padding-bottom: max(5.5rem, env(safe-area-inset-bottom) + 2rem) !important;
    }
}