/* ─── Reset & Variables ─── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #181a20;
    --bg-tertiary: #1e2028;
    --bg-elevated: #252830;
    --border: #2a2d37;
    --border-light: #353840;

    --text-primary: #eef0f6;
    --text-secondary: #9498a6;
    --text-muted: #6b7080;

    --xvs-color: #f43f5e;
    --xvs-bg: rgba(244, 63, 94, 0.12);
    --zorpro-color: #3b82f6;
    --zorpro-bg: rgba(59, 130, 246, 0.12);
    --garrett-color: #22c55e;
    --garrett-bg: rgba(34, 197, 94, 0.12);

    --accent: #818cf8;
    --accent-bg: rgba(129, 140, 248, 0.12);
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;

    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;

    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);

    --sidebar-width: 360px;
    --detail-width: 380px;

    --font: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* ─── Layout ─── */
body {
    display: flex;
}

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
}

.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* ─── Sidebar Header ─── */
.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    letter-spacing: -0.3px;
}

.logo-icon {
    font-size: 22px;
    color: var(--accent);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-connect {
    background: var(--accent);
    color: white;
    text-decoration: none;
    width: 100%;
    justify-content: center;
    padding: 10px 16px;
}

.btn-connect:hover {
    background: #6366f1;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(129,140,248,0.3);
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
    justify-content: center;
    padding: 10px 16px;
    margin-top: 8px;
}

.btn-primary:hover {
    background: #6366f1;
}

.btn-success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.3);
    width: 100%;
    justify-content: center;
    padding: 10px 16px;
    margin-top: 8px;
}

.btn-success:hover {
    background: rgba(34, 197, 94, 0.25);
}

.qb-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.qb-status.connected .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px rgba(34,197,94,0.5);
}

