/* ============================================
   Pathao Entry Magic — Loftique
   ============================================ */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --border: #e5e7eb;
  --border-light: #f0f1f3;
  --text: #111827;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --accent: #e95420;
  --accent-hover: #d14810;
  --accent-bg: #fff4ef;
  --green: #059669;
  --green-bg: #ecfdf5;
  --green-light: #d1fae5;
  --yellow: #d97706;
  --yellow-bg: #fffbeb;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.03);
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-alt: #21242f;
    --border: #2d3140;
    --border-light: #252836;
    --text: #f0f1f4;
    --text-2: #9ca3b4;
    --text-3: #6b7280;
    --accent: #f97316;
    --accent-hover: #fb923c;
    --accent-bg: #431407;
    --green: #34d399;
    --green-bg: #064e3b;
    --green-light: #065f46;
    --yellow: #fbbf24;
    --yellow-bg: #451a03;
    --red: #f87171;
    --red-bg: #450a0a;
    --blue: #60a5fa;
    --blue-bg: #1e3a5f;
    --purple: #a78bfa;
    --purple-bg: #2e1065;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-alt: #21242f;
  --border: #2d3140;
  --border-light: #252836;
  --text: #f0f1f4;
  --text-2: #9ca3b4;
  --text-3: #6b7280;
  --accent: #f97316;
  --accent-hover: #fb923c;
  --accent-bg: #431407;
  --green: #34d399;
  --green-bg: #064e3b;
  --green-light: #065f46;
  --yellow: #fbbf24;
  --yellow-bg: #451a03;
  --red: #f87171;
  --red-bg: #450a0a;
  --blue: #60a5fa;
  --blue-bg: #1e3a5f;
  --purple: #a78bfa;
  --purple-bg: #2e1065;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Top Bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  color: white;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px;
}
.logo-text { font-weight: 700; font-size: 15px; letter-spacing: -0.3px; }
.sandbox-badge {
  font-size: 10px; font-weight: 700;
  background: var(--yellow-bg); color: var(--yellow);
  padding: 2px 8px; border-radius: 4px;
  letter-spacing: 0.5px;
}

.theme-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-2); padding: 4px;
  display: flex; align-items: center;
}
.theme-toggle:hover { color: var(--text); }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon,
:root:not([data-theme="dark"]) .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

.topbar-stats { display: flex; gap: 16px; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-value { font-size: 16px; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stat-label { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }

/* ---- Tab Navigation ---- */
.tab-nav {
  display: flex;
  gap: 2px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 16px;
  border: none; background: none;
  cursor: pointer;
  font-size: 13px; font-weight: 500;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); background: var(--surface-alt); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab svg { opacity: 0.6; }
.tab.active svg { opacity: 1; stroke: var(--accent); }
.tab-count {
  font-size: 11px; font-weight: 600;
  background: var(--surface-alt);
  padding: 1px 6px; border-radius: 10px;
  color: var(--text-3);
}
.tab.active .tab-count {
  background: var(--accent-bg);
  color: var(--accent);
}

/* ---- Content ---- */
.content { padding: 16px 20px; max-width: 1400px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; }
.search-box {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
}
.search-box svg { color: var(--text-3); flex-shrink: 0; }
.search-box input {
  border: none; background: none; outline: none;
  font-size: 13px; color: var(--text); width: 180px;
  font-family: var(--font);
}
.search-box input::placeholder { color: var(--text-3); }
.panel-title { font-size: 15px; font-weight: 600; }
.panel-subtitle { font-size: 12px; color: var(--text-2); }

/* ---- Filter Chips ---- */
.filter-chips { display: flex; gap: 4px; }
.chip {
  font-size: 12px; font-weight: 500;
  padding: 4px 10px; border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer; transition: all 0.15s;
  font-family: var(--font);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ---- Buttons ---- */
.btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all 0.15s;
  font-family: var(--font);
}
.btn-primary {
  background: var(--accent); color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-alt); color: var(--text); }
.btn-count {
  font-size: 11px;
  background: rgba(255,255,255,0.2);
  padding: 1px 6px; border-radius: 8px;
}

/* ---- Data Table ---- */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead {
  background: var(--surface-alt);
  position: sticky; top: 0;
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px; font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-alt); }
.col-check { width: 36px; text-align: center; }
.col-check input { cursor: pointer; accent-color: var(--accent); }

