@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;
    --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);
}

/* 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;
}

/* 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;
}

.header-spacer {
    flex: 1;
}

.header-username {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.85rem;
    color: var(--gray-600);
    font-weight: 500;
    margin-right: 0.5rem;
}

.sidebar-toggle,
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius);
    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: var(--radius);
    background: transparent;
    color: var(--gray-500);
    cursor: pointer;
    margin-right: 0.25rem;
    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;
    overflow-x: hidden;
}

.main-content {
    flex: 1;
    background: var(--bg-page);
}

/* Mobile menu */
.mobile-menu {
    display: none;
    background: var(--bg);
    border-bottom: 1px solid var(--gray-200);
    padding: 0.5rem 0;
}

.mobile-menu.open {
    display: block;
}

.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;
}

/* Layout */
.page {
    max-width: 820px;
    margin: 0 auto;
    padding: 2rem;
}

.page-title {
    font-size: 1.625rem;
    font-weight: 800;
    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;
}

/* 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: min(90vw, 900px);
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-img {
    max-width: 100%;
    max-height: 90vh;
    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-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);
}

.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;
}

/* Dashboard layout */
.page-wide {
    max-width: 1280px;
    margin: 0 auto;
    padding: 2rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 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);
}

.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: #dcfce7;
    color: #15803d;
    border-color: #bbf7d0;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 320px;
    overflow-y: auto;
}

.task-card {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: var(--bg);
}

.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 {
    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: var(--gray-100);
    color: var(--gray-600);
}

.task-badge--done {
    background: #dcfce7;
    color: #15803d;
}

.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;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    border: 1px solid currentColor;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.task-toggle-btn--pending {
    color: #15803d;
}

.task-toggle-btn--pending:hover {
    background: #15803d;
    color: #fff;
}

.task-toggle-btn--done {
    color: var(--gray-500);
}

.task-toggle-btn--done:hover {
    background: var(--gray-200);
    color: var(--gray-700);
}

.appt-body {
    height: 300px;
    display: flex;
    flex-direction: column;
}

.appt-body .task-list {
    flex: 1;
    min-height: 0;
    max-height: none;
}

.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);
}

.route-map {
    height: 300px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--gray-200);
}

.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) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .prospect-stats {
        grid-template-columns: 1fr;
    }

    .page-wide {
        padding: 1.5rem;
    }
}

@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-menu.open {
        display: block;
    }
}

@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;
}

.map-topbar {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    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;
}

.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-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
   ================================ */

.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;
}

/* ── 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);
}

.callplan-apt-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    border: none;
    background: rgba(255,255,255,0.2);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.callplan-appointment:hover .callplan-apt-remove {
    opacity: 1;
}

.callplan-apt-remove:hover {
    background: rgba(255,255,255,0.4);
}

/* ── 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;
}

.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;
}

.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);
}

/* 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;
}

/* ================================
   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 {
    background: #fef2f2;
}

.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 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: 42px;
    height: 42px;
    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;
    width: 15px;
    height: 15px;
    background: var(--success);
    color: #fff;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 700;
    flex-shrink: 0;
    line-height: 1;
    cursor: default;
}

.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;
}

/* 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);
    overflow: hidden;
    border: 1px solid var(--gray-200);
}

.so-photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.so-photo-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 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;
}

.draft-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--gray-100);
}

.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;
    }

    /* Switch to mobile cart */
    .so-lines-table { display: none; }
    .so-cart-mobile { display: block; }
}

/* ============================================================
   Account / Customer Page
   ============================================================ */

.account-page {
    padding: 2rem;
}

@media (max-width: 900px) {
    .account-page {
        padding: 1.5rem;
    }
}

@media (max-width: 600px) {
    .account-page {
        padding: 1rem;
    }
}

/* 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;
}
.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;
    margin-top: 1rem;
}

/* 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 {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    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;
}

.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-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);
}

/* 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-apply-btn {
        width: 100%;
        justify-content: center;
    }

    .history-table-head,
    .history-table-row {
        grid-template-columns: 1fr 0.8fr 1fr;
        font-size: 0.8rem;
    }

    .history-table-head span:nth-child(3),
    .history-table-row span:nth-child(3),
    .history-table-head span:nth-child(4),
    .history-table-row span:nth-child(4) {
        display: none;
    }

    .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;
    }
}

/* ============================================================
   Sidebar logo
   ============================================================ */
