/* =========================================================================
   R K KNIT FAB — PI ORDER STATUS TRACKER
   Design system: Clean dashboard, fabric-inspired warm palette.
   Navy + red from the brand mark. Status colours per spec.
   Mobile-first, no framework.
   ========================================================================= */

/* ---- FONTS (loaded via CDN in index.html) ---- */

:root {
  /* brand */
  --navy:          #1B2559;
  --navy-ink:      #10173A;
  --navy-soft:     #2B3670;
  --red:           #C2272D;
  --red-deep:      #9E1E23;
  --gold:          #A67C2E;
  --gold-soft:     #C9A24B;

  /* canvas */
  --bg:            #F4F2ED;
  --bg-deep:       #EBE8E0;
  --surface:       #FFFFFF;
  --surface-hover: #FAFAF8;
  --ink:           #23262F;
  --ink-secondary: #555960;
  --muted:         #7A7567;
  --border:        #E2DDD0;
  --border-light:  #EDEAE3;

  /* status colours */
  --st-pending:          #E53E3E;
  --st-pending-bg:       #FED7D7;
  --st-in-process:       #C05621;
  --st-in-process-bg:    #FEEBC8;
  --st-getting-ready:    #97790A;
  --st-getting-ready-bg: #FEFCBF;
  --st-ready:            #2B6CB0;
  --st-ready-bg:         #BEE3F8;
  --st-dispatched:       #276749;
  --st-dispatched-bg:    #C6F6D5;
  --st-cancelled:        #718096;
  --st-cancelled-bg:     #E2E8F0;

  /* type */
  --font-display: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:    'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;

  /* layout */
  --radius:       10px;
  --radius-sm:    6px;
  --radius-pill:  999px;
  --shadow-card:  0 1px 3px rgba(16,23,58,0.06), 0 1px 2px rgba(16,23,58,0.04);
  --shadow-pop:   0 8px 30px rgba(16,23,58,0.14);
  --shadow-float: 0 4px 16px rgba(16,23,58,0.10);
  --transition:   0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 0;
  color: var(--navy-ink);
}

/* ---- TOPBAR -------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--navy);
  color: #fff;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
  box-shadow: 0 2px 8px rgba(16,23,58,0.18);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-brand img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
}

.topbar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.topbar-brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.topbar-brand-sub {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-soft);
  font-weight: 600;
}

.topbar-search {
  flex: 1;
  max-width: 400px;
  position: relative;
  margin-left: auto;
}

.topbar-search input {
  width: 100%;
  padding: 8px 14px 8px 36px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: background var(--transition), border var(--transition);
}

.topbar-search input::placeholder { color: rgba(255,255,255,0.5); }
.topbar-search input:focus {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.35);
}

.topbar-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255,255,255,0.5);
  pointer-events: none;
  width: 16px;
  height: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.mode-badge.demo {
  background: rgba(230,198,25,0.2);
  color: #E6C619;
  border-color: rgba(230,198,25,0.3);
}

.mode-badge.live {
  background: rgba(56,161,105,0.2);
  color: #68D391;
  border-color: rgba(56,161,105,0.3);
}

.topbar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.topbar-btn:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

/* ---- FILTER BAR ---------------------------------------------------------- */

.filter-bar {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 60px;
  z-index: 90;
}

.filter-select {
  padding: 7px 30px 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237A7567' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 140px;
  transition: border-color var(--transition);
}

.filter-select:focus {
  border-color: var(--navy-soft);
}

.filter-search {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  outline: none;
  min-width: 160px;
  transition: border-color var(--transition);
}

.filter-search:focus {
  border-color: var(--navy-soft);
}

.status-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--transition);
  user-select: none;
  opacity: 0.5;
}

.status-chip.active {
  opacity: 1;
  transform: scale(1.02);
}

.status-chip[data-status="PENDING"]       { background: var(--st-pending-bg); color: var(--st-pending); border-color: var(--st-pending); }
.status-chip[data-status="IN PROCESS"]    { background: var(--st-in-process-bg); color: var(--st-in-process); border-color: var(--st-in-process); }
.status-chip[data-status="GETTING READY"] { background: var(--st-getting-ready-bg); color: var(--st-getting-ready); border-color: var(--st-getting-ready); }
.status-chip[data-status="READY"]         { background: var(--st-ready-bg); color: var(--st-ready); border-color: var(--st-ready); }
.status-chip[data-status="DISPATCHED"]    { background: var(--st-dispatched-bg); color: var(--st-dispatched); border-color: var(--st-dispatched); }
.status-chip[data-status="CANCELLED"]     { background: var(--st-cancelled-bg); color: var(--st-cancelled); border-color: var(--st-cancelled); }