/* Order column */
.col-order { white-space: nowrap; }
.order-name { font-weight: 700; font-family: var(--mono); font-size: 13px; display: block; }
.order-date { font-size: 11px; color: var(--text-3); }

/* Customer column */
.customer-name { font-weight: 600; display: block; }
.item-count { font-size: 11px; color: var(--text-3); }
.gift-order { color: var(--purple); font-weight: 500; }

/* Phone column */
.col-phone { white-space: nowrap; }
.phone-raw { display: none; }
.phone-clean {
  font-family: var(--mono); font-size: 12px;
  background: var(--surface-alt);
  padding: 2px 6px; border-radius: 4px;
}

/* Address column */
.col-address { max-width: 220px; }
.address-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
}

/* Amount */
.amount { font-weight: 600; font-variant-numeric: tabular-nums; }

/* COD badges */
.cod-badge {
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 4px;
  white-space: nowrap;
}
.cod-full { background: var(--accent-bg); color: var(--accent); }
.cod-partial { background: var(--yellow-bg); color: var(--yellow); }
.cod-zero { background: var(--green-bg); color: var(--green); }
.cod-pending { background: var(--red-bg); color: var(--red); }

/* Tags */
.col-tags { max-width: 160px; }
.tag {
  font-size: 10px; font-weight: 600;
  padding: 2px 6px; border-radius: 3px;
  display: inline-block; margin: 1px 2px;
  letter-spacing: 0.3px;
}
.tag-callback { background: var(--blue-bg); color: var(--blue); }
.tag-confirmed { background: var(--green-bg); color: var(--green); }
.tag-paid { background: var(--green-bg); color: var(--green); }
.tag-partial { background: var(--yellow-bg); color: var(--yellow); }
.tag-warning { background: var(--red-bg); color: var(--red); }
.tag-pathao { background: var(--accent-bg); color: var(--accent); }

/* Status dots */
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}
.status-ready { background: var(--green); }
.status-hold { background: var(--yellow); }
.status-sent { background: var(--blue); }

/* ---- PRINT TAB ---- */
.label-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.label-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s;
}
.label-card:hover { box-shadow: var(--shadow-md); }
.label-header {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}
.label-logo {
  width: 36px; height: 36px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 16px;
}
.label-store strong { display: block; font-size: 14px; }
.label-store span { font-size: 11px; color: var(--text-3); }
.label-barcode {
  padding: 12px 0;
  text-align: center;
}
.barcode-placeholder {
  font-family: var(--mono);
  font-size: 13px; font-weight: 600;
  background: var(--surface-alt);
  border: 2px dashed var(--border);
  padding: 14px 8px;
  border-radius: 6px;
  color: var(--text-2);
  letter-spacing: 1px;
}
.label-customer {
  padding-top: 10px;
  border-top: 3px solid var(--text);
}
.label-name {
  font-size: 18px; font-weight: 800;
  margin-bottom: 6px;
}
.label-details {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-2);
  margin-bottom: 6px;
}
.label-cod {
  font-weight: 700; color: white;
  background: var(--text);
  padding: 2px 8px; border-radius: 4px;
  font-size: 12px;
}
.label-cod.partial { background: var(--yellow); }
.label-cod.zero { background: var(--green); }
.label-order { font-size: 13px; font-weight: 600; color: var(--text-2); }

