/* ============================================================
   Training Platform Theme System
   5 Themes: Default (Blue), Dark, Green, Purple, Orange
   ============================================================ */

/* ─── Theme Variables ──────────────────────────────────────── */

:root, [data-theme="default"] {
  --tp-primary: #4361ee;
  --tp-primary-light: #eef1ff;
  --tp-primary-dark: #3247c7;
  --tp-secondary: #6c757d;
  --tp-success: #2ec4b6;
  --tp-info: #4895ef;
  --tp-warning: #f8961e;
  --tp-danger: #ef476f;
  --tp-bg-body: #f0f2f5;
  --tp-bg-card: #ffffff;
  --tp-bg-sidebar: #1a1d2e;
  --tp-bg-sidebar-hover: #282c42;
  --tp-bg-sidebar-active: #4361ee;
  --tp-text-primary: #2d3436;
  --tp-text-secondary: #636e72;
  --tp-text-muted: #b2bec3;
  --tp-text-sidebar: #a4a6b3;
  --tp-text-sidebar-active: #ffffff;
  --tp-border-color: #e8ecf1;
  --tp-shadow: 0 2px 12px rgba(0,0,0,0.06);
  --tp-shadow-hover: 0 4px 20px rgba(0,0,0,0.1);
  --tp-radius: 10px;
  --tp-gradient-start: #4361ee;
  --tp-gradient-end: #7209b7;
}

[data-theme="dark"] {
  --tp-primary: #6c8cff;
  --tp-primary-light: #1e2440;
  --tp-primary-dark: #5474e0;
  --tp-bg-body: #12131a;
  --tp-bg-card: #1e2030;
  --tp-bg-sidebar: #0c0d14;
  --tp-bg-sidebar-hover: #1a1b2e;
  --tp-bg-sidebar-active: #6c8cff;
  --tp-text-primary: #e4e6eb;
  --tp-text-secondary: #8a8f98;
  --tp-text-muted: #555a65;
  --tp-text-sidebar: #8a8f98;
  --tp-text-sidebar-active: #ffffff;
  --tp-border-color: #2a2d3e;
  --tp-shadow: 0 2px 12px rgba(0,0,0,0.3);
  --tp-shadow-hover: 0 4px 20px rgba(0,0,0,0.4);
  --tp-gradient-start: #6c8cff;
  --tp-gradient-end: #a855f7;
}

[data-theme="green"] {
  --tp-primary: #10b981;
  --tp-primary-light: #ecfdf5;
  --tp-primary-dark: #059669;
  --tp-bg-sidebar: #0f2922;
  --tp-bg-sidebar-hover: #1a3d33;
  --tp-bg-sidebar-active: #10b981;
  --tp-gradient-start: #10b981;
  --tp-gradient-end: #06b6d4;
}

[data-theme="purple"] {
  --tp-primary: #8b5cf6;
  --tp-primary-light: #f3f0ff;
  --tp-primary-dark: #7c3aed;
  --tp-bg-sidebar: #1a1033;
  --tp-bg-sidebar-hover: #2d1f4e;
  --tp-bg-sidebar-active: #8b5cf6;
  --tp-gradient-start: #8b5cf6;
  --tp-gradient-end: #ec4899;
}

[data-theme="orange"] {
  --tp-primary: #f59e0b;
  --tp-primary-light: #fffbeb;
  --tp-primary-dark: #d97706;
  --tp-bg-sidebar: #2a1d06;
  --tp-bg-sidebar-hover: #3d2b0d;
  --tp-bg-sidebar-active: #f59e0b;
  --tp-text-sidebar: #c9a04e;
  --tp-gradient-start: #f59e0b;
  --tp-gradient-end: #ef4444;
}

/* ─── Base Layout ──────────────────────────────────────────── */

.tp-wrapper {
  display: flex;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--tp-bg-body);
  color: var(--tp-text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ─── Sidebar ──────────────────────────────────────────────── */

.tp-sidebar {
  width: 260px;
  min-height: 100vh;
  background: var(--tp-bg-sidebar);
  color: var(--tp-text-sidebar);
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  overflow-y: auto;
}

.tp-sidebar-brand {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 12px;
}

.tp-sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--tp-gradient-start), var(--tp-gradient-end));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
}

.tp-sidebar-brand .brand-text {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.tp-sidebar-brand .brand-sub {
  font-size: 11px;
  color: var(--tp-text-muted);
  font-weight: 400;
}

.tp-sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.tp-nav-section {
  padding: 8px 24px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--tp-text-muted);
  font-weight: 600;
}

.tp-nav-item {
  display: flex;
  align-items: center;
  padding: 10px 24px;
  color: var(--tp-text-sidebar);
  text-decoration: none;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  gap: 12px;
  font-size: 14px;
}

