/* MSN desk theme — layout, colour, density. Last stylesheet. No API changes.
   Atelier: ink navy + champagne gold (same as Suite / Claims / Follow-up). */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,650&family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --desk-ink: #0c1220;
  --desk-ink-2: #161e30;
  --desk-teal: #c9a227;
  --desk-teal-2: #a9841b;
  --desk-paper: #f3efe6;
  --desk-card: #fcfbf8;
  --desk-line: #e4dccb;
  --desk-muted: #8a8174;
  --desk-text: #141820;
  --desk-danger: #b42318;
  --desk-ok: #2f7d57;
  --desk-warn: #a9841b;
  --desk-action: #c9a227;
}

html:has(body.msn-desk) {
  height: auto;
}
body.msn-desk {
  font-family: Inter, "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  background: var(--desk-paper) !important;
  color: var(--desk-text);
  min-height: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

body.msn-desk button:hover,
body.msn-desk .stat-card:hover,
body.msn-desk .brand-tile:hover {
  transform: none;
}

body.msn-desk .navbar {
  position: sticky;
  top: 0;
  z-index: 900;
  flex: 0 0 auto;
  background: var(--desk-ink) !important;
  border-bottom: 3px solid var(--desk-teal);
  box-shadow: none;
  padding: 8px 16px;
  gap: 12px;
  flex-wrap: nowrap;
}
body.msn-desk .navbar h1 {
  font-size: 1.12rem;
  font-weight: 750;
  letter-spacing: .01em;
}
body.msn-desk .navbar-right {
  gap: 12px;
}
body.msn-desk .navbar-right a {
  color: #f4e9c4 !important;
  font-size: 13px;
  font-weight: 650;
  padding: 6px 8px;
  border-radius: 6px;
}
body.msn-desk .navbar-right a:hover {
  background: rgba(255,255,255,.08);
  color: #fff !important;
}
body.msn-desk .navbar-right button {
  background: var(--desk-teal) !important;
  transform: none;
}
body.msn-desk .navbar-right button:hover {
  background: var(--desk-teal-2) !important;
}

body.msn-desk .container {
  display: block;
  min-height: 0;
  max-width: none !important;
  width: 100%;
  margin: 0 !important;
  padding: 8px 16px 28px;
}

body.msn-desk .dashboard-grid {
  flex: 0 0 auto;
  gap: 8px;
  margin-bottom: 8px;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
}
body.msn-desk #advancedKpis {
  display: contents !important;
}
body.msn-desk .stat-card,
body.msn-desk .stat-card:nth-child(n) {
  background: var(--desk-card) !important;
  border: 1px solid var(--desk-line) !important;
  border-top: 3px solid var(--desk-teal) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
  padding: 8px 10px;
  min-width: 0;
}
body.msn-desk .stat-card.success { border-top-color: var(--desk-ok) !important; }
body.msn-desk .stat-card.warning { border-top-color: var(--desk-warn) !important; }
body.msn-desk .stat-card h3 {
  color: var(--desk-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
body.msn-desk .stat-value,
body.msn-desk #advancedKpis .stat-value {
  font-size: 1.18rem;
  font-variant-numeric: tabular-nums;
  color: var(--desk-ink);
}
body.msn-desk .stat-card.success .stat-value { color: var(--desk-ok); }
body.msn-desk .stat-card.warning .stat-value { color: var(--desk-warn); }

body.msn-desk .controls {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--desk-card);
  border: 1px solid var(--desk-line);
  border-radius: 10px;
  box-shadow: none !important;
}
body.msn-desk .advanced-alert-tools {
  display: contents;
}
body.msn-desk .advanced-alert-tools button {
  background: var(--desk-ink-2) !important;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 12px;
}
body.msn-desk .controls input,
body.msn-desk .controls select,
body.msn-desk .controls button {
  width: auto;
  min-height: 36px;
  flex: 0 1 auto;
}
body.msn-desk .controls input[type="text"],
body.msn-desk .controls input#searchOrder {
  flex: 1 1 220px;
  min-width: 180px;
}
body.msn-desk .controls button {
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 8px;
  background: var(--desk-teal);
  min-height: 36px;
}
body.msn-desk .controls button:hover {
  background: var(--desk-ink);
  transform: none;
}
body.msn-desk .sheet-toggle {
  background: var(--desk-ink-2) !important;
}