/* ---- SCAN TAB ---- */
.scan-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 800px) {
  .scan-layout { grid-template-columns: 1fr; }
}
.scan-input-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  position: sticky; top: 70px;
}
.scan-header h3 { font-size: 15px; margin-bottom: 2px; }
.scan-header p { font-size: 12px; color: var(--text-3); margin-bottom: 16px; }
.scan-field-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-alt);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 20px;
}
.scan-field-wrap svg { color: var(--accent); flex-shrink: 0; }
.scan-field {
  border: none; background: none; outline: none;
  font-size: 16px; font-weight: 600;
  font-family: var(--mono);
  color: var(--text);
  width: 100%;
}
.scan-field::placeholder { color: var(--text-3); font-weight: 400; }
.scan-counter {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; margin-bottom: 12px;
}
.counter-box { text-align: center; }
.counter-value {
  font-size: 36px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: block; line-height: 1;
}
.counter-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }
.counter-divider { font-size: 28px; color: var(--text-3); font-weight: 300; }
.scan-progress { margin-bottom: 12px; }
.progress-bar {
  height: 6px;
  background: var(--surface-alt);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.scan-result {
  display: flex; align-items: center; gap: 8px;
  padding: 10px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
}
.scan-result.success { background: var(--green-bg); color: var(--green); }
.scan-result.error { background: var(--red-bg); color: var(--red); }
.scan-result.warning { background: var(--yellow-bg); color: var(--yellow); }

/* Pack List */
.pack-list-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.pack-list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.pack-list-header h3 { font-size: 14px; }
.pack-filters { display: flex; gap: 4px; }
.pack-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}
.pack-item:last-child { border-bottom: none; }
.pack-item:hover { background: var(--surface-alt); }
.pack-item.packed { background: var(--green-bg); }
.pack-item.packed .pack-status-icon svg { stroke: var(--green); }
.pack-status-icon { flex-shrink: 0; color: var(--text-3); }
.pack-info { flex: 1; min-width: 0; }
.pack-consignment {
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  display: block;
}
.pack-name { font-size: 12px; color: var(--text-2); }
.pack-cod {
  font-weight: 700; font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pack-badge {
  font-size: 10px; font-weight: 700;
  padding: 3px 8px; border-radius: 4px;
  letter-spacing: 0.3px;
}
.badge-unpacked { background: var(--surface-alt); color: var(--text-3); }
.badge-packed { background: var(--green); color: white; }
.badge-fulfilled { background: var(--blue); color: white; }

/* Fulfill button */
.btn-success {
  background: var(--green); color: white;
}
.btn-success:hover { background: #047857; }
.btn-success:disabled { opacity: 0.4; cursor: not-allowed; }

/* Pack list header layout */
.pack-list-header {
  flex-wrap: wrap;
  gap: 8px;
}
.pack-list-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.pack-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.select-all-pack {
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.select-all-pack input { accent-color: var(--accent); cursor: pointer; }

/* Pack item checkbox */
.pack-check {
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* Fulfilled state */
.pack-item.fulfilled { background: var(--blue-bg); }
.pack-item.fulfilled .pack-status-icon svg { stroke: var(--blue); }

/* ---- STATUS TAB ---- */
.status-grid { display: flex; flex-direction: column; gap: 16px; }
.status-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.status-card-value {
  font-size: 28px; font-weight: 800;
  display: block; line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.status-card-label { font-size: 12px; color: var(--text-2); }
.status-card-trend {
  font-size: 11px; font-weight: 600; margin-top: 4px;
}
.status-card-trend.up { color: var(--green); }
.status-card-trend.neutral { color: var(--text-3); }
.card-warning .status-card-value { color: var(--yellow); }
.card-danger .status-card-value { color: var(--red); }

/* Date Filters */
.status-filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}
.date-filter-group {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.date-filter { display: flex; flex-direction: column; gap: 4px; }
.date-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.date-input {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
}
.date-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Errors Section */
.errors-section {
  background: var(--red-bg);
  border: 1px solid var(--red);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.errors-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--red);
}
.errors-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--red);
  display: flex;
  align-items: center;
  gap: 6px;
}
.errors-title svg { stroke: var(--red); }
.error-count-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--red);
  color: white;
  padding: 1px 7px;
  border-radius: 10px;
}
.errors-list { padding: 4px 0; }
.error-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid rgba(220,38,38,0.15);
}
.error-item:last-child { border-bottom: none; }
.error-icon { color: var(--red); flex-shrink: 0; }
.error-icon svg { stroke: var(--red); }
.error-info { flex: 1; min-width: 0; }
.error-order {
  font-weight: 700;
  font-family: var(--mono);
  font-size: 12px;
  margin-right: 6px;
}
.error-msg { font-size: 12px; color: var(--text); }
.error-time { font-size: 11px; color: var(--text-3); display: block; margin-top: 2px; }
.btn-sm { padding: 4px 10px; font-size: 11px; }

.delivery-status {
  font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 4px;
}
.status-transit { background: var(--blue-bg); color: var(--blue); }
.status-delivered { background: var(--green-bg); color: var(--green); }
.status-returned { background: var(--red-bg); color: var(--red); }

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 3px;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .topbar { padding: 0 12px; }
  .tab-nav { padding: 0 8px; overflow-x: auto; }
  .tab { padding: 8px 10px; font-size: 12px; white-space: nowrap; }
  .content { padding: 12px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left, .toolbar-right { flex-wrap: wrap; }
  .label-grid { grid-template-columns: 1fr; }
}
