:root {
  /* Modern Premium Palette 2.0 */
  --color-bg: #0b1120;
  /* Denser dark blue-black */
  --color-surface: rgba(17, 24, 39, 0.7);
  --color-surface-solid: #111827;
  --color-border: rgba(255, 255, 255, 0.08);

  --color-text-main: #f8fafc;
  --color-text-muted: #64748b;

  --color-primary: #38bdf8;
  --color-primary-glow: rgba(56, 189, 248, 0.15);

  --color-success: #10b981;
  --color-danger: #f43f5e;
  --color-warning: #f59e0b;

  /* Platform Accent Colors */
  --platform-fb: #1877f2;
  --platform-tiktok: #fe2c55;
  --platform-shopee: #ee4d2d;
  --platform-lazada: #101460;

  --shadow-premium: 0 20px 50px rgba(0, 0, 0, 0.5);
  --radius-lg: 24px;
  --radius-md: 12px;
  --font-family-th: 'Prompt', 'Inter', sans-serif;
}

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

/* Custom Premium Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

body {
  font-family: var(--font-family-th);
  background: var(--color-bg);
  background-image:
    radial-gradient(at 0% 0%, rgba(56, 189, 248, 0.07) 0px, transparent 40%),
    radial-gradient(at 100% 100%, rgba(244, 63, 94, 0.07) 0px, transparent 40%);
  color: var(--color-text-main);
  display: flex;
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Glassmorphism 2.0 */
.glass {
  background: var(--color-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--color-border);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.05), var(--shadow-premium);
}

/* Refined Sidebar */
.sidebar {
  width: 280px;
  height: 100vh;
  position: fixed;
  display: flex;
  flex-direction: column;
  padding: 2.5rem 1.25rem;
  z-index: 1000;
  border-right: 1px solid var(--color-border);
}

.logo-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 3.5rem;
  padding-left: 0.5rem;
}

.logo-icon {
  color: var(--color-primary);
  width: 28px;
  height: 28px;
}

.logo-wrapper h2 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.logo-wrapper h2 span {
  color: var(--color-primary);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 2.5rem;
}

.nav-section label {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #475569;
  letter-spacing: 0.15em;
  padding-left: 14px;
  margin-bottom: 1rem;
  display: block;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  margin-bottom: 4px;
}

.nav-item i {
  width: 18px;
  height: 18px;
  opacity: 0.7;
  transition: 0.25s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text-main);
  transform: translateX(4px);
}

.nav-item.active {
  background: var(--color-primary-glow);
  color: var(--color-primary);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.2);
}

.nav-item.active i {
  color: var(--color-primary);
  opacity: 1;
}

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1.5rem;
}

.avatar-box {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
}

.user-details .username {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text-main);
  display: block;
}

.role-badge {
  font-size: 0.65rem;
  font-weight: 800;
  background: rgba(56, 189, 248, 0.1);
  color: var(--color-primary);
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

.logout-link {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 1.25rem;
  color: #ef4444;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.8;
  transition: 0.2s;
}

.logout-link:hover {
  opacity: 1;
  transform: translateX(2px);
}

.main-content {
  flex: 1;
  margin-left: 280px;
  padding: 2rem 3rem;
  max-width: calc(100% - 280px);
}

.container {
  width: 100%;
  max-width: 1400px;
  margin: 0;
  padding: 0;
}

/* Redefine card structure */
.stat-card {
  padding: 2rem;
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
}

.stat-sales::before {
  background: var(--color-primary);
}

.stat-orders::before {
  background: var(--color-success);
}

.stat-ads::before {
  background: var(--color-warning);
}

.stat-roas::before {
  background: #818cf8;
}

.stat-label {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 800;
  margin: 0.5rem 0;
  letter-spacing: -1px;
}

.trend-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.trend-up {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.trend-down {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1.5rem;
}

.card-main {
  grid-column: span 12;
}

@media (min-width: 1200px) {
  .chart-box {
    grid-column: span 8;
  }

  .table-box {
    grid-column: span 4;
  }
}

.feedback-success {
  margin-top: 1rem;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  background-color: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Login Page Utilities */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-card {
  width: 100%;
  max-width: 440px;
  text-align: center;
  padding: 3.5rem;
}

.login-header {
  margin-bottom: 3rem;
}

.login-header h2 {
  font-size: 2.5rem;
  margin-bottom: 12px;
  letter-spacing: -1.5px;
  font-weight: 800;
}

.login-header p {
  font-size: 1rem;
  color: var(--color-text-muted);
  font-weight: 400;
}

.login-creds {
  margin-top: 2rem;
  text-align: left;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}

.login-creds strong {
  color: var(--color-primary);
}

.error-badge {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid rgba(244, 63, 94, 0.3);
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.card {
  padding: 2rem;
  border-radius: var(--radius-lg);
}

.card h3 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
  color: var(--color-text-main);
}

/* Table Styling */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
}

.data-table th {
  padding: 1rem;
  text-align: left;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.data-table td {
  padding: 1.25rem 1rem;
  background: rgba(255, 255, 255, 0.03);
}

.data-table tr td:first-child {
  border-radius: 12px 0 0 12px;
}

.data-table tr td:last-child {
  border-radius: 0 12px 12px 0;
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.06);
}

/* Badges */
.badge {
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

/* Form Elements Refinement */
.form-group label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

input[type="text"],
input[type="password"],
.date-input {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--color-border);
  color: white;
  padding: 14px 18px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  width: 100%;
  transition: all 0.3s ease;
}

input:focus,
.date-input:focus {
  outline: none;
  border-color: var(--color-primary);
  background: rgba(15, 23, 42, 0.8);
  box-shadow: 0 0 0 4px var(--color-primary-glow);
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), #818cf8);
  color: var(--color-bg);
  padding: 14px 28px;
  border-radius: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px var(--color-primary-glow);
}

.btn-primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 20px var(--color-primary-glow);
  filter: brightness(1.1);
}

