:root {
    --primary: #4F46E5;
    --primary-light: #818CF8;
    --primary-dark: #3730A3;
    --bg-color: #0F172A;
    --text-color: #F8FAFC;
    --text-muted: #94A3B8;
    --card-bg: rgba(30, 41, 59, 0.7);
    --card-border: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(15, 23, 42, 0.6);
    --input-border: rgba(255, 255, 255, 0.15);
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
}

[data-theme="light"] {
    --primary: #4F46E5;
    --primary-light: #818CF8;
    --primary-dark: #3730A3;
    --bg-color: #F1F5F9;
    --text-color: #0F172A;
    --text-muted: #64748B;
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(255, 255, 255, 0.5);
    --input-bg: rgba(255, 255, 255, 0.9);
    --input-border: rgba(0, 0, 0, 0.1);
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    background-image:
        radial-gradient(at 0% 0%, rgba(79, 70, 229, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(129, 140, 248, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, color 0.3s;
}

/* Auth Pages */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 40px !important;
}

/* Layout */
.container {
    width: 90%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 0;
    flex: 1;
}

.container-full {
    max-width: 98% !important;
    width: 98% !important;
}

/* Header */
.topbar {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-decoration: none;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 20px;
}

.topbar-nav a {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.topbar-nav a:hover,
.topbar-nav a.active {
    color: var(--primary-light);
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropbtn {
    cursor: pointer;
    padding-bottom: 5px;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: var(--card-bg);
    min-width: 200px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1001;
    border-radius: 8px;
    backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    margin-top: 5px;
}

.dropdown-content a {
    color: var(--text-color);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--card-border);
}

.dropdown-content a:last-child {
    border-bottom: none;
}

.dropdown-content a:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--primary-light);
}

.dropdown:hover .dropdown-content {
    display: block;
}

[data-theme="light"] .dropdown-content {
    background-color: #fff;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.1);
}

[data-theme="light"] .dropdown-content a:hover {
    background-color: #f1f5f9;
}

.user-info {
    font-size: 0.9rem;
    color: var(--text-muted);
    border-left: 1px solid var(--card-border);
    padding-left: 20px;
}

/* Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
    margin-bottom: 24px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    box-shadow: 0 15px 35px -10px rgba(0, 0, 0, 0.2);
}

.card-title {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title .actions {
    font-size: 0.9rem;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    box-sizing: border-box;
    transition: all 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(79, 70, 229, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    border: 1px solid var(--card-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #b91c1c);
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--card-border);
}

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Alerts */
.alert {
    padding: 15px 20px;
    border-radius: 8px;
    font-weight: 500;
    margin-bottom: 20px;
    border-left: 4px solid;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border-left-color: var(--danger);
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    color: #6ee7b7;
    border-left-color: var(--success);
}

/* Badges */
.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.badge-primary {
    background: rgba(79, 70, 229, 0.2);
    color: var(--primary-light);
}

.badge-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.clickable-customer {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dashed transparent;
    transition: all 0.2s;
}

.clickable-customer:hover {
    border-bottom-color: var(--primary);
    color: var(--primary-light);
}

/* Print Layout */
@media print {
    body {
        background: white !important;
        color: black !important;
        background-image: none !important;
    }

    .topbar,
    .no-print {
        display: none !important;
    }

    .container {
        width: 100%;
        max-width: none;
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: none;
        padding: 0;
        background: transparent !important;
        backdrop-filter: none;
    }

    table,
    th,
    td {
        border-color: #ddd !important;
        color: black !important;
    }

    .badge {
        border: 1px solid #999;
        color: black !important;
        background: transparent !important;
    }
}

/* Search Suggestion Dropdown */
.search-container {
    position: relative;
    width: 100%;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    margin-top: 5px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    display: none;
}

.search-result-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--card-border);
    transition: background 0.2s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.search-result-item div {
    font-weight: 600;
    font-size: 0.95rem;
}

.search-result-item small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

[data-theme="light"] .search-results {
    background: #fff;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .search-result-item:hover {
    background: #f1f5f9;
}

/* Grid-style Table Enhancement */
.table-grid {
    overflow-x: auto;
    width: 100%;
    margin-bottom: 20px;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    background: var(--card-bg);
    -webkit-overflow-scrolling: touch;
}

.table-grid table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

.table-grid th {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    font-weight: 700;
    font-size: 0.8rem;
    padding: 12px 16px;
    border-bottom: 2px solid var(--primary);
}

[data-theme="light"] .table-grid th {
    background: #f8fafc;
    border-bottom-color: var(--primary);
}

.table-grid td {
    padding: 10px 16px;
    vertical-align: middle;
}

.table-grid tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .table-grid tr:nth-child(even) td {
    background: #fcfdfe;
}

.table-grid tr:hover td {
    background: rgba(79, 70, 229, 0.1) !important;
}

/* Excel Spreadsheet Style Grid */
.table-grid.excel-grid {
    border-radius: 0;
    border: 1px solid var(--excel-border, rgba(255, 255, 255, 0.15));
    max-height: 75vh;
    overflow-y: auto;
}

.table-grid.excel-grid table {
    border-collapse: collapse;
}

.table-grid.excel-grid th, 
.table-grid.excel-grid td {
    border: 1px solid var(--excel-border, rgba(255, 255, 255, 0.15));
    padding: 6px 8px; /* Tighter padding for data density */
    white-space: nowrap;
}

.table-grid.excel-grid th {
    background: var(--card-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 0 var(--excel-border, rgba(255, 255, 255, 0.15)); /* Ensures no gap below header */
}

/* Ensure the filter row is sticky immediately below the header row */
.table-grid.excel-grid .grid-filter-row th,
.table-grid.excel-grid .grid-filter-row td {
    position: sticky;
    top: 36px; /* Approx height of main header row, adjusted if needed but works as fallback */
    z-index: 9;
    padding: 4px 6px !important;
}

[data-theme="light"] .table-grid.excel-grid {
    --excel-border: rgba(0, 0, 0, 0.2);
}

.grid-filter-row td {
    padding: 6px 8px !important;
    background: rgba(0, 0, 0, 0.15) !important;
    vertical-align: middle;
}


.grid-filter-row input, 
.grid-filter-row select {
    padding: 4px 8px;
    font-size: 0.75rem;
    height: 28px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 4px;
    color: var(--text-color);
    width: 100%;
    box-sizing: border-box;
    margin: 0;
}

.action-icons {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.action-icon-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--card-border);
    background: var(--input-bg);
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 1.2rem;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.action-icon-btn:hover {
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 10;
}

.action-icon-btn.edit:hover { background: var(--primary); }
.action-icon-btn.costs:hover { background: #f59e0b; }
.action-icon-btn.track:hover { background: #8b5cf6; }

/* Tooltip on hover */
.action-icon-btn[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: #000;
    color: #fff;
    font-size: 0.7rem;
    border-radius: 4px;
    white-space: nowrap;
    margin-bottom: 5px;
    z-index: 100;
}

.sort-icon {
    font-size: 0.6rem;
    margin-left: 3px;
    opacity: 0.5;
    vertical-align: middle;
}

.sticky-action {
    position: sticky;
    right: 0;
    background: #1e293b !important; /* Solid dark color for better contrast while scrolling */
    z-index: 2;
    box-shadow: -5px 0 10px rgba(0,0,0,0.2);
}

[data-theme="light"] .sticky-action {
    background: #ffffff !important;
}

th.sticky-action {
    background: #1e293b !important;
}

[data-theme="light"] th.sticky-action {
    background: #f8fafc !important;
}