body.msn-desk .tabs {
  flex: 0 0 auto;
  gap: 4px;
  padding: 4px;
  margin-bottom: 8px;
  background: var(--desk-card);
  border: 1px solid var(--desk-line);
  border-radius: 10px;
  box-shadow: none;
}
body.msn-desk .tab-btn {
  background: transparent;
  color: var(--desk-muted);
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
}
body.msn-desk .tab-btn.active {
  background: var(--desk-ink);
  color: #fff;
  border-color: transparent;
}

/* Unique status colours — approved ≠ delivered, shipped ≠ pending */
body.msn-desk .status-badge { border-radius: 999px; font-size: 11px; padding: 4px 9px; letter-spacing: .02em; }
body.msn-desk .status-new { background: #dbeafe; color: #1e40af; }
body.msn-desk .status-approved { background: #ccfbf1; color: #0f766e; }
body.msn-desk .status-pending { background: #ffedd5; color: #c2410c; }
body.msn-desk .status-confirmed { background: #e0e7ff; color: #3730a3; }
body.msn-desk .status-pick_pack { background: #ede9fe; color: #6d28d9; }
body.msn-desk .status-shipped { background: #fef3c7; color: #92400e; }
body.msn-desk .status-delivered { background: #dcfce7; color: #166534; }
body.msn-desk .status-canceled,
body.msn-desk .status-cancelled,
body.msn-desk .status-rejected { background: #fee2e2; color: #991b1b; }

body.msn-desk .status-strip {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin: 0 0 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
body.msn-desk .status-chip {
  background: var(--desk-card);
  color: var(--desk-ink);
  border: 1px solid var(--desk-line);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
body.msn-desk .status-chip .status-count {
  background: #eef4f5;
  color: var(--desk-muted);
  border-radius: 999px;
  min-width: 1.4em;
  padding: 0 6px;
  font-variant-numeric: tabular-nums;
}
body.msn-desk .status-chip.active {
  background: var(--desk-ink);
  color: #fff;
  border-color: var(--desk-ink);
}
body.msn-desk .status-chip.active .status-count { background: #243049; color: #fff; }
body.msn-desk .status-chip[data-status="new"] { box-shadow: inset 0 -3px 0 #2563eb; }
body.msn-desk .status-chip[data-status="approved"] { box-shadow: inset 0 -3px 0 #0f766e; }
body.msn-desk .status-chip[data-status="pending"] { box-shadow: inset 0 -3px 0 #c2410c; }
body.msn-desk .status-chip[data-status="pick_pack"] { box-shadow: inset 0 -3px 0 #7c3aed; }
body.msn-desk .status-chip[data-status="shipped"] { box-shadow: inset 0 -3px 0 #d97706; }
body.msn-desk .status-chip[data-status="delivered"] { box-shadow: inset 0 -3px 0 #16a34a; }
body.msn-desk .status-chip[data-status="cancelled"],
body.msn-desk .status-chip[data-status="canceled"],
body.msn-desk .status-chip[data-status="rejected"] { box-shadow: inset 0 -3px 0 #dc2626; }

body.msn-desk .orders-table {
  background: var(--desk-card);
  border: 1px solid var(--desk-line);
  border-radius: 10px;
  box-shadow: none !important;
}
body.msn-desk #ordersTab.orders-table,
body.msn-desk #salesTab,
body.msn-desk #stockTab,
body.msn-desk #fillrateTab,
body.msn-desk #whatsappTab {
  flex: none;
  height: auto;
  max-height: none;
  overflow-x: auto;
  overflow-y: visible;
}
body.msn-desk .ops-panel {
  flex: 0 0 auto;
  background: var(--desk-card) !important;
  border: 1px solid var(--desk-line) !important;
  border-radius: 10px !important;
  padding: 8px 12px !important;
  margin: 0 0 8px !important;
  box-shadow: none !important;
}
body.msn-desk .ops-refnote { display: none !important; }
body.msn-desk .ops-panel summary.ops-title {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
body.msn-desk .ops-panel summary.ops-title::-webkit-details-marker { display: none; }
body.msn-desk .ops-panel summary.ops-title h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 750;
}
body.msn-desk .ops-panel summary.ops-title small { color: var(--desk-muted); font-weight: 600; }
body.msn-desk .ops-kpis {
  margin-top: 8px;
  gap: 6px;
}
body.msn-desk .ops-kpi {
  background: #f7f3eb !important;
  padding: 6px 8px !important;
}
body.msn-desk .ops-kpi b { font-size: 13px !important; color: var(--desk-ink) !important; }
body.msn-desk .desk-foot {
  flex: 0 0 auto;
  max-width: none !important;
  width: 100%;
  margin: 0 !important;
  padding: 4px 16px 8px !important;
  color: var(--desk-muted) !important;
  font-size: 12px;
}
body.msn-desk .advanced-history {
  position: fixed;
  top: 0;
  right: 0;
  width: min(380px, 100%);
  height: 100%;
  background: var(--desk-card);
  border-left: 1px solid var(--desk-line);
  z-index: 1200;
  transform: translateX(100%);
  transition: transform .2s ease;
  padding: 16px;
  overflow: auto;
  box-shadow: -12px 0 32px rgba(12,18,32,.18);
}
body.msn-desk .advanced-history.open { transform: translateX(0); }
body.msn-desk #ordersTable thead th {
  position: static;
  top: auto;
  z-index: 1;
  background: #f4e9c4 !important;
  color: var(--desk-ink) !important;
  border-bottom: 1px solid var(--desk-line) !important;
  font-size: 11px !important;
  text-transform: uppercase;
  letter-spacing: .03em;
}
body.msn-desk #ordersTable tbody tr:nth-child(even) { background: #f7f3eb; }
body.msn-desk #ordersTable tbody tr:hover { background: #f4e9c4; }
body.msn-desk .btn-view { background: var(--desk-teal); }
body.msn-desk .btn-update { background: var(--desk-ok); }
body.msn-desk .btn-cancel { background: var(--desk-danger); }
body.msn-desk .btn-small { border-radius: 6px; }

body.msn-desk .modal { background: rgba(15,39,64,.55); }
body.msn-desk .modal-content {
  border-radius: 12px;
  border: 1px solid var(--desk-line);
  box-shadow: 0 16px 40px rgba(15,39,64,.2);
}
body.msn-desk #statusUpdateBtn,
body.msn-desk button[onclick*="shareOrderStatus"] {
  transform: none;
}
body.msn-desk button[onclick*="shareOrderStatus('retailer')"],
body.msn-desk button[onclick*='shareOrderStatus("retailer")'] {
  background: #128c7e !important;
}
body.msn-desk #msnWaChip {
  border: 1px solid #a7f3d0 !important;
}

body.msn-desk .desk-fill-form {
  display: grid !important;
  grid-template-columns: 1fr 1fr minmax(180px, 1fr) auto !important;
  gap: 10px !important;
}

body.msn-desk .msn-sticky-bar .msn-fab-new { background: var(--desk-teal); }
body.msn-desk .msn-sticky-bar .msn-fab-create { background: var(--desk-action); color: #fff; }

body.msn-desk .wa-ops { color: var(--desk-text); max-width: 1100px; }
body.msn-desk .wa-ops-head h3 { margin: 0 0 6px; font-size: 1.05rem; }
body.msn-desk .wa-ops-head p { margin: 0 0 14px; color: var(--desk-muted); font-size: 13px; line-height: 1.45; max-width: 70ch; }
body.msn-desk .wa-ops-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
body.msn-desk .wa-ops-grid label,
body.msn-desk .wa-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--desk-muted);
}
body.msn-desk .wa-span { grid-column: 1 / -1; }
body.msn-desk .wa-ops input,
body.msn-desk .wa-ops select,
body.msn-desk .wa-ops textarea {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--desk-line);
  border-radius: 8px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--desk-text);
  background: #fff;
}
body.msn-desk .wa-ops textarea { min-height: 120px; font-family: inherit; font-size: 13px; line-height: 1.45; }
body.msn-desk .wa-missing { min-height: 1.2em; color: var(--desk-danger); font-size: 12px; font-weight: 650; margin: 6px 0 10px; }
body.msn-desk .wa-recips { border: 1px solid var(--desk-line); border-radius: 10px; padding: 10px 12px; margin: 12px 0; background: #f7f3eb; }
body.msn-desk .wa-recips-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
body.msn-desk .wa-shop-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 6px; max-height: 220px; overflow: auto; }
body.msn-desk .wa-shop { display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 600; text-transform: none; color: var(--desk-text); background: var(--desk-card); border: 1px solid var(--desk-line); border-radius: 8px; padding: 6px 8px; }
body.msn-desk .wa-shop span { color: var(--desk-muted); font-weight: 500; margin-left: auto; }
body.msn-desk .wa-empty { margin: 0; font-size: 13px; color: var(--desk-muted); text-transform: none; font-weight: 500; }
body.msn-desk .wa-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
body.msn-desk .wa-actions button { min-height: 40px; }
body.msn-desk .wa-secondary { background: var(--desk-ink-2) !important; }
body.msn-desk .wa-status { margin: 10px 0 0; font-size: 13px; font-weight: 650; color: var(--desk-ok); }
body.msn-desk .wa-status.bad { color: var(--desk-danger); }
body.msn-desk .wa-log { margin: 6px 0 0; padding-left: 18px; color: var(--desk-muted); font-size: 12px; }
body.msn-desk .wa-ops h4 { margin: 16px 0 4px; font-size: 13px; }

@media (max-width: 1100px) {
  body.msn-desk .wa-ops-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  body.msn-desk .wa-ops-grid { grid-template-columns: 1fr; }
  body.msn-desk .wa-shop-list { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  body.msn-desk .navbar { flex-wrap: wrap; }
  body.msn-desk .dashboard-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  body.msn-desk .desk-fill-form { grid-template-columns: 1fr 1fr !important; }
}
@media (max-width: 900px) {
  html:has(body.msn-desk),
  body.msn-desk {
    height: auto;
    overflow: visible;
    min-height: 100%;
  }
  body.msn-desk .container {
    display: block;
    flex: none;
    min-height: 0;
    padding: 10px 12px 72px;
  }
  body.msn-desk #ordersTab.orders-table,
  body.msn-desk #salesTab,
  body.msn-desk #stockTab,
  body.msn-desk #fillrateTab,
  body.msn-desk #whatsappTab {
    flex: none;
    max-height: none;
    overflow: visible;
  }
  body.msn-desk .dashboard-grid { grid-template-columns: 1fr 1fr; }
  body.msn-desk .controls { display: grid; grid-template-columns: 1fr 1fr; }
  body.msn-desk .advanced-alert-tools { display: contents; }
  body.msn-desk .controls button[onclick*="create-order"],
  body.msn-desk .controls button[onclick*="create-order.html"] { grid-column: 1 / -1; }
  body.msn-desk .desk-fill-form { grid-template-columns: 1fr !important; }
  body.msn-desk #ordersTable thead th { position: static; }
  body.msn-desk .desk-foot { padding-bottom: 16px !important; }
}

/* Create-order page shares the same ink/teal */
body.create-desk {
  background: var(--desk-paper, #f3efe6);
  color: var(--desk-text, #141820);
}
body.create-desk header {
  background: #0c1220 !important;
  border-bottom: 3px solid #c9a227;
}
body.create-desk .btn { background: #c9a227; color: #1a1408; }
body.create-desk .btn.orange { background: #a9841b; color: #fff; }
body.create-desk .brand-tile:hover,
body.create-desk .brand-tile.active {
  transform: none;
  border-color: #c9a227;
}
body.create-desk .card { box-shadow: none; border-color: #e4dccb; }