.period-switch {
  background: var(--color-surface-solid);
  padding: 6px;
  border-radius: 12px;
  display: flex;
  gap: 4px;
}

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

.period-btn.active {
  background: var(--color-primary);
  color: var(--color-bg);
}

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

.highlight {
  color: var(--color-primary);
  font-weight: 700;
}
/* เพิ่มช่องว่างระหว่างบรรทัด */
.header-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 20px;
}

/* ปรับสีลิงก์ให้อ่านง่าย */
a {
    color: #00d4ff; /* สีฟ้าสว่าง */
    text-decoration: none;
    margin-bottom: 8px;
}

/* ทำปุ่ม Role ให้ดูดีขึ้น */
.role-badge {
    background-color: #1e293b;
    border-radius: 20px;
    padding: 5px 15px;
    display: inline-block;
}

/* Executive KPI Suite Styling */
.kpi-hero-row {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.kpi-card-premium {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 1.5rem;
    backdrop-filter: blur(15px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
}

.kpi-card-premium:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0,0,0,0.4);
    border-color: rgba(255, 255, 255, 0.15);
}

.kpi-label {
    font-size: 0.85rem;
    color: #94a3b8;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 800;
    color: white;
    margin-top: 5px;
    letter-spacing: -0.5px;
}

/* Modal System Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(11, 17, 32, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 2.5rem;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95) translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 1.5rem;
}

.modal-header h3 {
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

.modal-header p {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-body {
    margin-bottom: 2rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: white;
    padding: 14px 28px;
    border-radius: 12px;
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

/* Custom styling for native date input calendar picker indicator */
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1) brightness(1.2);
    cursor: pointer;
    opacity: 0.6;
    transition: all 0.2s ease;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* ==========================================
   Responsive & Adaptive Screen Adaptations
   ========================================== */

/* Tablet & Smaller Laptops */
@media (max-width: 1100px) {
  .sidebar {
    width: 250px;
    padding: 2rem 1rem;
  }
  .main-content {
    margin-left: 250px;
    max-width: calc(100% - 250px);
    padding: 2rem 2rem;
  }
}

/* Mobile & Small Tablets (Collapse Sidebar) */
@media (max-width: 992px) {
  body {
    flex-direction: column;
    overflow-x: hidden;
  }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 1.5rem;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .logo-wrapper {
    margin-bottom: 1.5rem;
  }
  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    overflow-y: visible;
  }
  .nav-section {
    margin-bottom: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }
  .nav-section label {
    display: none; /* Hide labels on mobile to save space */
  }
  .nav-item {
    margin-bottom: 0;
    padding: 8px 12px;
    font-size: 0.85rem;
  }
  .sidebar-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    margin-top: 1rem;
  }
  .user-info {
    margin-bottom: 0;
  }
  .logout-link {
    margin-top: 0;
  }
  .main-content {
    margin-left: 0;
    max-width: 100%;
    padding: 1.5rem 1rem;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .chart-box, .table-box, .card-main {
    grid-column: span 12 !important;
  }
  .grid-3 {
    grid-template-columns: 1fr !important;
  }
}

/* Mobile Phones */
@media (max-width: 576px) {
  .stat-value {
    font-size: 2rem;
  }
  .kpi-hero-row {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }
  .header-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .date-filter-group {
    flex-direction: column;
    align-items: stretch;
  }
  .premium-select, .premium-input {
    width: 100% !important;
  }
}