/* ==============================================================================
   HR ANALYTICS DASHBOARD - ONE PAGE "EMPLOYEE OVERVIEW" (Dashboard 2 Design)
   FULL RESPONSIVE DESIGN, DARK/LIGHT THEME, STICKY FROZEN TABLE COLUMNS & DRAG AND DROP
   ============================================================================== */

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

:root {
  --bg-main: #f4f7f6;
  --sidebar-bg: linear-gradient(180deg, #0d7c7b 0%, #085958 100%);
  --sidebar-width: 64px;
  
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  --card-hover-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);

  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  --navy-blue: #1e3a8a;
  --emerald-green: #10b981;
  --orange-accent: #f59e0b;
  --rose-accent: #f43f5e;
  --purple-accent: #a855f7;
  --cyan-accent: #06b6d4;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Dark Theme Toggle Variables */
body.dark-theme {
  --bg-main: #0f172a;
  --sidebar-bg: linear-gradient(180deg, #0f2b2a 0%, #091e1d 100%);
  --card-bg: #1e293b;
  --card-border: #334155;
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  --card-hover-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Kanit', 'Inter', -apple-system, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* ==============================================================================
   LEFT SIDEBAR (SLIM ICON BAR - DASHBOARD 2 STYLE)
   ============================================================================== */

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.25rem 0;
  z-index: 100;
  box-shadow: 4px 0 15px rgba(0, 0, 0, 0.05);
}

.sidebar-logo {
  font-size: 1.5rem;
  color: #ffffff;
  margin-bottom: 2rem;
  cursor: pointer;
}

.sidebar-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  flex: 1;
  width: 100%;
}

.sidebar-item {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.2rem;
  cursor: pointer;
  transition: var(--transition-smooth);
  position: relative;
}

.sidebar-item:hover, .sidebar-item.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.15);
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: #ffffff;
  border-radius: 0 4px 4px 0;
}

.sidebar-footer {
  margin-top: auto;
  color: rgba(255, 255, 255, 0.8);
  font-size: 1.2rem;
  cursor: pointer;
}

/* ==============================================================================
   MAIN CONTAINER & HEADER
   ============================================================================== */

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.75rem 2rem;
  max-width: 1650px;
  margin: 0 auto;
  width: calc(100vw - var(--sidebar-width));
}

/* Header Section */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 1rem;
}

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

.syntec-logo-img {
  height: 48px;
  width: auto;
  object-fit: contain;
}

.brand-info h1 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.1;
  letter-spacing: -0.3px;
}

body.dark-theme .brand-info h1 {
  color: #f8fafc;
}