.tp-nav-item:hover {
  background: var(--tp-bg-sidebar-hover);
  color: #fff;
  text-decoration: none;
}

.tp-nav-item.active {
  background: var(--tp-bg-sidebar-hover);
  color: var(--tp-text-sidebar-active);
  border-left-color: var(--tp-primary);
}

.tp-nav-item .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 16px;
  flex-shrink: 0;
}

.tp-nav-item .nav-label {
  flex: 1;
}

.tp-nav-item .nav-badge {
  background: var(--tp-primary);
  color: #fff;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.tp-sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ─── Main Content ─────────────────────────────────────────── */

.tp-main {
  flex: 1;
  margin-left: 260px;
  min-height: 100vh;
}

.tp-topbar {
  background: var(--tp-bg-card);
  border-bottom: 1px solid var(--tp-border-color);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 900;
}

.tp-topbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--tp-text-primary);
}

.tp-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tp-content {
  padding: 28px;
}

/* ─── Theme Switcher ───────────────────────────────────────── */

.tp-theme-switcher {
  position: relative;
  display: inline-block;
}

.tp-theme-btn {
  background: var(--tp-primary-light);
  border: 1px solid var(--tp-border-color);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--tp-text-secondary);
  transition: all 0.2s;
}

.tp-theme-btn:hover {
  border-color: var(--tp-primary);
  color: var(--tp-primary);
}

.tp-theme-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--tp-bg-card);
  border: 1px solid var(--tp-border-color);
  border-radius: 8px;
  box-shadow: var(--tp-shadow-hover);
  min-width: 160px;
  z-index: 1100;
  overflow: hidden;
}

.tp-theme-dropdown.show {
  display: block;
}

.tp-theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 13px;
  color: var(--tp-text-primary);
}

.tp-theme-option:hover {
  background: var(--tp-primary-light);
}

.tp-theme-option.active {
  color: var(--tp-primary);
  font-weight: 600;
}

.tp-theme-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Cards ────────────────────────────────────────────────── */

.tp-card {
  background: var(--tp-bg-card);
  border-radius: var(--tp-radius);
  box-shadow: var(--tp-shadow);
  border: 1px solid var(--tp-border-color);
  transition: all 0.2s ease;
}

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

.tp-card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--tp-border-color);
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tp-card-body {
  padding: 20px;
}

.tp-card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--tp-border-color);
  background: var(--tp-primary-light);
  border-radius: 0 0 var(--tp-radius) var(--tp-radius);
}

/* ─── Stat Cards ───────────────────────────────────────────── */

.tp-stat-card {
  background: var(--tp-bg-card);
  border-radius: var(--tp-radius);
  box-shadow: var(--tp-shadow);
  border: 1px solid var(--tp-border-color);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.25s ease;
}

.tp-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--tp-shadow-hover);
}