/* ---- MAIN CONTENT -------------------------------------------------------- */

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* ---- STATS ROW ----------------------------------------------------------- */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-float);
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  font-family: var(--font-mono);
  line-height: 1.1;
}

.stat-label {
  font-size: 11.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-top: 4px;
}

/* ---- ORDER CARDS --------------------------------------------------------- */

.order-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.order-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.order-card:hover {
  box-shadow: var(--shadow-float);
}

.order-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.order-card-header:hover {
  background: var(--surface-hover);
}

.order-pi {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  min-width: 80px;
}

.order-customer {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.order-date {
  font-family: var(--font-mono);
  font-size: 12px;
}

.order-item-count {
  background: var(--bg);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.order-expand-icon {
  width: 20px;
  height: 20px;
  color: var(--muted);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.order-card.expanded .order-expand-icon {
  transform: rotate(180deg);
}

/* ---- STATUS PILL --------------------------------------------------------- */

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-transform: uppercase;
}

.status-pill[data-status="PENDING"]       { background: var(--st-pending-bg); color: var(--st-pending); }
.status-pill[data-status="IN PROCESS"]    { background: var(--st-in-process-bg); color: var(--st-in-process); }
.status-pill[data-status="GETTING READY"] { background: var(--st-getting-ready-bg); color: var(--st-getting-ready); }
.status-pill[data-status="READY"]         { background: var(--st-ready-bg); color: var(--st-ready); }
.status-pill[data-status="DISPATCHED"]    { background: var(--st-dispatched-bg); color: var(--st-dispatched); }
.status-pill[data-status="CANCELLED"]     { background: var(--st-cancelled-bg); color: var(--st-cancelled); }

/* ---- ORDER DETAIL / LINE ITEMS TABLE ------------------------------------- */

.order-detail {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.order-card.expanded .order-detail {
  max-height: 3000px;
}

.order-detail-inner {
  border-top: 1px solid var(--border-light);
  padding: 16px 18px;
}

.order-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.order-detail-info {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--ink-secondary);
}

.order-detail-info span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.order-detail-info strong {
  color: var(--ink);
  font-weight: 600;
}

.order-actions {
  display: flex;
  gap: 6px;
}

.line-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -18px;
  padding: 0 18px;
}

.line-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.line-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
}

.line-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.line-table tr:last-child td {
  border-bottom: none;
}

.line-table tr:hover td {
  background: var(--surface-hover);
}

/* Inline edit cells */
.inline-input {
  border: none;
  border-bottom: 1.5px solid transparent;
  background: transparent;
  padding: 4px 2px;
  width: 100%;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color var(--transition);
  min-width: 60px;
}

.inline-input:hover {
  border-bottom-color: var(--border);
}

.inline-input:focus {
  border-bottom-color: var(--navy-soft);
}

.inline-input.remarks {
  min-width: 120px;
}

.inline-input.rolls,
.inline-input.lot-no {
  min-width: 60px;
  max-width: 90px;
}

/* Status select */
.status-select {
  padding: 4px 24px 4px 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  transition: all var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.status-select[data-status="PENDING"]       { background-color: var(--st-pending-bg); color: var(--st-pending); }
.status-select[data-status="IN PROCESS"]    { background-color: var(--st-in-process-bg); color: var(--st-in-process); }
.status-select[data-status="GETTING READY"] { background-color: var(--st-getting-ready-bg); color: var(--st-getting-ready); }
.status-select[data-status="READY"]         { background-color: var(--st-ready-bg); color: var(--st-ready); }
.status-select[data-status="DISPATCHED"]    { background-color: var(--st-dispatched-bg); color: var(--st-dispatched); }
.status-select[data-status="CANCELLED"]     { background-color: var(--st-cancelled-bg); color: var(--st-cancelled); }

/* Custom colour toggle */
.custom-colour-toggle {
  width: 18px;
  height: 18px;
  accent-color: var(--navy);
  cursor: pointer;
}

/* ---- BUTTONS ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.btn-primary:hover {
  background: var(--navy-soft);
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
}

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

.btn-danger {
  background: var(--st-pending);
  color: #fff;
  border-color: var(--st-pending);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--ink);
}

/* ---- TOAST --------------------------------------------------------------- */

.toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--navy);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  animation: toast-in 0.3s ease;
  max-width: 340px;
}

