@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* IntegraSell brand */
    --brand-violet: #0ea5e9;
    --brand-lavender: #38bdf8;
    --brand-deep: #0c1a2e;

    /* Primary — ocean blue */
    --primary: #0284c7;
    --primary-dark: #0369a1;
    --primary-light: #e0f2fe;
    --primary-mid: #38bdf8;

    /* Semantic */
    --success: #10b981;
    --danger: #ef4444;

    /* Neutrals */
    --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;

    --bg: #ffffff;
    --bg-page: #f0f9ff;

    --radius: 10px;
    --page-padding: 1rem;
    --shadow: 0 1px 4px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 20px rgba(2,132,199,0.1), 0 2px 6px rgba(0,0,0,0.06);
    --shadow-lg: 0 12px 40px rgba(2,132,199,0.18);

    /* Semantic aliases — resolve through the gray scale so dark mode remapping is automatic */
    --text-primary: var(--gray-800);
    --text-muted: var(--gray-500);
    --border-color: var(--gray-200);
}

/* Dark mode */
[data-theme="dark"] {
    --gray-50: #0c1a2e;
    --gray-100: #0f2233;
    --gray-200: #163347;
    --gray-300: #1e4560;
    --gray-400: #4a8bb5;
    --gray-500: #7ab3d0;
    --gray-600: #a8d0e6;
    --gray-700: #cce4f0;
    --gray-800: #e4f2f9;
    --gray-900: #f0f9ff;
    --bg: #0f2233;
    --bg-page: #0c1a2e;
    --primary: #38bdf8;
    --primary-dark: #7dd3fc;
    --primary-light: #163347;
    --shadow: 0 1px 4px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.4);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--gray-800);
    background: var(--bg-page);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: contain;
}

/* iOS Safari: prevent zoom-on-focus by ensuring inputs are >= 16px on mobile */
@media (max-width: 767px) {
    input, select, textarea {
        font-size: 16px;
    }
}

/* App layout */
.app-layout {
    display: grid;
    grid-template-columns: auto 1fr;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 220px;
    background: linear-gradient(180deg, #0c1a2e 0%, #0f2233 45%, #0d2b42 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    overflow: hidden;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 200;
    box-shadow: 2px 0 20px rgba(0,0,0,0.25);
}

[data-theme="dark"] .sidebar {
    background: linear-gradient(180deg, #060f1a 0%, #0c1a2e 45%, #0d2234 100%);
}

.sidebar.collapsed {
    width: 60px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    height: 56px;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    white-space: nowrap;
    border-bottom: 1px solid rgba(176, 171, 255, 0.15);
    background: rgba(0,0,0,0.15);
}

.sidebar-header svg {
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.75rem 0.625rem;
}

.sidebar-footer {
    border-top: 1px solid rgba(176, 171, 255, 0.12);
    padding: 0.625rem 0.625rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    color: rgba(176, 171, 255, 0.75);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s, border-left-color 0.15s;
    white-space: nowrap;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    cursor: pointer;
    width: 100%;
    font-family: inherit;
}

.sidebar-link:hover {
    background: rgba(176, 171, 255, 0.1);
    color: rgba(255,255,255,0.95);
}

.sidebar-link.active {
    background: rgba(176, 171, 255, 0.14);
    color: #fff;
    border-left-color: var(--brand-lavender);
    font-weight: 600;
}

/* Per-section icon colour when active */
.sidebar-nav .sidebar-link:nth-child(1).active .sidebar-icon { color: #c4b5fd; }
.sidebar-nav .sidebar-link:nth-child(2).active .sidebar-icon { color: #67e8f9; }
.sidebar-nav .sidebar-link:nth-child(3).active .sidebar-icon { color: #6ee7b7; }
.sidebar-nav .sidebar-link:nth-child(4).active .sidebar-icon { color: #fcd34d; }
.sidebar-nav .sidebar-link:nth-child(5).active .sidebar-icon { color: #fda4af; }

/* Subtle hover icon tint per section */
.sidebar-nav .sidebar-link:nth-child(1):hover .sidebar-icon { color: #c4b5fd; }
.sidebar-nav .sidebar-link:nth-child(2):hover .sidebar-icon { color: #67e8f9; }
.sidebar-nav .sidebar-link:nth-child(3):hover .sidebar-icon { color: #6ee7b7; }
.sidebar-nav .sidebar-link:nth-child(4):hover .sidebar-icon { color: #fcd34d; }
.sidebar-nav .sidebar-link:nth-child(5):hover .sidebar-icon { color: #fda4af; }

.sidebar-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-label {
    opacity: 1;
    width: auto;
    overflow: hidden;
    transition: opacity 0.2s ease, width 0.2s ease;
}

.sidebar.collapsed .sidebar-label {
    opacity: 0;
    width: 0;
}

/* Header bar */
.header {
	display: flex;
	align-items: center;
	height: 56px;
	padding: 0 1.25rem;
	background: var(--bg);
	border-bottom: 1px solid var(--gray-200);
	box-shadow: 0 1px 0 rgba(124,111,255,0.06);
	position: sticky;
	top: 0;
	z-index: 100;
	flex-shrink: 0;
	gap: 0.5rem;
}

.header-spacer {
    flex: 1;
}

.user-header-wrap {
    position: relative;
    flex-shrink: 0;
}

.header-username {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.85rem;
    color: var(--gray-600);
    font-weight: 500;
    background: none;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 0;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.header-username:hover,
.header-username.active {
    background: var(--primary-light, rgba(99,102,241,0.08));
    color: var(--primary, #6366f1);
}

.user-header-popup {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius, 6px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);
    padding: 0.75rem 1rem;
    z-index: 500;
    white-space: nowrap;
}

[data-theme="dark"] .user-header-popup {
    border-color: var(--gray-700);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.user-popup-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

.user-popup-role {
    font-size: 0.78rem;
    color: var(--gray-500);
    margin-top: 0.15rem;
}

@media (max-width: 600px) {
    .user-header-popup {
        position: fixed;
        top: 60px;
        right: 0.75rem;
        left: auto;
        white-space: normal;
    }
}

.sidebar-toggle,
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--gray-600);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sidebar-toggle:hover,
.theme-toggle:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

/* Cart button in header */
.cart-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 36px;
    height: 32px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--gray-500);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.cart-btn:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

.cart-btn.has-items {
    color: var(--primary);
}

.cart-badge {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    pointer-events: none;
}

/* Cart rows on home page */
.cart-row:hover {
    background: var(--gray-50);
}

.cart-open-arrow {
    font-size: 1.4rem;
    color: var(--gray-400);
    line-height: 1;
}

.draft-row-code {
    color: var(--gray-400);
    font-size: 0.8rem;
}

/* Main area */
.main-area {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	max-height: 100vh;
	overflow-x: hidden;
	overflow-y: auto;
}

.main-content {
    flex: 1;
    background: var(--bg-page);
}

/* Mobile menu — fixed left-drawer overlay */
.mobile-menu-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1999;
    background: rgba(0, 0, 0, 0.45);
}
.mobile-menu-backdrop.open {
    display: block;
}
.mobile-menu {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 300px;
    max-width: 90vw;
    z-index: 2000;
    background: var(--bg);
    border-left: 1px solid var(--gray-200);
    overflow-y: auto;
    padding-bottom: 1rem;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
    flex-direction: column;
}
.mobile-menu.open {
    display: flex;
}
.mobile-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    min-height: 56px;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.mobile-menu-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-600);
    font-size: 1.25rem;
    padding: 0.3rem 0.5rem;
    line-height: 1;
    border-radius: var(--radius);
}
.mobile-menu-close:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.mobile-menu-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s;
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    font-family: inherit;
}

.mobile-menu-link:hover {
    background: var(--gray-100);
}

.mobile-menu-link.active {
    color: var(--primary);
    background: var(--primary-light);
    font-weight: 600;
}

/* Utility classes */
.desktop-only {
    display: inline-flex;
}

.mobile-only {
    display: none;
}

.mobile-header-logo {
    display: none;
    height: 32px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Layout */
.page {
    max-width: 820px;
    margin: 0 auto;
    padding: 2rem;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 0.375rem;
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--gray-500);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

/* Card */
.card {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: box-shadow 0.2s;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-title::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 14px;
    background: linear-gradient(180deg, var(--primary) 0%, var(--brand-lavender) 100%);
    border-radius: 2px;
    flex-shrink: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(124,111,255,0.35);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, #075985 100%);
    box-shadow: 0 4px 12px rgba(2,132,199,0.4);
}

.btn-primary:disabled {
    background: var(--gray-300);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(239,68,68,0.3);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
    box-shadow: 0 4px 12px rgba(239,68,68,0.4);
}

.btn-danger:disabled {
    background: var(--gray-300);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.btn-success {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(22,163,74,0.3);
}
.btn-success:hover {
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
    box-shadow: 0 4px 12px rgba(22,163,74,0.4);
}
.btn-success:disabled {
    background: var(--gray-300);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* Purple — matches task-badge--done (#e0e7ff / #3730a3 palette) */
.btn-purple {
    background: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.btn-purple:hover {
    background: linear-gradient(135deg, #3730a3 0%, #312e81 100%);
    box-shadow: 0 4px 12px rgba(79,70,229,0.4);
}
.btn-purple:disabled {
    background: var(--gray-300);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.btn-ghost {
    background: var(--gray-100);
    color: var(--gray-700);
    box-shadow: none;
}

.btn-ghost:hover {
    background: var(--gray-200);
}

[data-theme="dark"] .btn-ghost {
    background: var(--gray-700);
    color: var(--gray-200);
}

[data-theme="dark"] .btn-ghost:hover {
    background: var(--gray-600);
}

/* Sync status */
.sync-status {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    display: none;
}

.sync-status.visible {
    display: block;
}

.sync-status.success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.sync-status.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.sync-status.loading {
    background: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid #bfdbfe;
}

/* ── Lightbox ───────────────────────────────────────────────────────────── */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    animation: lightbox-fade-in 0.15s ease;
}

@keyframes lightbox-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.lightbox-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9001;
    transition: background 0.15s;
}

.lightbox-close:hover {
    background: rgba(255,255,255,0.3);
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 85vh;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}

.lightbox-img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: lightbox-fade-in 0.2s ease;
}

.lightbox-zoom-controls {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 2rem;
    padding: 0.35rem 0.6rem;
    z-index: 9001;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.lightbox-zoom-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

.lightbox-zoom-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.28);
}

.lightbox-zoom-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.lightbox-zoom-pct {
    background: none;
    border: none;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 3.2rem;
    text-align: center;
    cursor: pointer;
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
    letter-spacing: 0.01em;
    transition: background 0.15s;
}

.lightbox-zoom-pct:hover {
    background: rgba(255,255,255,0.15);
}

.lightbox-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    min-height: 120px;
    color: #fff;
}

/* Zoomable cursor on clickable product images */
.product-img-zoomable {
    cursor: zoom-in;
}

/* Image sync progress bar */
.image-sync-progress {
    padding: 0.5rem 0;
}

.image-sync-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 0.35rem;
}

.image-sync-bar-track {
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
}

.image-sync-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.2s ease;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Search */
.search-container {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s;
    background: var(--bg);
    color: var(--gray-800);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(2,132,199,0.15);
}

.search-input::placeholder {
    color: var(--gray-400);
}

.search-hint {
    font-size: 0.8rem;
    color: var(--gray-400);
    margin-top: 0.375rem;
}

/* Dropdown */
.dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-height: 320px;
    overflow-y: auto;
    z-index: 50;
}

.dropdown-up {
    top: auto;
    bottom: calc(100% + 4px);
}

.dropdown-item {
    padding: 0.625rem 1rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.1s;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: var(--primary-light);
}

.dropdown-item-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.dropdown-item-code {
    font-size: 0.8rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
}

/* Customer detail */
.customer-detail {
    margin-top: 1.5rem;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.detail-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.detail-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.detail-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--gray-900);
}

.detail-code {
    font-size: 0.85rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.detail-field {
    padding: 0.75rem;
    background: var(--gray-50);
    border-radius: var(--radius);
}

.detail-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
}

.detail-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
}

.detail-value.positive {
    color: var(--success);
}

.detail-value.negative {
    color: var(--danger);
}

/* Offline banner */
.offline-banner {
    background: linear-gradient(90deg, #fef3c7, #fde68a);
    color: #78350f;
    text-align: center;
    padding: 0.5rem 1rem;
    font-size: 0.825rem;
    font-weight: 600;
    display: none;
    letter-spacing: 0.01em;
}

.offline-banner.visible {
    display: block;
}

/* No data message */
.no-data {
    text-align: center;
    padding: 2rem;
    color: var(--gray-400);
}

/* Stats row */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    padding: 1.25rem 1.25rem 1rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--brand-lavender) 100%);
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 0.375rem;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: url('/images/login-bg.jpg') center center / cover no-repeat;
    padding: 1.5rem;
    position: relative;
}

.login-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, rgba(12,26,46,0.72) 0%, rgba(15,34,51,0.60) 50%, rgba(5,46,22,0.55) 100%);
}

.login-panel {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 400px;
    gap: 2rem;
}

.login-logo-box {
    background: transparent;
    padding: 0 1rem;
    width: 100%;
    text-align: center;
}

.login-logo {
    height: 72px;
    width: auto;
    display: block;
    margin: 0 auto;
}

.login-card {
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.45), 0 4px 20px rgba(0,0,0,0.25);
    padding: 2.25rem 2.5rem 2.5rem;
    width: 100%;
}

.login-card-header {
    margin-bottom: 1.75rem;
    text-align: center;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--gray-500);
    font-size: 0.875rem;
    margin-bottom: 0;
}

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.375rem;
}

.form-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.95rem;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--bg);
    color: var(--gray-800);
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(2,132,199,0.15);
}
[data-theme="dark"] input[type="date"].form-input,
[data-theme="dark"] input[type="datetime-local"].form-input {
    color: var(--gray-800);
}
[data-theme="dark"] input[type="date"].form-input::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="datetime-local"].form-input::-webkit-calendar-picker-indicator {
    filter: invert(1) brightness(0.8);
    opacity: 0.75;
    cursor: pointer;
}

.login-btn {
    width: 100%;
    justify-content: center;
    margin-top: 0.75rem;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    letter-spacing: 0.01em;
    border-radius: 10px;
}

.login-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}
[data-theme="dark"] .login-card {
    background: var(--gray-100);
    box-shadow: 0 24px 64px rgba(0,0,0,0.7), 0 4px 20px rgba(0,0,0,0.5);
}
[data-theme="dark"] .login-title {
    color: var(--gray-800);
}
[data-theme="dark"] .login-subtitle {
    color: var(--gray-600);
}
[data-theme="dark"] .form-label {
    color: var(--gray-700);
}
[data-theme="dark"] .login-error {
    background: #3b0a0a;
    color: #fca5a5;
    border-color: #7f1d1d;
}

/* Dashboard layout */
.page-wide {
    max-width: none;
    padding: var(--page-padding);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

.dashboard-card {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    overflow: hidden;
}

.dashboard-card--full {
    grid-column: 1 / -1;
}

.dashboard-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    background: linear-gradient(90deg, var(--gray-50) 0%, rgba(237,233,255,0.5) 100%);
}

.dashboard-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-700);
}
[data-theme="dark"] .dashboard-card-header {
    background: linear-gradient(90deg, var(--gray-100) 0%, var(--gray-200) 100%);
}
[data-theme="dark"] .dashboard-card-title {
    color: var(--gray-800);
}

.dashboard-card-action {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    border: 1px solid var(--primary);
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.dashboard-card-action:hover {
    background: var(--primary);
    color: #fff;
}

.dashboard-card-body {
    padding: 1.25rem;
}

.dashboard-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    padding: 2rem;
    color: var(--gray-400);
    font-size: 0.9rem;
}

.dashboard-spinner {
    border-color: rgba(26, 86, 219, 0.2);
    border-top-color: var(--primary);
}

.dashboard-error {
    padding: 1.5rem;
    text-align: center;
    color: var(--danger);
    font-size: 0.875rem;
    background: #fef2f2;
    border-radius: var(--radius);
}

.dashboard-stale {
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
}

/* Dashboard tables */
.dashboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.dashboard-table thead th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
}

.dashboard-table tbody td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}

.dashboard-table tbody tr:last-child td {
    border-bottom: none;
}

.dashboard-table tbody tr:hover {
    background: var(--gray-50);
}

/* Promotion cards */
.promo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.promo-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    position: relative;
    transition: box-shadow 0.15s;
}

.promo-card:hover {
    box-shadow: var(--shadow-md);
}

.promo-badge {
    display: inline-block;
    background: var(--danger);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    letter-spacing: 0.02em;
}

.promo-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.375rem;
}

.promo-desc {
    font-size: 0.825rem;
    color: var(--gray-500);
    line-height: 1.45;
    margin-bottom: 0.625rem;
}

.promo-dates {
    font-size: 0.75rem;
    color: var(--gray-400);
    font-weight: 500;
}

/* Prospect summary */
.prospect-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.prospect-stat {
    background: linear-gradient(135deg, var(--primary-light) 0%, rgba(176,171,255,0.2) 100%);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    border: 1px solid rgba(124,111,255,0.15);
}

.prospect-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

.prospect-stat-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.125rem;
}

.prospect-status {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

.prospect-status--new {
    background: #eff6ff;
    color: #1d4ed8;
}

.prospect-status--contacted {
    background: #fefce8;
    color: #a16207;
}

.prospect-status--qualified {
    background: #f0fdf4;
    color: #15803d;
}

.prospect-status--converted {
    background: #ecfdf5;
    color: #047857;
}

/* Today's Tasks widget */
.task-stats-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.875rem;
    flex-wrap: wrap;
}

.task-stat-chip {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: var(--gray-100);
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
}

.task-stat-chip--pending {
    background: #fef9c3;
    color: #854d0e;
    border-color: #fde68a;
}

.task-stat-chip--done {
    background: #e0e7ff;
    color: #3730a3;
    border-color: #c7d2fe;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 320px;
    overflow-y: auto;
}

.task-card {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: var(--bg);
    flex-shrink: 0;
}

.task-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    text-transform: uppercase;
}

.task-body {
    flex: 1;
    min-width: 0;
}

.task-subject-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

.task-subject {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-customer {
    font-size: 0.8rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.3rem;
}

.task-meta {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--gray-400);
}

.task-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.task-badge--pending {
    background: #fef9c3;
    color: #a16207;
}

/* Use the same purple as apt-status-badge--complete so "Done" on Today's Tasks
   doesn't visually clash with the green PhoneCall colour. */
.task-badge--done {
    background: #e0e7ff;
    color: #3730a3;
}

.appt-type-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.appt-type-badge--phone {
    background: #dcfce7;
    color: rgb(22, 163, 74);
}

.appt-type-badge--visit {
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    color: var(--primary);
}

.task-empty {
    text-align: center;
    padding: 2rem;
    color: var(--gray-400);
    font-size: 0.875rem;
}

.task-card--link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.task-card--link:hover {
    background: var(--gray-50);
    border-color: var(--primary-mid);
}

.task-card--done-true {
    opacity: 0.6;
}

.task-toggle-btn {
    flex-shrink: 0;
    align-self: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    background: transparent;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.task-toggle-btn--pending {
    color: #f59e0b;
}

.task-toggle-btn--pending:hover {
    background: #f59e0b;
    color: #fff;
}

.task-toggle-btn--done {
    color: var(--gray-500);
}

.task-toggle-btn--done:hover {
    background: var(--gray-200);
    color: var(--gray-700);
}

/* ── Play button on appointment cards ───────────────────────────────────────── */
.task-play-btn {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: 1px solid var(--gray-300);
    background: #fff;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
/* VISIT = primary blue */
.task-play-btn--visit {
    color: var(--primary);
    border-color: var(--primary);
}
.task-play-btn--visit:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    transform: scale(1.08);
}
/* PHONECALL = green */
.task-play-btn--phone {
    color: #16a34a;
    border-color: #16a34a;
}
.task-play-btn--phone:hover {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
    transform: scale(1.08);
}

/* ── Show Overdue toggle button ─────────────────────────────────────────────── */
.task-overdue-toggle {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.65rem;
    border-radius: 1rem;
    border: 1px solid var(--gray-300);
    background: #fff;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.task-overdue-toggle:hover {
    border-color: #f59e0b;
    color: #92400e;
}
.task-overdue-toggle--on {
    background: #fffbeb;
    border-color: #f59e0b;
    color: #92400e;
}

/* ── AppointmentDetailsModal (.adm-*) ───────────────────────────────────────── */
.adm-overlay {
    z-index: 1100;
}
.adm-panel {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.adm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    gap: 0.75rem;
}
.adm-header-left {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}
.adm-type-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.adm-customer-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.adm-type-label {
    font-size: 0.75rem;
    font-weight: 500;
}
.adm-body {
    padding: 0.75rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.adm-row {
    display: flex;
    gap: 0.75rem;
    font-size: 0.875rem;
    align-items: baseline;
}
.adm-label {
    color: var(--text-muted);
    font-size: 0.78rem;
    min-width: 5rem;
    flex-shrink: 0;
}
.adm-value {
    color: var(--text-primary);
    font-weight: 500;
}
.adm-link {
    color: var(--primary);
    text-decoration: none;
}
.adm-link:hover { text-decoration: underline; }
.adm-footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--gray-200);
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ── NoteDetailModal / TaskDetailModal (.ndm-*) ─────────────────────────────── */
.ndm-overlay {
    z-index: 1100;
}
.ndm-panel {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ndm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    gap: 0.75rem;
}
.ndm-header-left {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
    flex: 1;
}
.ndm-type-dot {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ndm-type-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.ndm-date {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}
.ndm-body {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-height: 60vh;
    overflow-y: auto;
}
.ndm-loading {
    display: flex;
    justify-content: center;
    padding: 1rem 0;
}
.ndm-error {
    color: var(--danger);
    font-size: 0.875rem;
}
.ndm-subject {
    font-weight: 600;
    font-size: 0.975rem;
    color: var(--text-primary);
    line-height: 1.4;
}
.ndm-body-text {
    font-size: 0.875rem;
    color: var(--gray-600);
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.ndm-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.ndm-meta-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
}
.ndm-meta-label {
    color: var(--text-muted);
    font-size: 0.78rem;
    min-width: 4.5rem;
    flex-shrink: 0;
}
.ndm-meta-value {
    color: var(--text-primary);
    font-weight: 500;
}
.ndm-footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--gray-200);
    justify-content: flex-end;
}