.tp-stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.tp-stat-icon.blue { background: #eef1ff; color: #4361ee; }
.tp-stat-icon.green { background: #ecfdf5; color: #10b981; }
.tp-stat-icon.purple { background: #f3f0ff; color: #8b5cf6; }
.tp-stat-icon.orange { background: #fffbeb; color: #f59e0b; }
.tp-stat-icon.red { background: #fef2f2; color: #ef476f; }
.tp-stat-icon.teal { background: #f0fdfa; color: #2ec4b6; }
.tp-stat-icon.dark { background: #f3f4f6; color: #4b5563; }

[data-theme="dark"] .tp-stat-icon.blue { background: #1e2440; color: #6c8cff; }
[data-theme="dark"] .tp-stat-icon.green { background: #0f2922; color: #10b981; }
[data-theme="dark"] .tp-stat-icon.purple { background: #1a1033; color: #8b5cf6; }
[data-theme="dark"] .tp-stat-icon.orange { background: #2a1d06; color: #f59e0b; }
[data-theme="dark"] .tp-stat-icon.red { background: #2a0f15; color: #ef476f; }
[data-theme="dark"] .tp-stat-icon.teal { background: #0f2922; color: #2ec4b6; }
[data-theme="dark"] .tp-stat-icon.dark { background: #1e2030; color: #9ca3af; }

.tp-stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--tp-text-primary);
}

.tp-stat-label {
  font-size: 13px;
  color: var(--tp-text-secondary);
  margin-top: 4px;
}

/* ─── Tables ───────────────────────────────────────────────── */

.tp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.tp-table thead th {
  background: var(--tp-primary-light);
  color: var(--tp-text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  border-bottom: 2px solid var(--tp-border-color);
  white-space: nowrap;
}

.tp-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--tp-border-color);
  color: var(--tp-text-primary);
  vertical-align: middle;
}

.tp-table tbody tr:hover {
  background: var(--tp-primary-light);
}

.tp-table tbody tr:last-child td {
  border-bottom: none;
}

/* ─── Buttons ──────────────────────────────────────────────── */

.tp-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-decoration: none;
}

.tp-btn-primary {
  background: var(--tp-primary);
  color: #fff;
}

.tp-btn-primary:hover {
  background: var(--tp-primary-dark);
  color: #fff;
  text-decoration: none;
}

.tp-btn-outline {
  background: transparent;
  border: 1px solid var(--tp-border-color);
  color: var(--tp-text-secondary);
}

.tp-btn-outline:hover {
  border-color: var(--tp-primary);
  color: var(--tp-primary);
  text-decoration: none;
}

.tp-btn-danger {
  background: #fef2f2;
  color: var(--tp-danger);
  border: 1px solid #fecaca;
}

.tp-btn-danger:hover {
  background: var(--tp-danger);
  color: #fff;
}

.tp-btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ─── Forms ────────────────────────────────────────────────── */

.tp-form-group {
  margin-bottom: 16px;
}

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

.tp-form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--tp-border-color);
  border-radius: 8px;
  font-size: 14px;
  color: var(--tp-text-primary);
  background: var(--tp-bg-card);
  transition: border-color 0.2s;
}

.tp-form-control:focus {
  outline: none;
  border-color: var(--tp-primary);
  box-shadow: 0 0 0 3px var(--tp-primary-light);
}

/* ─── Badges ───────────────────────────────────────────────── */

.tp-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

.tp-badge-success { background: #ecfdf5; color: #059669; }
.tp-badge-warning { background: #fffbeb; color: #d97706; }
.tp-badge-danger { background: #fef2f2; color: #dc2626; }
.tp-badge-info { background: #eff6ff; color: #2563eb; }
.tp-badge-secondary { background: #f3f4f6; color: #6b7280; }

[data-theme="dark"] .tp-badge-success { background: #0f2922; }
[data-theme="dark"] .tp-badge-warning { background: #2a1d06; }
[data-theme="dark"] .tp-badge-danger { background: #2a0f15; }
[data-theme="dark"] .tp-badge-info { background: #1e2440; }
[data-theme="dark"] .tp-badge-secondary { background: #1e2030; }

/* ─── Alert ────────────────────────────────────────────────── */

.tp-alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tp-alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.tp-alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.tp-alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

[data-theme="dark"] .tp-alert-success { background: #0f2922; color: #6ee7b7; border-color: #065f46; }
[data-theme="dark"] .tp-alert-warning { background: #2a1d06; color: #fcd34d; border-color: #92400e; }
[data-theme="dark"] .tp-alert-info { background: #1e2440; color: #93c5fd; border-color: #1e40af; }

/* ─── Progress Bar ─────────────────────────────────────────── */

.tp-progress {
  height: 8px;
  background: var(--tp-border-color);
  border-radius: 4px;
  overflow: hidden;
}

.tp-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--tp-gradient-start), var(--tp-gradient-end));
  border-radius: 4px;
  transition: width 0.6s ease;
}

/* ─── Empty State ──────────────────────────────────────────── */

.tp-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--tp-text-muted);
}

.tp-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.tp-empty-text {
  font-size: 14px;
}

/* ─── Layout Optimization for Manage Pages ─── */

/* Make tp-content act as a proper Bootstrap container */
.tp-content .row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin: 0;
}

/* Left form panel: use flexible sizing instead of rigid col-xl-4 */
.tp-content .row > .col-xl-4,
.tp-content .row > [class*="col-"] {
  padding: 0;
}

.tp-content .row > .col-xl-4 {
  flex: 0 0 360px;
  max-width: 360px;
}

.tp-content .row > .col-xl-8 {
  flex: 1;
  min-width: 0;
}

.tp-content .row > .col-xl-3 {
  flex: 0 0 25%;
  max-width: 25%;
}

.tp-content .row > .col-xl-5 {
  flex: 0 0 42%;
  max-width: 42%;
}

.tp-content .row > .col-xl-6 {
  flex: 0 0 48%;
  max-width: 48%;
}

.tp-content .row > .col-xl-7 {
  flex: 0 0 58%;
  max-width: 58%;
}

.tp-content .row > .col-xl-12 {
  flex: 0 0 100%;
  max-width: 100%;
}

.tp-content .row > .col-md-3,
.tp-content .row > .col-md-4,
.tp-content .row > .col-md-5,
.tp-content .row > .col-md-7,
.tp-content .row > .col-md-12 {
  flex: 1;
  min-width: 120px;
  padding: 0 8px;
}

/* Form controls in manage pages */
.tp-content .tp-form-control {
  width: 100%;
  box-sizing: border-box;
}

/* ─── Responsive: Tablet (max-width: 1200px) ─── */

@media (max-width: 1200px) {
  .tp-content .row > .col-xl-4 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .tp-content .row > .col-xl-8 {
    flex: 0 0 100%;
  }
}

/* ─── Responsive: Mobile (max-width: 768px) ─── */

/* Sidebar overlay for mobile */
.tp-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  transition: opacity 0.3s;
}

.tp-sidebar-overlay.show {
  display: block;
}

@media (max-width: 768px) {
  /* Sidebar slides from left on mobile */
  .tp-sidebar {
    transform: translateX(-100%);
    position: fixed !important;
    z-index: 1000;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }
  .tp-sidebar.open {
    transform: translateX(0);
  }

  /* Show toggle button */
  .tp-sidebar-toggle {
    display: inline-flex !important;
  }

  /* Main content fills full width */
  .tp-main {
    margin-left: 0 !important;
  }

  /* Topbar compact */
  .tp-topbar {
    padding: 10px 14px;
  }
  .tp-topbar-title {
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .tp-topbar-actions {
    gap: 6px;
    flex-wrap: wrap;
  }
  .tp-topbar-actions .tp-btn {
    padding: 4px 8px;
    font-size: 11px;
  }

  /* Content padding */
  .tp-content {
    padding: 12px !important;
    overflow-x: hidden;
  }

  /* All columns full width */
  .tp-content .row > [class*="col-"] {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /* Tables: horizontal scroll wrapper */
  .tp-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
  }
  .tp-content .tp-table {
    min-width: 500px;
  }

  /* Stat cards: 2-column grid */
  .tp-content .row > .col-md-3 {
    flex: 0 0 48% !important;
    max-width: 48% !important;
  }
  .tp-stat-card {
    padding: 12px !important;
  }
  .tp-stat-value {
    font-size: 22px;
  }
  .tp-stat-icon {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  /* Cards compact */
  .tp-card {
    margin-bottom: 12px !important;
  }
  .tp-card-header {
    padding: 12px 14px;
    font-size: 14px;
  }
  .tp-card-body {
    padding: 14px;
  }

  /* Forms compact */
  .tp-form-group {
    margin-bottom: 10px !important;
  }

  /* Buttons compact */
  .tp-btn {
    padding: 6px 12px;
    font-size: 12px;
  }
  .tp-btn-sm {
    padding: 3px 8px;
    font-size: 11px;
  }

  /* Modals: full-width on mobile */
  .tp-modal,
  [style*="position:fixed"][style*="z-index:9999"] > div {
    width: 95% !important;
    max-width: 95% !important;
    max-height: 90vh !important;
    margin: 0 auto;
    padding: 16px !important;
  }

  /* Filter bar: wrap */
  .tp-filter-bar,
  [style*="display:flex"][style*="gap:8px"][style*="flex-wrap:wrap"] {
    flex-wrap: wrap !important;
  }

  /* Theme switcher compact */
  .tp-theme-btn-label {
    display: none;
  }
}

/* ─── User-facing page nav bar ─── */

.tp-page-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.tp-page-nav-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--tp-text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.tp-page-nav-subtitle {
  font-size: 13px;
  color: var(--tp-text-secondary);
  margin-top: 2px;
}
.tp-page-nav-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

@media (max-width: 768px) {
  .tp-page-nav {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .tp-page-nav-actions {
    margin-left: 0;
    width: 100%;
  }
  .tp-page-nav-actions .tp-btn {
    flex: 1;
    justify-content: center;
    min-width: 0;
    text-align: center;
  }
  .tp-page-nav-title {
    font-size: 17px;
  }
}

/* ─── Table horizontal scroll wrapper ─── */

.tp-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ─── Responsive stat grid for user pages ─── */

@media (max-width: 576px) {
  /* On very small screens, stat cards stack to 1-column */
  .tp-content .row > .col-md-3,
  .row > .col-md-3 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }
  .tp-content .row > .col-md-4,
  .row > .col-md-4 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }
}

/* ─── Scroll-to-top button ─── */

.tp-scroll-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tp-primary);
  color: #fff;
  border: none;
  font-size: 18px;
  cursor: pointer;
  z-index: 800;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.tp-scroll-top:hover {
  transform: translateY(-2px);
}
.tp-scroll-top.show {
  display: flex;
}

/* ─── Sidebar toggle button: hidden on desktop ─── */

@media (min-width: 769px) {
  .tp-sidebar-toggle {
    display: none !important;
  }
}
