:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --radius-lg: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Navigation */
.navbar {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 2rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    background: var(--primary);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.brand-text {
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--gray-900);
}

.nav-tabs {
    display: flex;
    gap: 0.5rem;
    background: var(--gray-100);
    padding: 4px;
    border-radius: var(--radius);
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--gray-600);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.nav-tab:hover {
    color: var(--gray-900);
}

.nav-tab.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.btn-refresh {
    background: white;
    border: 1px solid var(--gray-200);
    padding: 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--gray-600);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-refresh:hover {
    background: var(--gray-50);
    color: var(--primary);
    border-color: var(--primary);
}

.btn-refresh.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Views */
.view {
    display: none;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease-in-out;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* KPI Cards */
.kpi-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-icon {
    padding: 0.75rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

.kpi-content h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* Controls */
.controls-section {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.search-box {
    flex: 1;
    min-width: 300px;
    position: relative;
}

.search-box svg {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
}

.search-box input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.filter-select {
    padding: 0.625rem 2rem 0.625rem 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
    font-size: 0.875rem;
    color: var(--gray-700);
    cursor: pointer;
    appearance: none;
    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='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    min-width: 140px;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Table */
.table-section {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-container {
    overflow-x: auto;
    max-height: 70vh;
    position: relative;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--gray-50);
}

th {
    text-align: left;
    padding: 0.875rem 1rem;
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: top;
}

tr:hover td {
    background: var(--gray-50);
}

/* Cell Styles */
.cell-editable {
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 4px;
    border: 1px solid transparent;
    min-height: 2rem;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.cell-editable:hover {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.cell-input, .cell-select {
    width: 100%;
    padding: 0.375rem;
    border: 2px solid var(--primary);
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: inherit;
    background: white;
}

.cell-input:focus, .cell-select:focus {
    outline: none;
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-prospect { background: #f3f4f6; color: #374151; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-onhold { background: #fef3c7; color: #92400e; }
.badge-completed { background: #dbeafe; color: #1e40af; }

.badge-high { background: #fee2e2; color: #991b1b; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-low { background: #e0e7ff; color: #3730a3; }

.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-pending { background: #f3f4f6; color: #374151; }

/* Add these to your existing style.css */

/* Clickable KPI Card */
.kpi-clickable {
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.kpi-clickable:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border: 2px solid var(--warning);
}

.kpi-clickable:active {
    transform: translateY(0);
}

.kpi-clickable::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.3) 50%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
}

.kpi-clickable:hover::after {
    opacity: 1;
}

/* Active Filters Display */
.active-filters {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--warning);
    color: white;
    padding: 0.375rem 0.875rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    animation: fadeIn 0.3s ease;
}

.filter-tag button {
    background: rgba(255,255,255,0.3);
    border: none;
    color: white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    margin-left: 0.25rem;
}

.filter-tag button:hover {
    background: rgba(255,255,255,0.5);
}

/* Company Contact Info in Detail View */
.company-contact-info {
    margin-top: 0.5rem;
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.contact-item svg {
    color: var(--gray-400);
    width: 16px;
    height: 16px;
}

.contact-item a {
    color: var(--primary);
    text-decoration: none;
}

.contact-item a:hover {
    text-decoration: underline;
}

/* Enhanced Company Card */
.company-card {
    position: relative;
}

.company-card-contact {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-100);
    font-size: 0.8125rem;
    color: var(--gray-500);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.company-card-contact span {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

/* Priority Indicators */
.priority-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
}

.priority-high { background: var(--danger); }
.priority-medium { background: var(--warning); }
.priority-low { background: var(--success); }

/* Currency Formatting */
.currency {
    font-family: 'Inter', monospace;
    font-weight: 600;
}

.outstanding {
    color: var(--danger);
}

/* Companies View Styles */
.companies-container {
    max-width: 1200px;
    margin: 0 auto;
}

.companies-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.companies-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

.companies-subtitle {
    color: var(--gray-500);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.companies-search-section {
    margin-bottom: 2rem;
}

.company-search {
    max-width: 500px;
}

.companies-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

.companies-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.company-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.company-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.company-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.company-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.company-service-count {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.company-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-top: 0.5rem;
}

.company-detail {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 2rem;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.detail-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
}

.detail-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--gray-50);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
}

.empty-companies {
    text-align: center;
    padding: 4rem;
    color: var(--gray-500);
}

/* Form Styles */
.form-container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.form-header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--gray-100);
}

.form-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.5rem;
}

.form-subtitle {
    color: var(--gray-500);
    font-size: 0.875rem;
}

.client-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group.span-2 {
    grid-column: span 2;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

input, select, textarea {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    transition: all 0.2s;
    background: white;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

input:invalid:not(:placeholder-shown) {
    border-color: var(--danger);
}

.error-message {
    font-size: 0.75rem;
    color: var(--danger);
    display: none;
}

input:invalid:not(:placeholder-shown) ~ .error-message {
    display: block;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-100);
}

.btn-primary, .btn-secondary {
    padding: 0.625rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}

.btn-secondary:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 80px;
    right: 2rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    animation: slideIn 0.3s ease-out;
    border-left: 4px solid;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.info {
    border-left-color: var(--info);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Loading States */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

.hidden {
    display: none !important;
}

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--gray-500);
    gap: 1rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem;
    color: var(--gray-500);
}

.empty-state svg {
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Highlight Classes */
.highlight-overdue {
    background: #fef2f2 !important;
}

.highlight-priority {
    background: #fffbeb !important;
}

.highlight-followup {
    background: #eff6ff !important;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .navbar {
        padding: 0 1rem;
    }
    
    .brand-text {
        display: none;
    }
    
    .view {
        padding: 1rem;
    }
    
    .kpi-section {
        grid-template-columns: 1fr;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .form-group.span-2 {
        grid-column: span 1;
    }
    
    .controls-section {
        flex-direction: column;
    }
    
    .search-box {
        min-width: 100%;
    }
    
    .filters {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 0.5rem;
    }
    
    .table-container {
        font-size: 0.8125rem;
    }
    
    th, td {
        padding: 0.75rem 0.5rem;
    }
    
    .toast-container {
        left: 1rem;
        right: 1rem;
        top: auto;
        bottom: 1rem;
    }
    
    .toast {
        min-width: auto;
        width: 100%;
    }
    
    .companies-list {
        grid-template-columns: 1fr;
    }
    
    .detail-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
}

/* Date picker indicator */
input[type="date"] {
    position: relative;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.6;
    transition: 0.2s;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}