/* ============================================
   SPV Marketing Dashboard — Custom Styles
   J&T Express Brand: #CD001A
   ============================================ */

:root {
  --jt-red: #CD001A;
  --jt-red-dark: #A80015;
  --jt-red-light: #FF1A36;
  --bg-main: #F3F4F6;
  --bg-card: #FFFFFF;
  --text-primary: #1F2937;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --success: #16A34A;
  --success-bg: #DCFCE7;
  --warning: #F59E0B;
  --warning-bg: #FEF3C7;
  --danger: #EF4444;
  --danger-bg: #FEE2E2;
  --info: #3B82F6;
  --info-bg: #DBEAFE;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 200ms ease;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: #FFFFFF;
  border-right: 1px solid #E5E7EB;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transition: transform var(--transition);
  overflow-y: auto;
}
.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid #E5E7EB;
}
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}
.sidebar-section-title {
  padding: 8px 20px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.sidebar-link:hover {
  background: #F9FAFB;
  color: var(--text-primary);
}
.sidebar-link.active {
  background: #FFF1F2;
  color: var(--jt-red);
  border-left-color: var(--jt-red);
  font-weight: 600;
}
.sidebar-link.disabled {
  opacity: 0.4;
  pointer-events: none;
  cursor: not-allowed;
}
.sidebar-link .badge-soon {
  font-size: 10px;
  background: #E5E7EB;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: auto;
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #E5E7EB;
  font-size: 12px;
  color: var(--text-muted);
}

/* Main content */
.main-content {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.top-header {
  background: var(--jt-red);
  color: white;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 2px 8px rgba(205,0,26,0.25);
}
.top-header .logo-box {
  width: 40px;
  height: 40px;
  background: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--jt-red);
  font-size: 12px;
  flex-shrink: 0;
}
.top-header h1 {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 35;
}
.sidebar-overlay.active {
  display: block;
}

/* Content area */
.content-area {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ---- Filter Bar ---- */
.filter-bar {
  background: white;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.channel-tabs {
  display: flex;
  gap: 4px;
  background: #F3F4F6;
  border-radius: 6px;
  padding: 3px;
}
.channel-tab {
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.channel-tab.active {
  background: var(--jt-red);
  color: white;
}
.channel-tab:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.filter-select {
  padding: 7px 12px;
  border: 1px solid #D1D5DB;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-primary);
  background: white;
  cursor: pointer;
  min-width: 140px;
}
.filter-select:focus {
  outline: none;
  border-color: var(--jt-red);
  box-shadow: 0 0 0 2px rgba(205,0,26,0.15);
}
.filter-info {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  line-height: 1.4;
}
.filter-info strong {
  color: var(--text-primary);
}

/* ---- Health Cards ---- */
.health-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.health-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
  border-top: 3px solid transparent;
  position: relative;
  overflow: hidden;
}
.health-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.health-card .card-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 8px;
}
.health-card .card-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
}
.health-card .card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.health-card.total { border-top-color: var(--info); }
.health-card.total .card-value { color: var(--info); }
.health-card.on-track { border-top-color: var(--success); }
.health-card.on-track .card-value { color: var(--success); }
.health-card.behind { border-top-color: var(--warning); }
.health-card.behind .card-value { color: var(--warning); }
.health-card.critical { border-top-color: var(--danger); }
.health-card.critical .card-value { color: var(--danger); }
.health-card.denda { border-top-color: var(--danger); }
.health-card.denda .card-value { color: var(--danger); font-size: 22px; }
.health-card.reward { border-top-color: var(--success); }
.health-card.reward .card-value { color: var(--success); font-size: 22px; }

/* ---- Priority Actions ---- */
.priority-box {
  background: white;
  border: 2px solid var(--danger);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.priority-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.priority-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--danger);
}
.pulse-dot {
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.4); }
}
.priority-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.priority-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #FEF2F2;
  border-radius: var(--radius);
  border-left: 4px solid var(--danger);
}
.priority-item .pi-rank {
  width: 28px;
  height: 28px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.priority-item .pi-name {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  min-width: 0;
}
.priority-item .pi-detail {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.priority-item .pi-denda {
  font-weight: 700;
  color: var(--danger);
  font-size: 14px;
  white-space: nowrap;
}

/* ---- Program Matrix Table ---- */
.table-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 24px;
}
.table-card .table-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #E5E7EB;
}
.table-card .table-header h3 {
  font-size: 16px;
  font-weight: 700;
}
.table-wrapper {
  overflow-x: auto;
}
.program-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.program-table thead th {
  background: var(--jt-red);
  color: white;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.program-table thead th:hover {
  background: var(--jt-red-dark);
}
.program-table thead th .sort-icon {
  margin-left: 4px;
  opacity: 0.5;
  font-size: 10px;
}
.program-table thead th.sorted .sort-icon {
  opacity: 1;
}
.program-table tbody tr {
  border-bottom: 1px solid #F3F4F6;
  transition: background var(--transition);
}
.program-table tbody tr:hover {
  background: #F9FAFB;
}
.program-table tbody td {
  padding: 12px 16px;
  white-space: nowrap;
}
.program-table .prog-name {
  font-weight: 600;
  color: var(--text-primary);
}
.program-table .num-col {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Flag badges */
.flag-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}
.flag-badge.red { background: var(--danger-bg); color: var(--danger); }
.flag-badge.yellow { background: var(--warning-bg); color: #B45309; }
.flag-badge.green { background: var(--success-bg); color: var(--success); }
.flag-badge.blue { background: var(--info-bg); color: var(--info); }

/* Trend arrows */
.trend-up { color: var(--success); font-weight: 700; }
.trend-down { color: var(--danger); font-weight: 700; }
.trend-flat { color: var(--text-muted); font-weight: 700; }

/* Progress bar inline */
.progress-bar-mini {
  width: 80px;
  height: 6px;
  background: #E5E7EB;
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
}
.progress-bar-mini .fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}
.progress-bar-mini .fill.red { background: var(--danger); }
.progress-bar-mini .fill.yellow { background: var(--warning); }
.progress-bar-mini .fill.green { background: var(--success); }

/* ---- Daily Trend Section ---- */
.trend-section {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.trend-section h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}
.trend-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px;
}
.trend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #F9FAFB;
  border-radius: var(--radius);
  font-size: 13px;
}
.trend-item .trend-arrow {
  font-size: 18px;
  flex-shrink: 0;
}
.trend-item .trend-text {
  flex: 1;
  min-width: 0;
}
.trend-item .trend-delta {
  font-weight: 700;
  white-space: nowrap;
}