.appt-body {
    display: flex;
    flex-direction: column;
}

.appt-body .task-list {
    max-height: 600px; /* ~6 call cards */
    overflow-y: auto;
}

.appt-count {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
}

.appt-count-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-800);
    line-height: 1;
}

.appt-count-label {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.callplan-filter-tabs {
    display: flex;
    gap: 0.3rem;
}

.callplan-filter-tab {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    border: 1.5px solid var(--gray-200);
    background: var(--bg);
    color: var(--gray-600);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
}

.callplan-filter-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.callplan-filter-tab--active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.route-map {
    height: 300px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--gray-200);
    position: relative;
    z-index: 0;
}

.route-marker {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    line-height: 1;
}

/* Responsive */
@media (max-width: 900px) {

    .prospect-stats {
        grid-template-columns: 1fr;
    }

    .page-wide {
        padding: 1rem;
    }
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .app-layout {
        grid-template-columns: 1fr;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: inline-flex !important;
    }

    .mobile-header-logo { display: block; }

    /* Mobile header: dark background */
    .header {
        background: linear-gradient(90deg, #0c1a2e 0%, #0f2233 100%);
        border-bottom: 1px solid rgba(255,255,255,0.08);
        box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    }
    /* Adapt interactive element colours for dark header on mobile */
    .header .sidebar-toggle,
    .header .theme-toggle {
        color: rgba(255,255,255,0.7);
    }
    .header .sidebar-toggle:hover,
    .header .theme-toggle:hover {
        background: rgba(255,255,255,0.1);
        color: #fff;
    }
    .header .cart-btn {
        color: rgba(255,255,255,0.65);
    }
    .header .cart-btn:hover,
    .header .cart-btn.has-items {
        background: rgba(56,189,248,0.15);
        color: #38bdf8;
    }
    .header .cart-btn.has-items:hover {
        background: rgba(56,189,248,0.25);
    }
    .header .header-username {
        color: rgba(255,255,255,0.7);
    }
    .header .header-username:hover,
    .header .header-username.active {
        background: rgba(255,255,255,0.1);
        color: #fff;
    }
    .header .customer-pill {
        background: rgba(255,255,255,0.08);
        border-color: rgba(255,255,255,0.18);
        color: rgba(255,255,255,0.85);
    }
    .header .customer-pill:hover,
    .header .customer-pill.has-customer {
        background: rgba(56,189,248,0.2);
        border-color: #38bdf8;
        color: #38bdf8;
    }

    /* Mobile header: logo left, customer centered, hamburger right */
    .header .cart-btn,
    .header .sync-header-wrap,
    .header .user-header-wrap {
        display: none !important;
    }
    /* Center without transform so position:fixed on the dropdown still uses the viewport */
    .header .header-customer {
        position: absolute;
        left: 0;
        right: 0;
        margin: 0 auto;
        width: fit-content;
        z-index: 1;
    }
    .hamburger-btn {
        margin-left: auto;
    }

    /* On mobile, show only the customer code when a customer is selected */
    .customer-pill.has-customer .customer-pill-name { display: none; }
    .customer-pill.has-customer .customer-pill-code--mobile-primary {
        display: inline;
        font-size: 0.85rem;
        font-family: inherit;
        opacity: 1;
        font-weight: 600;
    }
}

@media (max-width: 600px) {
    .page {
        padding: 1rem;
    }
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

/* Map page layout */
.map-page-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* Title sits inside the edge-to-edge container so give it page-level padding */
.map-page-container > .page-title {
    padding: var(--page-padding) var(--page-padding) 0;
    flex-shrink: 0;
}

.map-topbar {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 1rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--bg);
    flex-shrink: 0;
}

.map-topbar-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-800);
}

.map-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    z-index: 10;
}

.map-main {
    flex: 1;
    position: relative;
    min-height: 0;
}

.map-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
}

/* Fix Leaflet container in dark mode */
[data-theme="dark"] .leaflet-container {
    background: #1f2937;
}

[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip {
    background: var(--bg);
    color: var(--gray-800);
}

[data-theme="dark"] .leaflet-control-zoom a {
    background: var(--bg);
    color: var(--gray-800);
}

[data-theme="dark"] .leaflet-control-attribution {
    background: rgba(31, 41, 55, 0.8);
    color: var(--gray-400);
}

.map-sidebar {
    width: 360px;
    min-width: 360px;
    background: var(--bg);
    border-left: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.28s ease, min-width 0.28s ease, border-left-width 0.28s ease;
    flex-shrink: 0;
}

.map-sidebar.sidebar-closed {
    width: 0;
    min-width: 0;
    border-left-width: 0;
}

.map-sidebar-inner {
    width: 360px;
    min-width: 360px;
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.map-results-count {
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: var(--gray-500);
    text-align: center;
}

/* Slider styling */
.slider-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.map-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--gray-200);
    outline: none;
}

.map-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.map-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.map-slider:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.map-slider:disabled::-webkit-slider-thumb {
    cursor: not-allowed;
}

.slider-value {
    min-width: 50px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
    text-align: right;
}

.btn-location {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    background: var(--primary-light);
    color: var(--primary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s;
}

.btn-location:hover {
    background: var(--primary);
    color: #fff;
}

.location-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.location-status.success {
    background: #f0fdf4;
    color: #166534;
}

.location-status.error {
    background: #fef2f2;
    color: #991b1b;
}

/* Customer list in sidebar */
.map-customer-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.map-customer-card {
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.875rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.map-customer-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.map-customer-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.125rem;
}

.map-customer-code {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
    margin-bottom: 0.25rem;
}

.map-customer-address {
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

.map-customer-contact {
    font-size: 0.8rem;
    margin-bottom: 0.125rem;
}

.map-customer-contact a {
    color: var(--primary);
    text-decoration: none;
}

.map-customer-contact a:hover {
    text-decoration: underline;
}

/* Map loading and error states */
.map-loading,
.map-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    height: 100%;
    padding: 2rem;
    font-size: 0.9rem;
}

.map-loading {
    color: var(--gray-400);
}

.map-error {
    color: var(--danger);
    background: #fef2f2;
}

/* Map popup styling */
.map-popup {
    min-width: 180px;
}

.map-popup-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--gray-200);
}

.map-popup-field {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

.map-popup-field a {
    color: var(--primary);
    text-decoration: none;
}

.map-popup-field a:hover {
    text-decoration: underline;
}

.map-popup-address {
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-top: 0.25rem;
}

.map-popup-date {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.375rem;
    margin-bottom: 0.375rem;
}

.map-popup-addresses {
    margin-top: 0.5rem;
    padding-top: 0.375rem;
    border-top: 1px solid var(--gray-200);
}

.map-popup-address-row {
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.map-popup-address-row:last-child {
    border-bottom: none;
}

.map-popup-address-row--default .map-popup-address-label {
    color: var(--primary);
}

.map-popup-address-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.map-popup-address-default-badge {
    font-size: 0.65rem;
    background: var(--primary-light, #eff6ff);
    color: var(--primary);
    border-radius: 3px;
    padding: 0 0.3rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.map-popup-address-line {
    font-size: 0.75rem;
    color: var(--gray-600);
}

.map-popup-navigate-link {
    font-size: 0.72rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    align-self: flex-start;
}

.map-popup-navigate-link:hover {
    text-decoration: underline;
}

.map-popup-btn-navigate {
    background: var(--gray-50);
    color: var(--primary);
    border: 1.5px solid var(--primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.map-popup-btn-navigate:hover {
    background: var(--primary-light, #eff6ff);
}

/* Leaflet popup customization */
.leaflet-pane {
    z-index: 4 !important;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.leaflet-popup-content {
    margin: 12px 14px;
}

/* Responsive map layout */
@media (max-width: 768px) {
    .map-body {
        position: relative;
        overflow: hidden;
    }

    .map-sidebar {
        position: absolute !important;
        right: 0;
        top: 0;
        bottom: 0;
        width: 90vw !important;
        min-width: 90vw !important;
        z-index: 900; /* above all Leaflet layers (max 800) */
        transform: translateX(100%);
        transition: transform 0.28s ease !important;
        border-left: 1px solid var(--gray-200) !important;
        box-shadow: -4px 0 24px rgba(0,0,0,0.12);
    }

    .map-sidebar.sidebar-open {
        transform: translateX(0) !important;
    }

    .map-sidebar.sidebar-closed {
        transform: translateX(100%) !important;
    }

    .map-sidebar-inner {
        width: 90vw;
        min-width: 90vw;
    }

    /* scoped to map-body so callplan backdrop is unaffected */
    .map-body .cp-sidebar-backdrop {
        display: block;
        position: absolute;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 899;
    }
}

/* ================================
   Call Plan Page Styles
   ================================ */

/* Title sits inside the edge-to-edge container so give it page-level padding */
.callplan-container > .page-title {
    padding: var(--page-padding) var(--page-padding) 0;
    flex-shrink: 0;
}

.callplan-container {
    --callplan-time-col-width: 56px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* ── Topbar ── */
.callplan-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1.25rem;
    background: var(--bg);
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
    gap: 0.75rem;
}

.callplan-week-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.callplan-nav-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: none;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s;
}

.callplan-nav-btn:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

.callplan-week-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-800);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    text-decoration: underline dotted var(--gray-400);
    text-underline-offset: 3px;
    transition: background 0.12s;
    white-space: nowrap;
}

.callplan-week-title:hover {
    background: var(--gray-50);
}

.callplan-sidebar-toggle {
    width: 34px;
    height: 34px;
    border: 1.5px solid var(--gray-300);
    background: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--gray-600);
    transition: background 0.12s, border-color 0.12s;
}

.callplan-sidebar-toggle:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

.callplan-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.callplan-main {
    flex: 1;
    overflow: auto;
    background: var(--bg-page);
    scroll-snap-type: x mandatory;
    scroll-padding-left: var(--callplan-time-col-width);
}

.callplan-grid {
    display: flex;
    min-width: max-content;
}

.callplan-time-column {
    width: var(--callplan-time-col-width);
    flex-shrink: 0;
    background: var(--bg);
    border-right: 1px solid var(--gray-200);
    position: sticky;
    left: 0;
    z-index: 10;
}

/* Spacer aligns with the day-column headers */
.callplan-time-header-spacer {
    height: 68px;
    border-bottom: 2px solid var(--gray-200);
    flex-shrink: 0;
}

/* Continuous time axis content */
.callplan-time-content {
    position: relative;
}

.callplan-time-label-abs {
    position: absolute;
    right: 0.375rem;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--gray-400);
    transform: translateY(-0.5em);
    white-space: nowrap;
    pointer-events: none;
}

.callplan-day-column {
    flex: 1;
    min-width: 240px;
    border-right: 1px solid var(--gray-200);
    scroll-snap-align: center;
}

.callplan-day-column:last-child {
    border-right: none;
}

.callplan-header-cell {
    height: 68px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    background: var(--bg);
    border-bottom: 2px solid var(--gray-200);
    cursor: pointer;
    transition: background 0.15s;
    padding: 0.25rem;
    position: relative;
}

.callplan-header-cell:hover {
    background: var(--gray-50);
}

.callplan-header-cell.selected {
    background: var(--primary-light);
    border-bottom-color: var(--primary);
}

.callplan-header-cell.today {
    position: relative;
}

.callplan-header-cell.today::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
}

.callplan-time-header {
    cursor: default;
}

.callplan-time-header:hover {
    background: var(--bg);
}

.callplan-header-day {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.callplan-header-date {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
}

/* Day content area — continuous absolute-positioned layout */
.callplan-day-content {
    position: relative;
    overflow: hidden;
}

/* Grid lines */
.cp-grid-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--gray-200);
    pointer-events: none;
    z-index: 1;
}

.cp-grid-line-half {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--gray-100);
    border-top: 1px dashed var(--gray-150, #e8eaed);
    pointer-events: none;
    z-index: 1;
}

/* Out-of-bounds shading */
.cp-oob-shade {
    position: absolute;
    left: 0;
    right: 0;
    background: rgba(245, 158, 11, 0.08);
    pointer-events: none;
    z-index: 1;
}

/* Absolutely positioned appointment cards */
.callplan-appointment {
    position: absolute;
    left: 2px;
    right: 2px;
    color: #fff;
    border-radius: 4px;
    padding: 0.2rem 0.375rem 0.2rem;
    font-size: 0.75rem;
    cursor: pointer;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.18);
    transition: transform 0.1s, box-shadow 0.1s;
    z-index: 3;
    user-select: none;
}

.callplan-appointment[draggable="true"] {
    cursor: grab;
}

.callplan-appointment[draggable="true"]:active {
    cursor: grabbing;
}

.callplan-appointment.compact {
    padding: 0.1rem 0.3rem;
    justify-content: center;
}

.callplan-appointment:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* Card body (scrollable content area) */
.callplan-apt-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding-right: 16px;
}

.callplan-apt-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.75rem;
    line-height: 1.3;
}

.callplan-apt-type {
    font-size: 0.6rem;
    opacity: 0.85;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 1px;
}

.callplan-apt-addr {
    font-size: 0.6rem;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

/* Card footer — always pinned to bottom */
.callplan-apt-footer {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-top: 2px;
    padding-right: 16px;
}

.callplan-apt-lock {
    font-size: 0.6rem;
    line-height: 1;
}

.callplan-apt-time-label {
    font-size: 0.63rem;
    opacity: 0.88;
    white-space: nowrap;
    overflow: hidden;
}

/* Compact mode: footer only (no body) */
.callplan-appointment.compact .callplan-apt-footer {
    margin-top: 0;
    padding-right: 14px;
}

.callplan-appointment.compact .callplan-apt-time-label {
    font-size: 0.6rem;
}

/* Locked card: slightly different cursor */
.callplan-appointment.locked {
    opacity: 0.92;
}

.callplan-appointment.status-complete,
.callplan-appointment.status-cancelled {
    opacity: 0.6;
}

/* Active call plan card — shimmer sweep on the coloured background */
.callplan-appointment.status-active::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 55%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.28) 50%,
        transparent 100%
    );
    transform: translateX(-180%);
    animation: active-shimmer 2.6s ease-in-out infinite;
    mix-blend-mode: screen;
    pointer-events: none;
}

/* ── Optimise Route button — inside timeline at top of selected day ── */
@keyframes cp-optimise-shine {
    0%   { box-shadow: 0 0 0 0 rgba(var(--primary-rgb, 99,91,230), 0.85); }
    45%  { box-shadow: 0 0 0 7px rgba(var(--primary-rgb, 99,91,230), 0.35), 0 0 18px 4px rgba(var(--primary-rgb, 99,91,230), 0.25); }
    100% { box-shadow: 0 0 0 0 rgba(var(--primary-rgb, 99,91,230), 0); }
}

.callplan-optimise-btn {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.4rem 1rem;
    background: var(--primary);
    color: #fff;
    border: 2px solid rgba(255,255,255,0.25);
    border-radius: 20px;
    cursor: pointer;
    white-space: nowrap;
    letter-spacing: 0.03em;
    transition: background 0.15s, transform 0.15s;
    animation: cp-optimise-shine 1.4s ease-out forwards;
}

.callplan-optimise-btn:hover {
    background: var(--primary-dark, #5a52d5);
    transform: translateX(-50%) scale(1.04);
}


/* ── Sidebar (desktop: animated width; mobile: overlay) ── */
.callplan-sidebar {
    width: 340px;
    min-width: 340px;
    background: var(--bg);
    border-left: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.28s ease, min-width 0.28s ease, border-left-width 0.28s ease;
    flex-shrink: 0;
}

.callplan-sidebar.sidebar-closed {
    width: 0;
    min-width: 0;
    border-left-width: 0;
}

/* ── Sidebar sections ── */
.cp-section {
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.cp-section-header {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.625rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    gap: 0.5rem;
    transition: background 0.1s;
}

.cp-section-header:hover {
    background: var(--gray-50);
}

.cp-section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-800);
    flex: 1;
}

.cp-section-arrow {
    font-size: 0.65rem;
    color: var(--gray-400);
    flex-shrink: 0;
}

.cp-search-summary {
    font-size: 0.72rem;
    color: var(--gray-500);
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cp-section-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.28s ease, padding 0.28s ease;
    padding: 0 1rem;
}

.cp-section-body.open {
    max-height: 800px;
    padding: 0.5rem 1rem 0.875rem;
}

/* ── Settings ── */
.cp-setting-group {
    margin-bottom: 0.875rem;
}

.cp-setting-label {
    font-size: 0.775rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.cp-day-toggles {
    display: flex;
    gap: 3px;
}

.cp-day-btn {
    width: 32px;
    height: 32px;
    border: 1.5px solid var(--gray-300);
    border-radius: 6px;
    background: none;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--gray-500);
    cursor: pointer;
    transition: all 0.12s;
    padding: 0;
}

.cp-day-btn.active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

/* Dual range slider */
.dual-slider {
    position: relative;
    height: 22px;
    margin: 0.375rem 0 0;
}

.dual-slider-track {
    position: absolute;
    height: 4px;
    top: 9px;
    left: 0;
    right: 0;
    background: var(--gray-200);
    border-radius: 2px;
}

.dual-slider-fill {
    position: absolute;
    height: 4px;
    background: var(--primary);
    border-radius: 2px;
}

.dual-slider-input {
    position: absolute;
    left: 0;
    width: 100%;
    height: 4px;
    top: 9px;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}

.dual-slider-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    pointer-events: all;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.dual-slider-input::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    pointer-events: all;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    border: none;
}

.dual-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-top: 0.375rem;
}

.cp-duration-select {
    width: 100%;
    font-size: 0.875rem;
    padding: 0.375rem 0.5rem;
}

/* ── Search criteria ── */
.cp-criterion {
    margin-bottom: 0.375rem;
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    transition: background 0.12s, opacity 0.12s;
    border: 1.5px solid transparent;
}

.cp-criterion--inactive {
    background: var(--gray-50);
    border-color: var(--gray-200);
}

.cp-criterion--inactive:hover {
    background: var(--gray-100);
    border-color: var(--gray-300);
}

.cp-criterion--active {
    background: rgba(22, 163, 74, 0.08);
    border-color: rgba(22, 163, 74, 0.3);
}

.cp-criterion--active:hover {
    background: rgba(22, 163, 74, 0.13);
}

/* Checkbox-style criterion (Requires Visit Only) */
.cp-criterion--checkbox {
    /* inherits active/inactive bg */
}

.cp-criterion-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 26px;
    pointer-events: none; /* clicks handled by parent .cp-criterion */
}

.cp-criterion-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
}

/* Toggle indicator (+/×) — visual only, no onClick */
.cp-criterion-toggle {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1.5px solid var(--gray-400);
    background: none;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-500);
    flex-shrink: 0;
    pointer-events: none;
}

.cp-criterion--active .cp-criterion-toggle {
    border-color: #16a34a;
    color: #16a34a;
}

.cp-criterion-toggle.remove {
    border-color: var(--danger, #dc2626);
    color: var(--danger, #dc2626);
}

.cp-criterion-input {
    margin-top: 0.3rem;
    width: 100%;
    font-size: 0.875rem;
    pointer-events: all;
}

.cp-criterion-checkbox {
    width: 18px;
    height: 18px;
    accent-color: #16a34a;
    cursor: pointer;
    flex-shrink: 0;
    pointer-events: all;
}

/* Distance controls */
.cp-distance-body {
    margin-top: 0.375rem;
}

.cp-location-btns {
    display: flex;
    gap: 0.375rem;
    margin-bottom: 0.375rem;
}

.cp-loc-btn {
    font-size: 0.775rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    border: 1.5px solid var(--gray-300);
    border-radius: 5px;
    background: none;
    color: var(--gray-700);
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s;
}

.cp-loc-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.cp-distance-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.cp-distance-slider {
    flex: 1;
}

.cp-distance-number {
    width: 52px;
    padding: 0.2rem 0.3rem;
    border: 1.5px solid var(--gray-300);
    border-radius: 5px;
    font-size: 0.825rem;
    text-align: right;
    background: var(--bg);
    color: var(--gray-800);
}

.cp-distance-unit {
    font-size: 0.825rem;
    color: var(--gray-500);
}

.cp-search-btn {
    width: 100%;
    justify-content: center;
    margin-top: 0.75rem;
}

/* ── Results ── */
.cp-results {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.cp-results-count {
    padding: 0.375rem 1rem;
    font-size: 0.775rem;
    color: var(--gray-500);
    flex-shrink: 0;
}

.callplan-results-count {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--gray-500);
    text-align: center;
}

/* AI Button */
.btn-ai {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-ai:hover {
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
}

.btn-ai:disabled {
    background: var(--gray-300);
}

.btn-ai svg {
    flex-shrink: 0;
}

/* Customer List */
.callplan-customer-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.callplan-customer-card {
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
}

.callplan-customer-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary);
    transform: translateX(-2px);
}

.callplan-customer-card.requires-visit {
    border-left: 3px solid var(--danger);
}

.callplan-customer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.callplan-customer-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-800);
}

.callplan-visit-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.125rem 0.375rem;
    background: #fef2f2;
    color: #991b1b;
    border-radius: 4px;
    white-space: nowrap;
}

/* Smart compound status badge (replaces separate visit-badge calls) */
.callplan-status-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    white-space: nowrap;
}
.callplan-status-badge--active {
    background: #dcfce7;
    color: #15803d;
}
.callplan-status-badge--planned {
    background: #eff6ff;
    color: #1d4ed8;
}
.callplan-status-badge--complete {
    background: var(--gray-100);
    color: var(--gray-600);
}
.callplan-status-badge--required {
    background: #fef2f2;
    color: #991b1b;
}
.callplan-status-badge--never {
    background: #fef2f2;
    color: #7f1d1d;
    font-style: italic;
}

.callplan-customer-code {
    font-size: 0.7rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
    margin-bottom: 0.375rem;
}

.callplan-customer-address {
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-bottom: 0.375rem;
    line-height: 1.4;
}

.callplan-customer-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.callplan-last-visit {
    font-size: 0.7rem;
    color: var(--gray-500);
}

.callplan-no-results {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--gray-400);
    font-size: 0.875rem;
}

