/* ============================================================
   AFFILIATE COMMAND CENTER - STYLES
   Tối ưu hiển thị, bảo mật, tương thích di động & máy tính
   ============================================================ */

:root {
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-card-hover: #27354f;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --shopee-color: #ee4d2d;
  --shopee-bg: rgba(238, 77, 45, 0.12);
  --shopee-border: rgba(238, 77, 45, 0.3);
  --tiktok-color: #00f2fe;
  --tiktok-alt: #fe2c55;
  --tiktok-bg: rgba(0, 242, 254, 0.1);
  --tiktok-border: rgba(0, 242, 254, 0.3);
  --success-color: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --danger-color: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --warning-color: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --nodata-color: #cbd5e1;
  --nodata-bg: #334155;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ================== LOCK SCREEN MODAL ================== */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.auth-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 460px;
  width: 100%;
  padding: 36px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #f38020, #faad3f, #00f2fe);
}

.auth-icon {
  width: 68px;
  height: 68px;
  background: rgba(243, 128, 32, 0.15);
  border: 1px solid rgba(243, 128, 32, 0.4);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 18px;
  color: #faad3f;
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #ffffff;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  margin-bottom: 24px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: block;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: #00f2fe;
  box-shadow: 0 0 0 2px rgba(0, 242, 254, 0.2);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #f38020, #ee4d2d);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  width: 100%;
  padding: 10px;
  background: #334155;
  color: #cbd5e1;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: #475569;
  color: #fff;
}

.auth-msg {
  font-size: 13px;
  padding: 10px;
  border-radius: var(--radius-sm);
  display: none;
}

.auth-msg.error {
  display: block;
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.auth-msg.success {
  display: block;
  background: var(--success-bg);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

/* ================== MAIN APP CONTAINER ================== */
.app-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ================== TOP HEADER ================== */
.top-header {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px 28px;
  margin-bottom: 28px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: var(--shadow);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo-stack {
  display: flex;
  align-items: center;
}

.logo-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.logo-shopee {
  background: #ee4d2d;
  color: #ffffff;
  z-index: 2;
}

.logo-tiktok {
  background: #000000;
  color: #00f2fe;
  border: 2px solid #fe2c55;
  margin-left: -12px;
  z-index: 1;
}

.brand-info h1 {
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
}

.brand-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #93c5fd;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.sync-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.sync-status {
  text-align: right;
}

.sync-time {
  font-size: 14px;
  font-weight: 600;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sync-schedule {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-refresh {
  background: #334155;
  color: #ffffff;
  border: 1px solid var(--border-color);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-refresh:hover {
  background: #475569;
  border-color: #64748b;
}

.btn-refresh.spinning svg {
  animation: spin 0.8s linear infinite;
}

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

/* ================== UNIFIED KPI HERO ROW ================== */
.hero-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-bottom: 32px;
}

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  position: relative;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.kpi-card:hover {
  border-color: #475569;
  transform: translateY(-2px);
}

.kpi-card.highlight {
  background: linear-gradient(135deg, rgba(30, 41, 59, 1), rgba(15, 23, 42, 1));
  border: 1px solid rgba(56, 189, 248, 0.4);
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.1);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.kpi-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-icon {
  font-size: 18px;
  opacity: 0.8;
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.kpi-compare {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
}

.kpi-compare.up {
  background: var(--success-bg);
  color: #34d399;
}

.kpi-compare.down {
  background: var(--danger-bg);
  color: #f87171;
}

.kpi-compare.neutral {
  background: var(--nodata-bg);
  color: var(--nodata-color);
}

.kpi-prev-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 6px;
}

/* Badge Chưa có dữ liệu */
.badge-nodata {
  display: inline-block;
  background: var(--nodata-bg);
  color: var(--nodata-color);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px dashed #64748b;
  font-style: italic;
}

/* ================== SOURCES SECTION ================== */
.section-title {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(540px, 1fr));
  gap: 24px;
  margin-bottom: 36px;
}

@media (max-width: 640px) {
  .sources-grid {
    grid-template-columns: 1fr;
  }
}

.source-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: relative;
  overflow: hidden;
}

.source-card.shopee-source {
  border-top: 4px solid var(--shopee-color);
}

.source-card.tiktok-source {
  border-top: 4px solid var(--tiktok-color);
}

.source-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.source-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.source-title-group h2 {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
}

.source-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 4px;
}

.shopee-source .source-tag {
  background: var(--shopee-bg);
  color: #ff7854;
  border: 1px solid var(--shopee-border);
}

.tiktok-source .source-tag {
  background: var(--tiktok-bg);
  color: var(--tiktok-color);
  border: 1px solid var(--tiktok-border);
}

/* Con số chính của mỗi nguồn (Tiêu chuẩn 1) */
.main-metric-box {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
}

.main-metric-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.main-metric-val-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.main-metric-number {
  font-size: 32px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.5px;
}

.shopee-source .main-metric-number {
  color: #ff6b4a;
}

.tiktok-source .main-metric-number {
  color: #22d3ee;
}

/* Biểu đồ So Sánh Tuần Này vs Tuần Trước (Tiêu chuẩn 1) */
.chart-container {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  width: 16px;
  height: 3px;
  border-radius: 2px;
}

.legend-line.dashed {
  border-top: 2px dashed #94a3b8;
  height: 0;
}

.custom-chart-wrapper {
  position: relative;
  width: 100%;
  height: 180px;
}

/* Bảng chỉ số phụ của nguồn */
.sub-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.sub-metric-item {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(51, 65, 85, 0.7);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.sub-metric-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.sub-metric-value {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
}

/* ================== EXPORT GUIDE & DROPZONE ================== */
.guide-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
  margin-bottom: 36px;
}

.guide-tabs {
  display: flex;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 14px;
  margin-bottom: 22px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: #334155;
  color: #ffffff;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.steps-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 22px;
}

.step-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
}

.step-num {
  width: 28px;
  height: 28px;
  background: #f38020;
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.step-text h4 {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 4px;
}

.step-text p {
  font-size: 13px;
  color: var(--text-muted);
}

/* Kéo Thả File */
.dropzone {
  border: 2px dashed #475569;
  border-radius: var(--radius-md);
  padding: 32px 20px;
  text-align: center;
  background: rgba(15, 23, 42, 0.4);
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: #00f2fe;
  background: rgba(0, 242, 254, 0.05);
}

.dropzone-icon {
  font-size: 36px;
  margin-bottom: 12px;
  color: #94a3b8;
}

.dropzone-title {
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 6px;
}

.dropzone-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* ================== FOOTER ================== */
.app-footer {
  text-align: center;
  padding: 24px 0 10px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 13px;
}

.security-checklist {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 12px;
}

.check-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #a7f3d0;
}