/* ─── Filters ─── */
.filter-section {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.filter-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chip:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.chip.active {
    background: var(--accent-bg);
    border-color: var(--accent);
    color: var(--accent);
}

.chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.chip-dot.all { background: var(--text-muted); }
.chip-dot.xvs { background: var(--xvs-color); }
.chip-dot.zorpro { background: var(--zorpro-color); }
.chip-dot.garrett { background: var(--garrett-color); }

/* ─── Search ─── */
.search-box {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease;
}

.search-box input:focus {
    border-color: var(--accent);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* ─── Customer List ─── */
.customer-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.customer-list::-webkit-scrollbar {
    width: 4px;
}

.customer-list::-webkit-scrollbar-track {
    background: transparent;
}

.customer-list::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 4px;
}

.customer-card {
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.customer-card:hover {
    background: var(--bg-elevated);
    border-color: var(--border-light);
    transform: translateX(2px);
}

.customer-card.active {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.customer-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.customer-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.customer-card-company {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.needs-service-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
    white-space: nowrap;
}

.customer-card-products {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}

.product-tag {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.product-tag.xvs {
    background: var(--xvs-bg);
    color: var(--xvs-color);
}

.product-tag.zorpro {
    background: var(--zorpro-bg);
    color: var(--zorpro-color);
}

.product-tag.garrett {
    background: var(--garrett-bg);
    color: var(--garrett-color);
}

/* ─── Loading / Empty ─── */
.loading-state, .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Stats Bar ─── */
.stats-bar {
    display: flex;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    gap: 24px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ─── Detail Panel ─── */
.detail-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: var(--detail-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 20;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.detail-panel.open {
    transform: translateX(0);
}

.detail-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    z-index: 1;
}

.detail-close:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

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

.detail-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
    padding-right: 36px;
}

.detail-company {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.detail-products {
    display: flex;
    gap: 5px;
    margin-top: 10px;
}

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.detail-body::-webkit-scrollbar {
    width: 4px;
}

.detail-body::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 4px;
}

.detail-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 0;
}

.info-row svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.info-row-plain {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: 6px 0;
}

.info-row-plain .label {
    color: var(--text-muted);
}

.info-row-plain span:last-child {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 12px;
}

.address-text {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ─── Service Controls ─── */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    margin-bottom: 10px;
}

.switch {
    position: relative;
    width: 40px;
    height: 22px;
}

.switch input { display: none; }

.slider {
    position: absolute;
    inset: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: 22px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    top: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.switch input:checked + .slider {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--danger);
}

.switch input:checked + .slider::before {
    transform: translateX(18px);
    background: var(--danger);
}

.date-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.date-row label {
    font-size: 12px;
    color: var(--text-muted);
}

.date-row input {
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
}

.date-row input:focus {
    border-color: var(--accent);
}

/* ─── Notes ─── */
textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    resize: vertical;
    outline: none;
    min-height: 80px;
    transition: border-color 0.15s ease;
}

textarea:focus {
    border-color: var(--accent);
}

textarea::placeholder {
    color: var(--text-muted);
}

/* ─── Toast Notification ─── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    border-color: rgba(34,197,94,0.3);
}

/* ─── Google Maps Overrides ─── */
.gm-style .gm-style-iw-c {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    padding: 0 !important;
    box-shadow: var(--shadow-lg) !important;
}

.gm-style .gm-style-iw-d {
    overflow: hidden !important;
}

.gm-style .gm-style-iw-tc::after {
    background: var(--bg-secondary) !important;
}

.gm-style .gm-ui-hover-effect {
    display: none !important;
}

.map-info-window {
    padding: 12px 14px;
    min-width: 200px;
}

.map-info-window h3 {
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.map-info-window p {
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-secondary);
    margin: 2px 0;
}

.map-info-window .iw-products {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
    .sidebar {
        width: 280px;
    }
    .detail-panel {
        width: 320px;
    }
}

@media (max-width: 600px) {
    body {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: 40vh;
    }
    .map-container {
        height: 60vh;
    }
    .detail-panel {
        width: 100%;
    }
}

/* ─── Import Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    width: 480px;
    max-width: 95vw;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    border-radius: 6px;
    transition: background 0.15s;
}
.modal-close:hover { background: var(--bg-elevated); }

.modal-body {
    padding: 20px 24px 24px;
}

.modal-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    margin-bottom: 16px;
}

.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--accent, #6366f1);
    background: rgba(99,102,241,0.05);
}

.upload-zone svg { margin-bottom: 12px; opacity: 0.6; }
.upload-zone p { font-size: 13px; color: var(--text-secondary); margin: 4px 0; }
.upload-hint { font-size: 11px !important; color: var(--text-muted, #555) !important; }

.link-text {
    color: var(--accent, #6366f1);
    cursor: pointer;
    text-decoration: underline;
}

.import-progress {
    margin-bottom: 12px;
}

.progress-bar-wrap {
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar {
    height: 100%;
    background: var(--accent, #6366f1);
    border-radius: 3px;
    transition: width 0.4s ease;
    width: 0%;
}

#progressText {
    font-size: 12px;
    color: var(--text-secondary);
}

.import-result {
    padding: 12px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 12px;
}

.import-result.success {
    background: rgba(34,197,94,0.1);
    border: 1px solid rgba(34,197,94,0.25);
    color: #22c55e;
}

.import-result.error {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.25);
    color: #ef4444;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-outline:hover { background: var(--bg-elevated); }

/* ─── Business Badge ─── */
.business-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-left: 4px;
}

.business-badge.pti {
    background: rgba(99,102,241,0.15);
    color: #818cf8;
    border: 1px solid rgba(99,102,241,0.3);
}

.business-badge.zorpro {
    background: rgba(245,158,11,0.15);
    color: #f59e0b;
    border: 1px solid rgba(245,158,11,0.3);
}

/* ─── Edit/Delete Actions in Detail Header ─── */
.detail-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    gap: 5px;
}

.btn-danger {
    background: rgba(239,68,68,0.15);
    color: #ef4444;
    border: 1px solid rgba(239,68,68,0.3);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-danger:hover { background: rgba(239,68,68,0.25); }

/* ─── Edit Form Grid ─── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group-full {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus {
    border-color: var(--accent);
}

/* ─── Small modal ─── */
.modal-sm {
    max-width: 400px;
}