/* ── Week Picker Modal ── */
.week-picker-panel {
    background: var(--bg);
    border-radius: 12px;
    padding: 1.125rem;
    width: 300px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.week-picker-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.875rem;
}

.week-picker-month {
    flex: 1;
    text-align: center;
    font-weight: 600;
    font-size: 0.925rem;
    color: var(--gray-800);
}

.week-picker-nav {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--gray-100);
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-700);
    transition: background 0.1s;
}

.week-picker-nav:hover {
    background: var(--gray-200);
}

.week-picker-close {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.week-picker-close:hover {
    background: var(--gray-100);
}

.week-picker-day-headers {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    margin-bottom: 0.25rem;
}

.week-picker-day-name {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--gray-500);
    padding: 0.2rem 0;
}

.week-picker-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}

.week-picker-row:hover,
.week-picker-row.hovered {
    background: var(--primary-light);
}

.week-picker-row.selected {
    background: var(--primary-light);
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

.week-picker-day {
    text-align: center;
    font-size: 0.8rem;
    padding: 0.3rem 0;
    border-radius: 4px;
}

.week-picker-day.other-month {
    color: var(--gray-300);
}

.week-picker-day.today {
    font-weight: 700;
    color: var(--primary);
}

.week-picker-footer {
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--gray-100);
    display: flex;
    justify-content: center;
}

.week-picker-today-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    transition: background 0.12s;
}

.week-picker-today-link:hover {
    background: var(--primary-light, rgba(99,91,230,0.08));
}

/* ── Location Picker Modal ── */
.location-picker-panel {
    background: var(--bg);
    border-radius: 12px;
    width: 580px;
    max-width: 92vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 90vh;
}

.location-picker-header {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    gap: 0.75rem;
}

.location-picker-title {
    font-size: 0.975rem;
    font-weight: 600;
    flex: 1;
    color: var(--gray-800);
}

.location-picker-hint {
    padding: 0.5rem 1.25rem 0;
    font-size: 0.8rem;
    color: var(--gray-500);
    margin: 0;
}

.location-picker-map {
    height: 340px;
    flex-shrink: 0;
}

.location-picker-footer {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--gray-200);
    flex-wrap: wrap;
}

.location-picker-coords {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
    margin-left: auto;
}

/* Mobile sidebar backdrop */
.cp-sidebar-backdrop {
    display: none;
}

/* ── Appointment Edit Modal ── */
.apt-edit-overlay {
    z-index: 200;
}

.apt-edit-panel {
    background: var(--bg);
    border-radius: 12px;
    width: 440px;
    max-width: 94vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
}

.apt-edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    gap: 0.5rem;
}

.apt-edit-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--gray-900);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.apt-edit-body {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

/* Out-of-work-hours warning banner inside the appointment edit modal */
.apt-oowh-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    font-size: 0.825rem;
    color: #92400e;
    line-height: 1.4;
}

.apt-edit-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.apt-edit-row--inline {
    flex-direction: row;
    gap: 0.75rem;
}

.apt-edit-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.apt-edit-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.apt-locked-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 0.375rem 0.5rem;
    border-radius: 6px;
    transition: background 0.1s;
}

.apt-locked-row:hover {
    background: var(--gray-50);
}

.apt-locked-label {
    cursor: inherit;
}

/* Appointment type toggle */
.apt-type-toggle {
    display: flex;
    gap: 0.5rem;
}

.apt-type-btn {
    flex: 1;
    padding: 0.45rem 0.5rem;
    border: 1.5px solid var(--gray-300);
    border-radius: 6px;
    background: var(--bg);
    color: var(--gray-700);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.apt-type-btn:hover:not(.active) {
    border-color: var(--gray-400);
    background: var(--gray-50);
}

/* Address + geocode */
.apt-address-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.apt-address-input {
    flex: 1;
    min-width: 0;
}

.apt-geocode-btn {
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 0.45rem 0.75rem;
}

.apt-geocode-msg {
    font-size: 0.75rem;
    margin-top: 0.2rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.apt-geocode-msg.ok {
    background: rgba(22, 163, 74, 0.1);
    color: #15803d;
    font-family: 'SF Mono', 'Consolas', monospace;
}

.apt-geocode-msg.err {
    background: rgba(220, 38, 38, 0.08);
    color: var(--danger, #dc2626);
}

.apt-edit-footer {
    display: flex;
    gap: 0.625rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--gray-200);
}

.apt-edit-delete-btn {
    margin-right: auto;
}

/* Timeline scale label (subtle) */
.cp-setting-label--subtle {
    color: var(--gray-400);
    font-size: 0.75rem;
}

/* ── Appointment type icon in footer ── */
.callplan-apt-type-icon {
    margin-left: auto;
    opacity: 0.85;
    flex-shrink: 0;
}

/* ── Overlap styles ── */
.callplan-apt-overlap-shade {
    position: absolute;
    left: 0;
    right: 0;
    background: rgb(220, 38, 38);
    opacity: 0.8;
    mix-blend-mode: color;
    pointer-events: none;
    z-index: 1;
}

.callplan-appointment.overlap-top {
    width: 90% !important;
    left: 5% !important;
    opacity: 0.9;
}

/* Bottom overlap card: raise on hover (desktop) or when focused (mobile tap) */
.callplan-appointment.overlap-bottom {
    z-index: 2;
}
.callplan-appointment.overlap-bottom:hover,
.callplan-appointment.overlap-bottom.focused {
    z-index: 4;
}

/* AUTO-FIX button */
.callplan-apt-autofix-btn {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    padding: 1px 5px;
    border-radius: 3px;
    border: none;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 1px 3px rgba(220,38,38,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
    white-space: nowrap;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    transition: transform 0.1s, box-shadow 0.1s;
}
.callplan-apt-autofix-btn::after {
    content: '';
    position: absolute;
    top: 0; left: -60%; width: 40%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
    animation: cp-autofix-shine 2.2s infinite;
}
@keyframes cp-autofix-shine {
    0%   { left: -60%; }
    60%  { left: 120%; }
    100% { left: 120%; }
}
.callplan-apt-autofix-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 6px rgba(220,38,38,0.5);
}
.callplan-apt-autofix-btn:active {
    transform: scale(0.97);
}

/* ── Toast container ── */
.cp-toast-container {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.cp-toast {
    padding: 0.625rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: cp-toast-in 0.25s ease forwards;
    max-width: 320px;
}
@keyframes cp-toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.cp-toast--success { background: var(--success, #16a34a); }
.cp-toast--warning { background: #d97706; }
.cp-toast--danger  { background: var(--danger, #dc2626); }
.cp-toast--info    { background: var(--primary); }

/* ── Customer card states ── */
.callplan-customer-card.card-greyed {
    opacity: 0.45;
    pointer-events: none;
}
.callplan-customer-card.has-week-apt {
    opacity: 0.6;
    border-style: dashed;
    border-color: var(--gray-400);
}
.callplan-customer-card.has-week-apt:hover {
    border-color: var(--primary);
    opacity: 0.8;
}

/* ── Results sort bar ── */
.cp-results-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem 0.25rem;
    flex-shrink: 0;
}
.cp-results-count {
    font-size: 0.75rem;
    color: var(--gray-500);
    flex: 1;
}
.cp-sort-select {
    font-size: 0.72rem;
    padding: 0.2rem 0.4rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--gray-700);
    cursor: pointer;
}

/* ── Confirm modal ── */
.cp-confirm-panel {
    background: var(--bg);
    border-radius: var(--radius-lg, 10px);
    box-shadow: var(--shadow-lg, 0 20px 60px rgba(0,0,0,0.2));
    width: min(360px, 90vw);
    overflow: hidden;
}
.cp-confirm-header {
    padding: 1rem 1.25rem 0.5rem;
    font-weight: 700;
    font-size: 1rem;
    color: var(--gray-800);
    border-bottom: 1px solid var(--gray-100);
}
.cp-confirm-body {
    padding: 0.875rem 1.25rem;
    font-size: 0.875rem;
    color: var(--gray-600);
    line-height: 1.5;
}
.cp-confirm-footer {
    display: flex;
    gap: 0.625rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--gray-100);
}

/* ── Responsive Call Plan ── */
@media (max-width: 1100px) {
    .callplan-sidebar {
        width: 360px;
        min-width: 300px;
    }
}

@media (max-width: 768px) {
    .callplan-topbar {
        padding: 0.5rem 0.875rem;
    }

    .callplan-body {
        position: relative;
        overflow: hidden;
    }

    /* Sidebar becomes fixed overlay on mobile */
    .callplan-sidebar {
        position: absolute !important;
        right: 0;
        top: 0;
        bottom: 0;
        width: 90vw !important;
        min-width: 90vw !important;
        z-index: 50;
        transform: translateX(100%);
        transition: transform 0.28s ease !important;
        border-left: 1px solid var(--gray-200) !important;
        box-shadow: -4px 0 24px rgba(0,0,0,0.12);
    }

    .callplan-sidebar.sidebar-open {
        transform: translateX(0) !important;
    }

    .callplan-sidebar.sidebar-closed {
        transform: translateX(100%) !important;
    }

    .cp-sidebar-backdrop {
        display: block;
        position: absolute;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 49;
    }

    .callplan-day-column {
        width: calc(100vw - 94px);
    }
}

/* ================================
   Modal Styles
   ================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    animation: fadeIn 0.15s ease;
}

.modal-panel {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from { transform: translateY(16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-sm { width: 100%; max-width: 400px; }
.modal-md { width: 100%; max-width: 600px; }
.modal-lg { width: 100%; max-width: 800px; }
.modal-full { width: 100%; max-width: 95vw; height: 90vh; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--gray-500);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ================================
   Dialog (themed alert / confirm)
   ================================ */

.dlg-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
    animation: fadeIn 0.15s ease;
}

.dlg-panel {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 380px;
    padding: 1.75rem 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    animation: slideUp 0.2s ease;
}

.dlg-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.25rem;
    flex-shrink: 0;
}

.dlg-icon-info {
    background: var(--primary-light);
    color: var(--primary);
}

.dlg-icon-danger {
    background: #fee2e2;
    color: var(--danger);
}

[data-theme="dark"] .dlg-icon-danger {
    background: rgba(239, 68, 68, 0.15);
}

.dlg-message {
    font-size: 0.9rem;
    color: var(--gray-700);
    line-height: 1.55;
    margin-bottom: 0.5rem;
}

.dlg-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    width: 100%;
    margin-top: 0.25rem;
}

.dlg-cancel {
    border: 1.5px solid var(--gray-300);
}

.dlg-panel-alert {
    align-items: stretch;
    text-align: left;
    gap: 0.75rem;
}

.dlg-inline {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dlg-inline .dlg-icon {
    width: 36px;
    height: 36px;
    margin-bottom: 0;
    flex-shrink: 0;
}

.dlg-inline .dlg-message {
    margin-bottom: 0;
}

/* ================================
   Tab Component
   ================================ */

.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 1rem;
    gap: 0;
}

.tab-btn {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-500);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    font-family: inherit;
}

.tab-btn:hover {
    color: var(--gray-700);
    background: var(--gray-50);
    border-radius: var(--radius) var(--radius) 0 0;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--primary-light);
    border-radius: var(--radius) var(--radius) 0 0;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ================================
   Sales Order Page Styles
   ================================ */

.so-page {
    max-width: 820px;
    margin: 0 auto;
    padding: 2rem;
}

.so-page.embedded {
    padding: 1.5rem 0 0;
}

.so-step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

.so-step {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-400);
    padding: 0.375rem 0.75rem;
    border-radius: 20px;
    transition: color 0.15s, background 0.15s;
}

.so-step.active {
    color: var(--primary);
    background: var(--primary-light);
}

.so-step.completed {
    color: var(--success);
}

.so-step-number {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--gray-200);
    color: var(--gray-500);
}

.so-step.active .so-step-number {
    background: var(--primary);
    color: #fff;
}

.so-step.completed .so-step-number {
    background: var(--success);
    color: #fff;
}

.so-step-divider {
    width: 24px;
    height: 2px;
    background: var(--gray-200);
}

/* Customer card in sales order */
.so-customer-card {
    background: var(--bg);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    animation: fadeIn 0.2s ease;
}

.so-customer-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--gray-900);
}

.so-customer-info {
    display: flex;
    gap: 1.5rem;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--gray-600);
}

/* Line items */
.so-line-item {
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.875rem;
    margin-bottom: 0.5rem;
    transition: border-color 0.15s;
}

.so-line-item.price-error {
    border-color: var(--danger);
    background: #fef2f2;
}

.so-line-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.so-line-product {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-top: 0.25rem;
}

.so-line-code {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
}

.so-line-fields {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.so-line-field {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.so-line-field label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.so-line-field input {
    width: 80px;
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    background: var(--bg);
    color: var(--gray-800);
}

.so-line-field input:focus {
    outline: none;
    border-color: var(--primary);
}

.so-line-field input.error {
    border-color: var(--danger);
}

.so-line-total {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-left: auto;
}

.so-line-actions {
    display: flex;
    gap: 0.375rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.so-line-btn {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    background: var(--gray-100);
    color: var(--gray-600);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s;
    font-family: inherit;
}

.so-line-btn:hover {
    background: var(--gray-200);
    color: var(--gray-800);
}

.so-line-btn.danger {
    color: var(--danger);
}

.so-line-btn.danger:hover {
    background: #fef2f2;
}

/* ---- Order lines table (tablet / desktop) ---- */
.so-lines-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.so-lines-table thead th {
    text-align: left;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
    white-space: nowrap;
}

.so-lt-row td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.so-lt-row:last-child td {
    border-bottom: none;
}

.so-lt-row.price-error,
.so-lt-row.stock-error {
    background: #fef2f2;
}
.so-lt-row.stock-error td:first-child {
    box-shadow: inset 3px 0 0 var(--danger);
}

.so-lines-table .so-lt-product { width: 148px; }
.so-lines-table .so-lt-img    { width: 48px; }
.so-lines-table .so-lt-qty    { width: 116px; }
.so-lines-table .so-lt-price  { width: 110px; }
.so-lines-table .so-lt-total  { width: 82px; font-weight: 700; text-align: right; white-space: nowrap; color: var(--gray-800); }
.so-lines-table .so-lt-remove { width: 38px; text-align: center; }

/* shrink typeahead inside table cell */
.so-lt-product .search-container { margin: 0; }
.so-lt-product .search-input {
    font-size: 0.8rem;
    padding: 0.3rem 0.5rem;
    height: auto;
}

/* Product code as label (default state) */
.so-line-code-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.15rem;
}
.so-line-code {
    font-family: ui-monospace, monospace;
    font-size: 0.78rem;
    color: var(--gray-600);
    font-weight: 500;
}
.so-line-edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    color: var(--gray-500);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.12s;
}
.so-line-edit-btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-300);
    color: var(--primary);
}

/* Editing state */
.so-line-edit-row { display: flex; align-items: center; gap: 0.35rem; }
.so-line-edit-row .search-container { flex: 1; }
.so-line-edit-input { border-color: var(--danger) !important; box-shadow: 0 0 0 1px var(--danger) !important; }
.so-line-edit-cancel {
    background: transparent;
    border: 1px solid var(--gray-300);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
}
.so-line-edit-cancel:hover { border-color: var(--danger); background: rgba(239,68,68,0.06); }
/* product code shown as placeholder should look like real text */
.so-lt-product .search-input::placeholder {
    color: var(--gray-800);
    opacity: 1;
}

/* Product image — order table */
.so-line-img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    background: var(--gray-100);
    border-radius: 4px;
    border: 1px solid var(--gray-200);
    flex-shrink: 0;
    display: block;
}

/* Qty stepper */
.so-qty-ctrl {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    overflow: hidden;
}

.so-qty-btn {
    width: 28px;
    height: 30px;
    background: var(--gray-50);
    border: none;
    cursor: pointer;
    font-size: 1.05rem;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s;
    font-family: inherit;
    flex-shrink: 0;
    user-select: none;
}

.so-qty-btn:hover { background: var(--gray-200); }

.so-qty-input {
    width: 40px;
    height: 30px;
    text-align: center;
    border: none;
    border-left: 1px solid var(--gray-200);
    border-right: 1px solid var(--gray-200);
    font-size: 0.875rem;
    color: var(--gray-800);
    background: var(--bg);
    -moz-appearance: textfield;
}

.so-qty-input::-webkit-inner-spin-button,
.so-qty-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.so-qty-input:focus { outline: none; }

.so-qty-display {
    width: 32px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
    line-height: 30px;
}

/* Price override */
.so-price-display-wrap {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.so-price-display {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
}

.so-special-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.2rem 0.55rem;
    background: var(--success);
    color: #fff;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    flex-shrink: 0;
    line-height: 1;
    cursor: default;
    white-space: nowrap;
}

.so-price-input {
    display: block;
    width: 80px;
    padding: 0.3rem 0.4rem;
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: var(--bg);
    color: var(--gray-800);
}

.so-price-input.error { border-color: var(--danger); }
.so-price-input:focus { outline: none; border-color: var(--primary); }

.so-override-btn {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.64rem;
    padding: 0.1rem 0.35rem;
    background: transparent;
    border: 1px solid var(--gray-300);
    border-radius: 3px;
    color: var(--gray-500);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.12s;
}

.so-override-btn:hover { background: var(--gray-100); color: var(--gray-700); }

.so-price-error-sm {
    font-size: 0.62rem;
    color: var(--danger);
    margin-top: 0.2rem;
    max-width: 108px;
    line-height: 1.3;
}

/* Remove button */
.so-remove-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--gray-300);
    cursor: pointer;
    transition: all 0.12s;
}

.so-remove-btn:hover { background: #fef2f2; color: var(--danger); }

/* ---- Mobile cart ---- */
.so-cart-mobile { display: none; }

.so-cart-item {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--gray-100);
}

.so-cart-item:last-of-type { border-bottom: none; }
.so-cart-item.price-error { background: #fef2f2; }

.so-cart-img {
    width: 44px;
    height: 44px;
    object-fit: cover;
    background: var(--gray-100);
    border-radius: 4px;
    border: 1px solid var(--gray-200);
    flex-shrink: 0;
    display: block;
}

.so-cart-main {
    flex: 1;
    min-width: 0;
}

.so-cart-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.so-cart-code {
    font-size: 0.7rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
    margin-bottom: 0.25rem;
}

.so-cart-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
    flex-shrink: 0;
}

.so-cart-total {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-800);
}

.so-cart-unit {
    font-size: 0.68rem;
    color: var(--gray-400);
}

.so-cart-hint {
    font-size: 0.7rem;
    color: var(--gray-400);
    text-align: center;
    padding: 0.4rem;
    font-style: italic;
}

/* Mobile inline block inside product cell (visible only when table cols are hidden ≤639px) */
.so-lt-mobile-block { display: none; }
.so-lt-mob-total { font-weight: 700; font-size: 0.875rem; color: var(--gray-800); white-space: nowrap; }

/* Order summary */
.so-summary {
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 1rem;
}

.so-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.375rem 0;
    font-size: 0.9rem;
    color: var(--gray-700);
}

.so-summary-row.total {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-900);
    border-top: 2px solid var(--gray-200);
    padding-top: 0.75rem;
    margin-top: 0.375rem;
}

/* Signature pad styles */
.signature-pad {
    text-align: center;
}

.signature-canvas {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    cursor: crosshair;
    max-width: 100%;
    height: auto;
}

.signature-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.75rem;
}

.signature-preview {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.5rem;
    text-align: center;
}

.signature-preview img {
    max-width: 200px;
    max-height: 80px;
}

/* Camera styles */
.camera-capture {
    text-align: center;
}

.camera-preview {
    margin-bottom: 0.75rem;
}

.camera-video {
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius);
    background: #000;
}

.camera-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.camera-error {
    padding: 1.5rem;
    text-align: center;
    color: var(--gray-600);
}

.camera-error p {
    margin-bottom: 0.75rem;
}

.camera-upload-label {
    cursor: pointer;
}

.camera-loading {
    padding: 2rem;
    color: var(--gray-400);
}

/* Photo thumbnails */
.so-photos {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.so-photo-thumb {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

.so-photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius);
    display: block;
}

.so-photo-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

/* Order status badges */
.so-status-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.so-status-badge.submitted {
    background: #eff6ff;
    color: #1d4ed8;
}

.so-status-badge.pending {
    background: #fefce8;
    color: #a16207;
}

.so-status-badge.synced {
    background: #f0fdf4;
    color: #15803d;
}

.so-status-badge.failed {
    background: #fef2f2;
    color: #991b1b;
}

/* Stock indicator colors */
.stock-high {
    color: var(--success);
    font-weight: 600;
}

.stock-medium {
    color: #d97706;
    font-weight: 600;
}

.stock-low {
    color: var(--danger);
    font-weight: 600;
}

/* Mini table for stock info */
.so-stock-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.so-stock-table th {
    text-align: left;
    padding: 0.5rem 0.625rem;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
}

.so-stock-table td {
    padding: 0.5rem 0.625rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}

/* Button outline variant */
.btn-outline {
    background: transparent;
    color: var(--gray-600);
    border: 1.5px solid var(--gray-300);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-outline:hover {
    background: var(--gray-100);
    color: var(--gray-800);
    border-color: var(--gray-400);
}

/* ================================
   Draft Orders list (home page)
   ================================ */

.draft-list {
    display: flex;
    flex-direction: column;
    max-height: calc(4 * 5rem);
    overflow-y: auto;
}

.draft-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--gray-100);
}

@media (max-width: 600px) {
    .draft-row {
        flex-wrap: wrap;
    }
    .draft-row-body {
        width: 100%;
    }
    .draft-row-actions {
        width: 100%;
        justify-content: flex-end;
        padding-bottom: 0.25rem;
    }
}

.draft-row:last-child {
    border-bottom: none;
}

.draft-row-body {
    flex: 1;
    min-width: 0;
}

.draft-row-customer {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.draft-row-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
    font-size: 0.78rem;
    color: var(--gray-500);
}

.draft-row-sep {
    color: var(--gray-300);
}

.draft-row-total {
    font-weight: 600;
    color: var(--gray-700);
}

