:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --sidebar-bg: #1e293b;
    --sidebar-text: #f1f5f9;
    --sidebar-active: #334155;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --flex-dir: row;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box !important;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

html,
body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    width: 100%;
    overflow-x: hidden;
    position: relative;
}

.main-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden !important;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: 100vh;
    position: fixed;
    display: flex;
    flex-direction: column;
    padding: 2rem 1rem;
    transition: all 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    margin-bottom: 2rem;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: white;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-item {
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 0.9375rem;
}

.nav-link:hover {
    background: var(--sidebar-active);
    color: white;
}

.nav-link.active {
    background: var(--primary);
    color: white;
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid #334155;
}

.main-wrapper {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: calc(100% - 260px);
}

header {
    height: 70px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 100;
    position: sticky;
    top: 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.header-search {
    position: relative;
    width: 300px;
}

.header-search input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
    background: #f1f5f9;
}

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

.avatar {
    width: 36px;
    height: 36px;
    background: #e2e8f0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

main {
    padding: 2rem;
}

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

.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.5rem;
}

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

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

.btn-secondary {
    background: #f1f5f9;
    color: var(--text-main);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.875rem;
    border-bottom: 2px solid var(--bg-main);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--bg-main);
    font-size: 0.9375rem;
}

tr:hover td {
    background-color: #f8fafc;
}

.badge {
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    letter-spacing: 0.025em;
}

.badge-new {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}

.badge-contacted {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.badge-quoted {
    background: #fef9c3;
    color: #a16207;
    border: 1px solid #fef08a;
}

.badge-completed {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.badge-cancelled {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.service-tag {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.85rem;
    background: #f1f5f9;
    color: #475569;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-right: 6px;
    margin-bottom: 6px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.service-tag:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: var(--text-main);
}

.filter-label {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: #f1f5f9;
    color: #475569;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    user-select: none;
}

.filter-label:hover {
    background: #e2e8f0;
    color: var(--text-main);
}

.filter-label.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.filter-label input {
    display: none;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal {
    background: white;
    padding: 2rem;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform 0.3s ease;
    text-align: center;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-icon {
    width: 64px;
    height: 64px;
    background: #fee2e2;
    color: #ef4444;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.modal-text {
    color: var(--text-muted);
    margin-bottom: 2rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Flash Messages */
.alert-box {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 2000;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    background: white;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 1rem;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-left: 4px solid var(--primary);
}

.alert-box.active {
    transform: translateX(0);
}

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

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: block;
    text-decoration: none;
    color: inherit;
    border: 2px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-title {
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Utility & Layout Classes */
.page-header {
    margin-bottom: 2rem;
}

.page-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.page-subtitle {
    color: var(--text-muted);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

.grid-2-gap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

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

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
}

/* Service History Card */
.service-history-item {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    transition: box-shadow 0.2s;
}

.service-history-item:hover {
    box-shadow: var(--shadow);
}

.service-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.service-name {
    font-weight: 600;
    color: var(--primary);
}

.service-price {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--success);
}

.service-meta {
    font-size: 0.875rem;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.service-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* Responsive Overrides */
@media (max-width: 768px) {

    /* Force 1x1 for all grids on mobile */
    .grid-2,
    .grid-2-gap,
    div[style*="display: grid"] {
        grid-template-columns: 1fr !important;
        width: 100% !important;
        gap: 1rem !important;
        --flex-dir: column;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding-top: 64px !important;
        flex: 1;
    }

    .main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding-top: 64px !important;
        position: relative;
        overflow-x: hidden !important;
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    header {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        width: 100% !important;
        padding: 0 1rem !important;
        height: 64px !important;
        background: white !important;
        z-index: 2000 !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .header-search {
        display: none;
    }

    .user-profile .avatar {
        margin-left: 0;
    }

    .hide-mobile {
        display: none !important;
    }

    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: #f1f5f9;
        border-radius: 8px;
        cursor: pointer;
        color: var(--text-main);
    }

    main {
        padding: 1rem;
    }

    .page-header-flex {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .page-header-flex .btn,
    .card .btn:not(.btn-icon):not(.service-tag),
    .grid-2 .btn,
    form button[type="submit"] {
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        white-space: nowrap !important;
        text-align: center !important;
        height: 54px !important;
        padding: 0 !important;
        /* Clear side padding to ensure centering */
        margin-top: 0.5rem;
        font-size: 1rem !important;
    }

    .header-actions {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .grid-2,
    .grid-2-gap,
    [style*="grid-template-columns"],
    [style*="display: grid"],
    .stats-grid,
    .header-actions {
        grid-template-columns: 1fr !important;
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100% !important;
        gap: 1.25rem !important;
        align-items: stretch !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .form-group {
        margin-bottom: 2rem !important;
        /* More space between fields */
    }

    .form-control {
        height: 60px !important;
        font-size: 1.125rem !important;
        padding: 0 1.5rem !important;
    }


    .stat-card {
        padding: 1.25rem !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        /* Changed from center to left */
        text-align: left !important;
        /* Changed from center to left */
        width: 100% !important;
        box-sizing: border-box !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .stat-value {
        font-size: 1.75rem !important;
        font-weight: 800 !important;
        text-align: left !important;
    }

    .stat-title {
        text-align: left !important;
        width: 100% !important;
    }

    /* Force left alignment for any table cell meant to be a message */
    td[colspan],
    td[style*="text-align: center"] {
        text-align: left !important;
        padding-left: 1.5rem !important;
    }

    .card {
        padding: 1rem;
    }

    .table-container {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

    .table-container table {
        min-width: 600px;
        /* Force scrollable content */
    }

    /* Modal responsiveness */
    .modal,
    .modal-overlay .card {
        width: 90% !important;
        max-width: 90% !important;
        margin: 1rem auto !important;
        padding: 1.25rem !important;
        transform: translateY(0) !important;
    }

    .modal-overlay .card form div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    .modal-overlay .card .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .modal-overlay .card div[style*="display: flex; gap: 1rem"] {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    /* Filters responsiveness */
    .filters-wrapper {
        display: flex;
        overflow-x: auto;
        padding-bottom: 0.5rem;
        gap: 0.5rem;
        margin-bottom: 1rem;
        -webkit-overflow-scrolling: touch;
    }

    .chart-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    .chart-inner {
        min-width: 500px;
    }
}

.mobile-menu-toggle {
    display: none;
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 95;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

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

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-control {
    width: 100% !important;
    padding: 0 1.25rem !important;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    transition: all 0.2s;
    font-size: 1.1rem !important;
    height: 60px !important;
    display: block !important;
    background: white !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    font-weight: 500 !important;
    color: var(--text-main) !important;
    box-sizing: border-box !important;
}

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

.form-control:focus {
    border-color: var(--primary);
}

/* Login */
.login-container {
    max-width: 400px;
    width: 100%;
    margin: auto;
    padding: 2rem;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}