/* ==========================================================================
   Makro CDC Chilled Logistics Dashboard - CSS Stylesheet
   Theme: Industrial Cold Logistics (Dark Slate, Makro Red, Amber, Sky Cyan)
   Font: Sarabun & Inter
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --bg-main: #0b1120;
  --bg-card: #151f32;
  --bg-card-hover: #1c2a44;
  --bg-elevated: #1e293b;
  --border-color: #27354f;
  --border-focus: #3b82f6;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-red: #e11d48;
  --accent-red-hover: #be123c;
  --accent-amber: #f59e0b;
  --accent-blue: #0284c7;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-purple: #8b5cf6;

  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Sarabun', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #0f172a;
}
::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* Header Styles */
.header-glass {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Cards */
.card-industrial {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.card-industrial:hover {
  border-color: #3b5074;
}

/* KPI Card */
.kpi-card {
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  transition: background 0.3s ease;
}
.kpi-card.red-border::before { background: var(--accent-red); }
.kpi-card.blue-border::before { background: var(--accent-blue); }
.kpi-card.emerald-border::before { background: var(--accent-emerald); }
.kpi-card.amber-border::before { background: var(--accent-amber); }
.kpi-card.cyan-border::before { background: var(--accent-cyan); }
.kpi-card.purple-border::before { background: var(--accent-purple); }

/* Tabs */
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}
.tab-btn.active {
  color: #ffffff;
  background: #1e293b;
  border-color: #3b82f6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Tables */
.table-container {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}
table.data-table th {
  background: #111a2d;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}
table.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(39, 53, 79, 0.5);
  color: var(--text-main);
  white-space: nowrap;
}
table.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-chilled { background: rgba(2, 132, 199, 0.18); color: #38bdf8; border: 1px solid rgba(2, 132, 199, 0.3); }
.badge-fresh, .badge-food { background: rgba(16, 185, 129, 0.18); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-frozen, .badge-ft { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-class-a { background: rgba(225, 29, 72, 0.18); color: #fb7185; border: 1px solid rgba(225, 29, 72, 0.3); }
.badge-class-b { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-class-c { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.3); }
.badge-shipped { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge-released { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.badge-packed { background: rgba(2, 132, 199, 0.2); color: #38bdf8; }
.badge-cancelled { background: rgba(239, 68, 68, 0.2); color: #f87171; }

/* Filter Controls */
.filter-select, .filter-input {
  background: #0e1726;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s ease;
}
.filter-select:focus, .filter-input:focus {
  border-color: var(--border-focus);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 90%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  transform: translateY(20px);
  transition: transform 0.2s ease;
}
.modal-backdrop.open .modal-box {
  transform: translateY(0);
}

/* ==========================================================================
   New Integrated Features: Capture Buttons, Segment Switchers, BoH & Gaps
   ========================================================================== */

/* Per-Chart Camera Capture Button */
.btn-capture-chart {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-capture-chart:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: #3b82f6;
  color: #60a5fa;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.25);
}

/* Segmented Buttons Control */
.seg-control {
  display: inline-flex;
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}
.seg-control button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.seg-control button.active {
  background: #2563eb;
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* BoH Status Badges */
.b-ok {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}
.b-ext {
  background: rgba(2, 132, 199, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(2, 132, 199, 0.35);
}
.b-part {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}
.b-hold {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.35);
}
.b-none {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

/* Stock Cards */
.stockcards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.scard {
  background: #111a2d;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}
.scard:hover {
  transform: translateY(-2px);
  border-color: #475569;
}
.scard.active {
  border-color: #38bdf8 !important;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.3);
}
.scard .lab {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.scard .val {
  font-size: 20px;
  font-weight: 700;
  margin-top: 4px;
  color: #ffffff;
}
.scard .val .u {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}
.scard.ok { border-left: 3px solid #10b981; }
.scard.ext { border-left: 3px solid #0284c7; }
.scard.warn { border-left: 3px solid #f59e0b; }
.scard.hold { border-left: 3px solid #8b5cf6; }
.scard.bad { border-left: 3px solid #ef4444; }
.scard.neu { border-left: 3px solid #64748b; }

/* Stock Bar Comparison Widget */
.stkrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.stkrank {
  width: 22px;
  text-align: right;
  color: var(--text-dim);
  font-size: 12px;
  flex: none;
}
.stklabel {
  width: 230px;
  flex: none;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stkbarwrap {
  flex: 1;
  position: relative;
  height: 26px;
  background: #0f172a;
  border-radius: 6px;
  overflow: hidden;
  min-width: 120px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.stkgap {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: linear-gradient(90deg, #f87171, #dc2626);
  border-radius: 6px;
}
.stkcov {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: linear-gradient(90deg, #34d399, #059669);
  border-radius: 6px;
  display: flex;
  overflow: hidden;
}
.stkseg {
  height: 100%;
  min-width: 0;
}
.stkval {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  color: #f8fafc;
}
.stkbadge {
  width: 110px;
  flex: none;
  text-align: right;
}

/* Collapsible Detail Section */
.toggle-detail {
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  margin-top: 10px;
}
.toggle-detail:hover {
  background: #27354f;
  color: #ffffff;
}
.toggle-detail .arrow {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 10px;
}
.toggle-detail.open .arrow {
  transform: rotate(180deg);
}
.detail-wrap {
  display: none;
  margin-top: 14px;
}
.detail-wrap.show {
  display: block;
}

/* Top 10 Bars */
.t10row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.t10rank {
  width: 20px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}
.t10label {
  width: 200px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.t10barwrap {
  flex: 1;
  background: #0f172a;
  border-radius: 6px;
  height: 24px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.t10bar {
  height: 100%;
  border-radius: 6px;
  transition: width 0.3s ease;
}
.t10val {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
}

/* Pill Status */
.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}
.pill.hi { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.pill.mid { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.pill.lo { background: rgba(239, 68, 68, 0.2); color: #f87171; }

/* Buyer Badges & Popover */
.badge-buyer {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 11px;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
}
.badge-buyer:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: #f59e0b;
  transform: translateY(-1px);
}

.buyer-card {
  background: #111a2e;
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 14px;
  transition: all 0.2s ease;
}
.buyer-card:hover {
  border-color: rgba(245, 158, 11, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

/* Wave Status Dropdown & Badges */
.wave-status-select {
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.wave-status-select:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.wave-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}
.wave-status-released { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; border: 1px solid #475569; }
.wave-status-allocated { background: rgba(2, 132, 199, 0.2); color: #38bdf8; border: 1px solid #0284c7; }
.wave-status-partial { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid #d97706; }
.wave-status-packing { background: rgba(168, 85, 247, 0.2); color: #c084fc; border: 1px solid #9333ea; }
.wave-status-packed { background: rgba(6, 182, 212, 0.2); color: #22d3ee; border: 1px solid #0891b2; }
.wave-status-shipped { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid #059669; }
.wave-status-cancelled { background: rgba(244, 63, 94, 0.2); color: #fb7185; border: 1px solid #e11d48; }

.remark-badge {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

/* 5-Tier Expiry Risk Badges */
.tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  font-family: ui-monospace, monospace;
}
.tier-badge-critical { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.5); }
.tier-badge-urgent   { background: rgba(249, 115, 22, 0.2); color: #fb923c; border: 1px solid rgba(249, 115, 22, 0.5); }
.tier-badge-warning  { background: rgba(234, 179, 8, 0.2); color: #facc15; border: 1px solid rgba(234, 179, 8, 0.5); }
.tier-badge-monitor  { background: rgba(59, 130, 246, 0.2); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.5); }
.tier-badge-safe     { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.5); }
.tier-badge-nostock  { background: rgba(100, 116, 139, 0.2); color: #94a3b8; border: 1px solid rgba(100, 116, 139, 0.4); }

/* Hold Code Badges */
.hold-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  font-family: ui-monospace, monospace;
  cursor: pointer;
  transition: all 0.15s ease;
}
.hold-badge:hover {
  transform: scale(1.05);
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.3);
}
.hold-badge-ava { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }
.hold-badge-buyer { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }
.hold-badge-qc { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.hold-badge-other { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.4); }

/* Smart Capture Button Styles */
.btn-smart-capture {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid #3b82f6;
  color: #60a5fa;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-smart-capture:hover {
  background: #2563eb;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.4);
}

/* Full-view expanded capture mode for modals/tables */
.capture-full-view {
  max-height: none !important;
  height: auto !important;
  overflow: visible !important;
}

/* Interactive Expiry Tier Cards */
.expiry-tier-card {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}
.expiry-tier-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.5);
}
.expiry-tier-card.active {
  box-shadow: 0 0 0 2px #38bdf8, 0 8px 24px -4px rgba(56, 189, 248, 0.25);
}