.draft-row-delete {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    color: var(--gray-400);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.draft-row-delete:hover {
    background: #fee2e2;
    color: var(--danger);
    border-color: var(--danger);
}

.draft-row-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.draft-row-load {
    height: 30px;
    padding: 0 0.6rem;
    font-size: 0.78rem;
    font-weight: 600;
    background: none;
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    color: var(--primary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.draft-row-load:hover {
    background: var(--primary);
    color: #fff;
}

/* Pending sync badge on nav */
.nav-badge {
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    margin-left: 0.25rem;
}

/* Price error message */
.so-price-error {
    font-size: 0.75rem;
    color: var(--danger);
    margin-top: 0.25rem;
}

/* Confirmation page */
.so-confirm {
    text-align: center;
    padding: 2rem 0;
}

.so-confirm-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #f0fdf4;
    color: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}

.so-confirm-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.5rem;
}

.so-confirm-order-id {
    font-size: 1rem;
    color: var(--primary);
    font-family: 'SF Mono', 'Consolas', monospace;
    font-weight: 600;
    margin-bottom: 1rem;
}

.so-confirm-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1.5rem;
}

/* Checkbox styled */
.so-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-700);
    cursor: pointer;
    margin: 0.75rem 0;
}

.so-checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* Review section */
.so-review-section {
    margin-bottom: 1.25rem;
}

.so-review-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--gray-200);
}

/* History bar chart container */
.so-history-chart {
    height: 200px;
    margin-bottom: 1rem;
}

.so-history-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.so-history-stat {
    text-align: center;
    padding: 0.75rem;
    background: var(--gray-50);
    border-radius: var(--radius);
}

.so-history-stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.so-history-stat-label {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* Responsive sales order */
@media (max-width: 639px) {
    .so-page {
        padding: 1rem;
    }
    .so-page.embedded {
        padding: 0.75rem 0 0;
    }

    .so-step-indicator {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .so-step {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }

    .so-step-divider {
        width: 12px;
    }

    .so-customer-info {
        flex-direction: column;
        gap: 0.25rem;
    }

    .so-history-stats {
        grid-template-columns: 1fr;
    }

    .so-confirm-actions {
        flex-direction: column;
    }

    /* Responsive table — hide price/qty/total/remove cols, show mobile block in product cell */
    .so-lines-table .so-lt-price,
    .so-lines-table .so-lt-qty,
    .so-lines-table .so-lt-total,
    .so-lines-table .so-lt-remove { display: none; }
    .so-lt-mobile-block { display: block !important; }
    .so-lt-mob-row {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        margin-top: 0.4rem;
        flex-wrap: wrap;
    }
}

/* ============================================================
   Account / Customer Page
   ============================================================ */

.account-page {
    /* padding via .page-wide */
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.note-type-badge { display: inline-flex; align-items: center; gap: 0.25rem; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-primary { background: var(--primary-light); color: var(--primary); }

[data-theme="dark"] .badge-success { background: #14532d; color: #4ade80; }
[data-theme="dark"] .badge-danger  { background: #450a0a; color: #f87171; }
[data-theme="dark"] .badge-warning { background: #422006; color: #fcd34d; }

/* Account header */
.account-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem 1.25rem;
}

.account-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.account-info {
    flex: 1;
    min-width: 0;
}

.account-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-code {
    font-size: 0.8rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
}

.account-balance-block {
    text-align: right;
    flex-shrink: 0;
}

.account-balance-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-500);
}

.account-balance {
    font-size: 1.3rem;
    font-weight: 700;
}

.account-balance.positive { color: var(--success); }
.account-balance.negative { color: var(--danger); }

/* Tab navigation */
.tab-nav {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0;
    border-bottom: 2px solid var(--gray-200);
    padding-bottom: 0;
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    border-radius: 0;
}

.tab-btn:hover {
    color: var(--gray-800);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-content {
    padding: 1.5rem;
}

@media (max-width: 768px) {
    .tab-nav {
        overflow-x: auto;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }
    .tab-nav::-webkit-scrollbar {
        display: none;
    }
    .tab-btn {
        white-space: nowrap;
        flex-shrink: 0;
    }
}

/* Filter bar */
.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-bar-dates {
    display: flex;
    gap: 0.75rem;
    flex: 1;
    flex-wrap: wrap;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 140px;
}

.filter-field-search {
    flex: 1;
    min-width: 180px;
}

.filter-apply-btn {
    align-self: flex-end;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

/* History table */
.history-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.history-table {
    min-width: 480px;
    overflow: hidden;
}

.history-table-head {
    display: grid;
    grid-template-columns: 1.6fr 1fr 1fr 0.6fr 1fr;
    gap: 0;
    background: var(--gray-50);
    padding: 0.625rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    border-bottom: 1px solid var(--gray-200);
}

.history-table-row {
    display: grid;
    grid-template-columns: 1.6fr 1fr 1fr 0.6fr 1fr;
    gap: 0;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background 0.1s;
    align-items: center;
}

.history-table-row:last-child { border-bottom: none; }

.history-table-row:hover { background: var(--primary-light); }

/* Prospects table — 6 columns: Account No, Name, Email, Phone, Status, Action */
.prospects-table .history-table-head,
.prospects-table .history-table-row {
    grid-template-columns: 1fr 1.5fr 1.5fr 1fr 0.7fr 0.5fr;
}

@media (max-width: 640px) {
    .prospects-table .history-table-head,
    .prospects-table .history-table-row {
        grid-template-columns: 1.2fr 1.5fr 0.8fr 0.5fr;
        font-size: 0.8rem;
    }

    /* Hide Email (3rd) and Phone (4th) on mobile */
    .prospects-table .history-table-head span:nth-child(3),
    .prospects-table .history-table-row span:nth-child(3),
    .prospects-table .history-table-head span:nth-child(4),
    .prospects-table .history-table-row span:nth-child(4) {
        display: none;
    }
}

.history-id {
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 600;
}

.history-po {
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.8rem;
}

.history-total {
    font-weight: 600;
}

.history-pending-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
    margin-left: 0.375rem;
    vertical-align: middle;
}

.history-table-row--pending {
    background: #fffbeb;
}

.history-offline-note {
    font-size: 0.8rem;
    color: var(--gray-500);
    text-align: center;
    padding: 0.5rem 0 0.25rem;
    font-style: italic;
}

.text-right { text-align: right; }

/* Transaction detail modal extras */
.tx-invoice-link {
    color: var(--primary);
    text-decoration: underline;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.875rem;
}

.tx-meta-row-narrative .tx-meta-value {
    line-height: 1.6;
    font-size: 0.875rem;
    color: var(--gray-600);
}

/* Pagination bar */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.875rem;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-nav {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.pagination-page {
    min-width: 90px;
    text-align: center;
    font-size: 0.875rem;
}

.pagination-size {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

/* Address cards */
.addresses-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-subtitle {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
}

.address-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: var(--bg);
    transition: border-color 0.15s;
}

.address-card-default {
    border-color: var(--primary);
    background: var(--primary-light);
}

.address-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.address-label {
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
}

.address-card-actions {
    display: flex;
    gap: 0.25rem;
}

.btn-icon {
    background: none;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.3rem;
    cursor: pointer;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, color 0.1s;
}

.btn-icon:hover { background: var(--gray-100); color: var(--gray-900); }

.btn-icon-danger:hover { background: #fee2e2; color: var(--danger); border-color: var(--danger); }

.address-body {
    font-size: 0.875rem;
    color: var(--gray-600);
    line-height: 1.6;
}

/* Address form */
.address-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.85rem;
}

/* Transaction detail modal */
.tx-detail {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tx-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.tx-detail-meta {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.tx-meta-row {
    display: flex;
    gap: 0.75rem;
    font-size: 0.875rem;
    align-items: baseline;
}

.tx-meta-label {
    font-weight: 600;
    color: var(--gray-500);
    min-width: 80px;
    font-size: 0.8rem;
}

.tx-meta-value {
    color: var(--gray-800);
}

.tx-detail-total {
    text-align: right;
    flex-shrink: 0;
}

.tx-total-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
}

.tx-total-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* Transaction line items */
.tx-lines {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
}

.tx-lines-header {
    display: grid;
    grid-template-columns: 44px 1fr 60px 60px 90px 90px;
    padding: 0.5rem 0.75rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    gap: 0.5rem;
    align-items: center;
}

.tx-line-row {
    display: grid;
    grid-template-columns: 44px 1fr 60px 60px 90px 90px;
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.875rem;
    gap: 0.5rem;
    align-items: center;
}

.tx-line-row:last-child { border-bottom: none; }

.tx-col-img { display: flex; align-items: center; }
.tx-col-qty, .tx-col-uom, .tx-col-price, .tx-col-total { text-align: right; }

.tx-product-img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--gray-200);
    background: var(--gray-100);
}

.tx-product-name {
    font-weight: 500;
    font-size: 0.875rem;
}

.tx-product-code {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-family: 'SF Mono', 'Consolas', monospace;
}

.tx-col-total { font-weight: 600; }

.tx-line-total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.625rem 0.75rem;
    background: var(--gray-50);
    font-weight: 700;
    font-size: 0.9rem;
    border-top: 2px solid var(--gray-200);
}

/* Order attachments (photos / signature in detail modal) */
.tx-attachments {
    margin-bottom: 1rem;
    padding: 0.875rem 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.tx-attachments-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin-bottom: 0.625rem;
}

.tx-attachments-grid {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tx-attachment-thumb {
    width: 80px;
    height: 80px;
    border-radius: var(--radius);
    border: 2px solid var(--gray-200);
    overflow: hidden;
    cursor: pointer;
    padding: 0;
    background: var(--gray-100);
    transition: border-color 0.15s;
}

.tx-attachment-thumb:hover {
    border-color: var(--primary);
}

.tx-attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Email dialog */
.email-dialog {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
}

.email-dialog-inner {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.email-dialog-inner .form-input {
    flex: 1;
    min-width: 200px;
}

.email-success {
    color: var(--success);
    font-weight: 500;
    font-size: 0.9rem;
}

.email-error {
    color: var(--danger);
    font-weight: 500;
    font-size: 0.9rem;
}

/* Transaction action buttons */
.tx-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    flex-wrap: wrap;
    padding-top: 0.5rem;
    border-top: 1px solid var(--gray-200);
}

/* Responsive */
@media (max-width: 640px) {
    .account-header {
        flex-wrap: wrap;
    }

    .account-balance-block {
        width: 100%;
        text-align: left;
        padding-top: 0.5rem;
        border-top: 1px solid var(--gray-200);
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar-dates {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar-dates .filter-field {
        min-width: 0;
    }

    .filter-apply-btn {
        width: 100%;
        justify-content: center;
    }

    .tx-lines-header,
    .tx-line-row {
        grid-template-columns: 36px 1fr 50px 70px 70px;
        font-size: 0.8rem;
    }

    .tx-col-uom { display: none; }

    .tx-lines-header span:nth-child(4),
    .tx-line-row span:nth-child(4) { display: none; }

    .tx-actions {
        flex-direction: column;
    }

    .form-row-2 {
        grid-template-columns: 1fr;
    }

    .modal-panel {
        height: 90vh;
    }

    .modal-panel.modal-sm {
        height: auto;
        max-height: 90vh;
    }
}

/* ============================================================
   Sidebar logo
   ============================================================ */
.sidebar-logo-full {
    max-width: 160px;
    width: 100%;
    height: auto;
    max-height: 44px;
    object-fit: contain;
    object-position: left center;
    display: block;
    flex-shrink: 0;
}

.sidebar-logo-icon {
    width: 36px;
    height: 36px;
    object-fit: contain;
    object-position: center center;
    display: none;
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-logo-full { display: none; }
.sidebar.collapsed .sidebar-logo-icon { display: block; }

/* ============================================================
   Header customer selector
   ============================================================ */
.header-customer {
    position: relative;
}

.customer-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.3rem 0.65rem;
    border-radius: 0;
    border: 1px solid var(--gray-300);
    background: var(--gray-50);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--gray-600);
    white-space: nowrap;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    font-family: inherit;
}

.customer-pill:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.customer-pill.has-customer {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
    border-radius: var(--radius);
}

[data-theme="dark"] .customer-pill {
    background: rgba(176,171,255,0.08);
    border-color: rgba(176,171,255,0.25);
    color: rgba(176,171,255,0.75);
}

[data-theme="dark"] .customer-pill:hover {
    border-color: var(--brand-lavender);
    color: var(--brand-lavender);
    background: rgba(176,171,255,0.15);
}

[data-theme="dark"] .customer-pill.has-customer {
    background: rgba(176,171,255,0.15);
    border-color: var(--brand-lavender);
    color: var(--brand-lavender);
}

.customer-pill-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.customer-pill-code {
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.72rem;
    opacity: 0.65;
    flex-shrink: 0;
}

.customer-picker-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 340px;
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);
    padding: 0.5rem;
    z-index: 500;
}

[data-theme="dark"] .customer-picker-dropdown {
    border-color: var(--gray-700);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.recent-customers-section {
    margin-top: 0.25rem;
    border-top: 1px solid var(--gray-200);
    max-height: 240px;
    overflow-y: auto;
}

[data-theme="dark"] .recent-customers-section {
    border-top-color: var(--gray-700);
}

.recent-customers-label {
    padding: 0.3rem 1rem 0.2rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    user-select: none;
}

/* ── Customer picker dropdown — sections ───────────────────────────────────── */

.cpd-section-label {
    padding: 0.3rem 0.75rem 0.2rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    user-select: none;
}

.cpd-current-customer {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.35rem;
    cursor: pointer;
    transition: background 0.12s;
    border: 1px solid var(--primary-light, #ede9fe);
    background: var(--primary-light, #ede9fe);
}

.cpd-current-customer:hover,
.cpd-current-customer:focus {
    background: var(--primary-light-hover, #ddd6fe);
    border-color: var(--primary, #7c6fff);
    outline: none;
}

.cpd-current-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--primary, #7c6fff);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cpd-current-code {
    font-size: 0.75rem;
    font-family: 'SF Mono', 'Consolas', monospace;
    color: var(--gray-500);
    opacity: 0.85;
}

.cpd-change-section {
    border-top: 1px solid var(--gray-200);
    padding-top: 0.35rem;
    margin-top: 0.1rem;
}

[data-theme="dark"] .cpd-current-customer {
    background: rgba(124,111,255,0.15);
    border-color: rgba(124,111,255,0.35);
}

[data-theme="dark"] .cpd-current-customer:hover,
[data-theme="dark"] .cpd-current-customer:focus {
    background: rgba(124,111,255,0.25);
    border-color: rgba(124,111,255,0.6);
}

[data-theme="dark"] .cpd-current-name {
    color: var(--brand-lavender, #b0abff);
}

[data-theme="dark"] .cpd-change-section {
    border-top-color: var(--gray-700);
}

@media (max-width: 600px) {
    .customer-pill-code { display: none; }
    .customer-pill-code--mobile-primary { display: inline; }
    .customer-picker-dropdown {
        position: fixed;
        top: 60px;
        left: 0.75rem;
        right: 0.75rem;
        width: auto;
    }
}

.rep-search-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 0.45rem 0.75rem;
    margin-bottom: 0.25rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    font-family: inherit;
}
.rep-search-input:focus {
    border-color: var(--brand-violet);
    box-shadow: 0 0 0 2px rgba(124,111,255,0.15);
}
[data-theme="dark"] .rep-search-input {
    background: var(--gray-800, #1f2937);
    border-color: var(--gray-600, #4b5563);
    color: var(--text);
}

.rep-dropdown-list {
    max-height: 260px;
    overflow-y: auto;
}

.rep-dropdown-item {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text);
    transition: background 0.1s;
}
.rep-dropdown-item:hover {
    background: var(--gray-50, #f9fafb);
}
.rep-dropdown-item--active {
    background: rgba(124, 111, 255, 0.08);
    color: var(--brand-violet);
    font-weight: 600;
}
[data-theme="dark"] .rep-dropdown-item:hover {
    background: rgba(255,255,255,0.06);
}
[data-theme="dark"] .rep-dropdown-item--active {
    background: rgba(56,189,248,0.12);
    color: var(--brand-lavender, #38bdf8);
}

/* ============================================================
   Customer page — new-order tab
   ============================================================ */
.no-customer-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3.5rem 2rem;
    text-align: center;
    color: var(--gray-500);
    font-size: 1rem;
    gap: 0.5rem;
}

.new-order-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 2.5rem 2rem;
}

.new-order-customer-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.new-order-hint {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin: 0;
}

.new-order-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-lg {
    padding: 0.7rem 1.75rem;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
}

/* ============================================================
   Customer page — account info tab
   ============================================================ */
.account-info-tab {
    padding: 0.25rem 0;
}

.account-info-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.account-info-details {
    flex: 1;
    min-width: 0;
}

.account-avatar.lg {
    width: 64px;
    height: 64px;
    font-size: 1.3rem;
}

@media (max-width: 640px) {
    .account-info-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .account-balance-block {
        width: 100%;
    }
}

/* ---- Account Info Tab — Enhanced Sections ---- */
.ai-callplan-btn {
    margin-left: auto;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.78rem;
}

.ai-stop-credit-badge {
    font-size: 0.72rem;
    text-transform: none;
    letter-spacing: 0;
}

/* Detail grid (label / value pairs) */
.ai-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 2rem;
}

.ai-detail-row {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.ai-detail-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.ai-detail-value {
    font-size: 0.925rem;
    font-weight: 500;
    color: var(--gray-900);
    word-break: break-word;
}

.ai-detail-value a {
    color: var(--primary);
    text-decoration: none;
}
.ai-detail-value a:hover { text-decoration: underline; }

@media (max-width: 480px) {
    .ai-detail-grid { grid-template-columns: 1fr; }
}

/* Credit info grid */
.ai-credit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}

.ai-credit-item {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
}

.ai-credit-item-total {
    background: var(--primary-light);
    border-color: var(--primary-mid);
}

.ai-credit-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.2rem;
}

.ai-credit-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--gray-800);
}

.ai-credit-item-total .ai-credit-label { color: var(--primary-dark); }
.ai-credit-item-total .ai-credit-value { color: var(--primary-dark); }

/* Contacts table */
.ai-contacts-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ai-contacts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.ai-contacts-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

.ai-contacts-table td {
    padding: 0.6rem 0.75rem;
    color: var(--gray-800);
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.ai-contacts-table tbody tr:last-child td { border-bottom: none; }

.ai-contacts-table a {
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}
.ai-contacts-table a:hover { text-decoration: underline; }

/* Location map */
.ai-map-container {
    height: 300px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--gray-200);
}

@media (max-width: 640px) {
    .ai-map-container { height: 220px; }
}

/* Call History Timeline */
.ai-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.ai-timeline-entry {
    display: flex;
    gap: 0.85rem;
    cursor: pointer;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--gray-100);
    position: relative;
}

.ai-timeline-entry:last-child { border-bottom: none; }

.ai-timeline-entry--clickable:hover {
    background: var(--gray-50);
    border-radius: 6px;
}

.ai-timeline-dot {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 0.45rem;
}

.dot-visit { background: var(--success); }
.dot-appt  { background: var(--primary); }

.ai-timeline-content {
    flex: 1;
    min-width: 0;
}

.ai-timeline-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    user-select: none;
}

.ai-timeline-date {
    font-size: 0.78rem;
    color: var(--gray-500);
    white-space: nowrap;
    flex-shrink: 0;
}

.ai-timeline-summary {
    flex: 1;
    font-size: 0.875rem;
    color: var(--gray-800);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-timeline-chevron {
    flex-shrink: 0;
    color: var(--gray-400);
    transition: transform 0.2s ease;
}

.ai-timeline-entry.expanded .ai-timeline-chevron {
    transform: rotate(180deg);
}

.ai-timeline-body {
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px dashed var(--gray-200);
}

.ai-timeline-detail { display: flex; flex-direction: column; gap: 0.75rem; }

.ai-timeline-body-html {
    font-size: 0.875rem;
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.ai-timeline-no-body {
    font-size: 0.85rem;
    color: var(--gray-500);
    font-style: italic;
}

.ai-timeline-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ---- Notes Tab ---- */
.notes-tab {}

.notes-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
}

.notes-filter-bar .filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 130px;
}

.notes-filter-bar .filter-field-search {
    flex: 1;
    min-width: 180px;
}

.notes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.note-card {
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: var(--surface);
    transition: border-left-color 0.2s, background-color 0.2s;
}

.note-card:last-child { margin-bottom: 0; }

/* ── Overdue task styling (shared) ────────────────────────────────────────── */
.note-card--overdue,
.task-card--overdue,
.todo-item--overdue,
.ai-timeline-entry--overdue {
    border-left-color: var(--danger) !important;
    background: color-mix(in srgb, var(--danger) 4%, transparent);
}
.note-card--overdue:hover,
.task-card--overdue:hover,
.todo-item--overdue:hover {
    background: color-mix(in srgb, var(--danger) 8%, transparent);
}
.badge-overdue {
    background: var(--danger, #ef4444);
    color: #fff;
    border-radius: 0.75rem;
    padding: 0.18rem 0.55rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* Assigned-rep tag (manager view of prospects) */
.assigned-rep-tag {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.1rem 0.45rem;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--gray-600);
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 0.75rem;
    vertical-align: middle;
}

/* Per-type left border — driven by --ntc CSS variable set inline per card from NOTE_TYPE_CONFIG */
.note-card                                                            { border-left-color: color-mix(in srgb, var(--ntc, #9ca3af) 30%, transparent); }
.note-card:hover                                                      { border-left-color: var(--ntc, #9ca3af); background-color: color-mix(in srgb, var(--ntc, #9ca3af) 5%, transparent); }

.note-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.note-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.note-card-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.note-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.note-meta-item {
    color: var(--text-muted);
}

.note-meta-date {
    margin-left: auto;
}

.note-body {
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
    margin-top: 0.25rem;
    /* Quill ql-editor resets */
    padding-left: 0;
    min-height: unset;
}

/* Modified-by link in note meta row */
.note-meta-modified {
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.note-meta-modified:hover { color: var(--primary-dark); }

/* Modal backdrop/panel (shared by note history and any future inline modals) */
.tx-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.tx-modal-panel {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    width: 100%;
    overflow: hidden;
}

.tx-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tx-modal-body {
    overflow-y: auto;
    padding: 1.25rem;
    flex: 1;
}

/* Note edit history modal */
.note-history-modal { max-width: 580px; }

.note-history-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

/* Timeline */
.note-history-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.note-history-node {
    position: relative;
    padding: 0.9rem 0 0.9rem 1.25rem;
    border-left: 2px solid var(--border);
}

.note-history-node::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 1.1rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 2px var(--border);
}

.note-history-node:last-child { border-left-color: transparent; }

.note-history-node-meta {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.2rem;
}

.note-history-node-date {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.note-history-node-by {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.note-history-node-summary {
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.6rem;
}

/* Inline diff rows (Status, Subject, Assignee, Due Date) */
.note-history-diff-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.4rem;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}

.note-history-diff-label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    min-width: 5rem;
}

.note-history-diff-old {
    text-decoration: line-through;
    color: #dc2626;
    opacity: 0.85;
}

.note-history-diff-arrow {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.note-history-diff-new {
    color: #16a34a;
    font-weight: 500;
}

/* Body diff block */
.note-history-diff-body {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

.note-history-diff-body > .note-history-diff-label {
    display: block;
    margin-bottom: 0.35rem;
}

.note-history-diff-body-old,
.note-history-diff-body-new {
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    min-height: unset;
}

.note-history-diff-body-old {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #7f1d1d;
    text-decoration: line-through;
    opacity: 0.85;
}

.note-history-diff-body-new {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #14532d;
}

.note-history-diff-body-arrow {
    text-align: center;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.5;
    padding: 0.15rem 0;
}

.note-history-empty { color: var(--text-muted); font-style: italic; }

/* ---- Note Form ---- */
.note-form {}

/* ---- Note Attachments ---- */
.note-attachment-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.att-item {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.att-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: block;
}

.att-loading {
    width: 72px;
    height: 72px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.att-offline {
    width: 72px;
    height: 72px;
    border-radius: var(--radius);
    border: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    color: var(--text-muted);
    opacity: 0.6;
}

.att-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: var(--danger, #ef4444);
    color: #fff;
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.att-remove:hover { background: #dc2626; }

.att-doc-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.6rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    color: var(--text-secondary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.att-doc-pill-btn {
    cursor: pointer;
    transition: background 0.15s;
}
.att-doc-pill-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.att-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

/* Attachment indicator icon in note list (badge row) */
.note-att-indicator {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 3px;
    color: var(--primary, #3b82f6);
    opacity: 0.65;
    transition: opacity 0.15s;
    vertical-align: middle;
    line-height: 1;
}
.note-att-indicator:hover { opacity: 1; }

.note-form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ---- Rich Text Editor ---- */
.rich-text-editor-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg);
    /* Reserve full Quill height (toolbar ≈ 42px + editor 160px) so Quill
       initialisation never causes a layout shift. */
    min-height: 205px;
}

.rich-text-editor-inner {
    min-height: 160px;
}

/* Skeleton shown while note data is loading from the API.
   Same size as the editor wrap so the card doesn't jump when Quill appears. */
@keyframes rte-skeleton-sweep {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.aaw-note-skeleton {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius, 6px);
    min-height: 205px;
    background: linear-gradient(
        90deg,
        var(--gray-100, #f3f4f6) 25%,
        var(--gray-200, #e5e7eb) 50%,
        var(--gray-100, #f3f4f6) 75%
    );
    background-size: 400% 100%;
    animation: rte-skeleton-sweep 1.4s ease-in-out infinite;
}

/* Override Quill snow theme to fit our design */
.rich-text-editor-wrap .ql-toolbar {
    border: none;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt, var(--gray-50));
}

.rich-text-editor-wrap .ql-container {
    border: none;
    font-family: inherit;
    font-size: 0.9rem;
}

.rich-text-editor-wrap .ql-editor {
    min-height: 140px;
    color: var(--text-primary);
}

.cr-last-request {
    margin-top: 1.25rem;
    padding: 0.75rem 1rem;
    background: var(--gray-50);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.cr-last-request-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-weight: 500;
    margin-bottom: 0.4rem;
}
.cr-last-request-body {
    font-size: 0.825rem;
    color: var(--gray-600);
    min-height: unset;
    padding: 0;
    border: none;
    opacity: 0.8;
}

.badge-neutral {
    background: var(--gray-100);
    color: var(--gray-600);
}

[data-theme="dark"] .badge-neutral {
    background: var(--gray-700);
    color: var(--gray-300);
}

@media (max-width: 640px) {
    .note-form-row-2 {
        grid-template-columns: 1fr;
    }
    .note-meta-date {
        margin-left: 0;
    }
}

/* ============================================================
   Route Planner Modal
   ============================================================ */

.rp-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.rp-warnings {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.8rem;
    color: #92400e;
    flex-shrink: 0;
}

[data-theme="dark"] .rp-warnings {
    background: #3b2700;
    border-color: #b45309;
    color: #fcd34d;
}

.rp-warning-item + .rp-warning-item { margin-top: 0.25rem; }

.rp-layout {
    display: flex;
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

.rp-timeline-panel {
    flex: 0 0 360px;
    max-width: 360px;
    overflow-y: auto;
    max-height: 62vh;
    position: relative;
    padding-right: 0.25rem;
}

.rp-map-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.rp-map {
    flex: 1;
    height: 62vh;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--gray-200);
}

.rp-map-no-location {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-align: center;
    padding: 0.25rem 0;
}

.rp-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
    margin-top: 0.75rem;
    flex-shrink: 0;
}

.rp-loading-overlay {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 0;
    color: var(--gray-500);
    font-size: 0.875rem;
}

.rp-empty {
    color: var(--gray-400);
    font-size: 0.875rem;
    padding: 1rem 0;
}

.rp-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--gray-600);
    background: var(--gray-50);
    border-radius: var(--radius);
    padding: 0.4rem 0.75rem;
    margin-bottom: 0.75rem;
    flex-shrink: 0;
}

.rp-stats b { color: var(--gray-800); }

.rp-origin {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    margin-bottom: 0.25rem;
}

.rp-origin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--primary-dark);
    flex-shrink: 0;
}

.rp-origin-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
}

.rp-origin--excluded { opacity: 0.6; }

.rp-origin-dot--excluded { background: var(--gray-300); border-color: var(--gray-400); }

.rp-origin-label--excluded { color: var(--gray-400); }

.rp-no-location {
    font-size: 0.75rem;
    color: #b45309;
    background: #fef3c7;
    border-radius: var(--radius);
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.5rem;
}

.rp-transition {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    padding: 0.4rem 0.4rem 0.4rem 1.25rem;
    font-size: 0.78rem;
    color: var(--gray-500);
    border-left: 2px solid var(--gray-200);
    margin-left: 0.85rem;
}

.rp-transition--conflict {
    color: var(--danger);
    border-left-color: var(--danger);
}

.rp-transition--stale {
    color: var(--gray-400);
    font-style: italic;
}

.rp-transition-icon { font-size: 0.7rem; margin-top: 2px; flex-shrink: 0; }

.rp-transition-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.rp-transition-travel { font-weight: 500; }

.rp-traffic-badge {
    display: inline-block;
    font-size: 0.7rem;
    background: #fef3c7;
    color: #92400e;
    border-radius: 3px;
    padding: 0 3px;
    margin-left: 3px;
}

.rp-transition-free { color: var(--success); font-size: 0.75rem; }

.rp-conflict-label {
    color: var(--danger);
    font-weight: 600;
    font-size: 0.75rem;
}

.rp-stop {
    display: flex;
    gap: 0.6rem;
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.625rem 0.75rem;
    margin-bottom: 0.25rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.rp-stop:hover { border-color: var(--primary-light); box-shadow: var(--shadow); }

.rp-stop--excluded { opacity: 0.5; background: var(--gray-50); }

.rp-stop--conflict {
    border-color: #fca5a5;
    background: #fff5f5;
}

[data-theme="dark"] .rp-stop--conflict {
    border-color: #7f1d1d;
    background: #2d1111;
}

.rp-stop-badge {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.rp-stop--excluded .rp-stop-badge { background: var(--gray-400); }

/* Phonecall stops — offset right, off the route line */

/* Wrapper draws the vertical route line behind the offset stop */
.rp-phonecall-wrap {
    position: relative;
    margin-bottom: 0.25rem;
}
.rp-phonecall-wrap::before {
    content: '';
    position: absolute;
    left: 0.85rem;       /* matches margin-left of .rp-transition */
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-200);
    pointer-events: none;
}

.rp-stop--phonecall {
    margin-left: 2rem;
    margin-bottom: 0;    /* wrapper handles spacing */
    border-left: 3px solid #16a34a;
    background: var(--gray-50);
    opacity: 0.92;
}
.rp-stop-badge--phone {
    background: #16a34a;
    font-size: 0.85rem;
}
.rp-phone-in-leg {
    font-size: 0.72rem;
    color: #16a34a;
    margin-top: 2px;
    font-style: italic;
}
.rp-phone-locked {
    font-size: 0.8rem;
    opacity: 0.7;
}
.rp-stop-actions--phone {
    flex-direction: row;
    align-items: center;
}

.rp-stop-body { flex: 1; min-width: 0; }

.rp-stop-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.rp-stop-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rp-stop-actions { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }

.rp-action-btn {
    width: 26px;
    height: 26px;
    border: 1px solid var(--gray-200);
    background: var(--gray-50);
    color: var(--gray-500);
    font-size: 0.7rem;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, color 0.1s;
    padding: 0;
    font-family: inherit;
}

.rp-action-btn:hover:not(:disabled) {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-light);
}

.rp-action-btn:disabled { opacity: 0.3; cursor: default; }

.rp-action-btn--active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

.rp-stop-meta {
    margin-top: 0.3rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.rp-stop-time {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
}

.rp-time-btn {
    background: none;
    border: none;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    padding: 0;
    border-bottom: 1px dashed var(--primary-mid);
}

.rp-time-btn:hover { color: var(--primary-dark); }

.rp-time-input {
    font: inherit;
    font-size: 0.82rem;
    color: var(--gray-800);
    border: 1px solid var(--primary);
    border-radius: 4px;
    padding: 0.1rem 0.3rem;
    background: var(--bg);
    width: 90px;
}

.rp-stop-duration { font-size: 0.78rem; color: var(--gray-500); }

.rp-stop-address {
    font-size: 0.78rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rp-geocode-error { font-size: 0.75rem; color: var(--danger); }

.rp-stop-excluded-label {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 0.2rem;
    font-style: italic;
}

.rp-excluded-section {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--gray-200);
}

.rp-excluded-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

/* Settings panel ──────────────────────────────────────────────────────────── */

.rp-settings {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.25rem;
    padding: 0.6rem 1rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.82rem;
}

.rp-setting-check {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    color: var(--gray-700);
    font-weight: 500;
    white-space: nowrap;
}

.rp-setting-check input[type="checkbox"] { cursor: pointer; }

.rp-setting-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--gray-700);
    white-space: nowrap;
}

.rp-setting-label {
    font-weight: 600;
    color: var(--gray-500);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.rp-setting-range {
    width: 90px;
    accent-color: var(--primary);
    cursor: pointer;
}

.rp-setting-value {
    min-width: 3rem;
    color: var(--gray-700);
    font-variant-numeric: tabular-nums;
}

.rp-setting-select {
    font: inherit;
    font-size: 0.82rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 0.15rem 0.35rem;
    background: var(--bg);
    color: var(--gray-800);
    cursor: pointer;
}

.rp-setting-time {
    font: inherit;
    font-size: 0.82rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 0.15rem 0.35rem;
    background: var(--bg);
    color: var(--gray-800);
    width: 6.5rem;
}

.rp-setting-sep {
    color: var(--gray-400);
    font-size: 0.75rem;
}

[data-theme="dark"] .rp-settings {
    background: var(--gray-100);
    border-color: var(--gray-300);
}
[data-theme="dark"] .rp-setting-check,
[data-theme="dark"] .rp-setting-item {
    color: var(--gray-800);
}
[data-theme="dark"] .rp-setting-label {
    color: var(--gray-600);
}
[data-theme="dark"] .rp-setting-value {
    color: var(--gray-800);
}
[data-theme="dark"] .rp-setting-sep {
    color: var(--gray-500);
}
[data-theme="dark"] .rp-setting-select,
[data-theme="dark"] .rp-setting-time {
    color: var(--gray-800);
    border-color: var(--gray-300);
}
[data-theme="dark"] .rp-setting-range::-webkit-slider-runnable-track {
    background: var(--gray-300);
    height: 4px;
    border-radius: 2px;
}
[data-theme="dark"] .rp-setting-time::-webkit-calendar-picker-indicator {
    filter: invert(1) brightness(0.8);
    opacity: 0.75;
    cursor: pointer;
}

/* Edit buttons (clickable time / duration inside a stop node) */

.rp-stop-time-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.rp-edit-btn {
    background: none;
    border: none;
    font: inherit;
    cursor: pointer;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    transition: background 0.1s, color 0.1s;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary);
    border-bottom: 1px dashed var(--primary-mid);
    line-height: 1.3;
}

.rp-edit-btn:hover {
    background: var(--primary-light);
    color: var(--primary-dark);
    border-bottom-style: solid;
}

.rp-edit-btn--subtle {
    color: var(--gray-500);
    font-weight: 400;
    font-size: 0.78rem;
    border-bottom-color: transparent;
}

.rp-edit-btn--subtle:hover {
    color: var(--gray-700);
    background: var(--gray-100);
    border-bottom-color: var(--gray-300);
}

/* Sub-modal overlays (time picker, duration picker) */

.rp-submodal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.rp-submodal-panel {
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg, 10px);
    padding: 1.5rem;
    width: 100%;
    max-width: 320px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.rp-submodal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-800);
}

.rp-submodal-time-input {
    font: inherit;
    font-size: 1.1rem;
    color: var(--gray-800);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 0.4rem 0.6rem;
    background: var(--bg);
    width: 100%;
    box-sizing: border-box;
}

.rp-submodal-note {
    font-size: 0.78rem;
    color: var(--gray-500);
    margin: 0;
}

.rp-submodal-footer {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Duration chip grid */

.rp-duration-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
}

.rp-duration-chip {
    padding: 0.35rem 0.25rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: var(--gray-50);
    color: var(--gray-700);
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    text-align: center;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.rp-duration-chip:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-light);
}

.rp-duration-chip--active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
}

[data-theme="dark"] .rp-submodal-panel {
    border-color: var(--gray-700);
}

[data-theme="dark"] .rp-duration-chip {
    background: var(--gray-800);
    border-color: var(--gray-700);
    color: var(--gray-200);
}

/* Navigation badge (↗ in transition rows) */
.rp-nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    color: var(--primary);
    font-size: 0.72rem;
    padding: 0 0.3rem;
    line-height: 1.4;
    cursor: pointer;
    vertical-align: middle;
    margin-left: 0.25rem;
    transition: background 0.1s, border-color 0.1s;
}
.rp-nav-badge:hover { background: var(--primary-light); border-color: var(--primary-mid); }

/* Footer spacer pushes nav buttons left, action buttons right */
.rp-footer-spacer { flex: 1; }

/* Navigation footer buttons — slightly muted vs primary actions */
.rp-nav-btn { color: var(--primary); }

/* Footer groups */
.rp-footer-nav { display: flex; gap: 0.5rem; flex: 1; }
.rp-footer-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* Collapsible settings section */
.rp-settings-section { margin-bottom: 0.5rem; }
.rp-settings-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    border-bottom: 1px solid var(--gray-200);
    padding: 0.35rem 0;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.rp-settings-toggle:hover { color: var(--primary); }
.rp-settings-arrow { font-size: 0.65rem; }

/* Mobile tab bar — hidden on desktop */
.rp-mobile-tabs { display: none; }

@media (max-width: 768px) {
    /* Show tab bar on mobile */
    .rp-mobile-tabs {
        display: flex;
        border-bottom: 1px solid var(--gray-200);
        margin-bottom: 0.5rem;
    }
    .rp-mobile-tab {
        flex: 1;
        padding: 0.5rem;
        background: none;
        border: none;
        border-bottom: 2px solid transparent;
        cursor: pointer;
        font-size: 0.875rem;
        color: var(--gray-500);
    }
    .rp-mobile-tab.active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }

    /* Hide inactive panel on mobile */
    .rp-panel--mobile-hidden { display: none !important; }

    /* Stack layout vertically; panels fill full height on mobile */
    .rp-layout { flex-direction: column; }
    .rp-timeline-panel { flex: none; max-width: 100%; max-height: 55vh; }
    .rp-map-panel { flex: none; }
    .rp-map { height: 55vh; min-height: 250px; }
    .rp-footer { flex-wrap: wrap; gap: 0.4rem; }
    .rp-footer-nav { order: 2; width: 100%; justify-content: center; }
    .rp-footer-actions { order: 1; width: 100%; justify-content: flex-end; }
}

/* ── Customer Insights Section ─────────────────────────────── */
.customer-insights-section {
    margin-top: 2rem;
}

.customer-insights-header {
    margin-bottom: 1.25rem;
}

.customer-insights-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-800);
}

.customer-insights-name {
    font-weight: 500;
    color: var(--primary);
}

.customer-insights-prompt {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-500);
    padding: 1.5rem;
    background: var(--gray-50);
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius);
    text-align: center;
}

