:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --success-gradient: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    --warning-gradient: linear-gradient(135deg, #f2994a 0%, #f2c94c 100%);
    --danger-gradient: linear-gradient(135deg, #eb3349 0%, #f45c43 100%);
    --sidebar-width: 260px;
}

/* Dark Theme (default) */
body,
body[data-theme="dark"] {
    --dark-bg: #1a1a2e;
    --darker-bg: #16213e;
    --card-bg: rgba(255, 255, 255, 0.05);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-focus-bg: rgba(255, 255, 255, 0.08);
    --table-hover-bg: rgba(255, 255, 255, 0.03);
    --btn-outline-color: var(--text-secondary);
    --auth-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color-scheme: dark;
}

/* Force white text in dark theme - override Bootstrap #212529 */
body[data-theme="dark"],
body[data-theme="dark"] h1,
body[data-theme="dark"] h2,
body[data-theme="dark"] h3,
body[data-theme="dark"] h4,
body[data-theme="dark"] h5,
body[data-theme="dark"] h6,
body[data-theme="dark"] p,
body[data-theme="dark"] span,
body[data-theme="dark"] label,
body[data-theme="dark"] div,
body[data-theme="dark"] .card,
body[data-theme="dark"] .card-header,
body[data-theme="dark"] .card-body,
body[data-theme="dark"] .card-title,
body[data-theme="dark"] .card-text,
body[data-theme="dark"] .text-dark,
body[data-theme="dark"] .nav-link,
body[data-theme="dark"] .list-group-item,
body[data-theme="dark"] i {
    color: #ffffff !important;
}

/* Light Theme */
body[data-theme="light"] {
    --dark-bg: #f0f2f5;
    --darker-bg: #ffffff;
    --card-bg: rgba(255, 255, 255, 0.9);
    --text-primary: #1a1a2e;
    --text-secondary: rgba(26, 26, 46, 0.7);
    --border-color: rgba(0, 0, 0, 0.1);
    --input-bg: rgba(0, 0, 0, 0.02);
    --input-focus-bg: rgba(0, 0, 0, 0.04);
    --table-hover-bg: rgba(0, 0, 0, 0.02);
    --btn-outline-color: #1a1a2e;
    --auth-bg: linear-gradient(135deg, #e8eaf6 0%, #c5cae9 50%, #9fa8da 100%);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--dark-bg);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--darker-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Auth Wrapper */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--auth-bg);
    padding: 20px;
    transition: background 0.3s ease;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: 40px;
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.logo-icon {
    width: 80px;
    height: 80px;
    background: var(--primary-gradient);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 36px;
    color: white;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}

.login-header h2 {
    font-weight: 700;
    margin-bottom: 5px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-floating>.form-control {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 12px;
    height: 56px;
}

.form-floating>.form-control:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
    color: var(--text-primary);
}

.form-floating>label {
    color: #ffffff !important;
    background: transparent !important;
}

.form-floating>label::after {
    background: transparent !important;
}

.form-floating>.form-control:focus~label,
.form-floating>.form-control:not(:placeholder-shown)~label {
    color: #ffffff !important;
    background: transparent !important;
}

.form-floating>.form-control:focus~label::after,
.form-floating>.form-control:not(:placeholder-shown)~label::after {
    background: transparent !important;
}

.btn-login {
    background: var(--primary-gradient);
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.3s ease;
}

.btn-login:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}

/* Sidebar */
.wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--darker-bg);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: all 0.3s ease;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed {
    margin-left: calc(var(--sidebar-width) * -1);
}

.sidebar-header {
    padding: 25px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-header h3 i {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar .nav {
    padding: 20px 0;
    flex: 1;
}

.sidebar .nav-item {
    margin: 4px 12px;
}

.sidebar .nav-link {
    color: var(--text-secondary);
    padding: 12px 16px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.sidebar .nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.sidebar .nav-link.active {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.sidebar .nav-link i {
    font-size: 18px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

/* Content */
.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 20px;
    transition: all 0.3s ease;
}

.sidebar.collapsed+.content {
    margin-left: 0;
}

/* Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    transition: all 0.3s ease;
}

.summary-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 20px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Summary Cards */
.summary-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.summary-card.primary::before {
    background: var(--primary-gradient);
}

.summary-card.success::before {
    background: var(--success-gradient);
}

.summary-card.warning::before {
    background: var(--warning-gradient);
}

.summary-card.danger::before {
    background: var(--danger-gradient);
}

.summary-card .icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    margin-bottom: 16px;
}

.summary-card.primary .icon {
    background: var(--primary-gradient);
}

.summary-card.success .icon {
    background: var(--success-gradient);
}

.summary-card.warning .icon {
    background: var(--warning-gradient);
}

.summary-card.danger .icon {
    background: var(--danger-gradient);
}

.summary-card h3 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.summary-card p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

/* Forms */
.form-control,
.form-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 10px;
    padding: 12px 16px;
    transition: all 0.2s ease;
}

.form-control:focus,
.form-select:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
    color: var(--text-primary);
}

.form-control::placeholder {
    color: var(--text-secondary);
}

.form-label {
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 8px;
}

.form-select option {
    background: var(--darker-bg);
    color: var(--text-primary);
}

/* Buttons */
.btn-primary {
    background: var(--primary-gradient);
    border: none;
    border-radius: 10px;
    padding: 12px 24px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    background: var(--primary-gradient);
}

.btn-success {
    background: var(--success-gradient);
    border: none;
}

.btn-warning {
    background: var(--warning-gradient);
    border: none;
    color: #1a1a2e;
}

.btn-danger {
    background: var(--danger-gradient);
    border: none;
}

.btn-outline-light {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-outline-light:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* Tables */
.table {
    color: var(--text-primary);
}

.table thead th {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-color);
    font-weight: 600;
    padding: 16px;
}

.table tbody td {
    border-color: var(--border-color);
    padding: 14px 16px;
    vertical-align: middle;
}

.table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Modals */
.modal-content {
    background: var(--darker-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 20px 24px;
}

.modal-title {
    font-weight: 600;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 16px 24px;
}

.btn-close {
    filter: invert(1);
}

/* Badges */
.badge {
    padding: 6px 12px;
    border-radius: 6px;
    font-weight: 500;
}

.badge.bg-success {
    background: var(--success-gradient) !important;
}

.badge.bg-warning {
    background: var(--warning-gradient) !important;
    color: #1a1a2e !important;
}

.badge.bg-danger {
    background: var(--danger-gradient) !important;
}

.badge.bg-primary {
    background: var(--primary-gradient) !important;
}

/* Alerts */
.alert {
    border-radius: 12px;
    border: none;
}

/* Radio & Checkbox */
.form-check-input {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: var(--border-color);
}

.form-check-input:checked {
    background-color: #667eea;
    border-color: #667eea;
}

.form-check-label {
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        margin-left: calc(var(--sidebar-width) * -1);
    }

    .sidebar.show {
        margin-left: 0;
    }

    .content {
        margin-left: 0;
    }

    .summary-card {
        margin-bottom: 16px;
    }
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.fade-in {
    animation: fadeIn 0.5s ease forwards;
}

/* Custom Select with Add Button */
.select-with-add {
    display: flex;
    gap: 10px;
}

.select-with-add .form-select {
    flex: 1;
}

.select-with-add .btn {
    flex-shrink: 0;
}

/* File Input */
.form-control[type="file"] {
    padding: 10px;
}

.form-control[type="file"]::file-selector-button {
    background: var(--primary-gradient);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    margin-right: 12px;
    cursor: pointer;
}

/* Invoice Styles */
.invoice-container {
    background: white;
    color: #333;
    padding: 40px;
    border-radius: 16px;
}

.invoice-container h1,
.invoice-container h2,
.invoice-container h3 {
    color: #1a1a2e;
}

.invoice-container .table {
    color: #333;
}

.invoice-container .table thead th {
    background: #f8f9fa;
}

/* Search highlight */
.highlight {
    background: rgba(102, 126, 234, 0.3);
    padding: 2px 4px;
    border-radius: 4px;
}

/* Loading spinner */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
}

/* Conditional fields animation */
.conditional-field {
    transition: all 0.3s ease;
}

.conditional-field.hidden {
    display: none;
}

/* Light Theme Overrides */
body[data-theme="light"] .card {
    background: var(--card-bg);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

body[data-theme="light"] .login-card {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .form-control,
body[data-theme="light"] .form-select {
    background: #ffffff !important;
    border-color: var(--border-color);
    color: #1a1a2e !important;
}

body[data-theme="light"] .form-control:focus,
body[data-theme="light"] .form-select:focus {
    background: #ffffff !important;
    color: #1a1a2e !important;
}

body[data-theme="light"] .form-check-input {
    background-color: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.25);
}

body[data-theme="light"] .form-check-input:checked {
    background-color: #667eea;
    border-color: #667eea;
}

body[data-theme="light"] .form-check-input:checked[type="checkbox"] {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e");
}

body[data-theme="light"] .form-floating>label,
body[data-theme="light"] .form-floating>.form-control:focus~label,
body[data-theme="light"] .form-floating>.form-control:not(:placeholder-shown)~label {
    color: #1a1a2e !important;
}

/* Browser autofill overrides for Light Theme */
body[data-theme="light"] input:-webkit-autofill,
body[data-theme="light"] input:-webkit-autofill:hover,
body[data-theme="light"] input:-webkit-autofill:focus,
body[data-theme="light"] input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px #ffffff inset !important;
    -webkit-text-fill-color: #1a1a2e !important;
    box-shadow: 0 0 0 1000px #ffffff inset !important;
    background-color: #ffffff !important;
    caret-color: #1a1a2e !important;
}

/* Browser autofill overrides for Dark Theme */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.05) inset !important;
    -webkit-text-fill-color: #ffffff !important;
    box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.05) inset !important;
    caret-color: #ffffff !important;
}

body[data-theme="light"] .btn-close {
    filter: none;
}

body[data-theme="light"] .btn-outline-light {
    border-color: var(--border-color);
    color: var(--btn-outline-color);
}

body[data-theme="light"] .btn-outline-light:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: var(--text-primary);
}

body[data-theme="light"] .table thead th {
    background: rgba(0, 0, 0, 0.03);
}

body[data-theme="light"] .table tbody tr:hover {
    background: var(--table-hover-bg);
}

body[data-theme="light"] .sidebar .nav-link.active {
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

body[data-theme="light"] ::-webkit-scrollbar-track {
    background: #f0f2f5;
}

body[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Theme toggle button */
#themeToggle {
    transition: all 0.3s ease;
}

#themeToggle:hover {
    transform: rotate(20deg);
}