@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

  :root {
    --bg: #f5f0eb;
    --card: #ffffff;
    --primary: #2d6a4f;
    --primary-light: #40916c;
    --primary-dark: #1b4332;
    --accent: #d4a373;
    --accent-light: #e9c89b;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --border: #e5e0db;
    --border-light: #f0ebe6;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --success: #16a34a;
    --success-light: #f0fdf4;
    --info: #2563eb;
    --info-light: #eff6ff;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; -webkit-font-smoothing: antialiased; }
  ::-webkit-scrollbar { width: 5px; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

  .header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%);
    color: white; padding: 0 20px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 12px rgba(45,106,79,0.3); min-height: 58px;
  }
  .header-brand { display: flex; flex-direction: column; line-height: 1.15; padding: 10px 0; }
  .header-brand .brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; }
  .header-brand .brand-sub { font-size: 10px; font-weight: 500; opacity: 0.7; letter-spacing: 0.5px; text-transform: uppercase; margin-top: 1px; }
  .header-divider { width: 1px; height: 30px; background: rgba(255,255,255,0.2); margin: 0 4px; }
  .header-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

  .tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--border); padding: 0 24px; position: sticky; top: 58px; z-index: 99; }
  .tab { padding: 14px 20px; font-size: 14px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; user-select: none; }
  .tab:hover { color: var(--primary); }
  .tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

  .container { max-width: 900px; margin: 0 auto; padding: 24px; }
  .tab-content { display: none; }
  .tab-content.active { display: block; }

  .card { background: var(--card); border-radius: var(--radius-lg); border: 1px solid var(--border); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
  .card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
  .card-title { font-size: 15px; font-weight: 600; color: var(--primary-dark); display: flex; align-items: center; gap: 8px; }
  .card-badge { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }

  .section-label { font-size: 12px; font-weight: 700; color: var(--primary); letter-spacing: 0.5px; text-transform: uppercase; margin: 20px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border-light); }
  .section-label:first-child { margin-top: 0; }

  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-bottom: 16px; }
  .form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px 16px; margin-bottom: 16px; }
  .form-field { display: flex; flex-direction: column; gap: 4px; }
  .form-field label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }

  .inp { padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: 'DM Sans', sans-serif; font-size: 14px; color: var(--text); background: var(--card); transition: border-color 0.2s, box-shadow 0.2s; outline: none; width: 100%; }
  .inp:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45,106,79,0.1); }
  .inp::placeholder { color: var(--text-light); }
  textarea.inp { resize: vertical; }

  .search-wrapper { position: relative; }
  .search-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm); max-height: 240px; overflow-y: auto; z-index: 50; box-shadow: var(--shadow-lg); display: none; }
  .search-dropdown.show { display: block; }
  .search-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border-light); transition: background 0.15s; }
  .search-item:hover { background: var(--success-light); }
  .search-item .si-hindi { font-weight: 600; font-size: 14px; color: var(--text); }
  .search-item .si-botanical { font-size: 12px; color: var(--text-muted); font-style: italic; }

  /* ── Unified Product Cards — FROM B ── */
  .pc-list { display: flex; flex-direction: column; gap: 12px; }
  .pc-card {
    border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
    background: linear-gradient(135deg, #fafaf8, #f8f6f3); position: relative; transition: border-color 0.2s;
  }
  .pc-card.pc-filled { border-color: #a7d9a8; }
  .pc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 6px; }
  .pc-num { font-size: 11px; font-weight: 600; color: var(--primary); background: rgba(45,106,79,0.08); padding: 2px 9px; border-radius: 12px; flex-shrink: 0; }
  .pc-title { font-size: 13px; font-weight: 600; color: var(--primary-dark); flex: 1; text-align: center; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pc-remove { width: 26px; height: 26px; border: none; background: var(--danger-light); color: var(--danger); border-radius: 50%; cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.15s; }
  .pc-remove:hover { background: var(--danger); color: white; }
  .pc-search-wrap { position: relative; margin-bottom: 10px; }
  .pc-dropdown {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--card); border: 1px solid var(--primary); border-radius: var(--radius);
    max-height: 200px; overflow-y: auto; z-index: 200; box-shadow: var(--shadow-lg); margin-top: 2px; display: none;
  }
  .pc-dropdown .pc-opt {
    padding: 9px 13px; cursor: pointer; font-size: 13px;
    border-bottom: 1px solid var(--border-light); transition: background 0.1s;
  }
  .pc-dropdown .pc-opt:last-child { border-bottom: none; }
  .pc-dropdown .pc-opt:hover { background: var(--success-light); color: var(--primary); }
  .pc-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
  .pc-fields .pc-f { display: flex; flex-direction: column; gap: 3px; }
  .pc-fields .pc-f label { font-size: 10px; font-weight: 600; color: var(--text-light); letter-spacing: 0.4px; text-transform: uppercase; }
  .pc-fields .pc-f .inp { font-size: 13px; padding: 7px 10px; }
  .pc-add-btn {
    width: 100%; padding: 12px; border: 2px dashed var(--border); border-radius: var(--radius);
    background: transparent; color: var(--text-muted); font-family: 'DM Sans', sans-serif;
    font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.2s; margin-top: 8px;
  }
  .pc-add-btn:hover { border-color: var(--primary); color: var(--primary); background: rgba(45,106,79,0.03); }
  @media (max-width: 480px) { .pc-fields { grid-template-columns: 1fr; } }

  .btn { padding: 9px 16px; border: none; border-radius: var(--radius-sm); font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px; }
  .btn-primary { background: var(--primary); color: white; }
  .btn-primary:hover { background: var(--primary-dark); }
  .btn-secondary { background: var(--border-light); color: var(--text); border: 1px solid var(--border); }
  .btn-secondary:hover { background: var(--border); }
  .btn-accent { background: var(--accent); color: white; }
  .btn-accent:hover { background: #c4965f; }
  .btn-danger { background: var(--danger); color: white; }
  .btn-danger:hover { background: #b91c1c; }
  .btn-sm { padding: 7px 14px; font-size: 12px; }
  .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

  .action-bar { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--border-light); margin-top: 10px; }

  .customer-history { margin-top: 12px; padding: 12px; background: var(--info-light); border-radius: var(--radius-sm); border: 1px solid #dbeafe; display: none; }
  .customer-history.show { display: block; }
  .history-title { font-size: 12px; font-weight: 600; color: var(--info); margin-bottom: 8px; }
  .history-item { font-size: 13px; color: var(--text); padding: 6px 0; border-bottom: 1px dashed #dbeafe; display: flex; justify-content: space-between; }
  .history-item:last-child { border-bottom: none; }
  .history-date { color: var(--text-muted); font-family: 'JetBrains Mono', monospace; font-size: 12px; }

  .table-wrapper { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; font-size: 13px; }
  th { text-align: left; padding: 10px 12px; background: var(--primary-dark); color: white; font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; position: sticky; top: 0; }
  th:first-child { border-radius: var(--radius-sm) 0 0 0; }
  th:last-child { border-radius: 0 var(--radius-sm) 0 0; }
  td { padding: 10px 12px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
  tr:hover td { background: #fafaf8; }
  .table-empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }

  /* ════════════════════════════════════════════════
     POLISH LAYER — additive only
     ════════════════════════════════════════════════ */
  .txt-primary   { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.3; }
  .txt-secondary { font-size: 13px; font-weight: 500; color: var(--text-muted); line-height: 1.4; }
  .txt-tertiary  { font-size: 11px; font-weight: 400; color: var(--text-light); line-height: 1.4; }
  .num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; text-align: right; }
  button[title]:hover, a[title]:hover { filter: brightness(0.95); }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  [data-empty="true"]::before { content: "—"; color: var(--text-muted); }
  @media (max-width: 640px) {
    body { overflow-x: hidden; }
    table { word-break: break-word; }
  }

  .badge-active { background: var(--success-light); color: var(--success); }
  .badge-converted { background: var(--info-light); color: var(--info); }
  .badge-closed { background: #fee2e2; color: #dc2626; }
  .badge-returning { background: var(--success-light); color: var(--success); }
  .badge-in-crm { background: var(--warning-light); color: var(--warning); }

  /* ── Duplicate Detection System ── */
  .badge-duplicate { background: #fee2e2; color: var(--danger); border: 1px solid #fca5a5; animation: dupPulse 2s ease-in-out infinite; }
  .badge-returning-cust { background: var(--success-light); color: var(--success); border: 1px solid #86efac; }
  @keyframes dupPulse { 0%,100% { opacity:1; } 50% { opacity:0.7; } }

  #dupWarningCard {
    display: none;
    background: linear-gradient(135deg, #fff7ed, #fef2f2);
    border: 1.5px solid #f97316;
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 16px;
    animation: slideDown 0.25s ease;
  }
  #dupWarningCard.show { display: block; }
  @keyframes slideDown { from { opacity:0; transform:translateY(-8px); } to { opacity:1; transform:translateY(0); } }

  .dup-header {
    display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
  }
  .dup-icon { font-size: 20px; flex-shrink: 0; }
  .dup-title { font-size: 14px; font-weight: 700; color: #c2410c; line-height: 1.2; }
  .dup-subtitle { font-size: 11px; color: #9a3412; margin-top: 2px; font-weight: 500; }
  .dup-level-badge {
    margin-left: auto; font-size: 10px; font-weight: 700;
    padding: 2px 9px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.4px; flex-shrink: 0;
  }
  .dup-level-high   { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; }
  .dup-level-medium { background: var(--warning-light); color: var(--warning); border: 1px solid #fcd34d; }
  .dup-level-low    { background: var(--info-light); color: var(--info); border: 1px solid #93c5fd; }

  .dup-info-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px;
    background: white; border-radius: var(--radius-sm); padding: 10px 12px;
    border: 1px solid #fed7aa; margin-bottom: 12px; font-size: 12px;
  }
  .dup-info-row { display: flex; gap: 6px; align-items: baseline; }
  .dup-info-label { color: var(--text-muted); font-weight: 600; min-width: 60px; flex-shrink: 0; font-size: 10px; text-transform: uppercase; letter-spacing: 0.3px; }
  .dup-info-value { color: var(--text); font-weight: 500; word-break: break-word; }

  .dup-products { font-size: 11px; color: #9a3412; margin-bottom: 12px; padding: 6px 10px; background: #fff7ed; border-radius: var(--radius-sm); border: 1px solid #fed7aa; }
  .dup-products strong { color: #c2410c; margin-right: 4px; }

  .dup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
  .btn-dup-open { background: #c2410c; color: white; }
  .btn-dup-open:hover { background: #9a3412; }
  .btn-dup-continue { background: white; color: var(--text-muted); border: 1px solid var(--border); font-size: 12px; }
  .btn-dup-continue:hover { background: var(--border-light); }

  /* Duplicate confirm modal */
  #dupConfirmModal .modal { max-width: 440px; }
  .dup-modal-icon { font-size: 36px; text-align: center; margin-bottom: 12px; }
  .dup-modal-body { font-size: 13px; color: var(--text-muted); text-align: center; line-height: 1.6; margin-bottom: 20px; }
  .dup-modal-body strong { color: var(--text); font-size: 14px; display: block; margin-bottom: 6px; }
  /* ── Find Duplicates Modal ── */
  #findDupModal .modal { max-width: 680px; max-height: 85vh; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
  .fdup-header { padding: 22px 24px 16px; border-bottom: 1px solid var(--border-light); flex-shrink: 0; }
  .fdup-title { font-size: 16px; font-weight: 700; color: var(--primary-dark); margin-bottom: 4px; }
  .fdup-subtitle { font-size: 12px; color: var(--text-muted); }
  .fdup-body { flex: 1; overflow-y: auto; padding: 16px 24px; }
  .fdup-footer { padding: 14px 24px; border-top: 1px solid var(--border-light); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
  .fdup-summary { font-size: 12px; color: var(--text-muted); }
  .fdup-summary strong { color: var(--danger); }

  .fdup-group {
    border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden;
  }
  .fdup-group-header {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    background: linear-gradient(135deg, #fff7ed, #fef2f2);
    border-bottom: 1px solid #fed7aa; font-size: 12px;
  }
  .fdup-group-reason { font-weight: 600; color: #c2410c; flex: 1; }
  .fdup-group-count { font-size: 10px; font-weight: 700; background: #fee2e2; color: var(--danger); padding: 2px 8px; border-radius: 10px; }
  .fdup-level { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 10px; text-transform: uppercase; }
  .fdup-level-HIGH   { background: #fee2e2; color: #dc2626; }
  .fdup-level-MEDIUM { background: var(--warning-light); color: var(--warning); }
  .fdup-level-LOW    { background: var(--info-light); color: var(--info); }

  .fdup-row {
    display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px 12px;
    padding: 10px 14px; border-bottom: 1px solid var(--border-light);
    font-size: 12px; align-items: center;
  }
  .fdup-row:last-child { border-bottom: none; }
  .fdup-row:hover { background: #fafaf8; }
  .fdup-row-name { font-weight: 600; color: var(--text); }
  .fdup-row-meta { color: var(--text-muted); font-size: 11px; margin-top: 2px; }
  .fdup-row-products { color: var(--text-muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .fdup-row-date { color: var(--text-light); font-family: 'JetBrains Mono', monospace; font-size: 11px; }
  .fdup-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

  .fdup-empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
  .fdup-empty .fdup-empty-icon { font-size: 36px; margin-bottom: 10px; }
  .fdup-scanning { text-align: center; padding: 32px 20px; color: var(--text-muted); font-size: 14px; }

  @media (max-width: 640px) {
    .fdup-row { grid-template-columns: 1fr auto; }
    .fdup-row-products, .fdup-row-date { display: none; }
  }


  .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 200; display: none; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
  .modal-overlay.show { display: flex; }
  .modal { background: var(--card); border-radius: var(--radius-lg); padding: 28px; width: 90%; max-width: 500px; box-shadow: var(--shadow-lg); animation: modalIn 0.2s ease; }
  @keyframes modalIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
  .modal-title { font-size: 17px; font-weight: 700; margin-bottom: 20px; color: var(--primary-dark); }
  .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

  .preview-box { background: #1a1a1a; color: #e5e5e5; padding: 20px; border-radius: var(--radius); font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; margin-bottom: 16px; }

  .toast { position: fixed; bottom: 24px; right: 24px; background: var(--primary-dark); color: white; padding: 12px 20px; border-radius: var(--radius); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 300; transform: translateY(100px); opacity: 0; transition: all 0.3s ease; }
  .toast.show { transform: translateY(0); opacity: 1; cursor: pointer; }
  .toast.error { background: var(--danger); }
  .toast.warning { background: var(--warning); }

  .setup-banner { background: linear-gradient(135deg, var(--warning-light), #fef3c7); border: 1px solid #fbbf24; border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px; display: flex; align-items: flex-start; gap: 12px; }
  .status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
  .status-dot.online  { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,0.4); }
  .status-dot.cached  { background: #f59e0b; box-shadow: 0 0 6px rgba(245,158,11,0.4); }
  .status-dot.offline { background: #ef4444; }

  /* ── Offline-data warning banner ── */
  #offlineBanner {
    display: none; align-items: center; gap: 10px;
    background: linear-gradient(135deg, #fffbeb, #fef3c7);
    border: 1px solid #fbbf24; border-radius: var(--radius);
    padding: 10px 16px; margin-bottom: 16px;
    font-size: 13px; color: #92400e;
  }
  #offlineBanner.show { display: flex; }
  #offlineBanner .ob-icon { font-size: 18px; flex-shrink: 0; }
  #offlineBanner strong { font-weight: 700; }
  #offlineBanner .ob-detail { font-size: 11px; opacity: 0.8; margin-top: 2px; }
  #offlineBanner .ob-close {
    margin-left: auto; background: none; border: none;
    font-size: 16px; cursor: pointer; color: #92400e; opacity: 0.6; padding: 0 4px;
  }
  #offlineBanner .ob-close:hover { opacity: 1; }
  .spin { display: inline-block; animation: spin 1s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  .filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
  .filters .inp { min-width: 120px; }

  .landline-row { display: flex; gap: 0; }
  .area-code { width: 70px; border-radius: var(--radius-sm) 0 0 var(--radius-sm); border-right: none; flex-shrink: 0; }
  .landline-row .inp:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

  @media print { .header, .tabs, .action-bar, .btn, .no-print, .filters { display: none !important; } .container { max-width: 100%; padding: 0; } .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; } body { background: white; } }
  @media (max-width: 640px) { .form-grid, .form-grid-3 { grid-template-columns: 1fr; } .container { padding: 16px; } .card { padding: 16px; } .tabs { padding: 0 12px; overflow-x: auto; } .tab { padding: 12px 14px; font-size: 13px; white-space: nowrap; } .action-bar { flex-direction: column; } .action-bar .btn { width: 100%; justify-content: center; } }

  /* ── Phase 3: Global Loader ── */
  #globalLoader {
    position: fixed; top: 10px; right: 14px; z-index: 9999;
    display: none; align-items: center; gap: 6px;
    background: rgba(27,67,50,0.92); color: white;
    font-size: 11px; font-weight: 600;
    padding: 5px 10px; border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.18);
    pointer-events: none; letter-spacing: 0.2px;
  }
  #globalLoader.active { display: flex; }
  #globalLoader .loader-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: #4ade80;
    animation: loaderPulse 0.9s ease-in-out infinite;
  }
  @keyframes loaderPulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
  }