.dashboard-card-subtitle {
    font-size: 0.75rem;
    color: var(--gray-400);
    font-weight: 400;
}
[data-theme="dark"] .dashboard-card-subtitle {
    color: var(--gray-600);
}

/* ── Customer Sales Widget (cs-) ────────────────────────────── */
.cs-summary {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.cs-stat {
    display: flex;
    flex-direction: column;
}

.cs-stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.1;
}

.cs-stat-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.125rem;
}

.cs-no-data {
    text-align: center;
    color: var(--gray-400);
    font-size: 0.875rem;
    padding: 2rem 0;
}

/* ── Customer Timeline Widget (ct-) ─────────────────────────── */
.ct-empty {
    text-align: center;
    color: var(--gray-400);
    font-size: 0.875rem;
    padding: 2rem 0;
}

.ct-timeline {
    padding: 0.25rem 0;
}

.ct-node {
    display: flex;
    gap: 0.875rem;
    align-items: flex-start;
}

.ct-node-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    width: 36px;
}

.ct-dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.10);
    z-index: 1;
}

.ct-dot-icon {
    font-size: 0.9rem;
    line-height: 1;
}

.ct-line {
    width: 2px;
    background: var(--gray-200);
    position: relative;
    display: flex;
    justify-content: center;
    min-height: 40px;
}

.ct-line-gap-label {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    color: var(--gray-400);
    white-space: nowrap;
    font-weight: 500;
}

.ct-card {
    flex: 1;
    border-radius: var(--radius);
    padding: 0.75rem 0.875rem;
    margin-bottom: 0.25rem;
    cursor: pointer;
    transition: box-shadow 0.15s, transform 0.1s;
    border: 1px solid transparent;
}

.ct-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.ct-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    gap: 0.5rem;
}

.ct-type-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ct-date {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
}

.ct-date-relative {
    font-size: 0.7rem;
    color: var(--gray-400);
    white-space: nowrap;
}

.ct-date-full {
    font-size: 0.65rem;
    color: var(--gray-300);
    white-space: nowrap;
}

.ct-subject {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.ct-linked-orders {
    margin-top: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    border-top: 1px solid var(--gray-200);
    padding-top: 0.4rem;
}

.ct-linked-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--gray-600);
}

.ct-preview {
    font-size: 0.8rem;
    color: var(--gray-600);
    line-height: 1.4;
    margin-bottom: 0.25rem;
}

.ct-person {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}

/* Show-more separator row replaces the old outline button */
.ct-show-more-sep {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    cursor: pointer;
    padding: 0.25rem 0;
    user-select: none;
}
.ct-show-more-sep:hover .ct-show-more-label { color: var(--primary); }
.ct-show-more-sep:hover .ct-show-more-line  { border-color: var(--primary); }
.ct-show-more-line {
    flex: 1;
    height: 0;
    border-top: 1px dashed var(--gray-300);
    transition: border-color 0.15s;
}
.ct-show-more-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-400);
    white-space: nowrap;
    transition: color 0.15s;
}
.ct-show-more-count {
    font-weight: 400;
    color: var(--gray-300);
}

.ct-confirm-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--blue-50, #eff6ff);
    border: 1px solid var(--blue-200, #bfdbfe);
    border-radius: 8px;
    padding: 0.6rem 0.875rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
}
.ct-confirm-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.ct-upcoming {
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--gray-50, #f9fafb);
    border-radius: 8px;
    border: 1px solid var(--gray-200, #e5e7eb);
}
.ct-upcoming-title { font-size: 0.75rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.35rem; }
.ct-upcoming-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0; font-size: 0.875rem; color: var(--gray-600); border-radius: 4px; }
.ct-upcoming-row--clickable { cursor: pointer; padding: 0.3rem 0.5rem; margin: 0 -0.5rem; transition: background-color 0.12s; }
.ct-upcoming-row--clickable:hover { background: var(--gray-100); color: var(--gray-800); }
.ct-upcoming-type { font-size: 1rem; }
.ct-upcoming-time { font-weight: 500; }

/* ── Shared widget cache / stale indicators ─────────────────── */
.widget-cache-label {
    font-size: 0.7rem;
    color: var(--gray-400);
    white-space: nowrap;
}

.widget-stale-warning {
    font-size: 0.8rem;
    color: #b45309;
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 5px;
    padding: 0.4rem 0.75rem;
    margin-bottom: 0.75rem;
}

/* ── Customer Top Sellers Widget (cts-) ─────────────────────── */
.cts-table-wrap {
    overflow-x: auto;
}

.cts-table .text-right {
    text-align: right;
}

.cts-product-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--gray-800);
}

.cts-product-code {
    font-size: 0.7rem;
    color: var(--gray-400);
    font-family: monospace;
}

.cts-uom-inline {
    font-size: 0.7rem;
    color: var(--gray-500);
    font-family: monospace;
}

.cts-col-qty { width: 70px; }
.cts-col-price { width: 90px; }
.cts-col-order { width: 170px; text-align: center; }

.cts-qty-total {
    font-weight: 600;
    color: var(--gray-700);
}

/* Action cell: qty control + toggle button stacked vertically on mobile,
   inline on desktop */
.cts-action-cell {
    padding: 0.375rem 0.5rem !important;
}

.cts-qty-control {
    display: flex;
    align-items: center;
    gap: 2px;
    justify-content: center;
}

.cts-qty-btn {
    width: 26px;
    height: 26px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: var(--gray-50);
    color: var(--gray-600);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.1s;
    line-height: 1;
    flex-shrink: 0;
}