.toast.error {
  background: var(--st-pending);
}

.toast.success {
  background: var(--st-dispatched);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- MODAL / DRAWER ------------------------------------------------------ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16,23,58,0.45);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s ease;
  padding: 20px;
}

.modal-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  animation: modal-in 0.25s ease;
}

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

.modal-header h2 {
  font-size: 17px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 18px;
}

.modal-close:hover {
  background: var(--border);
  color: var(--ink);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- SETTINGS PANEL ------------------------------------------------------ */

.settings-group {
  margin-bottom: 18px;
}

.settings-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

.settings-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color var(--transition);
  background: var(--surface);
}

.settings-input:focus {
  border-color: var(--navy-soft);
}

.settings-mode-toggle {
  display: flex;
  gap: 8px;
}

.settings-mode-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
  color: var(--ink-secondary);
}

.settings-mode-btn.active {
  border-color: var(--navy);
  background: rgba(27,37,89,0.06);
  color: var(--navy);
}

/* ---- EXPORT MODAL -------------------------------------------------------- */

.export-columns {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.export-col-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
}

.export-col-option:hover {
  background: var(--bg);
}

.export-col-option.selected {
  border-color: var(--navy);
  background: rgba(27,37,89,0.06);
}

.export-col-option input[type="checkbox"] {
  accent-color: var(--navy);
}

.export-format-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.export-format-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  transition: all var(--transition);
}

.export-format-btn.active {
  border-color: var(--navy);
  background: rgba(27,37,89,0.06);
  color: var(--navy);
}

/* ---- EXPORT REPORT (rendered off-screen for capture) --------------------- */

.export-report {
  background: #fff;
  padding: 32px;
  font-family: 'Inter', Arial, sans-serif;
  color: #23262F;
  min-width: 800px;
}

.export-report-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 6px;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--navy);
}

.export-report-header img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}

.export-report-company {
  font-size: 22px;
  font-weight: 800;
  color: var(--navy);
}

.export-report-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
  margin: 16px 0 6px;
}

.export-report-meta {
  display: flex;
  gap: 24px;
  font-size: 13px;
  color: #555;
  margin-bottom: 16px;
}

.export-report table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.export-report table th {
  background: var(--navy);
  color: #fff;
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.export-report table td {
  padding: 7px 10px;
  border-bottom: 1px solid #E2DDD0;
}

.export-report table tr:nth-child(even) td {
  background: #F9F8F5;
}

.export-report-footer {
  margin-top: 20px;
  padding-top: 10px;
  border-top: 1px solid #E2DDD0;
  font-size: 11px;
  color: #999;
  text-align: center;
}

/* ---- EMPTY STATE --------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state-text {
  font-size: 15px;
  font-weight: 500;
}

/* ---- LOADING SPINNER ----------------------------------------------------- */

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

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

/* ---- RESPONSIVE ---------------------------------------------------------- */

@media (max-width: 768px) {
  .topbar {
    padding: 0 12px;
    height: 54px;
  }

  .topbar-brand-text { display: none; }

  .topbar-search {
    max-width: none;
    margin-left: 8px;
  }

  .filter-bar {
    padding: 10px 12px;
    top: 54px;
  }

  .filter-select, .filter-search {
    min-width: 0;
    flex: 1;
    font-size: 12px;
  }

  .status-chips {
    margin-left: 0;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .status-chip {
    flex-shrink: 0;
  }

  .main-content {
    padding: 12px;
  }

  .stats-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
  }

  .stat-card {
    padding: 10px 8px;
  }

  .stat-value {
    font-size: 20px;
  }

  .stat-label {
    font-size: 9.5px;
  }

  .order-card-header {
    padding: 12px 14px;
    flex-wrap: wrap;
  }

  .order-meta {
    order: 3;
    width: 100%;
    margin-top: 2px;
  }

  .order-detail-inner {
    padding: 12px 14px;
  }

  .line-table-wrap {
    margin: 0 -14px;
    padding: 0 14px;
  }

  .line-table {
    font-size: 12px;
  }

  .line-table th, .line-table td {
    padding: 6px 6px;
  }

  .modal-panel {
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 90vh;
  }
}

@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .order-pi {
    font-size: 13px;
    min-width: 60px;
  }

  .order-customer {
    font-size: 13px;
  }
}