.sidebar-logo-full {
    height: 22px;
    width: auto;
    display: block;
    flex-shrink: 0;
}

.sidebar-logo-icon {
    height: 34px;
    width: 34px;
    display: none;
    flex-shrink: 0;
    border-radius: 6px;
}

.sidebar.collapsed .sidebar-logo-full { display: none; }
.sidebar.collapsed .sidebar-logo-icon { display: block; }

/* ============================================================
   Header customer selector
   ============================================================ */
.header-customer {
    position: relative;
    margin-right: 0.75rem;
}

.customer-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--gray-300);
    background: var(--gray-50);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--gray-600);
    max-width: 300px;
    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;
}

[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;
    max-width: 180px;
}

.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;
}

@media (max-width: 600px) {
    .customer-pill-code { display: none; }
    .customer-pill-name { max-width: 120px; }
    .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-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; }

/* Per-type left border colours — subtle at rest, full on hover */
.note-card[data-note-type="VISIT"]                                    { border-left-color: rgba(16, 185, 129, 0.3); }
.note-card[data-note-type="PHONECALL"]                                { border-left-color: rgba(124, 111, 255, 0.3); }
.note-card[data-note-type="TASK"]                                     { border-left-color: rgba(245, 158, 11, 0.3); }
.note-card[data-note-type="GENERAL"],
.note-card[data-note-type="DELIVERY"],
.note-card[data-note-type="PICKUP"]                                   { border-left-color: rgba(156, 163, 175, 0.3); }

.note-card[data-note-type="VISIT"]:hover                              { border-left-color: #10b981; background-color: rgba(16, 185, 129, 0.04); }
.note-card[data-note-type="PHONECALL"]:hover                          { border-left-color: #0284c7; background-color: rgba(2, 132, 199, 0.04); }
.note-card[data-note-type="TASK"]:hover                               { border-left-color: #f59e0b; background-color: rgba(245, 158, 11, 0.04); }
.note-card[data-note-type="GENERAL"]:hover,
.note-card[data-note-type="DELIVERY"]:hover,
.note-card[data-note-type="PICKUP"]:hover                             { border-left-color: #9ca3af; background-color: rgba(156, 163, 175, 0.04); }

.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-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;
}

.rich-text-editor-inner {
    min-height: 160px;
}

/* 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);
}

.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;
    min-height: 400px;
    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); }

.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-900);
    border-color: var(--gray-700);
}

[data-theme="dark"] .rp-setting-select,
[data-theme="dark"] .rp-setting-time {
    border-color: var(--gray-600);
}

/* 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); }

@media (max-width: 768px) {
    .rp-layout { flex-direction: column; }
    .rp-timeline-panel { flex: none; max-width: 100%; max-height: 50vh; }
    .rp-map { height: 40vh; min-height: 250px; }
    .rp-footer { flex-wrap: wrap; }
}

/* ── 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;
}

/* ── 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 {
    font-size: 0.7rem;
    color: var(--gray-400);
    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-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;
}

/* ── 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-top: 0.875rem;
    font-size: 0.75rem;
    color: var(--gray-400);
    font-style: italic;
}

.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;
}

.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 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-picker {
    margin-bottom: 0.75rem;
}

.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 {
    flex: 1;
    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;
}

.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);
}

.todo-summary-chip--call {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.todo-summary-chip--task {
    background: #f0fdf4;
    color: #15803d;
    border-color: #bbf7d0;
}

.todo-summary-chip--appt {
    background: #f5f3ff;
    color: #6d28d9;
    border-color: #ddd6fe;
}

.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: #15803d;
}

.todo-item--appointment {
    border-left-color: #7c3aed;
}

.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--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: #f0fdf4;
    color: #15803d;
}

.todo-type-badge--appointment {
    background: #f5f3ff;
    color: #6d28d9;
}

.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: 1.25rem 1.5rem 1rem;
    position: sticky;
    top: 56px; /* below the main header */
    z-index: 50;
}

.catalog-title-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
    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(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--gray-800);
    cursor: pointer;
}

.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;
}

.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;
}

/* Responsive */
@media (max-width: 768px) {
    .cart-footer {
        left: 0; /* sidebar hidden on mobile */
    }
}

@media (max-width: 600px) {
    .catalog-header {
        padding: 1rem;
    }
    .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;
}

/* 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;
}

/* 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;
    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: 52px; }
.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-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;
}

.so-lines-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
    flex-shrink: 0;
}

/* 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: 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; }

/* 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; }
}