.cts-qty-btn:hover {
    background: var(--gray-200);
}

.cts-qty-input {
    width: 50px;
    height: 26px;
    text-align: center;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 0.875rem;
    color: var(--gray-800);
    background: var(--bg);
    padding: 0 4px;
}

.cts-qty-input::-webkit-inner-spin-button,
.cts-qty-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

/* Toggle button (+ / ✓) */
.cts-toggle-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: transparent;
    color: var(--primary);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
    flex-shrink: 0;
    margin-left: 6px;
}

.cts-toggle-btn:hover:not(:disabled) {
    background: var(--primary-light);
    transform: scale(1.08);
}

.cts-toggle-btn--selected {
    background: #16a34a !important;
    border-color: #16a34a !important;
    color: #fff !important;
}

.cts-toggle-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.cts-row--selected td {
    background: #f0fdf4;
    transition: background 0.2s;
}

/* On desktop, qty control + toggle side-by-side */
.cts-action-cell > .cts-qty-control,
.cts-action-cell > .cts-toggle-btn {
    display: inline-flex;
}
.cts-action-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: nowrap;
}

/* Create Order bar */
.cts-create-order-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    border: 1px solid #86efac;
    border-radius: var(--radius);
    gap: 1rem;
}

.cts-create-order-count {
    font-size: 0.875rem;
    font-weight: 600;
    color: #15803d;
}

.cts-create-order-btn {
    padding: 0.5rem 1.25rem;
    background: #16a34a;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}

.cts-create-order-btn:hover {
    background: #15803d;
    transform: translateY(-1px);
}

.cts-hint {
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: var(--gray-600);
}

/* Show desktop table, hide mobile cards on wide screens */
.cts-mobile-only { display: none; }
.cts-desktop-only { display: block; }

@media (max-width: 640px) {
    .cts-mobile-only { display: block; }
    .cts-desktop-only { display: none; }
}

.cts-card-mobile {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--white);
}

.cts-card-mobile--selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.cts-cm-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--gray-800);
    margin-bottom: 0.25rem;
}

.cts-cm-meta {
    font-size: 0.78rem;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.cts-cm-sep {
    color: var(--gray-300);
}

.cts-cm-stats {
    font-size: 0.78rem;
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

.cts-cm-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cts-cm-total {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    margin-left: auto;
    margin-right: 0.25rem;
}

.cts-empty {
    text-align: center;
    color: var(--gray-400);
    font-size: 0.875rem;
    padding: 2rem 0;
}

/* ── Customer Patterns Widget (cp-) ─────────────────────────── */
.cp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--gray-400);
    font-size: 0.9rem;
}

.cp-header-right {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.cp-ai-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 4px;
    letter-spacing: 0.02em;
}

.cp-cached-at {
    font-size: 0.7rem;
    color: var(--gray-400);
    white-space: nowrap;
}
[data-theme="dark"] .cp-cached-at {
    color: var(--gray-600);
}

.cp-refresh-btn {
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--gray-300);
    border-radius: 5px;
    background: var(--bg);
    color: var(--gray-600);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.cp-refresh-btn:hover:not(:disabled) {
    background: var(--gray-100);
    color: var(--gray-800);
}

.cp-refresh-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cp-refresh-btn--spinning {
    color: var(--primary);
    border-color: var(--primary);
}

.cp-refreshing-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--primary);
    padding: 0.375rem 0;
    margin-bottom: 0.5rem;
}

.cp-summary {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    background: var(--primary-light);
    border: 1px solid rgba(124,111,255,0.2);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    color: var(--gray-700);
    line-height: 1.5;
}

.cp-summary-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.cp-patterns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.cp-pattern-card {
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    border-left-width: 4px;
    padding: 1rem;
    transition: box-shadow 0.15s;
}

.cp-pattern-card:hover {
    box-shadow: var(--shadow-md);
}

.cp-pattern-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.625rem;
}

.cp-pattern-icon {
    font-size: 1.5rem;
    line-height: 1;
    flex-shrink: 0;
}

.cp-pattern-meta {
    flex: 1;
    min-width: 0;
}

.cp-pattern-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.cp-category-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
}

.cp-pattern-desc {
    font-size: 0.825rem;
    color: var(--gray-600);
    line-height: 1.45;
    margin-bottom: 0.75rem;
}

.cp-confidence {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cp-confidence-bar {
    flex: 1;
    height: 5px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
}

.cp-confidence-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.cp-confidence-label {
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 2.5rem;
    text-align: right;
}

@media (max-width: 900px) {
    .cp-patterns-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .cp-patterns-grid {
        grid-template-columns: 1fr;
    }

    /* On narrow screens, stack qty control and toggle button vertically */
    .cts-action-cell {
        flex-direction: column;
        align-items: center;
        gap: 4px;
    }

    .cts-toggle-btn {
        margin-left: 0;
    }

    /* Hide less-critical columns on small screens */
    .cts-col-qty,
    .cts-col-price {
        display: none;
    }

    .cts-create-order-bar {
        flex-direction: column;
        text-align: center;
    }

    .cp-header-right {
        flex-direction: column;
        align-items: flex-end;
        gap: 0.25rem;
    }
}

/* ============================================================
   Map card action buttons (sidebar customer list)
   ============================================================ */

.map-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.625rem;
    padding-top: 0.625rem;
    border-top: 1px solid var(--gray-100);
}

.map-card-btn {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: inherit;
    border-radius: 6px;
    border: 1px solid var(--gray-200);
    background: var(--gray-50);
    color: var(--gray-700);
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.map-card-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.map-card-btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.map-card-btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

.map-card-btn-success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success);
    color: var(--success);
}

.map-card-btn-success:hover {
    background: var(--success);
    color: #fff;
}

.map-card-row {
    display: flex;
    gap: 0.375rem;
    width: 100%;
}

.map-card-btn-navigate {
    background: rgba(2, 132, 199, 0.08);
    border-color: #0284c7;
    color: #0284c7;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.map-card-btn-navigate:hover {
    background: #0284c7;
    color: #fff;
}

/* ============================================================
   Map popup action buttons (Leaflet popup — no CSS vars to be safe)
   ============================================================ */

.map-popup-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.625rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
}

.map-popup-btn {
    width: 100%;
    padding: 0.35rem 0.625rem;
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    border-radius: 5px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    color: #374151;
    cursor: pointer;
    text-align: center;
    line-height: 1.4;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.map-popup-btn:hover {
    background: #e0f2fe;
    border-color: #0284c7;
    color: #0284c7;
}

.map-popup-btn-primary {
    background: #0284c7;
    border-color: #0284c7;
    color: #fff;
}

.map-popup-btn-primary:hover {
    background: #0369a1;
    border-color: #0369a1;
    color: #fff;
}

.map-popup-btn-success {
    background: rgba(16, 185, 129, 0.1);
    border-color: #10b981;
    color: #10b981;
}

.map-popup-btn-success:hover {
    background: #10b981;
    color: #fff;
}

/* ============================================================
   New Call Plan modal content
   ============================================================ */

.cp-modal-customer-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 1rem;
}

.cp-modal-date-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.cp-modal-date-btn {
    flex: 1 1 auto;
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    border-radius: 6px;
    border: 1px solid var(--gray-200);
    background: var(--gray-50);
    color: var(--gray-700);
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    min-width: 0;
}

.cp-modal-date-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.cp-modal-date-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.cp-modal-date-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.cp-modal-date-picker {
    margin-bottom: 0.75rem;
}


.cp-modal-snap-time-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.cp-modal-time-item {
    flex: 1;
    min-width: 0;
}

.cp-modal-time-select-full {
    flex: 1;
    min-width: 0;
    width: 100%;
}

.cp-modal-time-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.cp-modal-time-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    flex-shrink: 0;
}

.cp-modal-time-select {
    width: 100%;
    min-width: 140px;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    background: var(--bg);
    color: var(--gray-800);
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
}

.cp-modal-time-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cp-modal-locked-row {
    margin-bottom: 1rem;
}

.cp-modal-locked-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
    user-select: none;
}

.form-field-error {
    font-size: 0.78rem;
    color: var(--danger);
    margin-top: 0.25rem;
}

.form-error {
    font-size: 0.82rem;
    color: var(--danger);
    background: rgba(220, 38, 38, 0.06);
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
}

.input-error {
    border-color: var(--danger) !important;
}

.cp-modal-time-select-wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.cp-modal-type-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.cp-modal-error {
    color: var(--danger, #ef4444);
    font-size: 0.78rem;
    margin-top: -0.4rem;
    margin-bottom: 0.6rem;
}

.cp-modal-type-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
}

.cp-modal-phone-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.cp-modal-phone-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

.cp-modal-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-100);
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Responsive: stack card buttons on small sidebar widths */
@media (max-width: 400px) {
    .map-card-actions {
        flex-direction: column;
    }

    .cp-modal-date-row {
        flex-direction: column;
    }

    .cp-modal-date-btn {
        width: 100%;
    }
}
}

/* ── To Do Page ───────────────────────────────────────────── */

.todo-page-header {
    margin-bottom: 1.25rem;
}

/* Filter tabs */
.todo-filter-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.todo-tab {
    font-size: 0.83rem;
    font-weight: 500;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    border: 1.5px solid var(--gray-200);
    background: var(--bg);
    color: var(--gray-600);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.todo-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.todo-tab--active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.todo-tab--picker {
    cursor: pointer;
}

/* Hidden date input — opened programmatically via showPicker() */
.todo-date-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
    border: 0;
    padding: 0;
}

/* Summary chips */
.todo-summary-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.todo-summary-chip {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: var(--gray-100);
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
    cursor: pointer;
    transition: opacity 0.15s, box-shadow 0.15s;
}
button.todo-summary-chip { font-family: inherit; line-height: inherit; }
button.todo-summary-chip:hover { opacity: 0.8; }
.todo-summary-chip--active { box-shadow: 0 0 0 2px var(--gray-400); }

.todo-summary-chip--call {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.todo-summary-chip--task {
    background: #fef9c3;
    color: #854d0e;
    border-color: #fde68a;
}

.todo-summary-chip--appt {
    background: #e0f2fe;
    color: #0369a1;
    border-color: #bae6fd;
}

.todo-summary-chip--phone-appt {
    background: #dcfce7;
    color: #15803d;
    border-color: #86efac;
}

.todo-summary-chip--visit {
    background: #fff7ed;
    color: #c2410c;
    border-color: #fed7aa;
}

.todo-summary-chip--general {
    background: var(--gray-100);
    color: var(--gray-600);
    border-color: var(--gray-200);
}

.todo-summary-chip--delivery {
    background: #ecfeff;
    color: #0e7490;
    border-color: #a5f3fc;
}

.todo-summary-chip--pickup {
    background: #fffbeb;
    color: #b45309;
    border-color: #fde68a;
}

/* Pending chip: mobile-only — hidden on desktop */
.todo-summary-chip--pending-mobile {
    display: none;
    background: #fef9c3;
    color: #854d0e;
    border-color: #fde68a;
}

.todo-summary-chip--done {
    background: var(--gray-50);
    color: var(--gray-500);
    border-color: var(--gray-200);
}

/* On mobile: hide per-type chips, show the Pending chip instead */
@media (max-width: 640px) {
    .todo-summary-chip--type {
        display: none;
    }

    .todo-summary-chip--pending-mobile {
        display: inline-block;
    }
}

/* Item list */
.todo-items {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.todo-item {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--gray-200);
    border-left-width: 4px;
    border-radius: var(--radius);
    background: var(--bg);
    border-left-color: var(--gray-300);
}

.todo-item--phonecall {
    border-left-color: #1d4ed8;
}

.todo-item--task {
    border-left-color: #f59e0b;
}

.todo-item--appointment {
    border-left-color: #0284c7;
}

.todo-item--visit {
    border-left-color: #c2410c;
}

.todo-item--general {
    border-left-color: var(--gray-400);
}

.todo-item--delivery {
    border-left-color: #0e7490;
}

.todo-item--pickup {
    border-left-color: #b45309;
}

.todo-item--done {
    opacity: 0.65;
}

.todo-item--pending {
    border-style: dashed;
    opacity: 0.8;
}

.todo-item--clickable {
    cursor: pointer;
}

.todo-item--clickable:hover {
    background: var(--gray-50);
    border-color: var(--primary-mid, var(--gray-300));
}

/* Item content */
.todo-item-content {
    flex: 1;
    min-width: 0;
}

.todo-item-header-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

/* Type badge */
.todo-type-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

.todo-type-badge--phonecall {
    background: #eff6ff;
    color: #1d4ed8;
}

.todo-type-badge--task {
    background: #fef9c3;
    color: #854d0e;
}

.todo-type-badge--phone-appt {
    background: #dcfce7;
    color: #15803d;
}

.todo-item--phone-appt {
    border-left-color: #16a34a;
}

.todo-item--phone-appt.todo-item--clickable:hover {
    background: #f0fdf4;
    border-color: #86efac;
}

.todo-type-badge--appointment {
    background: #e0f2fe;
    color: #0369a1;
}

.todo-type-badge--visit {
    background: #fff7ed;
    color: #c2410c;
}

.todo-type-badge--general {
    background: var(--gray-100);
    color: var(--gray-500);
}

.todo-type-badge--delivery {
    background: #ecfeff;
    color: #0e7490;
}

.todo-type-badge--pickup {
    background: #fffbeb;
    color: #b45309;
}

.todo-item-time {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--gray-500);
}

.todo-item-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.todo-item-name--done {
    text-decoration: line-through;
    color: var(--gray-400);
}

.todo-item-subject {
    font-size: 0.82rem;
    color: var(--gray-500);
    margin-bottom: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.todo-item-detail {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.78rem;
    color: var(--gray-400);
    margin-top: 0.2rem;
}

.todo-item-detail--phone { color: #1d4ed8; }
.todo-item-detail--address { color: var(--gray-500); }

/* Action buttons */
.todo-item-actions {
    flex-shrink: 0;
    align-self: center;
}

.todo-view-btn,
.todo-status-btn {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.3rem 0.7rem;
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.todo-view-btn {
    border: 1.5px solid var(--gray-300);
    background: var(--bg);
    color: var(--gray-600);
}

.todo-view-btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-400);
}

.todo-status-btn--pending {
    border: 1.5px solid #15803d;
    background: transparent;
    color: #15803d;
}

.todo-status-btn--pending:hover {
    background: #15803d;
    color: #fff;
}

.todo-status-btn--done {
    border: 1.5px solid var(--gray-300);
    background: transparent;
    color: var(--gray-400);
}

.todo-status-btn--done:hover {
    background: var(--gray-100);
    color: var(--gray-600);
}

/* Loading / error / empty */
.todo-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 2rem;
    color: var(--gray-400);
    font-size: 0.875rem;
}

.todo-error {
    padding: 1rem;
    background: #fef2f2;
    color: #b91c1c;
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.todo-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-400);
    font-size: 0.875rem;
}

@media (max-width: 500px) {
    .todo-item {
        flex-wrap: wrap;
    }

    .todo-item-actions {
        width: 100%;
        display: flex;
        justify-content: flex-end;
    }
}

/* ═══════════════════════════════════════════════════════
   M11 Catalogue
   ═══════════════════════════════════════════════════════ */

.catalog-page {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-bottom: 5rem; /* space for cart footer */
}

/* Header / search bar */
.catalog-header {
    background: var(--bg);
    border-bottom: 1px solid var(--gray-200);
    /* padding via .page-wide */
}

.catalog-title-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: space-between;
}

/* Dev: tile width slider */
.dev-tile-width-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.dev-tile-width-label {
    font-size: 0.75rem;
    color: var(--gray-400);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    min-width: 5.5ch;
}

.dev-tile-width-slider {
    width: 100px;
    accent-color: var(--primary);
    cursor: pointer;
}

.catalog-search-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.catalog-action-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.catalog-sort-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}
.catalog-sort-label { color: var(--gray-600); }
.catalog-sort-select {
    padding: 0.3rem 0.5rem;
    border: 1.5px solid var(--primary);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--primary-light);
    color: var(--primary-dark);
    cursor: pointer;
}

.catalog-quick-order-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
    background: linear-gradient(135deg, #0d9488, #0f766e);
    color: #fff;
    border: none;
    box-shadow: 0 2px 6px rgba(13,148,136,0.3);
}
.catalog-quick-order-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #0f766e, #115e59);
    box-shadow: 0 3px 10px rgba(13,148,136,0.4);
}
.catalog-quick-order-btn:disabled {
    background: var(--gray-300);
    color: var(--gray-500);
    box-shadow: none;
    cursor: not-allowed;
}

.catalog-keyword-input {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem 0.75rem;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.925rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--gray-800);
    outline: none;
    transition: border-color 0.15s;
}
.catalog-keyword-input:focus {
    border-color: var(--primary);
}

/* Category filter button + dropdown */
.cat-filter-wrap {
    position: relative;
}

.cat-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--gray-700);
    font-size: 0.875rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    min-width: 360px;
    transition: border-color 0.15s, background 0.15s;
}
.cat-filter-btn:hover,
.cat-filter-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.cat-dropdown-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 360px;
    max-width: 480px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 200;
}

/* Category tree */
.cat-tree-container {
    padding: 0.5rem;
}

.cat-tree-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.4rem 0.5rem;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 0.4rem;
}

.cat-tree-sep {
    color: var(--gray-400);
    font-size: 0.8rem;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.btn-link:hover {
    color: var(--primary-dark);
}

.cat-tree {
    font-size: 0.875rem;
}

.cat-node {
    user-select: none;
}

.cat-node-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.25rem;
    border-radius: 6px;
    cursor: default;
}
.cat-node-row:hover {
    background: var(--gray-100);
}

.cat-expand-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    padding: 0;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}
.cat-expand-btn:hover {
    color: var(--primary);
}

.cat-expand-spacer {
    width: 14px;
    flex-shrink: 0;
}

.cat-checkbox {
    flex-shrink: 0;
    accent-color: var(--primary);
    cursor: pointer;
    width: 14px;
    height: 14px;
}

.cat-node-label {
    color: var(--gray-700);
    font-size: 0.85rem;
    line-height: 1.3;
    cursor: pointer;
    flex: 1;
}

.cat-children {
    padding-left: 1.25rem;
}

/* Results grid */
.catalog-results {
    padding: 1.25rem 1.5rem;
}

.catalog-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
    font-size: 0.95rem;
}

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 1rem;
}

/* Product Tile */
.product-tile {
    background: var(--bg);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.product-tile:hover {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-md);
}

.product-tile.queued {
    border-color: var(--success);
    box-shadow: 0 0 0 2px rgba(16,185,129,0.15), var(--shadow-md);
}

.product-tile-image {
    height: 150px;
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    position: relative; /* anchor for qty-warning overlay */
}

.product-tile-image img,
.product-tile-image .product-tile-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-tile-placeholder,
.product-img-placeholder {
    color: var(--gray-400);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: var(--gray-100);
}

.product-tile-body {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
}

.product-tile-code {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.product-tile-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--gray-800);
    line-height: 1.3;
}

.product-tile-price-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.product-tile-price {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
}

.product-tile-price.price-struck {
    text-decoration: line-through;
    color: var(--gray-400);
    font-size: 0.82rem;
    font-weight: 500;
}

.product-tile-uom {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--gray-500);
}

.btn-override-toggle {
    font-size: 0.72rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1.5px solid var(--gray-300);
    background: var(--bg);
    color: var(--gray-600);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-override-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Inline override input — replaces the Override button in-place */
.price-override-inline {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--primary);
    border-radius: 6px;
    background: var(--primary-light);
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.price-override-dollar {
    padding: 0 0.2rem 0 0.4rem;
    font-size: 0.8rem;
    color: var(--primary);
    flex-shrink: 0;
}

.price-override-input {
    border: none;
    outline: none;
    padding: 0.2rem 0.2rem 0.2rem 0;
    font-size: 0.875rem;
    font-family: inherit;
    font-weight: 600;
    color: var(--primary-dark);
    background: transparent;
    width: 100%;
    min-width: 0;
    -moz-appearance: textfield;
}
.price-override-input::-webkit-inner-spin-button,
.price-override-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.price-override-cancel {
    background: none;
    border: none;
    border-left: 1px solid rgba(124,111,255,0.3);
    color: var(--primary);
    cursor: pointer;
    padding: 0.1rem 0.4rem;
    font-size: 0.9rem;
    font-family: inherit;
    flex-shrink: 0;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}
.price-override-cancel:hover {
    background: rgba(239,68,68,0.1);
    color: var(--danger);
}

/* Stock display */
.product-tile-stock-row {
    margin-top: 0.1rem;
}

.stock-display {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    font-size: 0.75rem;
    font-family: inherit;
    color: var(--gray-600);
    transition: border-color 0.15s, background 0.15s;
}
.stock-display:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

.stock-avail {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.stock-incoming {
    color: var(--success);
    font-weight: 500;
}

.stock-incoming--no-bo {
    text-decoration: line-through;
    color: var(--gray-400);
}

/* Note toggle */
/* ── Note field (3-state) ──────────────────────────────────────────────────── */

/* Clear state: just a dashed "add" button, full width */
.note-btn-clear {
    display: block;
    width: 100%;
    text-align: left;
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    border: 1.5px dashed var(--gray-300);
    background: transparent;
    color: var(--gray-400);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s, color 0.15s;
}
.note-btn-clear:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Focussed / Unfocussed wrapper */
.note-wrap {
    border: 1.5px solid var(--primary);
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
}
.note-wrap--unfocused {
    border-color: var(--gray-300);
    cursor: pointer;
}

.note-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    user-select: none;
}
.note-wrap--focused .note-header {
    background: var(--primary-light);
    color: var(--primary);
    border-bottom: 1px solid rgba(124,111,255,0.2);
}
.note-wrap--unfocused .note-header {
    background: var(--gray-50);
    color: var(--gray-500);
    border-bottom: 1px solid var(--gray-200);
}

.note-header-label {
    flex: 1;
}

.note-header-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    font-size: 0.9rem;
    line-height: 1;
    padding: 0 0.1rem;
    font-family: inherit;
    transition: color 0.15s;
}
.note-header-clear:hover {
    color: var(--danger);
}

