*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f0f2f5;
  --surface: #fff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-secondary: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --processing: #f59e0b;
  --shipped: #06b6d4;
  --completed: #22c55e;
  --cancelled: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --radius: 8px;
  --radius-sm: 6px;
  --radius-full: 9999px;
  /* ── Adaptive density tokens: dense desktop default, roomy on touch/small ── */
  --tap: 32px; --fs: 13px; --pad-y: 6px; --pad-x: 12px;
  --table-fs: 12.5px; --th-y: 6px; --td-y: 5px; --card-pad: 12px;
  --filter-gap: 10px; --app-pad: 12px 16px; --app-max: 1720px;
}
@media (max-width: 640px), (hover: none) and (pointer: coarse) {
  :root {
    --tap: 44px; --fs: 14px; --pad-y: 10px; --pad-x: 16px;
    --table-fs: 12px; --th-y: 7px; --td-y: 8px; --card-pad: 14px;
    --filter-gap: 8px; --app-pad: 10px 12px; --app-max: 1720px;
  }
}
body {
  font: var(--fs)/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
  background: var(--bg); color: var(--text);
}

#app { padding: var(--app-pad); max-width: var(--app-max); margin: 0 auto; }

/* ─── Header ─── */
header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
header h1 {
  font-size: 20px; font-weight: 700; letter-spacing: -.02em;
  background: linear-gradient(135deg, #1e40af, #2563eb);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.header-actions { display: flex; align-items: center; gap: 8px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-secondary);
}
.badge-inv { background: var(--green-bg); border-color: #bbf7d0; color: var(--green); }
.badge-api { background: var(--blue-bg); border-color: #bfdbfe; color: var(--blue); }

.btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--pad-y) var(--pad-x);
  min-height: var(--tap);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: #f9fafb; border-color: #d1d5db; box-shadow: var(--shadow-sm); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* ─── Tabs ─── */
.tab-bar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.tab {
  padding: var(--pad-y) var(--pad-x); min-height: var(--tap);
  font-size: 13px; font-weight: 500;
  border-radius: var(--radius-full); cursor: pointer; white-space: nowrap;
  background: transparent; border: 1px solid transparent; color: var(--text-secondary);
  transition: all .15s;
}
.tab:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.tab.active {
  background: var(--surface); border-color: var(--border); color: var(--text);
  box-shadow: var(--shadow-sm); font-weight: 600;
}
.fulfillment-tabs { margin: 2px 0 10px 0; }
.tab.hidden { display: none; }
.region-tabs.hidden { display: none; }
.fulfillment-tabs.hidden { display: none; }
.fulfillment-tabs .tab { font-size: 12px; padding: 4px 12px; }

/* ─── Utilities: category row (tier 1) + sub-tabs (tier 2) ─── */
.util-group-tabs { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.util-group-tabs .tab { font-size: 13px; }
.util-group-tabs .tab.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.util-tabs[data-active-group="pricing"] .tab:not([data-ugroup="pricing"]),
.util-tabs[data-active-group="supply"] .tab:not([data-ugroup="supply"]),
.util-tabs[data-active-group="admin"] .tab:not([data-ugroup="admin"]) { display: none; }

/* ─── Filter card (sticky, dense) ─── */
.filter-card {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--filter-gap);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px;
  margin-bottom: 8px; box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 5;
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-label {
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
.filter-divider { width: 1px; height: 24px; background: var(--border); }
.radio-group { display: flex; gap: 2px; }
.radio-group label {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 13px; cursor: pointer; color: var(--text-secondary); font-weight: 500;
  transition: all .15s;
}
.radio-group label:hover { background: #f9fafb; color: var(--text); }
.radio-group input[type="radio"]:checked + span { color: var(--primary); font-weight: 600; }
.radio-group input[type="radio"] { accent-color: var(--primary); }
.filter-group input[type="date"],
.filter-group input[type="text"] {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 10px; font-size: 13px; background: var(--bg);
  min-height: var(--tap);
  transition: border-color .15s;
}
.filter-group input[type="date"]:focus,
.filter-group input[type="text"]:focus { outline: none; border-color: var(--primary); }
.filter-group input[type="text"] { min-width: 180px; }
.sep { color: var(--text-secondary); font-size: 13px; }
/* Collapsible filter wrapper: always inline on desktop/tablet; on phone the
   "More filters" button toggles `.filter-extra.open` (no <details>, so the
   browser can never hide it by cascade/closed-state). */
.filter-extra { display: contents; }
.filter-more-toggle { display: none; }

/* ─── Actions bar (compact) ─── */
.actions-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px 12px;
  margin-bottom: 8px; box-shadow: var(--shadow-sm);
}
.action-group { display: flex; align-items: center; gap: 6px; }

/* ─── Global utility: single source of truth for hiding ─── */
.hidden { display: none !important; }

/* ─── Main layout ─── */
#mainContent, #ordersContent { display: flex; gap: 14px; min-height: 400px; }
#leftPanel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#tableWrap { overflow-x: auto; overflow-y: auto; max-height: 70vh; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }

/* ─── Table (dense) ─── */
table { width: 100%; border-collapse: collapse; font-size: var(--table-fs); }
thead th {
  background: #f9fafb; position: sticky; top: 0; z-index: 2;
  padding: var(--th-y) 8px; text-align: left; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary);
  border-bottom: 2px solid var(--border); white-space: nowrap; user-select: none;
}
thead th::after {
  content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 6px;
  cursor: col-resize; z-index: 3; transition: background .15s;
}
thead th:hover::after { background: var(--primary); }
thead th:last-child::after { width: 3px; }
tbody td { padding: var(--td-y) 8px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
tbody tr { background: var(--surface); cursor: pointer; transition: background .08s; }
tbody tr:hover { background: var(--blue-bg); }
tbody tr.selected { background: #eff6ff; }
tbody tr.highlighted { background: #dbeafe; outline: 2px solid var(--primary); outline-offset: -2px; }
tbody tr:last-child td { border-bottom: none; }

.col-check { width: 36px; min-width: 36px; text-align: center; }
.col-sl { width: 36px; min-width: 36px; text-align: center; }
tbody .col-sl { color: var(--text-secondary); font-size: 12px; }
.col-discount, .col-total { text-align: right; font-variant-numeric: tabular-nums; }
.col-weight { text-align: right; }
.col-status { min-width: 80px; }
tbody .col-created, tbody .col-paid, tbody .col-ship { white-space: nowrap; font-size: 12px; color: var(--text-secondary); }
.col-fulfillment { width: 50px; min-width: 50px; text-align: center; }
tbody .col-fulfillment { font-size: 15px; }
.col-fulfilledby { width: 90px; min-width: 90px; text-align: center; }
tbody .col-fulfilledby { font-size: 12px; color: var(--text-secondary); }
.hide-stock .col-fulfilledby { display: none; }
.hide-ship-col .col-ship { display: none; }
.fb-badge { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.fb-chennai { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* ─── COD / Unpaid marker + quick filter toggle ─── */
.cod-badge {
  display: inline-block; margin-left: 5px; padding: 1px 7px;
  border-radius: var(--radius-full); font-size: 10px; font-weight: 700;
  letter-spacing: .03em; vertical-align: middle; cursor: help;
  background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
}
#orderCards .cod-badge { padding: 2px 8px; }
.cod-toggle.on { background: #fef3c7; border-color: #fde68a; color: #92400e; font-weight: 600; }
.changed-badge {
  display: inline-block; margin-left: 5px; padding: 1px 7px;
  border-radius: var(--radius-full); font-size: 10px; font-weight: 600;
  vertical-align: middle; white-space: nowrap;
  background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;
}
#orderCards .changed-badge { padding: 2px 8px; }

/* ─── Watchlist table + toolbar + pagination ─── */
.watch-toolbar { gap: 10px; }
.watch-toolbar select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 10px; font-size: 13px; background: var(--bg); min-height: var(--tap);
}
.watch-table { width: 100%; }
/* Higher specificity than `.query-table tbody tr` (styles.css) so the cascade
   order can't turn Watchlist rows back into a clickable hand cursor. */
.query-table.watch-table tbody tr { cursor: default; }
.query-table.watch-table tbody tr:hover { background: var(--blue-bg); }
.watch-table .watch-sl { width: 56px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.watch-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.watch-sort:hover { color: var(--text); }
.watch-sort.on { color: var(--primary); }
.watch-pager {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 8px; padding: 8px 12px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary);
}
.watch-pages { display: inline-flex; align-items: center; gap: 6px; }
.watch-pages .btn { padding: 4px 10px; font-size: 12px; }
.watch-pageno { font-variant-numeric: tabular-nums; }

.fulfillment-icon--unfulfillable {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 3px;
  background: #fee2e2;
  border-radius: 5px;
}
.icon-unfulfillable {
  width: 16px; height: 16px; object-fit: contain; display: inline-block;
  vertical-align: middle; border-radius: 2px; flex-shrink: 0;
}
.fulfillment-tabs .tab { display: inline-flex; align-items: center; gap: 4px; }
.fulfillment-tabs .icon-unfulfillable, .ship-picker .icon-unfulfillable { width: 14px; height: 14px; }
.mobile-detail-fulfillment-icon .icon-unfulfillable { width: 18px; height: 18px; }

/* ─── Ship-state picker (direct-select dropdown) ─── */
.ship-picker {
  position: fixed;
  z-index: 1000;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  padding: 6px;
  min-width: 190px;
}
.ship-picker.hidden { display: none; }
.ship-picker-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 4px 10px 6px;
}
.ship-picker-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  border-radius: 6px;
  color: var(--text);
}
.ship-picker-option:hover { background: var(--surface); }
.ship-picker-option.active { background: var(--primary-bg, #eff6ff); font-weight: 600; }
.ship-picker-option .ship-picker-tag {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
}

/* ─── Inline detail row ─── */
.detail-row td { padding: 14px 16px; background: #f8fafc; border-bottom: 2px solid var(--border); }
.detail-content .shortfall-inline {
  margin-bottom: 10px; padding: 8px 12px; background: var(--red-bg);
  border: 1px solid #fecaca; border-radius: var(--radius-sm); font-size: 12px;
}
.detail-content .shortfall-inline strong { color: var(--red); display: block; margin-bottom: 4px; }
.detail-content .shortfall-inline table { width: 100%; font-size: 12px; border-collapse: collapse; }
.detail-content .shortfall-inline th { padding: 3px 6px; background: #fee2e2; border-bottom: 1px solid #fecaca; text-align: left; font-size: 11px; }
.detail-content .shortfall-inline td { padding: 3px 6px; border-bottom: 1px solid #fecaca; }
.detail-content .shortfall-inline .short-num { text-align: right; font-weight: 600; color: var(--red); }

.detail-items-table { width: 100%; font-size: 12px; border-collapse: collapse; background: var(--surface); border-radius: var(--radius-sm); }
.detail-items-table th { padding: 5px 8px; background: var(--bg); border-bottom: 1px solid var(--border); text-align: left; font-size: 11px; }
.detail-items-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.detail-items-table .num { text-align: right; }
.detail-items-table .detail-total td { font-weight: 600; background: #f9fafb; border-top: 2px solid var(--border); }

/* ─── Status badges ─── */
.status-badge {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 600; text-transform: capitalize; white-space: nowrap;
}
.status-processing { background: var(--amber-bg); color: #92400e; }
.status-shipped { background: #ecfeff; color: #0e7490; }
.status-completed { background: var(--green-bg); color: #166534; }
.status-cancelled { background: var(--red-bg); color: #991b1b; }
.status-pending { background: #f9fafb; color: var(--text-secondary); }

.loading { text-align: center; padding: 40px; color: var(--text-secondary); }

/* ─── Detail panel ─── */
#detailPanel {
  width: 340px; min-width: 340px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 180px); position: sticky; top: 16px;
}
#detailPanel.hidden { display: none; }
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.panel-header h3 { font-size: 15px; font-weight: 600; }
.btn-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-secondary); padding: 2px; border-radius: 4px; }
.btn-close:hover { color: var(--text); background: #f3f4f6; }
.panel-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.panel-customer h4, .panel-fulfillment h4 { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px; }
.panel-fulfillment { margin-top: 4px; }

.customer-card { display: table; width: 100%; border-collapse: collapse; }
.c-row { display: table-row; }
.c-row .c-label, .c-row .c-value { display: table-cell; padding: 4px 8px 4px 0; font-size: 13px; }
.c-row .c-label { font-weight: 600; color: var(--text-secondary); white-space: nowrap; width: 80px; }
.c-row .c-value { color: var(--text); }

/* ─── Toast ─── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 10px 24px; border-radius: var(--radius);
  font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.25); z-index: 1000;
  transition: opacity .25s;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* ─── Bundle ─── */
#bundleActions { border-top: 1px solid var(--border); margin-top: 10px; }
#customerNote { border-top: 1px solid var(--border); }
.panel-highlight {
  background: var(--amber-bg); border-left: 3px solid var(--amber);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 14px; margin: 8px 0;
}
.panel-highlight.hidden { display: none; }

.bundle-assembly-header { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.bundle-assembly-qty { color: var(--text-secondary); font-weight: 400; }
.bundle-comp-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 4px 0 8px; }
.bundle-comp-table th { text-align: left; padding: 3px 6px; color: var(--text-secondary); font-weight: 600; border-bottom: 1px solid var(--border); }
.bundle-comp-table td { padding: 3px 6px; }
.bundle-comp-table .shortfall-row td { background: var(--red-bg); color: var(--red); }
.bundle-assembly-actions { margin: 6px 0; }
.bundle-flag-insufficient { font-size: 12px; font-weight: 600; color: var(--red); margin-left: 8px; }
.bundle-bundled-badge {
  display: inline-block; margin: 4px 0; padding: 2px 10px; font-size: 12px; font-weight: 600;
  color: #166534; background: #dcfce7; border: 1px solid #86efac; border-radius: var(--radius-full);
}
.bundle-pending { color: var(--text-secondary); font-size: 12px; }
.btn-assemble {
  background: #ea580c; color: #fff; border: none; padding: 5px 14px; border-radius: var(--radius-sm);
  font-size: 12px; cursor: pointer; font-weight: 600; transition: background .15s;
}
.btn-assemble:hover { background: #c2410c; }
.btn-assemble:disabled { background: #d1d5db; cursor: not-allowed; }

#customerNoteContent .note-text { font-size: 13px; color: #5d4037; padding: 4px 0; line-height: 1.4; }
#customerNoteContent strong { font-size: 12px; color: var(--text-secondary); }

.bundle-contents { font-size: 11px; color: var(--text-secondary); margin-top: 4px; line-height: 1.5; }
.bundle-part { display: inline-block; margin-right: 4px; }
.bundle-ok { color: var(--green); }
.bundle-short { color: var(--red); font-weight: 600; }

.bundle-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px;
  border-radius: 4px; background: var(--amber-bg); color: #c2410c;
  font-weight: 600; margin-left: 4px;
}
.note-badge { cursor: help; margin-left: 3px; font-size: 13px; }
.displace-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; margin-left: 4px;
  border-radius: 4px; background: var(--amber-bg); color: #92400e;
  border: 1px solid #fde68a; font-weight: 600; white-space: nowrap; cursor: help;
}
.displace-badge:hover { background: #fef3c7; }

/* ─── Panel open: auto-comfort columns ─── */
#ordersContent.panel-open .col-sl,
#ordersContent.panel-open .col-city,
#ordersContent.panel-open .col-pin,
#ordersContent.panel-open .col-coupon { display: none; }

/* ─── Hide the eligibility (ship-state) column off Processing, and the
       "Fulfilled by" column off the Bengaluru region ─── */
.hide-eligibility-col .col-fulfillment { display: none; }

/* ─── Order notes ─── */
#orderNotes { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; }
#orderNotes h4 { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.note-item { margin-bottom: 8px; padding: 6px 8px; background: #f9fafb; border-radius: 4px; font-size: 12px; }
.note-author { font-weight: 600; color: var(--primary); display: block; margin-bottom: 2px; font-size: 11px; }
.note-text { color: var(--text); line-height: 1.4; }

/* ─── Nav tabs ─── */
.nav-tabs { margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.nav-tabs .tab { font-size: 14px; padding: 8px 20px; }
.nav-tabs .tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ─── View toggle ─── */
.view.hidden { display: none; }

/* ─── Query results (Stock & Customers) ─── */
/* Zoho item typeahead — a short list under one box, so it borrows the search
   panel's surface/border rather than adding a new visual language. */
.zi-suggest { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; max-width: 560px; }
.zi-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); font-size: 13px; }
.zi-row:last-child { border-bottom: none; }
.zi-row code { flex: 0 0 auto; color: var(--text-secondary); }
.zi-row .zi-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zi-row .zi-tail { flex: 0 0 auto; color: var(--text-secondary); font-weight: 600; }
a.zi-row { color: inherit; text-decoration: none; }
a.zi-row:hover { background: var(--bg); }
.zi-row.zi-done { opacity: .5; cursor: default; }

.query-results {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.query-placeholder {
  padding: 40px; text-align: center; color: var(--text-secondary); font-size: 14px;
}
.cache-status {
  padding: 7px 12px; margin-bottom: 10px; font-size: 12px; line-height: 1.5;
  color: var(--text-secondary); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.cache-status.running { color: var(--primary); border-color: var(--primary); }
.cache-status.warn { color: #b45309; border-color: #fcd34d; background: #fffbeb; }
.cache-status .warn-text { color: #b45309; }
.query-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.query-table th {
  background: #f9fafb; padding: 7px 12px; text-align: left; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary);
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
.query-table td { padding: 6px 12px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.query-table tbody tr { cursor: pointer; }
.query-table tbody tr:hover { background: var(--blue-bg); }
.query-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.query-table .stock-ok { color: var(--green); font-weight: 600; }
.query-table .stock-low { color: var(--red); font-weight: 600; }
.margin-pos { color: var(--green); font-weight: 600; }
.margin-neg { color: var(--red); font-weight: 600; }
.margin-na { color: var(--text-secondary); }

/* ─── Detail slide-in panel (shared) ─── */
#detailOverlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.3); z-index: 999;
}
#detailOverlay.hidden { display: none; }
#slidePanel {
  position: fixed; top: 0; right: 0; width: 420px; max-width: 90vw; height: 100vh;
  background: var(--surface); box-shadow: -4px 0 20px rgba(0,0,0,.15);
  z-index: 1000; display: flex; flex-direction: column; overflow: hidden;
}
#slidePanel.hidden { display: none; }
#slidePanel .panel-header { flex-shrink: 0; }
#slidePanel .panel-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.slide-field { margin-bottom: 12px; }
.slide-field .sf-label { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.slide-field .sf-value { font-size: 14px; color: var(--text); }
.slide-field .sf-value.sf-empty { color: var(--text-secondary); font-style: italic; }

/* ─── Analysis (AI query) ─── */
.analysis-response {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 16px 20px; overflow-x: auto;
}
.analysis-model-badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  color: var(--text-secondary); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-full);
  padding: 2px 10px; margin-bottom: 10px;
}
.analysis-response.hidden { display: none; }
.analysis-response h1, .analysis-response h2, .analysis-response h3 { margin: 12px 0 6px; }
.analysis-response h1 { font-size: 18px; } .analysis-response h2 { font-size: 16px; } .analysis-response h3 { font-size: 14px; }
.analysis-response p { margin: 6px 0; line-height: 1.55; }
.analysis-response ul, .analysis-response ol { margin: 6px 0 6px 20px; }
.analysis-response li { margin: 3px 0; }
.analysis-response table { border-collapse: collapse; margin: 10px 0; font-size: 13px; width: 100%; }
.analysis-response th, .analysis-response td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.analysis-response th { background: #f9fafb; font-weight: 600; }
.analysis-response code { background: var(--bg); padding: 2px 5px; border-radius: 4px; font-size: 12px; }
.analysis-response pre { background: #1f2937; color: #f9fafb; padding: 12px; border-radius: 6px; overflow-x: auto; margin: 10px 0; }
.analysis-response pre code { background: none; color: inherit; padding: 0; }
.analysis-response blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-secondary); margin: 8px 0; }
.analysis-response a { color: var(--primary); }
.analysis-thinking { color: var(--text-secondary); padding: 10px; }
.analysis-error { color: var(--red); padding: 10px; font-weight: 500; }
#analysisDownload.hidden { display: none; }
#analysisModel:focus { outline: none; border-color: var(--primary); }

/* ─── View toggle for card/table mode ─── */
#viewToggle { display: none; }

/* ─── Card styles (mobile, roomy via tokens) ─── */
#orderCards {
  display: none; flex-direction: column; gap: 12px;
}
#orderCards .order-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--card-pad) 14px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: box-shadow .15s;
}
#orderCards .order-card:active { box-shadow: var(--shadow-md); }
#orderCards .order-card.selected { border-color: var(--primary); background: var(--primary-light); }
#orderCards .card-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
#orderCards .card-row:last-child { margin-bottom: 0; }
#orderCards .card-order-num {
  font-size: 15px; font-weight: 700; color: var(--primary);
  display: flex; align-items: center; gap: 4px;
}
#orderCards .card-name {
  font-size: 14px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#orderCards .card-detail {
  font-size: 12px; color: var(--text-secondary);
  display: flex; align-items: center; gap: 8px;
}
#orderCards .card-total {
  font-size: 14px; font-weight: 600; color: var(--text);
}
#orderCards .card-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
#orderCards .card-left input[type="checkbox"] {
  width: 22px; height: 22px; flex-shrink: 0; cursor: pointer;
}
#orderCards .card-right {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
#orderCards .card-badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-full); }
#orderCards .card-badge.bundle-badge { background: var(--amber-bg); color: #c2410c; }
#orderCards .card-badge.inv-badge { background: var(--green-bg); color: var(--green); border: 1px solid #bbf7d0; cursor: pointer; }

/* ─── Mobile slide panel (full screen from bottom) ─── */
.mobile-detail-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 1000; display: none;
}
.mobile-detail-overlay.open { display: block; }
.mobile-detail-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-height: 85vh; background: var(--surface);
  border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.15);
  z-index: 1001; display: none; flex-direction: column;
  overflow: hidden; animation: slideUp .25s ease-out;
}
.mobile-detail-panel.open { display: flex; }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.mobile-detail-panel .panel-header {
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.mobile-detail-panel .panel-header h3 { font-size: 16px; font-weight: 600; }
.mobile-detail-panel .panel-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: #d1d5db; margin: 8px auto 0;
}
.mobile-detail-panel .panel-body {
  padding: 16px 18px; overflow-y: auto; flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* ─── Responsive ─── */

/* Tablet (641px - 1024px): table kept, Paid kept per owner call */
@media (min-width: 641px) and (max-width: 1024px) {
  #ordersContent { flex-direction: column; }
  #detailPanel { width: 100%; min-width: unset; max-height: none; position: static; }
  .filter-card { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; }
  .filter-divider { display: none; }
  .radio-group { flex-wrap: wrap; }
  .filter-group input[type="text"] { min-width: 140px; }
  .actions-bar { flex-wrap: wrap; gap: 8px; }
  .action-group { flex-wrap: wrap; }

  /* Hide less important columns on tablet — Paid kept (owner must-have) */
  #ordersContent.panel-open .col-sl,
  #ordersContent.panel-open .col-city,
  #ordersContent.panel-open .col-pin,
  #ordersContent.panel-open .col-coupon { display: none; }
  .col-sl, .col-coupon, .col-weight { display: none; }

  /* Touch tablets get roomy targets via tokens; mouse tablets stay dense */
  input[type="checkbox"] { width: 18px; height: 18px; }

  /* Detail panel in tablet */
  #slidePanel { width: 50vw; max-width: 400px; }
}

/* Phone (≤ 640px) */
@media (max-width: 640px) {
  /* App container */
  #app { padding: 10px 12px; }

  /* Header */
  header { flex-wrap: wrap; gap: 8px; }
  header h1 { font-size: 18px; }
  .header-actions { flex-wrap: wrap; gap: 4px; }
  .header-actions .badge { font-size: 10px; padding: 2px 8px; }
  .header-actions .badge-user { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  #userEmail { font-size: 11px; }

  /* Nav tabs */
  .nav-tabs { gap: 4px; margin-bottom: 10px; padding-bottom: 6px; }
  .nav-tabs .tab { font-size: 12px; padding: 6px 12px; }

  /* Filter card */
  .filter-card { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px; }
  .filter-divider { display: none; }
  .filter-group { flex-direction: column; align-items: stretch; gap: 4px; }
  .filter-group .filter-label { font-size: 10px; }
  .radio-group { flex-wrap: wrap; gap: 4px; }
  .radio-group label { padding: 8px 14px; font-size: 14px; min-height: 44px; display: flex; align-items: center; }
  .filter-group input[type="date"],
  .filter-group input[type="text"] {
    padding: 10px 12px; font-size: 16px; min-height: 44px;
    width: 100%; min-width: unset;
  }
  .filter-group .sep { display: none; }
  .filter-group input[type="date"] { width: 100%; }
  .filter-group input[type="text"] { width: 100%; }
  .btn { min-height: 44px; font-size: 14px; padding: 10px 16px; justify-content: center; }
  .btn-primary { width: 100%; }

  /* Actions bar */
  .actions-bar { flex-direction: column; gap: 8px; padding: 10px 12px; position: sticky; bottom: 0; z-index: 5; }
  .action-group { width: 100%; flex-wrap: wrap; gap: 6px; }
  .action-group .btn { flex: 1; min-width: 0; }
  /* Collapsible extra filters (collapsed by default on phone) */
  .filter-extra { display: none; width: 100%; flex-direction: column; gap: 8px; padding-top: 4px; }
  .filter-extra.open { display: flex; }
  .filter-more-toggle {
    display: inline-flex; width: 100%; justify-content: center; align-items: center;
    min-height: 44px; font-size: 13px; font-weight: 600; color: var(--primary);
    border-style: dashed;
  }

  /* Table → hide in favor of cards */
  #tableWrap { display: none; }
  #orderCards { display: flex; }

  /* Fulfillment tabs */
  .fulfillment-tabs { gap: 4px; }
  .fulfillment-tabs .tab { font-size: 11px; padding: 6px 10px; }

  /* Region tabs */
  .region-tabs .tab { font-size: 12px; padding: 6px 12px; }

  /* Utilities category tabs */
  .util-group-tabs .tab { font-size: 12px; padding: 6px 10px; }
  .util-group-tabs .ug-tail { display: none; }

  /* Detail panel (existing) — hide on phone, use mobile panel instead */
  #detailPanel { display: none !important; }

  /* Stock / Customers */
  #viewStock .filter-card,
  #viewCustomers .filter-card { flex-direction: column; align-items: stretch; }
  #stockSearch, #custSearch { width: 100%; min-width: unset; }
  .query-results { overflow-x: auto; }
  .query-table { font-size: 12px; }
  .query-table th, .query-table td { padding: 6px 8px; }

  /* Admin panel */
  .admin-add-user { flex-direction: column; align-items: stretch; }
  .admin-add-user input,
  .admin-add-user select { width: 100%; min-width: unset; }
  .perm-grid { grid-template-columns: 1fr; }
  .admin-section .batch-table-wrap {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .admin-section .batch-table-wrap .query-table { min-width: 600px; }
  .role-perm-row { flex-wrap: wrap; gap: 6px; }

  /* Modal */
  .modal-card { max-width: 100vw; max-height: 100vh; border-radius: 0; width: 100%; height: 100%; }
  .modal-body { padding: 12px 14px; }
  .bf-row input[type="text"] { width: 100%; }
  .bf-actions { flex-direction: column; }
  .bf-actions .btn { width: 100%; }
  .batch-table-wrap { max-height: 50vh; }
  .chip-row { gap: 4px; }
  .chip { font-size: 11px; padding: 2px 8px; }

  /* Login */
  .login-card { padding: 32px 24px; }
  .login-card h1 { font-size: 20px; }

  /* Toast */
  #toast { bottom: 16px; left: 16px; right: 16px; transform: none; text-align: center; font-size: 13px; }

  /* Slide panel */
  #slidePanel { width: 100vw; max-width: 100vw; }
}

/* Touch-friendly overrides for any touch device */
@media (hover: none) and (pointer: coarse) {
  .btn, .tab, .radio-group label, select, .role-select {
    min-height: 44px;
  }
  input[type="checkbox"] { width: 20px; height: 20px; }
  input[type="date"], input[type="text"], input[type="email"], input[type="password"], select {
    font-size: 16px; /* prevents iOS zoom */
  }
  thead th::after { width: 10px; } /* Larger resize handle for touch */
}

/* ─── Mini status badge for cards ─── */
.card-status {
  display: inline-block; padding: 2px 8px; border-radius: var(--radius-full);
  font-size: 10px; font-weight: 600; white-space: nowrap;
}

/* ─── Zoho Batch modal ─── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 1100;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md);
  width: 960px; max-width: 94vw; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-body { padding: 16px 20px; overflow-y: auto; }

.batch-form p { margin: 0 0 14px; font-size: 13px; color: var(--text-secondary); }
.bf-row { margin-bottom: 14px; }
.bf-row label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.bf-row input[type="text"] {
  width: 280px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit;
}
.bf-row input[type="text"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.bf-chk { display: flex !important; align-items: center; gap: 6px; font-size: 13px !important; color: var(--text) !important; font-weight: 400 !important; }
.bf-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.bf-override-warn { margin-bottom: 14px; padding: 12px; background: #fef3c7; border: 1px solid #fde68a; border-radius: var(--radius-sm); font-size: 13px; }
.bf-override-warn .query-table { margin-top: 8px; margin-bottom: 10px; }
.bf-override-warn .query-table td { padding: 2px 8px; font-size: 12px; }
.bf-override-warn .bf-chk { margin-top: 4px; }
.bf-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: var(--radius-full);
  background: var(--blue-bg); color: var(--blue); border: 1px solid #bfdbfe;
}
.chip-ok { background: var(--green-bg); color: var(--green); border-color: #bbf7d0; }
.chip-warn { background: var(--amber-bg); color: var(--amber); border-color: #fde68a; }
.chip-bad { background: var(--red-bg); color: var(--red); border-color: #fecaca; }
.chip-info { background: #f5f3ff; color: #7c3aed; border-color: #ddd6fe; }

.batch-table-wrap { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.batch-table-wrap .query-table tbody tr { cursor: default; }
.batch-loading { padding: 40px; text-align: center; color: var(--text-secondary); font-size: 14px; }
.batch-error { padding: 14px; background: var(--red-bg); color: var(--red); border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; }
.batch-skipped { margin-top: 14px; font-size: 13px; }
.batch-skipped .query-table tbody tr:hover { background: none; }

.flag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: var(--radius-full); margin-right: 4px; white-space: nowrap; }
.flag-dummy { background: var(--amber-bg); color: var(--amber); border: 1px solid #fde68a; }
.flag-item { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }
.flag-bundle { background: #f5f3ff; color: #7c3aed; border: 1px solid #ddd6fe; }
.flag-override { background: #fef3c7; color: #d97706; border: 1px solid #fde68a; }
/* Low priority: how many more units of which item would let this order ship. */
.flag-short { background: var(--amber-bg); color: var(--amber); border: 1px solid #fde68a; font-weight: 600; }

.res-ok { color: var(--green); font-weight: 600; }
.res-err { color: var(--red); font-weight: 600; }

.inv-badge {
  font-size: 10px; font-weight: 600; background: var(--green-bg); color: var(--green);
  border: 1px solid #bbf7d0; border-radius: 4px; padding: 0 4px; margin-left: 4px; white-space: nowrap;
  cursor: pointer;
}
.inv-badge:hover { background: #fef2f2; color: var(--red); border-color: #fecaca; }

/* ─── Login view ─── */
#loginView { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
#loginView.hidden { display: none; }
#app.hidden { display: none; }
#dashboardContent.hidden { display: none; }
#viewerMessage.hidden { display: none; }
.login-card { background: var(--surface); border-radius: 12px; padding: 48px 40px; text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,0.08); max-width: 400px; width: 90%; }
.login-card h1 { font-size: 24px; margin-bottom: 8px; color: var(--text); }
.login-sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 32px; }
#gSignIn { display: flex; justify-content: center; margin-bottom: 16px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 16px; }

.badge-user { background: #f0fdf4; color: var(--green); border-color: #bbf7d0; font-size: 12px; }

.admin-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.admin-section.hidden { display: none; }
.admin-section-body { padding: 12px; }
.admin-section-header { padding: 12px; border-bottom: 1px solid var(--border); }
.admin-section-header h4 { font-size: 14px; margin: 0; }
.admin-add-user { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.admin-add-user input { flex: 1; min-width: 200px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; }
.admin-add-user select { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: var(--surface); }
.gms-pincode-input { flex: 0 0 auto; width: 130px; letter-spacing: .08em; }
.gms-lookup-card { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); padding: 10px 12px; font-size: 13px; line-height: 1.6; }
.gms-lookup-card .gms-lookup-hint { color: var(--text-secondary); }
.gms-lookup-card .gms-lookup-row { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; }
.gms-lookup-card .gms-lookup-label { color: var(--text-secondary); min-width: 175px; }
.gms-lookup-card .gms-lookup-value { font-weight: 600; }
.gms-pill { display: inline-block; padding: 1px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600; border: 1px solid transparent; }
.gms-pill.available { background: #f0fdf4; color: #16a34a; border-color: #bbf7d0; }
.gms-pill.oda { background: #fffbeb; color: #d97706; border-color: #fde68a; }
.gms-pill.noservice { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.gms-pill.neutral { background: var(--bg); color: var(--text-secondary); border-color: var(--border); }
.role-select { padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; background: var(--surface); cursor: pointer; }
.name-input { border: 1px solid transparent; border-radius: 3px; padding: 2px 4px; font-size: 13px; background: transparent; width: 140px; }
.name-input:hover { border-color: var(--border); }
.name-input:focus { border-color: var(--primary); outline: none; background: var(--surface); }
.btn-toggle { border: none; cursor: pointer; font-size: 14px; font-weight: 600; vertical-align: middle; padding: 4px 12px; border-radius: 6px; line-height: 1; }
.btn-toggle.on { background: #dcfce7; color: #16a34a; }
.btn-toggle.off { background: #f3f4f6; color: #9ca3af; }
.btn-toggle.on:hover { background: #bbf7d0; }
.btn-toggle.off:hover { background: #e5e7eb; }
.btn-sm { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; font-size: 13px; padding: 4px 10px; display: inline-flex; align-items: center; gap: 4px; }
.btn-sm:hover { background: var(--bg); }
/* Primary + small: .btn-sm would otherwise override the primary background, leaving
   white text on a light button (invisible active chips / small primary buttons). */
.btn-sm.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-sm.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* Fulfillment Recon — ledger right block + recon strip */
.fr-section td { background: var(--bg); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-secondary); }
.fr-pay-row td { color: var(--text-secondary); }
.fr-pay-row > td:first-child { border-left: 3px solid #22c55e; font-style: italic; }
.fr-recon-chip { display: inline-flex; align-items: baseline; gap: 6px; font-size: 19px; font-weight: 700; border: 1px solid var(--border); border-radius: var(--radius-full); padding: 5px 14px; background: var(--surface); }
.fr-recon-chip .fr-chip-k { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.fr-recon-chip .fr-chip-s { font-size: 14px; font-weight: 700; color: var(--text-secondary); }
.fr-recon-chip .fr-chip-sub { font-size: 19px; color: var(--primary); font-weight: 700; }
.btn-del { width: 28px; height: 28px; border-radius: 50%; border: none; background: #fef2f2; cursor: pointer; font-size: 13px; color: var(--red); display: inline-flex; align-items: center; justify-content: center; padding: 0; line-height: 1; }
.btn-del:hover { background: #fee2e2; }
.btn-invite { width: 28px; height: 28px; border-radius: 50%; border: none; background: #eff6ff; cursor: pointer; font-size: 13px; color: var(--blue); display: inline-flex; align-items: center; justify-content: center; padding: 0; line-height: 1; margin-right: 4px; }
.btn-invite:hover { background: #dbeafe; }

.role-perms-list { padding: 12px; }
.role-perm-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.role-perm-row:last-child { border-bottom: none; }
.role-perm-summary { font-size: 12px; color: var(--text-secondary); flex: 1; }
.role-perm-row .btn-sm { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; font-size: 13px; padding: 4px 10px; }
.role-perm-row .btn-sm:hover { background: var(--bg); }
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.perm-chk { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 8px; border-radius: var(--radius-sm); cursor: pointer; }
.perm-chk:hover { background: var(--bg); }
.perm-chk input { margin: 0; }
.role-badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-full); }
.role-admin { background: #fef3c7; color: #d97706; border: 1px solid #fde68a; }
.role-operations { background: #dbeafe; color: #2563eb; border: 1px solid #bfdbfe; }
.role-sales { background: #d1fae5; color: #059669; border: 1px solid #a7f3d0; }
.role-viewer { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.role-unregistered { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.status-online { background: #16a34a; box-shadow: 0 0 0 2px #bbf7d0; }
.status-away { background: #d97706; box-shadow: 0 0 0 2px #fde68a; }
.status-offline { background: #9ca3af; box-shadow: 0 0 0 2px #e5e7eb; }
/* ─── Customer CRM ─── */
.crm-data-badge { font-size: 12px; color: var(--text-secondary); margin-left: 8px; align-self: center; }
.crm-disambig { margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.crm-disambig-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.crm-cand { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; text-align: left; font-family: inherit; font-size: 14px; }
.crm-cand:hover { border-color: var(--primary); background: var(--primary-light); }
.crm-cand-name { font-weight: 600; min-width: 160px; }
.crm-cand-meta { color: var(--text-secondary); font-size: 13px; }
.crm-loading { text-align: center; padding: 32px; color: var(--text-secondary); }
.crm-no-result { text-align: center; padding: 40px; color: var(--text-secondary); }
.crm-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.crm-header { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.crm-avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 18px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.crm-name { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.crm-badge-repeat { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-full); background: #d1fae5; color: #059669; border: 1px solid #a7f3d0; }
.crm-contact { display: flex; flex-wrap: wrap; gap: 12px; color: var(--text-secondary); font-size: 13px; margin-top: 4px; }
.crm-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 16px; }
.crm-kpi { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.crm-kpi-val { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.crm-kpi-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.crm-section { margin-top: 14px; }
.crm-section-title { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }
.crm-spark { display: flex; align-items: flex-end; gap: 3px; height: 48px; padding: 4px 2px; }
.crm-bar { flex: 1; min-width: 4px; background: var(--primary); border-radius: 2px 2px 0 0; opacity: .85; }
.crm-bar:hover { opacity: 1; }
.crm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.crm-chip { font-size: 12px; padding: 3px 10px; border-radius: var(--radius-full); background: var(--primary-light); color: var(--primary); border: 1px solid var(--border); }
.crm-table-wrap { overflow-x: auto; }
.crm-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.crm-items-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-empty { text-align: center; color: var(--text-secondary); }
.ai-panel { margin-top: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.ai-panel summary { padding: 12px 16px; cursor: pointer; font-weight: 600; font-size: 14px; }
.ai-note { font-weight: 400; font-size: 12px; color: var(--text-secondary); }

/* ─── CRM Sync Data ─── */
.crm-sync-status { font-size: 12px; color: var(--text-secondary); margin-left: 6px; align-self: center; }
.crm-sync-busy { color: var(--amber); font-weight: 600; }

/* ─── CRM Fulfillment badge ─── */
.crm-fulfill { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.crm-fbadge { font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: var(--radius-full); }
.crm-fbadge.chennai { background: #dbeafe; color: #2563eb; border: 1px solid #bfdbfe; }
.crm-fbadge.bangalore { background: #d1fae5; color: #059669; border: 1px solid #a7f3d0; }
.crm-fbadge.hybrid { background: #fef3c7; color: #d97706; border: 1px solid #fde68a; }
.crm-fbadge.none { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }
.crm-fcount { font-size: 12px; color: var(--text-secondary); }
.crm-more { margin-top: 8px; align-self: flex-start; }
.crm-hint { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }

/* ─── CRM card billing address line ─── */
.crm-address { margin-top: 6px; font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

/* ─── CRM hidden toggles (covered by global .hidden) ─── */
.crm-fdetail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 16px; font-size: 12px; color: var(--text); line-height: 1.6; }

/* ─── CRM animated loading bar + narration ─── */
.crm-loading { text-align: center; padding: 18px 12px; color: var(--text-secondary); }
.crm-loading-narr { font-size: 13px; margin-bottom: 10px; }
.crm-loading-bar-track { position: relative; height: 6px; max-width: 420px; margin: 0 auto; border-radius: 3px; background: var(--border); overflow: hidden; }
.crm-loading-bar { position: absolute; inset: 0; width: 40%; border-radius: 3px; background: linear-gradient(90deg, var(--primary), var(--primary-hover)); animation: crmBarSlide 1.1s ease-in-out infinite; }
@keyframes crmBarSlide { 0% { left: -40%; } 100% { left: 100%; } }

/* ─── CRM candidate wrapper + inline detail (Orders-style unfold) ─── */
.crm-cand-wrap { display: flex; flex-direction: column; gap: 6px; }
.crm-cand-wrap .crm-cand { width: 100%; }
.crm-cand-detail { margin-left: 8px; }

/* ─── Role editor permission sections (grouped by tab) ─── */
.perm-section { margin-bottom: 14px; }
.perm-section-title { font-size: 13px; font-weight: 700; color: var(--primary); padding: 6px 10px; background: var(--primary-light); border-radius: var(--radius-sm); margin-bottom: 8px; }

/* ─── Price Sync filter buttons ─── */
.priceSyncFilterBtn, .rateCompareFilterBtn { font-size: 12px; padding: 4px 10px; }

/* ─── Batch table horizontal scroll (desktop fix) ─── */
.batch-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.batch-table-wrap .query-table { min-width: 800px; }

/* ─── Purchase Order foldable sections ─── */
.po-acc { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; overflow: hidden; }
.po-acc-head { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 14px; background: transparent; border: 0; cursor: pointer; text-align: left; font-family: inherit; font-size: 14px; color: inherit; }
.po-acc-head:hover { background: var(--primary-light); }
.po-acc-chev { font-size: 11px; color: var(--text-secondary); transition: transform .15s ease; transform: rotate(90deg); }
.po-acc.collapsed .po-acc-chev { transform: rotate(0deg); }
.po-acc-title { font-weight: 600; }
.po-acc-summary { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--text-secondary); text-align: right; }
.po-acc-body { padding: 4px 14px 16px; border-top: 1px solid var(--border); }
.po-acc.collapsed .po-acc-body { display: none; }
.po-hint { font-size: 12.5px; color: var(--text-secondary); margin: 10px 0 12px; }

/* ─── Stock Report ─── */
.sr-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.sr-mode-toggle { margin: 0; }
.sr-summary { font-size: 13px; color: var(--text-secondary); }
.sr-table .sr-cat-row td { background: var(--blue-bg, #eff6ff); font-weight: 600; font-size: 13px; }
.sr-cat-count { color: var(--text-secondary); font-weight: 400; }
.sr-shelf-input { width: 84px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; text-align: right; font-size: 14px; background: var(--surface); }
.sr-shelf-input:focus { outline: 2px solid var(--primary, #2563eb); outline-offset: 0; }
.sr-row-inactive { background: #fff7ed; }
.sr-diff { font-weight: 600; font-variant-numeric: tabular-nums; }
.sr-diff-ok { color: var(--green, #16a34a); }
.sr-diff-plus { color: #b45309; }
.sr-diff-minus { color: var(--red, #dc2626); }
.sr-diff-none { color: var(--text-secondary); }
.sr-remark { color: #b45309; font-size: 11px; font-weight: 600; }
.sr-sub-row td { background: #f9fafb; font-size: 12px; color: var(--text-secondary); }
.sr-total-row td { font-weight: 700; border-top: 2px solid var(--border); }

.sr-count-card { max-width: 520px; margin: 0 auto; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.sr-count-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-secondary); }
.sr-count-cat { font-weight: 600; color: var(--text); }
.sr-progress { height: 6px; background: #e5e7eb; border-radius: 4px; overflow: hidden; margin: 8px 0 14px; }
.sr-progress > div { height: 100%; background: var(--primary, #2563eb); transition: width .15s ease; }
.sr-count-name { font-size: 17px; font-weight: 600; }
.sr-count-sku { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.sr-count-zoho { margin: 12px 0 6px; }
.sr-stepper { display: flex; gap: 8px; align-items: center; }
.sr-stepper .btn { min-width: 56px; font-size: 22px; line-height: 1; }
.sr-count-input { flex: 1; text-align: center; font-size: 26px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); min-width: 0; }
.sr-count-input:focus { outline: 2px solid var(--primary, #2563eb); outline-offset: 0; }
.sr-count-diff { margin: 10px 0 14px; }
.sr-count-actions { display: flex; gap: 8px; }
.sr-count-actions .btn { flex: 1; }
.sr-hint { font-size: 12px; color: var(--text-secondary); margin-top: 10px; }

@media (max-width: 640px) {
  .sr-count-actions { flex-wrap: wrap; }
  .sr-count-actions .btn { flex: 1 1 40%; }
}

/* ─── Stock Report — filter / sort / AutoFilter ─── */
.sr-search { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: var(--surface); min-width: 200px; }
.sr-group-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.sr-shown { color: #b45309; }
.sr-table { min-width: 1040px; }
.sr-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.sr-sort.on { color: var(--primary, #2563eb); }
.sr-funnel { margin-left: 6px; border: 0; background: transparent; cursor: pointer; font-size: 9px; color: var(--text-secondary); padding: 0 2px; vertical-align: middle; }
.sr-funnel.on { color: #b45309; }
.sr-st-active { color: #166534; font-size: 12px; }
.sr-st-inactive { color: #b45309; font-weight: 600; font-size: 12px; }

.sr-pop { display: none; position: absolute; z-index: 1200; width: 250px; max-height: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 10px; font-size: 13px; }
.sr-pop-head { font-weight: 600; margin-bottom: 8px; }
.sr-pop-search, .sr-pop-input { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; margin-bottom: 8px; }
.sr-pop-all { display: flex; align-items: center; gap: 6px; padding: 4px 2px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.sr-pop-list { max-height: 180px; overflow: auto; }
.sr-pop-item { display: flex; align-items: center; gap: 6px; padding: 3px 2px; }
.sr-pop-actions { display: flex; gap: 8px; margin-top: 10px; }
.sr-pop-actions .btn { flex: 1; }

/* ─── Stock Report — sessions ─── */
.sr-session { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.sr-session-label { font-size: 12px; color: var(--text-secondary); }
.sr-session-date { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: var(--surface); }
.sr-sessions { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 10px; background: var(--surface); }
.sr-sessions-title { font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.sr-session-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--border); }
.sr-session-row:last-child { border-bottom: 0; }
.sr-session-date-txt { font-weight: 600; font-size: 13px; min-width: 140px; }
.sr-session-meta { font-size: 12px; color: var(--text-secondary); flex: 1; }
.sr-session-dl { display: flex; gap: 6px; }
.sr-session-dl .btn { padding: 4px 10px; font-size: 12px; }
@media (max-width: 640px) {
  .sr-session-date-txt { min-width: 0; }
  .sr-session-meta { flex: 1 1 100%; }
}

/* ─── Environment flag: owner-only header pill (muted) ─── */
.env-badge { font-weight: 700; letter-spacing: .04em; cursor: help; }
body.env-local .env-badge { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
body.env-render .env-badge { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }

/* ─── Perf + a11y tightening ─── */
tbody tr { content-visibility: auto; contain-intrinsic-size: auto 40px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
#toast[aria-live] { position: fixed; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 640px) {
  thead th::after { display: none; } /* disable col-resize on touch */
  button, .btn, input, select { min-height: 40px; }
}

/* ─── Dummy Customer mapper (Zoho batch preview) ─── */
.cm-panel {
  margin: 12px 0; padding: 12px; border: 1px solid #fde68a;
  border-radius: var(--radius-sm); background: #fffbeb;
}
.cm-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cm-row .cm-phone { flex: 1; min-width: 130px; padding: 6px 8px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.cm-cell { min-width: 260px; }
.cm-result { font-size: 12px; margin-top: 4px; }
.cm-note { color: var(--amber); }
.cm-ok { color: var(--green); font-weight: 600; }
.cm-picks { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.cm-woo { min-width: 170px; }
.cm-zoho { min-width: 210px; }
.cm-sub { font-size: 11px; color: var(--text-secondary); }
/* Woo ship-to: only shown when it differs from the billing address, so it must
   read as a qualifier of the line above rather than as a second address. */
.cm-ship { font-style: italic; color: #7c5e10; }
.cm-warn { color: #d97706; font-size: 11px; font-weight: 600; margin-left: 4px; }