/* ---- UTILITY ------------------------------------------------------------- */

.mono { font-family: var(--font-mono); letter-spacing: 0.01em; }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mb-12 { margin-bottom: 12px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* Pulse animation for status changes */
@keyframes status-flash {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.status-flash {
  animation: status-flash 0.3s ease;
}

/* ---- CUSTOM SEARCHABLE SELECT ---- */
.searchable-select {
  position: relative;
  display: inline-block;
  min-width: 180px;
}

.searchable-select-trigger {
  padding: 7px 32px 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  min-width: 140px;
  transition: border-color var(--transition);
}

.searchable-select-trigger:hover {
  border-color: var(--navy-soft);
}

.searchable-select-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  color: var(--muted);
  pointer-events: none;
  transition: transform var(--transition);
}

.searchable-select.active .searchable-select-arrow {
  transform: translateY(-50%) rotate(180deg);
}

.searchable-select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 250px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
  z-index: 110;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.searchable-select.active .searchable-select-dropdown {
  display: flex;
}

.searchable-select-search-wrap {
  padding: 8px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface-hover);
}

.searchable-select-search-wrap input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--transition);
}

.searchable-select-search-wrap input:focus {
  border-color: var(--navy-soft);
}

.searchable-select-options {
  max-height: 220px;
  overflow-y: auto;
}

.searchable-select-option {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.searchable-select-option:hover {
  background: var(--surface-hover);
}

.searchable-select-option.selected {
  background: var(--navy);
  color: #ffffff;
  font-weight: 600;
}

/* ---- ORDER SELECTION CHECKBOX ---- */
.order-select-wrap {
  display: flex;
  align-items: center;
  margin-right: 12px;
}

.order-select-cb {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--navy);
}

/* ---- FLOATING BULK BAR ---- */
.floating-bulk-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  z-index: 95;
  background: var(--navy);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50px;
  box-shadow: 0 10px 30px rgba(16,23,58,0.3);
  padding: 10px 24px;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.floating-bulk-bar.active {
  transform: translateX(-50%) translateY(0);
}

.floating-bulk-content {
  display: flex;
  align-items: center;
  gap: 16px;
  color: #ffffff;
  font-weight: 500;
  font-size: 13px;
}

.floating-bulk-content .bulk-count {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.15);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

.bulk-btn-group {
  display: flex;
  gap: 8px;
}

/* ---- BULK REPORT VIEW ---- */
.bulk-report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1.5px solid var(--border);
}

.bulk-report-title-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border: none;
  background: transparent;
  padding: 6px 0;
  transition: color var(--transition);
}

.btn-back:hover {
  color: var(--navy);
}

.bulk-report-filters {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-card);
}

.bulk-report-search {
  flex: 1;
  min-width: 200px;
}

.bulk-report-party {
  min-width: 180px;
}

.bulk-report-status-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---- HEADER FILTER STYLING ---- */
.th-filter-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.th-filter-btn {
  background: transparent;
  border: none;
  padding: 2px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  margin-left: 2px;
}

.th-filter-btn:hover {
  color: var(--navy);
  background: rgba(27, 37, 89, 0.08);
}

.th-filter-btn.active {
  color: #276749; /* Dispatched/success Green */
  background: rgba(39, 103, 73, 0.12); /* Subtle green highlight background */
}

.header-filter-popover {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  width: 220px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  padding: 10px;
  font-family: var(--font-body);
}

.header-filter-search {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 8px;
  outline: none;
}

.header-filter-search:focus {
  border-color: var(--navy);
}

.header-filter-actions {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 6px;
}

.header-filter-options {
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 4px;
  background: var(--surface-hover);
}

.header-filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 12.5px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  color: var(--ink);
}

.header-filter-option:hover {
  background: var(--border-light);
}

.header-filter-option input[type="checkbox"] {
  accent-color: var(--navy);
  flex-shrink: 0;
}