.note-textarea {
    display: block;
    width: 100%;
    resize: none;
    border: none;
    outline: none;
    padding: 0.4rem 0.5rem;
    font-size: 0.82rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--gray-800);
    min-height: 52px;
}
.note-textarea--readonly {
    font-size: 0.75rem;
    color: var(--gray-500);
    background: var(--gray-50);
    cursor: pointer;
    resize: none;
    min-height: unset;
    height: auto;
}

/* ── Cart row ──────────────────────────────────────────────────────────────── */

.product-tile-cart-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    min-height: 32px;
}

/* Fused qty group [-[#]+] */
.qty-group {
    display: inline-flex;
    align-items: stretch;
    border: 1.5px solid var(--gray-300);
    border-radius: 6px;
    overflow: hidden;
    transition: border-color 0.15s;
    flex-shrink: 0;
}
.qty-group:focus-within {
    border-color: var(--primary);
}
.qty-group .qty-btn {
    border: none;
    border-radius: 0;
    background: var(--gray-50);
    color: var(--gray-700);
    width: 28px;
    height: 28px;
    font-size: 1.05rem;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
}
.qty-group .qty-btn:hover:not(:disabled) {
    background: var(--primary-light);
    color: var(--primary);
}
.qty-group .qty-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.qty-group .qty-input {
    border: none;
    border-left: 1px solid var(--gray-200);
    border-right: 1px solid var(--gray-200);
    border-radius: 0;
    width: 44px;
    text-align: center;
    padding: 0.2rem 0.15rem;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 600;
    background: var(--bg);
    color: var(--gray-800);
    outline: none;
    -moz-appearance: textfield;
}
.qty-group .qty-input::-webkit-inner-spin-button,
.qty-group .qty-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.qty-line-total {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--success);
    flex: 1;
    text-align: center;
    white-space: nowrap;
    min-width: 0;
}

/* Compact mode: large line totals (≥$1000) shrink spinner + total text */
.product-tile-cart-row--compact .qty-group .qty-input { width: 32px; font-size: 0.78rem; }
.product-tile-cart-row--compact .qty-group .qty-btn { padding: 0 6px; }
.product-tile-cart-row--compact .qty-line-total { font-size: 0.7rem; }

.qty-btn-zero {
    background: none;
    border: 1.5px solid var(--gray-200);
    border-radius: 6px;
    color: var(--gray-400);
    cursor: pointer;
    font-size: 0.95rem;
    font-family: inherit;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.qty-btn-zero:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: rgba(239,68,68,0.06);
}


/* Stock warning — absolute overlay at bottom of product image */
.qty-warning {
    position: absolute;
    bottom: 0.35rem;
    left: 0.35rem;
    right: 0.35rem;
    font-size: 0.7rem;
    line-height: 1.3;
    border-radius: 4px;
    padding: 0.2rem 0.4rem;
    margin: 0;
    pointer-events: none;
    z-index: 1;
}
.qty-warning.warn {
    background: rgba(245, 158, 11, 0.88);
    color: #7c3a00;
    border: 1px solid rgba(245, 158, 11, 0.5);
    backdrop-filter: blur(4px);
}
.qty-warning.danger {
    background: rgba(239, 68, 68, 0.88);
    color: #fff;
    border: 1px solid rgba(239, 68, 68, 0.5);
    backdrop-filter: blur(4px);
}

/* Stock popup modal */
.stock-popup {
	width: 400px;
	max-width: 95vw;
	background-color: var(--bg);
}

.stock-popup-summary {
    display: flex;
    gap: 1.5rem;
    padding: 1rem 0 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 0.75rem;
}

.stock-popup-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.stock-popup-stat-val {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gray-800);
}

.stock-popup-no-bo {
    text-decoration: line-through;
    color: var(--gray-400);
}

.stock-popup-stat-lbl {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-align: center;
}

.stock-popup-offline {
    font-size: 0.82rem;
    color: var(--gray-500);
    font-style: italic;
    padding: 0.5rem 0;
}

.stock-popup-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.stock-popup-table th {
    text-align: left;
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
    color: var(--gray-500);
    font-weight: 600;
    border-bottom: 1px solid var(--gray-200);
}

.stock-popup-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}

.stock-popup-table tr:last-child td {
    border-bottom: none;
}

/* Cart footer */
.cart-footer {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-w, 0);
    right: 0;
    background: var(--bg);
    border-top: 2px solid var(--success);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    z-index: 150;
    box-shadow: 0 -4px 20px rgba(16,185,129,0.15);
}

.cart-footer-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--gray-700);
    flex-wrap: wrap;
}

.cart-footer-count,
.cart-footer-qty {
    font-weight: 500;
}

.cart-footer-total {
    font-weight: 700;
    color: var(--success);
    font-size: 1rem;
}

.cart-footer-sep {
    color: var(--gray-400);
}

.cart-footer-bo {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--gray-500);
}

.cart-footer-btn {
    white-space: nowrap;
    flex-shrink: 0;
}

.cart-footer-clear {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    color: var(--gray-500);
    border-color: var(--gray-300);
}

.cart-footer-clear:hover {
    color: var(--danger, #dc2626);
    border-color: var(--danger, #dc2626);
}

/* ── Order page: lines card header ──────────────────────────────────────────── */
.so-lines-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    background: var(--gray-50);
}

.so-lines-card-count {
    font-size: 0.8125rem;
    color: var(--gray-500);
    font-weight: 500;
}

.so-clear-cart-btn {
    display: flex;
    align-items: center;
    color: var(--gray-500);
    border-color: var(--gray-300);
}

.so-clear-cart-btn:hover {
    color: var(--danger, #dc2626);
    border-color: var(--danger, #dc2626);
}

/* Responsive */
@media (max-width: 768px) {
    .cart-footer {
        left: 0; /* sidebar hidden on mobile */
    }
}

@media (max-width: 600px) {
    .catalog-results {
        padding: 1rem;
    }
    .product-tile-image {
        height: 120px;
    }
    .dev-tile-width-wrap {
        display: none; /* hide dev slider on small screens */
    }
}

/* =====================================================
   SmartOrderButton
   ===================================================== */

.sob-wrap {
    position: relative;
    display: inline-flex;
    flex-direction: column;
}

/* Split button */
.sob-split-btn {
    display: flex;
    align-items: stretch;
}

.sob-main-btn {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    display: flex;
    align-items: center;
    gap: 0;
}

.sob-gear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    padding: 0;
    background: var(--brand-blue, #3b82f6);
    color: #fff;
    border: none;
    border-left: 1px solid rgba(255,255,255,0.25);
    border-radius: 0 var(--radius, 0.375rem) var(--radius, 0.375rem) 0;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}
.sob-gear-btn:hover { background: var(--brand-blue-dark, #2563eb); }
.sob-gear-btn:focus-visible { outline: 2px solid var(--brand-blue, #3b82f6); outline-offset: 2px; }

/* Dropdown panel (desktop) */
.sob-panel-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 500;
    min-width: 240px;
}

/* Bottom sheet (mobile) */
.sob-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1200;
    display: flex;
    align-items: flex-end;
}

.sob-panel-sheet {
    width: 100%;
    border-radius: 1rem 1rem 0 0;
}

.sob-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--gray-300);
    border-radius: 2px;
    margin: 0.75rem auto 0.5rem;
}

.sob-sheet-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 1rem;
    padding: 0.5rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--gray-200);
}

.sob-sheet-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    opacity: 0.5;
    padding: 0.25rem;
    line-height: 1;
}

/* Shared panel card */
.sob-panel {
    background: var(--card-bg, #fff);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius, 0.375rem);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    padding: 0.875rem 1rem;
}
[data-theme="dark"] .sob-panel {
    background: var(--gray-100);
    border-color: var(--gray-300);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

/* Settings content */
.sob-settings-content {}

.sob-settings-section {
    margin-bottom: 0.875rem;
}
.sob-settings-section:last-child { margin-bottom: 0; }

.sob-settings-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
}

.sob-indent {
    padding-left: 0.75rem;
    border-left: 2px solid var(--gray-200);
}

/* Radio chips */
.sob-radio-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.sob-radio-chip {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 2rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--gray-700);
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    user-select: none;
}
.sob-radio-chip input[type="radio"] { display: none; }
.sob-radio-chip.active {
    border-color: var(--brand-blue, #3b82f6);
    background: color-mix(in srgb, var(--brand-blue, #3b82f6) 8%, transparent);
    color: var(--brand-blue, #3b82f6);
    font-weight: 600;
}

/* Checkbox rows */
.sob-checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-700);
    cursor: pointer;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}
.sob-checkbox-row:last-child { margin-bottom: 0; }
.sob-checkbox-row input[type="checkbox"] { margin-top: 0.15em; flex-shrink: 0; }

@media (max-width: 600px) {
    .sob-settings-content { padding: 0.75rem 1.25rem 1.5rem; }
}

/* =====================================================
   M17 — Order / Quote page
   ===================================================== */

/* Nav item badge (cart count on sidebar Order/Quote link) */
.nav-item-badge {
    position: absolute;
    top: -4px;
    right: -6px;
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    line-height: 1;
    pointer-events: none;
}

/* Compact read-only lines table (steps 2 & 3) */
.oq-compact-lines {
    overflow-x: auto;
}

.oq-compact-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.oq-compact-table thead th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--gray-200);
    font-weight: 600;
    color: var(--gray-600);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.oq-compact-table tbody td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.oq-compact-table tbody tr:last-child td {
    border-bottom: none;
}

.oq-col-qty   { width: 60px; text-align: right; white-space: nowrap; }
.oq-col-price { width: 90px; text-align: right; white-space: nowrap; }
.oq-col-total { width: 90px; text-align: right; white-space: nowrap; font-weight: 600; color: var(--gray-800); }

/* Category-sort group header row */
.oq-category-header-row td { padding: 0; border-bottom: none; }
.oq-category-header {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    background: var(--gray-50);
    padding: 0.3rem 0.75rem !important;
    border-top: 1px solid var(--gray-200);
}
.oq-category-header-row:first-child .oq-category-header { border-top: none; }

/* Card title row with sort toggle — sits inside .card (which already has padding) */
.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.card-title-row .card-title { margin-bottom: 0; }
.oq-sort-toggle { font-size: 0.8rem; padding: 0.25rem 0.6rem; }

/* Extra bottom breathing room so action buttons don't sit flush at the viewport edge */
.so-page.embedded {
    padding-bottom: 2.5rem;
}

/* Action row with Create Quote / Create Order buttons */
.oq-action-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.oq-btn-quote,
.oq-btn-order {
    display: flex;
    align-items: center;
}

.so-stock-block-msg {
    flex: 1;
    font-size: 0.8125rem;
    color: var(--warning-700, #b45309);
    background: var(--warning-50, #fffbeb);
    border: 1px solid var(--warning-200, #fde68a);
    border-radius: 0.375rem;
    padding: 0.25rem 0.625rem;
}

/* Print/Email card */
.oq-print-email-card {}

/* Email form */
.oq-email-form {
    border-top: 1px solid var(--gray-200);
    padding-top: 1rem;
    margin-top: 0.25rem;
}

@media (max-width: 480px) {
    .oq-action-row {
        flex-direction: column;
    }
    .oq-btn-quote,
    .oq-btn-order {
        width: 100%;
        justify-content: center;
    }
}

/* ── Product item shared components ────────────────────────────────────────── */

/* NOT IMPLEMENTED banner (History/Info modals) */
.pi-not-impl {
    background: #fef9c3;
    border: 1px solid #fde047;
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #713f12;
}

/* Icon-only action buttons (History, Info in action row) */
.pi-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--gray-300);
    border-radius: 0.25rem;
    background: var(--bg);
    color: var(--gray-600);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    flex-shrink: 0;
    position: relative;
}
.pi-icon-btn:hover { background: var(--gray-100); border-color: var(--gray-400); }

/* Note dot indicator */
.pi-note-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary);
}
.pi-note-has-value { border-color: var(--primary); color: var(--primary); }

/* Note popup */
.pi-note-popup {
    background: var(--bg);
    border: 1px solid var(--gray-300);
    border-radius: 0.5rem;
    padding: 0.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.pi-note-textarea {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    font-size: 0.8rem;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.25rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--gray-800);
    min-height: 64px;
}
.pi-note-textarea:focus { outline: none; border-color: var(--primary); }
.pi-note-clear {
    align-self: flex-start;
    font-size: 0.75rem;
    color: var(--danger);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}
.pi-note-clear:hover { text-decoration: underline; }

/* Stock button in product action rows */
.pi-stock-btn {
    font-size: 0.72rem;
    height: 22px;
}

/* Product tile actions row (History + Info icons) */
.product-tile-actions-row {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.25rem;
    margin-bottom: 0.1rem;
}

/* Unit price cell in order lines */
.so-unit-price-cell {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.so-unit-price-override {
    display: flex;
    align-items: center;
}
.product-price-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
}
.product-price-value.price-struck {
    text-decoration: line-through;
    color: var(--gray-400);
    font-weight: 400;
}
.product-price-uom {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-weight: 400;
}

/* Updated lines table column widths — product col grows to fill */
.so-lines-table .so-lt-product { width: auto; min-width: 180px; }
.so-lines-table .so-lt-img    { width: 90px; min-width: 90px; }
.so-lines-table .so-lt-price  { width: 120px; }
.so-lines-table .so-lt-qty    { width: 112px; }
.so-lines-table .so-lt-total  { width: 80px; font-weight: 700; text-align: right; white-space: nowrap; color: var(--gray-800); }
.so-lines-table .so-lt-remove { width: 38px; text-align: center; }

/* SOB panel dropdown: override to ensure no position:absolute rules interfere */
.sob-panel-dropdown {
    z-index: 3000 !important;
}

/* ---- Lines step: full-width page layout (issues 1, 2, 6) ---- */
.so-lines-page {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-bottom: 4.5rem; /* space for fixed footer */
}

.so-lines-page > .page-title {
    padding: var(--page-padding) var(--page-padding) 0;
    flex-shrink: 0;
}

.so-lines-header {
    background: var(--bg);
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 56px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}


/* Strip card look from stepper when inline in header */
.so-lines-header .so-step-indicator {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    flex-shrink: 0;
}

.so-lines-body {
    padding: 1.5rem;
}

.so-lines-footer {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-w, 0px);
    right: 0;
    background: var(--bg);
    border-top: 1px solid var(--gray-200);
    padding: 0.875rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    z-index: 150;
    box-shadow: 0 -4px 20px rgba(124,111,255,0.12);
}

@media (max-width: 768px) {
    .so-lines-footer {
        left: 0;
    }
}

@media (max-width: 480px) {
    .so-lines-footer {
        flex-wrap: wrap;
        padding: 0.625rem 0.875rem;
        gap: 0.5rem;
    }
    /* Create Quote + Create Order: side-by-side, equal halves, first row */
    .so-lines-footer .oq-btn-quote,
    .so-lines-footer .oq-btn-order {
        flex: 1;
        justify-content: center;
        white-space: nowrap;
        order: 0;
    }
    /* Save as Draft: full-width second row */
    .so-lines-footer .btn:not(.oq-btn-quote):not(.oq-btn-order) {
        width: 100%;
        order: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        white-space: nowrap;
    }
}

@media (max-width: 600px) {
    .so-lines-header {
        padding: 0.75rem 1rem;
        top: 48px;
    }
    .so-lines-body {
        padding: 1rem;
    }
}

/* Add Products section inside the lines card (issue 4) */
.so-add-products-section {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--gray-100);
}

/* ── ProductPopup (item 2.2) ─────────────────────────────────────────── */

/* 2-line clamp on catalog tile description */
.pp-name-clamp {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Clickable name in order lines */
.pp-name-link {
    cursor: pointer;
    color: inherit;
}
.pp-name-link:hover { text-decoration: underline; }

/* Two-panel layout: image left, content right */
.pp-layout {
    display: flex;
    gap: 1.25rem;
    min-height: 260px;
}
.pp-image-panel {
    flex: 0 0 180px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}
.pp-product-image {
    width: 180px;
    height: 180px;
    object-fit: contain;
    border-radius: var(--radius);
    background: var(--gray-50);
}
.pp-content-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.pp-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
    border-bottom: 1.5px solid var(--gray-200);
    padding-bottom: 0.25rem;
}
.pp-tab-btn {
    padding: 0.3rem 0.85rem;
    border: none;
    background: none;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--gray-600);
    cursor: pointer;
    border-radius: var(--radius) var(--radius) 0 0;
    transition: color 0.12s, background 0.12s;
}
.pp-tab-btn:hover { color: var(--gray-800); background: var(--gray-100); }
.pp-tab-btn.active { color: var(--primary); font-weight: 600; border-bottom: 2px solid var(--primary); margin-bottom: -1.5px; }
.pp-tab-body { flex: 1; overflow-y: auto; }
.pp-loading { display: flex; align-items: center; gap: 0.5rem; color: var(--gray-500); padding: 1rem 0; font-size: 0.875rem; }
.pp-error   { color: var(--danger); padding: 0.5rem 0; font-size: 0.875rem; }
.pp-empty   { color: var(--gray-500); padding: 0.5rem 0; font-size: 0.875rem; }
.pp-info-tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; }
.pp-meta  { font-size: 0.8rem; color: var(--gray-500); margin-bottom: 0.4rem; }
.pp-description { color: var(--gray-700); line-height: 1.6; margin-bottom: 0.75rem; font-size: 0.9rem; }
.pp-overview { font-size: 0.9rem; }
.pp-long-description {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
    font-size: 0.85rem;
    color: var(--gray-700);
    line-height: 1.6;
    white-space: pre-wrap;
}

/* Mobile: stack image above content */
@media (max-width: 600px) {
    .pp-layout { flex-direction: column; }
    .pp-image-panel { flex: none; width: 100%; justify-content: center; }
    .pp-product-image { width: 140px; height: 140px; }
}

/* ============================================================
   Header sync button + popup  (Prompt 5)
   ============================================================ */
.sync-header-wrap {
    position: relative;
}

.sync-header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 36px;
    height: 32px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--warning, #f59e0b);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sync-header-btn:hover,
.sync-header-btn.active {
    background: rgba(245, 158, 11, 0.12);
    color: var(--warning, #f59e0b);
}

.sync-header-badge {
    position: absolute;
    top: 1px;
    right: 1px;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    background: var(--warning, #f59e0b);
    color: #fff;
    border-radius: 7px;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
    pointer-events: none;
}

.sync-header-popup {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 280px;
    background: var(--bg);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);
    padding: 0.875rem;
    z-index: 500;
}

[data-theme="dark"] .sync-header-popup {
    border-color: var(--gray-700);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.sync-popup-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
}

.sync-popup-reasons {
    margin: 0 0 0.75rem 0;
    padding: 0 0 0 1.1rem;
    font-size: 0.8rem;
    color: var(--gray-600);
    line-height: 1.6;
}

.sync-popup-reasons li { margin-bottom: 0.1rem; }

.sync-popup-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Make header popup mobile-friendly */
@media (max-width: 600px) {
    .sync-header-popup {
        position: fixed;
        top: 60px;
        right: 0.75rem;
        left: 0.75rem;
        width: auto;
    }
}

/* ============================================================
   Mobile customer pill — centered in header
   ============================================================ */
@media (max-width: 600px) {
    .header-spacer { display: none; }
    .header-customer {
        position: absolute;
        left: 0;
        right: 0;
        margin: 0 auto;
        width: fit-content;
        flex: unset;
        min-width: unset;
        z-index: 1;
    }
    .header { gap: 0.25rem; }
    .header-username { padding: 0.25rem; }
}

/* ============================================================
   Mobile menu — action strip (cart / sync / user) at top
   ============================================================ */
/* Mobile menu selector section (customer + rep pickers stacked) */
.mobile-menu-selectors {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.mobile-menu-picker-wrap {
    position: relative;
    border-bottom: 1px solid var(--gray-100);
}
.mobile-menu-picker-wrap:last-child { border-bottom: none; }

.mobile-menu-picker-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.65rem 1.25rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: left;
}
.mobile-menu-picker-btn.has-value { color: var(--text); font-weight: 500; }
.mobile-menu-picker-btn span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mobile-menu-picker-dropdown {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.5rem 0.75rem 0.75rem;
    max-height: 280px;
    overflow-y: auto;
}

.mobile-menu-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: var(--primary-light);
    border-bottom: 2px solid var(--primary);
    flex-shrink: 0;
}
[data-theme="dark"] .mobile-menu-actions {
    background: rgba(56,189,248,0.08);
    border-bottom-color: rgba(56,189,248,0.35);
}
.mobile-menu-actions .cart-btn,
.mobile-menu-actions .sync-header-btn {
    border-radius: 0;
}
.mobile-action-user {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary);
    margin-left: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.mobile-action-user span {
    overflow: hidden;
    text-overflow: ellipsis;
}
[data-theme="dark"] .mobile-action-user {
    color: var(--primary);
}

/* ============================================================
   Home page — compact sync card  (Prompt 5 rev)
   ============================================================ */

/* Card with no internal padding — sections provide their own */
.hs-card { padding: 0 !important; }

/* Each section inside the sync card */
.hs-section {
    padding: 0.75rem 1.1rem;
    border-bottom: 1px solid var(--gray-100);
}
.hs-section-last { border-bottom: none; }
[data-theme="dark"] .hs-section { border-bottom-color: var(--gray-800); }

/* Section header row: title+badge on left, button on right */
.hs-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.hs-title-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ALL-CAPS section title with left accent bar */
.hs-section-title {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    color: var(--gray-600);
    text-transform: uppercase;
    border-left: 3px solid var(--primary);
    padding-left: 0.45rem;
    line-height: 1.2;
}