.brand-info p {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Title: EMPLOYEE overview */
.header-title {
  text-align: center;
}

.header-title h2 {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
}

.header-title h2 span.text-navy {
  color: #1e3a8a;
  text-transform: UPPERCASE;
}

body.dark-theme .header-title h2 span.text-navy {
  color: #60a5fa;
}

.header-title h2 span.text-green {
  color: #10b981;
  font-weight: 500;
}

/* Header Filters & Controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-select {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

.btn-import {
  padding: 7px 14px;
  background: #10b981;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition-smooth);
}

.btn-import:hover {
  background: #059669;
}

/* ==============================================================================
   TOP 4 BIG NUMBER KPI CARDS
   ============================================================================== */

.kpi-row-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.kpi-card-colored {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  border: 1px solid var(--card-border);
}

.kpi-card-colored:hover {
  transform: translateY(-4px);
  box-shadow: var(--card-hover-shadow);
}

/* Top Accent Colored Header */
.kpi-banner {
  padding: 8px 12px;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-transform: capitalize;
  letter-spacing: 0.3px;
}

.bg-navy        { background: #1e3a8a; }
.bg-teal        { background: #0d7c7b; }
.bg-purple-pink { background: #a855f7; }
.bg-emerald     { background: #10b981; }
.bg-amber       { background: #f59e0b; }
.bg-rose        { background: #f43f5e; }
.bg-cyan        { background: #06b6d4; }
.bg-inactive    { background: #94a3b8 !important; }

.kpi-body {
  padding: 1rem;
  text-align: center;
}

.kpi-number {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-caption {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ==============================================================================
   10 CORE DEMOGRAPHIC CHARTS GRID & DRAG AND DROP
   ============================================================================== */

.charts-main-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1.25rem;
}

.grid-col-3 { grid-column: span 3; }
.grid-col-4 { grid-column: span 4; }
.grid-col-6 { grid-column: span 6; }
.grid-col-8 { grid-column: span 8; }
.grid-col-12 { grid-column: span 12; }

.chart-box {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
}

.chart-box:hover {
  box-shadow: var(--card-hover-shadow);
}

.chart-box-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-right: 4px;
  transition: color 0.2s ease;
}

.chart-box:hover .drag-handle {
  color: #10b981;
}

/* Dragging active states */
.chart-box.dragging {
  opacity: 0.45;
  transform: scale(0.97);
  border: 2px dashed #06b6d4 !important;
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.3) !important;
}

.chart-box.drag-over {
  border: 2px solid #10b981 !important;
  background: rgba(16, 185, 129, 0.06) !important;
  transform: scale(1.02);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.25) !important;
}

.chart-canvas-container {
  position: relative;
  flex: 1;
  min-height: 260px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==============================================================================
   STAFF DIRECTORY TABLE (VERTICAL + HORIZONTAL SCROLL & FROZEN COLUMNS 1 & 2)
   ============================================================================== */

.directory-section {
  margin-top: 1.5rem;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
}

.directory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.directory-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Scroll Container for Vertical + Horizontal Scroll */
.table-responsive {
  width: 100%;
  max-height: 520px;
  overflow-y: auto;
  overflow-x: auto;
  margin-top: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  position: relative;
  scroll-behavior: smooth;
}

/* Customize Vertical Scrollbar styling */
.table-responsive::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.table-responsive::-webkit-scrollbar-track {
  background: rgba(148, 163, 184, 0.1);
  border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

body.dark-theme .table-responsive::-webkit-scrollbar-thumb {
  background: #475569;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  text-align: left;
}

/* Sticky Table Header */
.data-table th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #e6f4f1;
  color: #10b981;
  padding: 12px 14px;
  font-weight: 700;
  border-bottom: 2px solid var(--card-border);
  white-space: nowrap;
}

body.dark-theme .data-table th {
  background: #112624;
  color: #34d399;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--card-border);
  color: var(--text-primary);
  white-space: nowrap;
  background: var(--card-bg);
}

/* ------------------------------------------------------------------------------
   FREEZE COLUMN 1 (รหัสพนักงาน) & COLUMN 2 (ชื่อ-นามสกุล)
   ------------------------------------------------------------------------------ */

/* Column 1: รหัสพนักงาน (Frozen Left) */
.data-table th:nth-child(1),
.data-table td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 12;
  background: var(--card-bg);
  min-width: 120px;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
}

.data-table th:nth-child(1) {
  z-index: 20;
  background: #e6f4f1;
}

/* Column 2: ชื่อ-นามสกุล (ไทย) (Frozen Left) */
.data-table th:nth-child(2),
.data-table td:nth-child(2) {
  position: sticky;
  left: 120px;
  z-index: 12;
  background: var(--card-bg);
  min-width: 220px;
  border-right: 2px solid #10b981;
  box-shadow: 4px 0 10px rgba(0, 0, 0, 0.08);
}

.data-table th:nth-child(2) {
  z-index: 20;
  background: #e6f4f1;
}

/* Dark Theme Overrides for Frozen Columns */
body.dark-theme .data-table th:nth-child(1),
body.dark-theme .data-table th:nth-child(2) {
  background: #112624;
}

body.dark-theme .data-table td:nth-child(1),
body.dark-theme .data-table td:nth-child(2) {
  background: var(--card-bg);
}

.badge-tenure {
  background: rgba(6, 182, 212, 0.12);
  color: #0891b2;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.78rem;
  display: inline-block;
  border: 1px solid rgba(6, 182, 212, 0.25);
}

/* Pagination Controls */
.pagination-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0 0.5rem;
  border-top: 1px solid var(--card-border);
  margin-top: 0.75rem;
  flex-wrap: wrap;
  gap: 10px;
}

.pagination-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.pagination-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-page {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-page:hover:not(:disabled) {
  background: #10b981;
  color: #ffffff;
  border-color: #10b981;
}

.btn-page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==============================================================================
   RESPONSIVE BREAKPOINTS (TABLET & MOBILE)
   ============================================================================== */

@media (max-width: 1024px) {
  body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: 54px;
    flex-direction: row;
    padding: 0 1rem;
    position: sticky;
    top: 0;
  }

  .sidebar-logo {
    margin-bottom: 0;
    margin-right: 1rem;
  }

  .sidebar-menu {
    flex-direction: row;
    gap: 0.5rem;
  }

  .sidebar-item {
    width: 44px;
  }

  .sidebar-item.active::before {
    width: 100%;
    height: 3px;
    top: auto;
    bottom: 0;
    border-radius: 3px 3px 0 0;
  }

  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
  }

  .main-wrapper {
    width: 100vw;
    padding: 1rem;
  }

  .kpi-row-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-col-3, .grid-col-4, .grid-col-6, .grid-col-8 {
    grid-column: span 12;
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-title h2 {
    font-size: 1.6rem;
  }

  .header-controls {
    width: 100%;
    justify-content: space-between;
  }

  .filter-select {
    flex: 1;
    min-width: 120px;
  }

  .kpi-row-4 {
    grid-template-columns: repeat(1, 1fr);
  }

  .kpi-number {
    font-size: 2.1rem;
  }

  .directory-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .directory-controls {
    width: 100%;
    flex-direction: column;
  }

  .directory-controls input, .directory-controls div {
    width: 100% !important;
  }

  .pagination-container {
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }
}