/* ---- Charts Grid ---- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}
.chart-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.chart-card h4 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-primary);
}
.chart-card canvas {
  width: 100% !important;
  height: 250px !important;
}

/* ---- DP Detail Accordion ---- */
.dp-section {
  margin-bottom: 24px;
}
.dp-section h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}
.dp-accordion {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dp-item {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.dp-header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  gap: 12px;
  transition: background var(--transition);
}
.dp-header:hover {
  background: #F9FAFB;
}
.dp-header .dp-toggle {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform var(--transition);
}
.dp-header.open .dp-toggle {
  transform: rotate(90deg);
}
.dp-header .dp-name {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
}
.dp-header .dp-score {
  font-weight: 700;
  font-size: 14px;
}
.dp-body {
  display: none;
  padding: 0 20px 16px;
  border-top: 1px solid #F3F4F6;
}
.dp-body.open {
  display: block;
}
.dp-program-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #F9FAFB;
  font-size: 13px;
}
.dp-program-row:last-child { border-bottom: none; }
.dp-program-bar {
  width: 120px;
  height: 8px;
  background: #E5E7EB;
  border-radius: 4px;
  overflow: hidden;
  margin: 0 12px;
  flex-shrink: 0;
}
.dp-program-bar .fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
}

/* ---- Upload Page ---- */
.checklist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.checklist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
}
.checklist-item .cl-icon {
  font-size: 20px;
  flex-shrink: 0;
}
.checklist-item .cl-name {
  flex: 1;
  font-weight: 500;
}
.checklist-item .cl-status {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
}
.cl-status.uploaded { background: var(--success-bg); color: var(--success); }
.cl-status.pending { background: var(--warning-bg); color: #B45309; }
.cl-status.overdue { background: var(--danger-bg); color: var(--danger); }

/* Upload dropzone */
.dropzone {
  border: 2px dashed #D1D5DB;
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  background: #FAFAFA;
  transition: all var(--transition);
  cursor: pointer;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--jt-red);
  background: #FFF5F5;
}
.dropzone .dz-icon {
  font-size: 48px;
  margin-bottom: 12px;
  color: var(--text-muted);
}
.dropzone .dz-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.dropzone .dz-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Progress bar full */
.progress-bar {
  width: 100%;
  height: 10px;
  background: #E5E7EB;
  border-radius: 5px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-bar .fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.4s ease;
}

/* Upload result */
.upload-result {
  padding: 16px;
  border-radius: var(--radius);
  margin-top: 16px;
  font-size: 14px;
}
.upload-result.success { background: var(--success-bg); color: var(--success); }
.upload-result.error { background: var(--danger-bg); color: var(--danger); }

/* Status badges for table */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.status-badge.success { background: var(--success-bg); color: var(--success); }
.status-badge.error { background: var(--danger-bg); color: var(--danger); }
.status-badge.processing { background: var(--warning-bg); color: #B45309; }

/* ---- Toast Notification ---- */
.toast-container {
  position: fixed;
  top: 72px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: white;
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  animation: toast-in 0.3s ease;
  border-left: 4px solid var(--info);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.empty-state p {
  font-size: 15px;
}

/* ---- Loading Skeleton ---- */
.skeleton {
  background: linear-gradient(90deg, #E5E7EB 25%, #F3F4F6 50%, #E5E7EB 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: 4px;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Footer ---- */
.app-footer {
  padding: 20px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid #E5E7EB;
  margin-top: auto;
}

/* ================================================
   RESPONSIVE
   ================================================ */
@media (max-width: 1024px) {
  .health-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .hamburger-btn {
    display: block;
  }
  .health-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-info {
    margin-left: 0;
    text-align: left;
  }
  .content-area {
    padding: 16px;
  }
  .priority-item {
    flex-wrap: wrap;
  }
  .priority-item .pi-detail,
  .priority-item .pi-denda {
    margin-left: 40px;
  }
  .trend-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .health-grid {
    grid-template-columns: 1fr;
  }
  .health-card .card-value {
    font-size: 24px;
  }
  .top-header h1 {
    font-size: 15px;
  }
}

/* ================================================
   PRINT STYLES
   ================================================ */
@media print {
  .sidebar,
  .sidebar-overlay,
  .hamburger-btn,
  .filter-bar,
  .toast-container,
  .app-footer {
    display: none !important;
  }
  .main-content {
    margin-left: 0 !important;
  }
  .top-header {
    position: static;
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    border-bottom: 2px solid var(--jt-red);
  }
  .top-header .logo-box {
    border: 2px solid var(--jt-red);
  }
  .health-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  .chart-card canvas {
    max-height: 200px !important;
  }
  body { background: white; }
  .health-card, .table-card, .chart-card, .priority-box, .trend-section, .dp-item {
    box-shadow: none !important;
    border: 1px solid #E5E7EB;
    break-inside: avoid;
  }
}