/* Status badges */
.hs-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.hs-badge-none    { background: var(--gray-100);              color: var(--gray-500);           border: 1px solid var(--gray-200); }
.hs-badge-fresh   { background: rgba(16,185,129,0.1);         color: #059669;                    border: 1px solid rgba(16,185,129,0.25); }
.hs-badge-pending { background: rgba(245,158,11,0.12);        color: var(--warning, #f59e0b);    border: 1px solid rgba(245,158,11,0.3); }

[data-theme="dark"] .hs-badge-none    { background: var(--gray-800); color: var(--gray-400); border-color: var(--gray-700); }
[data-theme="dark"] .hs-badge-fresh   { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.3); }
[data-theme="dark"] .hs-badge-pending { background: rgba(245,158,11,0.18); border-color: rgba(245,158,11,0.4); }

/* Sub-text below Sync All title */
.hs-sub {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin: 0;
    line-height: 1.4;
}

/* Row list (upload + download items) */
.hs-rows {
    display: flex;
    flex-direction: column;
    margin-top: 0.25rem;
}

.hs-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.22rem 0;
    font-size: 0.82rem;
}

/* Bullet dot */
.hs-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gray-300);
    flex-shrink: 0;
}
.hs-dot-active { background: var(--warning, #f59e0b); }

/* Step icon wrapper (download rows) */
.hs-step-icon {
    width: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.hs-check  { color: var(--success); font-weight: 700; font-size: 0.9rem; line-height: 1; }
.hs-error  { color: var(--danger);  font-weight: 700; font-size: 0.9rem; line-height: 1; }
.hs-spinner {
    width: 12px !important;
    height: 12px !important;
    border-color: var(--gray-300) !important;
    border-top-color: var(--primary) !important;
}

/* Clickable row (orders/quotes with pending items) */
.hs-row-clickable {
    cursor: pointer;
    border-radius: 4px;
}
.hs-row-clickable:hover {
    background: var(--primary-light);
}

/* Row label — grows to fill space */
.hs-row-label { flex: 1; color: var(--gray-700); }
.hs-muted     { color: var(--gray-400) !important; }

/* Time / age text on right */
.hs-row-time { font-size: 0.78rem; color: var(--gray-400); text-align: right; white-space: nowrap; }
.hs-stale    { color: var(--warning, #f59e0b) !important; font-weight: 600; }

/* Upload link button */
.hs-upload-link {
    font-size: 0.78rem;
    color: var(--primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    white-space: nowrap;
    transition: color 0.12s;
}
.hs-upload-link:hover:not(:disabled) { color: var(--primary-dark, #5b4dd4); text-decoration: underline; }
.hs-upload-link:disabled,
.hs-upload-link.hs-muted { color: var(--gray-400); cursor: default; }

/* Quick Order preview modal table */
.qop-table { width: 100%; border-collapse: collapse; }
.qop-table th { padding: 0.4rem 0.75rem; border-bottom: 2px solid var(--gray-200); font-size: 0.8rem; color: var(--gray-500); text-align: left; font-weight: 600; }
.qop-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.qop-table tr:last-child td { border-bottom: none; }
.qop-table .qop-price { text-align: right; white-space: nowrap; font-weight: 600; width: 100px; }
.qop-table .qop-check { width: 36px; padding-left: 0.75rem; padding-right: 0.25rem; }
.qop-table .qop-qty { width: 80px; text-align: center; }
.qop-qty-input { width: 60px; padding: 0.25rem 0.35rem; border: 1px solid var(--gray-300); border-radius: 4px; font-size: 0.875rem; text-align: center; }
.qop-qty-input:disabled { background: var(--gray-100); color: var(--gray-400); }
.qop-row-unchecked td { opacity: 0.4; }
.qop-name { font-weight: 600; font-size: 0.875rem; color: var(--gray-800); }
.qop-code { font-size: 0.72rem; color: var(--gray-500); font-family: 'SF Mono', 'Consolas', monospace; }

/* ============================================================
   Settings Page
   ============================================================ */

.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--gray-100);
    gap: 1rem;
}

.settings-row:last-of-type {
    border-bottom: none;
}

.settings-label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.settings-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-900);
}

[data-theme="dark"] .settings-value {
    color: var(--gray-100);
}

.settings-description {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 1.25rem;
}
.settings-welcome-link {
    display: inline-block;
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--brand-blue, #2563eb);
    text-decoration: none;
}
.settings-welcome-link:hover { text-decoration: underline; }

.settings-counts {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

@media (max-width: 480px) {
    .settings-counts {
        grid-template-columns: repeat(2, 1fr);
    }
}

.settings-count-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.75rem 0.5rem;
    gap: 0.25rem;
}

[data-theme="dark"] .settings-count-item {
    background: rgba(255,255,255,0.04);
    border-color: rgba(255,255,255,0.08);
}

.settings-count-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}

.settings-count-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
}

.settings-alert {
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.settings-alert--success {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.settings-alert--error {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

[data-theme="dark"] .settings-alert--success {
    background: #14532d;
    color: #4ade80;
    border-color: #166534;
}

[data-theme="dark"] .settings-alert--error {
    background: #450a0a;
    color: #f87171;
    border-color: #7f1d1d;
}

.settings-version-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.settings-version-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 4.5rem;
}
.settings-version-value {
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.settings-confirm {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.5rem;
}

[data-theme="dark"] .settings-confirm {
    background: rgba(255,255,255,0.04);
    border-color: rgba(255,255,255,0.08);
}

.settings-confirm p {
    font-size: 0.875rem;
    color: var(--gray-700);
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

[data-theme="dark"] .settings-confirm p {
    color: var(--gray-300);
}

.settings-confirm-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Theme segmented control */
.theme-segment {
    display: inline-flex;
    background: var(--gray-100);
    border-radius: var(--radius);
    padding: 3px;
    gap: 2px;
}

[data-theme="dark"] .theme-segment {
    background: rgba(255,255,255,0.07);
}

.theme-segment-btn {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 1.1rem;
    border-radius: calc(var(--radius) - 2px);
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}

.theme-segment-btn:hover:not(.active) {
    color: var(--gray-700);
    background: rgba(0,0,0,0.04);
}

[data-theme="dark"] .theme-segment-btn:hover:not(.active) {
    color: var(--gray-200);
    background: rgba(255,255,255,0.06);
}

.theme-segment-btn.active {
    background: var(--bg);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12), 0 0 0 1.5px rgba(0,0,0,0.07);
    font-weight: 600;
}

[data-theme="dark"] .theme-segment-btn.active {
    background: rgba(255,255,255,0.1);
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* ── Offline block ── */
.offline-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--gray-500);
}
.offline-block-icon {
    font-size: 2.5rem;
}
.offline-block-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-700);
}
.offline-block-msg {
    font-size: 0.9rem;
    max-width: 280px;
}

/* Offline notice inside home sync card */
.hs-offline-notice {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    color: var(--gray-600);
    font-size: 0.82rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

/* ── M18 Active Appointment Widget ────────────────────────────────────────── */

/* ── Dark card for active appointments ─────────────────────────────────────
   The card itself carries an animated dark gradient that acts as the shimmer.
   The header is transparent so the card bg shows through; the body uses
   mix-blend-mode:screen with a near-white background — near-white screened
   against dark ≈ near-white, keeping it readable while letting the gradient
   ripple show faintly through. */
@keyframes aaw-card-bg-shimmer {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.aaw-card--active {
    animation: aaw-card-bg-shimmer 7s ease infinite;
}

.aaw-card--blue {
    background: linear-gradient(
        135deg,
        #0f172a 0%,
        #4865b9 35%,
        #172554 65%,
        #0f172a 100%
    );
    background-size: 300% 300%;
    border-color: transparent;
}
.aaw-card--green {
    background: linear-gradient(
        135deg,
        #0f172a 0%,
        #34995c 35%,
        #052e16 65%,
        #0f172a 100%
    );
    background-size: 300% 300%;
    border-color: transparent;
}

/* Header: transparent so dark card gradient shows through */
.aaw-active-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.aaw-active-header--blue,
.aaw-active-header--green,
.aaw-imminent-header--blue,
.aaw-imminent-header--green {
    background: transparent;
    border-bottom-color: rgba(255,255,255,0.1);
}

/* Light foreground in dark header */
.aaw-card--active .dashboard-card-title,
.aaw-card--imminent .dashboard-card-title {
    color: #f1f5f9;
}
.aaw-card--active .aaw-timer {
    color: rgba(255,255,255,0.6);
}

/* Card body: near-white with screen blend so the card shimmer shows subtly.
   screen(near-white, dark) ≈ near-white — body stays light and readable. */
.aaw-card--active .dashboard-card-body,
.aaw-card--imminent .dashboard-card-body {
    background: rgba(255,255,255,0.94);
    mix-blend-mode: screen;
}

/* Pulsing dot — bright colours for dark background */
.aaw-pulse-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    animation: aaw-pulse 1.5s infinite;
}
.aaw-pulse-dot--blue  { background: #60a5fa; }
.aaw-pulse-dot--green { background: #34d399; }

@keyframes aaw-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}

/* ── Active appointment shimmer — shared wave sweep ─────────────────────────
   Uses mix-blend-mode: screen so it brightens any background colour without
   washing it out. Most visible on coloured backgrounds (call plan cards,
   widget header gradient); barely visible on white (fine — those surfaces
   use pulsing dot / border instead). Pointer-events:none keeps it inert. */

@keyframes active-shimmer {
    0%   { transform: translateX(-180%); }
    100% { transform: translateX(180%); }
}

/* Utility: add this class (or target via CSS) to give the shimmer sweep.
   Requires position:relative + overflow:hidden on the element. */
.appt-active-shimmer,
.appt-active-shimmer::after {
    /* defined below via ::after only */
}
.appt-active-shimmer {
    position: relative;
    overflow: hidden;
}
.appt-active-shimmer::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 55%;
    background: linear-gradient(
        90deg,
        transparent   0%,
        rgba(255,255,255,0.28) 50%,
        transparent 100%
    );
    transform: translateX(-180%);
    animation: active-shimmer 2.6s ease-in-out infinite;
    mix-blend-mode: screen;
    pointer-events: none;
    z-index: 1;
}

.aaw-timer {
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Imminent mode: time chip next to title */
.aaw-time-chip {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    vertical-align: middle;
}
.aaw-time-chip--blue  { background: #dbeafe; color: #1d4ed8; }
.aaw-time-chip--green { background: #dcfce7; color: #15803d; }

/* Imminent mode: customer name prominence */
.aaw-imminent-customer {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: var(--text-primary);
}

/* Conflict message */
.aaw-conflict-msg {
    font-size: 0.875rem;
    color: var(--text-muted);
    background: var(--gray-50, #f9fafb);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.65rem 0.75rem;
    margin: 0;
}

.aaw-note-section {
    margin-bottom: 0.75rem;
}

.aaw-note-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.aaw-saved-indicator {
    font-size: 0.7rem;
    color: #16a34a;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.aaw-note-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 0.5rem 0;
}

.aaw-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 0.75rem;
}

.aaw-end-btn {
    margin-left: auto;
}

.aaw-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.aaw-impromptu-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0 0 0.75rem;
}

/* Retrospective mode (COMPLETE / CANCELLED appointment review card) */
.aaw-retro-times {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.aaw-retro-times strong {
    color: var(--text-primary, #111827);
    font-weight: 600;
}

/* Ensure the status badge sits comfortably in the card header */
.dashboard-card-header .apt-status-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.45rem;
}

/* Outline variants for End button (don't use btn-danger for a normal workflow action) */
.btn-primary-outline {
    background: transparent;
    border: 1.5px solid var(--brand-blue, #2563eb);
    color: var(--brand-blue, #2563eb);
}
.btn-primary-outline:hover { background: rgba(37,99,235,0.07); }
.btn-success-outline {
    background: transparent;
    border: 1.5px solid #16a34a;
    color: #16a34a;
}
.btn-success-outline:hover { background: rgba(22,163,74,0.07); }

/* ── M18 Header Badge ─────────────────────────────────────────────────────── */

.appt-header-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem 0.25rem 0.5rem;
    border-radius: 1rem;
    border: none;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    font-family: inherit;
    max-width: 240px;
    transition: opacity 0.15s;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.appt-header-badge:hover { opacity: 0.82; }
.appt-header-badge::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 55%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.45) 50%,
        transparent 100%
    );
    transform: translateX(-180%);
    animation: active-shimmer 2.6s ease-in-out infinite;
    mix-blend-mode: screen;
    pointer-events: none;
}

/* Badge is always dark (inverted accent) regardless of app theme */
.appt-header-badge--blue {
    background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 100%);
    color: #bfdbfe;
}
.appt-header-badge--green {
    background: linear-gradient(135deg, #14532d 0%, #166534 100%);
    color: #bbf7d0;
}
[data-theme="dark"] .appt-header-badge--blue {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
    color: #dbeafe;
}
[data-theme="dark"] .appt-header-badge--green {
    background: linear-gradient(135deg, #14532d 0%, #15803d 100%);
    color: #dcfce7;
}

.appt-badge-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: aaw-pulse 1.5s infinite;
}
/* Bright dot colours for dark badge background */
.appt-badge-dot--blue  { background: #93c5fd; }
.appt-badge-dot--green { background: #86efac; }

.appt-badge-type {
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    font-weight: 700;
    opacity: 0.75;
    flex-shrink: 0;
}
.appt-badge-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Customer pill compresses to icon+chevron-only when appointment badge is present */
.customer-pill--compressed .customer-pill-name,
.customer-pill--compressed .customer-pill-code { display: none; }

@media (max-width: 600px) {
    .appt-badge-name { display: none; }
    .appt-header-badge { padding: 0.25rem 0.4rem; }
}

/* ── M18 Dashboard — active appointment indicator on Today's Plan card ────── */

/* Base: stacking context; border/animation come from the type-specific class */
.task-card--active-appt {
    position: relative;
    overflow: hidden;
}

/* VISIT — blue border pulse */
@keyframes active-border-pulse-visit {
    0%, 100% { border-left-color: #2563eb; box-shadow: inset 3px 0 0 #2563eb; }
    50%       { border-left-color: #93c5fd; box-shadow: inset 3px 0 0 #93c5fd; }
}
.task-card--active-visit {
    border-left: 3px solid #2563eb;
    animation: active-border-pulse-visit 1.5s ease-in-out infinite;
}
.task-card--active-visit::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: 55%;
    background: linear-gradient(90deg, transparent 0%, rgba(37,99,235,0.07) 50%, transparent 100%);
    transform: translateX(-180%);
    animation: active-shimmer 2.6s ease-in-out infinite;
    pointer-events: none;
}

/* PHONECALL — green border pulse */
@keyframes active-border-pulse-phone {
    0%, 100% { border-left-color: #16a34a; box-shadow: inset 3px 0 0 #16a34a; }
    50%       { border-left-color: #4ade80; box-shadow: inset 3px 0 0 #4ade80; }
}
.task-card--active-phone {
    border-left: 3px solid #16a34a;
    animation: active-border-pulse-phone 1.5s ease-in-out infinite;
}
.task-card--active-phone::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: 55%;
    background: linear-gradient(90deg, transparent 0%, rgba(22,163,74,0.07) 50%, transparent 100%);
    transform: translateX(-180%);
    animation: active-shimmer 2.6s ease-in-out infinite;
    pointer-events: none;
}

/* Active type badge — dark style matching the header badge */
.appt-type-badge--live {
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 100%);
    color: #bfdbfe;
}
.appt-type-badge--phone.appt-type-badge--live {
    background: linear-gradient(135deg, #14532d 0%, #166534 100%);
    color: #bbf7d0;
}
.appt-type-badge--live::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: 55%;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.45) 50%, transparent 100%);
    transform: translateX(-180%);
    animation: active-shimmer 2.6s ease-in-out infinite;
    mix-blend-mode: screen;
    pointer-events: none;
}

/* Pulsing dot inside the live type badge */
.appt-active-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 3px;
    flex-shrink: 0;
    animation: aaw-pulse 1.5s infinite;
    vertical-align: middle;
}
.appt-active-dot--visit { background: #93c5fd; }
.appt-active-dot--phone { background: #86efac; }

/* ── M18 Call Plan — audit times section ─────────────────────────────────── */

.apt-audit-section {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
}

.apt-audit-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.apt-audit-readonly {
    font-size: 0.9rem;
    color: var(--text);
    padding: 0.4rem 0;
}

/* ── M18 Call Plan — appointment status badge ─────────────────────────────── */

.apt-status-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.apt-status-badge--active   { background: #dcfce7; color: #15803d; }
.apt-status-badge--complete { background: #e0e7ff; color: #3730a3; }
.apt-status-badge--cancelled { background: #fee2e2; color: #b91c1c; }
.apt-status-badge--planned  { background: #f3f4f6; color: #6b7280; }

/* ── Welcome page ──────────────────────────────────────────────────────────── */
.welcome-msg-card {
    background: var(--primary-light);
    border-color: var(--primary-mid);
}

/* Initial-sync overlay — blurred backdrop */
.initial-sync-overlay {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* Initial-sync modal — fixed width, no close affordance */
.initial-sync-modal {
    width: 100%;
    max-width: 440px;
}

.initial-sync-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0;
}

/* Page Tour button */
.welcome-tour-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.6rem 1.4rem;
    background: linear-gradient(135deg, var(--primary) 0%, #0369a1 100%);
    color: #fff;
    border: none;
    border-radius: 2rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(2, 132, 199, 0.35);
    transition: opacity 0.15s, box-shadow 0.15s, transform 0.15s;
    letter-spacing: 0.01em;
}

.welcome-tour-btn:hover {
    opacity: 0.9;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.45);
    transform: translateY(-1px);
}

.welcome-tour-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);
}

/* Redirect notice shown after tour completes */
.welcome-redirect-banner {
    margin-top: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 1rem 1.375rem;
    border-radius: 0.75rem;
    background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 100%);
    color: #bfdbfe;
    font-size: 1rem;
    font-weight: 600;
    animation: fadeIn 0.3s ease;
}
[data-theme="dark"] .welcome-redirect-banner {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
    color: #dbeafe;
}
.welcome-redirect-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #93c5fd;
    flex-shrink: 0;
    animation: pulse 1.5s ease-in-out infinite;
}

.welcome-message {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0;
}

.welcome-section + .welcome-section {
    margin-top: 1.25rem;
}

.welcome-section--divided {
    padding-top: 1.25rem;
    border-top: 1px solid var(--gray-200);
}

[data-theme="dark"] .welcome-section--divided {
    border-top-color: rgba(255,255,255,0.08);
}

.welcome-section-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0.5rem 0 0.75rem;
}

.welcome-tour-link {
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
}

/* ── Speech / Dictation ─────────────────────────────────────────────────── */

/* Shared mic button — used inside both SpeechInput and SpeechRichEditor */
.speech-mic-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s;
}
.speech-mic-icon-btn:hover:not(:disabled) { color: var(--primary); }
.speech-mic-icon-btn:disabled { opacity: 0.4; cursor: default; }

/* Waveform bars — heights driven by JS AudioAnalyser, no CSS animation */
.speech-waveform-bar {
    width: 3px;
    background: var(--primary);
    border-radius: 2px;
    flex-shrink: 0;
    transition: height 0.05s ease-out;
    position: relative;
    z-index: 1;
}

/* Cancel (×): plain borderless icon, muted colour */
.speech-record-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}
.speech-cancel-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s;
}
.speech-cancel-btn:hover { color: var(--danger, #e53e3e); }

/* Confirm (✓): solid primary blue pill */
.speech-confirm-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.speech-confirm-btn:hover { opacity: 0.88; }

/* Error message below any speech field */
.speech-field-error {
    font-size: 0.8rem;
    color: var(--danger, #e53e3e);
    margin-top: 0.2rem;
}

/* ── SpeechInput (<input> or <textarea> wrapper) ── */
.speech-input-wrap {
    position: relative;
}
/* Right padding so text doesn't slide under the mic icon */
.speech-input-wrap .speech-field.has-mic {
    padding-right: 34px;
}
/* Single-line: mic is vertically centred */
.speech-input-wrap .speech-mic-icon-btn {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
}
/* Multiline (textarea): mic pins to the top */
.speech-input-wrap.is-multiline .speech-mic-icon-btn {
    top: 8px;
    transform: none;
}
/* Spinner mirrors mic position */
.speech-input-wrap .spinner-anchor {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
}
.speech-input-wrap.is-multiline .spinner-anchor {
    top: 10px;
    transform: none;
}
/* Recording block replaces the field during capture */
.speech-recording-block {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius, 4px);
    background: var(--bg, var(--surface));
    min-height: 38px;
}
.speech-recording-block.is-multiline {
    min-height: 80px;
}
/* SpeechInput waveform (inside recording block, centred in the field height) */
.speech-recording-block .speech-waveform {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    height: 28px;
    padding-right: 8px;
}

/* ── SpeechRichEditor (Quill wrapper) ── */
.speech-rich-wrap {
    position: relative; /* positioning context for the absolute overlay */
}

/* Idle: mic button floating at bottom-right inside the editor */
.speech-rich-overlay {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg, var(--surface));
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 7px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.14);
}

/* Recording + transcribing: full-width bar flush with the editor bottom */
.speech-rich-overlay.is-recording,
.speech-rich-overlay.is-transcribing {
    left: 0;
    right: 0;
    bottom: 0;
    height: 44px;
    border-radius: 0 0 var(--radius, 4px) var(--radius, 4px);
    border: none;
    border-top: 1px solid var(--border);
    padding: 0 12px;
    box-shadow: none;
    background: var(--bg, var(--surface));
}
.speech-rich-overlay.is-recording    { justify-content: space-between; margin: 5px; }
.speech-rich-overlay.is-transcribing { justify-content: center; gap: 10px; }

.speech-transcribing-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Waveform — dotted centre baseline via ::before, bars float above it */
.speech-waveform {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    height: 32px;
    padding-right: 8px;
    position: relative;
}
.speech-waveform::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    border-top: 1.5px dotted var(--border);
    z-index: 0;
}

/* ── Group Patterns & Insights widget ─────────────────────────────── */
.grp-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary, #666);
}
.grp-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}
.grp-empty-sub {
    margin-top: 0.4rem;
    font-size: 0.85rem;
}
.grp-section {
    margin-top: 1.25rem;
}
.grp-members-table {
    grid-template-columns: 2fr repeat(4, 1fr);
}
.grp-products-table {
    grid-template-columns: 2fr repeat(4, 1fr);
}
.grp-row-mine {
    background: var(--primary-tint, #eff6ff);
    font-weight: 500;
}
.grp-row-opportunity {
    background: var(--warning-tint, #fffbeb);
}
.grp-mine-badge {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 1px 6px;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--primary, #2563eb);
    color: #fff;
    vertical-align: middle;
}
.grp-pct-bar-wrap {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.grp-pct-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--primary, #2563eb);
    min-width: 2px;
    max-width: 80px;
    flex-shrink: 0;
}
@media (max-width: 700px) {
    .grp-members-table,
    .grp-products-table {
        grid-template-columns: 1fr;
    }
}

