/* ============================================
   CRM Admin (Admin-only)
   Designed to match public/style.css tokens.
   ============================================ */

:root {
  --crm-primary: #1b8a4f;
  /* Emerald green from mockup */
  --crm-primary-hover: #156d3e;
  --crm-bg: #f5f7f9;
  --crm-surface: #ffffff;
  --crm-text-main: #2c3e50;
  --crm-text-muted: #7f8c8d;
  --crm-nav-height: 64px;
  --crm-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --crm-radius: 8px;
}

body {
  margin: 0;
  font-family: 'Outfit', sans-serif;
  background-color: var(--crm-bg);
  color: var(--crm-text-main);
  -webkit-font-smoothing: antialiased;
}

.crm-admin {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================
   Header & Navigation
   ============================================ */

.crm-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--crm-nav-height);
  padding: 0 24px;
  background: var(--crm-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.crm-header-left {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 100%;
}

.crm-logo-box {
  display: flex;
  align-items: center;
  margin-right: 12px;
}

.crm-logo-img {
  height: 34px;
  filter: none;
}

.crm-nav {
  height: 100%;
}

.crm-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 2px;
  height: 100%;
}

.crm-nav-item {
  appearance: none;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.9);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.88rem;
  padding: 0 12px;
  height: 100%;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  display: flex;
  align-items: center;
  border-radius: 4px;
  position: relative;
  white-space: nowrap;
}

/* Prevent width shift on bold */
.crm-nav-item::after {
  content: attr(data-label);
  display: block;
  font-weight: 700;
  height: 0;
  overflow: hidden;
  visibility: hidden;
}

.crm-nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.crm-nav-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  font-weight: 700;
  box-shadow: inset 0 -3px 0 #ffffff;
}

/* Dropdown */
.crm-nav-dropdown {
  position: relative;
  height: 100%;
}

.crm-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: #ffffff;
  min-width: 220px;
  padding: 8px 0;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  list-style: none;
  margin: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1001;
}

.crm-nav-dropdown:hover .crm-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.crm-dropdown-menu li button {
  width: 100%;
  text-align: left;
  padding: 12px 20px;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--crm-text-main);
  cursor: pointer;
  transition: background 0.2s;
}

.crm-dropdown-menu li button:hover {
  background: #f8f9fa;
  color: var(--crm-primary);
}

/* Header Right Actions */
.crm-header-right {
  display: flex;
  align-items: center;
}

.crm-header-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.crm-icon-btn {
  background: transparent;
  border: none;
  color: #ffffff;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crm-icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.crm-user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 12px;
}

.crm-user-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.crm-avatar {
  width: 32px;
  height: 32px;
  background: #ffffff;
  color: var(--crm-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

/* ============================================
   Tabs (Legacy / To be adjusted)
   ============================================ */

.crm-tabbar,
.crm-subtabwrap {
  display: none;
  /* Hide old tabs in favor of top nav */
}

/* ============================================
   Content & Layout
   ============================================ */

.crm-content {
  flex: 1;
  padding: 24px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.crm-panel {
  animation: crmFadeIn 0.25s ease-out;
}

@keyframes crmFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

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

/* Dashboard Grid */
.crm-dashboard-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

.crm-report-card,
.crm-side-card {
  background: #ffffff;
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow);
  overflow: hidden;
}

.crm-report-header,
.crm-side-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #edf2f7;
}

.crm-report-header h3,
.crm-side-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--crm-text-main);
}

.crm-report-filters {
  display: flex;
  gap: 12px;
}

.crm-select,
.crm-select-sm {
  appearance: none;
  background: #f8f9fa;
  border: 1px solid #e2e8f0;
  padding: 6px 32px 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--crm-text-main);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%234a5568'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
  cursor: pointer;
}

/* Table Styles */
.crm-table-container {
  overflow-x: auto;
}

.crm-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.crm-table th {
  background: #f8fbfa;
  padding: 14px 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--crm-text-muted);
  border-bottom: 1px solid #edf2f7;
}

.crm-table td {
  padding: 16px 20px;
  font-size: 0.9rem;
  border-bottom: 1px solid #f7fafc;
}

.td-bold {
  font-weight: 700;
  color: var(--crm-text-main);
}

.status-waiting {
  padding: 4px 10px;
  background: #fff5f5;
  color: #c53030;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Side Column Lists */
.crm-side-col {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.crm-side-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.crm-side-list li {
  padding: 16px 20px;
  border-bottom: 1px solid #f7fafc;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.crm-side-list li:last-child {
  border-bottom: none;
}

.list-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.list-type {
  font-size: 0.85rem;
  color: var(--crm-text-muted);
}

.list-pending {
  align-self: flex-end;
  font-size: 0.8rem;
  color: #e53e3e;
  font-weight: 600;
}

.crm-placeholder-card {
  background: #ffffff;
  padding: 40px;
  text-align: center;
  border-radius: var(--crm-radius);
  color: var(--crm-text-muted);
  border: 2px dashed #e2e8f0;
}

.crm-table-host {
  background: #ffffff;
  border-radius: var(--crm-radius);
  border: 1px solid #edf2f7;
  overflow: hidden;
}

/* ============================================
   Loading / Gate
   ============================================ */

.crm-loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  z-index: 9999;
}

.crm-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--crm-primary);
  border-radius: 50%;
  animation: crmSpin 1s linear infinite;
}

@keyframes crmSpin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@media (max-width: 1100px) {
  .crm-dashboard-layout {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   Buttons & Inputs
   ============================================ */

.crm-btn-primary {
  background-color: var(--crm-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--crm-radius);
  padding: 8px 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.2s;
}

.crm-btn-primary:hover {
  background-color: var(--crm-primary-hover);
}

.crm-btn-secondary {
  background-color: #e2e8f0;
  color: var(--crm-text-main);
  border: none;
  border-radius: var(--crm-radius);
  padding: 8px 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.2s;
}

.crm-btn-secondary:hover {
  background-color: #cbd5e0;
}

.crm-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--crm-text-main);
  transition: border-color 0.2s;
}

.crm-input:focus {
  outline: none;
  border-color: var(--crm-primary);
  box-shadow: 0 0 0 2px rgba(27, 138, 79, 0.1);
}

/* ============================================
   Modals
   ============================================ */
.crm-modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 24px;
}

.crm-modal-container {
  background: #ffffff;
  width: 100%;
  max-width: 900px;
  height: 80vh;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

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

.crm-modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid #edf2f7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fbfa;
}

.crm-modal-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.crm-modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--crm-text-main);
}

.crm-student-id-badge {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--crm-primary);
  background: rgba(27, 138, 79, 0.08);
  border: 1px solid rgba(27, 138, 79, 0.22);
  padding: 6px 10px;
  border-radius: 999px;
}

.crm-muted {
  margin: 0;
  color: var(--crm-text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.crm-entrance-test-panel {
  margin-top: 28px;
  padding: 18px;
  border: 1px solid #edf2f7;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: var(--crm-shadow);
}

.crm-entrance-test-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.crm-entrance-test-header h4 {
  margin: 0 0 6px 0;
  font-size: 1.05rem;
  color: var(--crm-text-main);
}

.crm-entrance-test-link-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.crm-entrance-tests-list {
  border-top: 1px solid #edf2f7;
  padding-top: 12px;
}

.crm-entrance-tests-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.crm-entrance-tests-table th,
.crm-entrance-tests-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
  vertical-align: top;
}

.crm-entrance-tests-table th {
  color: var(--crm-text-muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.crm-test-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.8rem;
}

.crm-test-status.created {
  background: rgba(249, 171, 0, 0.12);
  color: #8a5700;
  border: 1px solid rgba(249, 171, 0, 0.35);
}

.crm-test-status.started {
  background: rgba(26, 115, 232, 0.1);
  color: #0b4ca8;
  border: 1px solid rgba(26, 115, 232, 0.28);
}

.crm-test-status.submitted {
  background: rgba(30, 142, 62, 0.12);
  color: #137333;
  border: 1px solid rgba(30, 142, 62, 0.28);
}

.crm-test-link {
  color: var(--crm-primary);
  text-decoration: none;
  font-weight: 600;
}

.crm-test-link:hover {
  text-decoration: underline;
}

.crm-student-link {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 700;
  color: var(--crm-primary);
  cursor: pointer;
  text-align: left;
}

.crm-student-link:hover {
  text-decoration: underline;
}

.crm-student-link:focus-visible {
  outline: 3px solid rgba(27, 138, 79, 0.22);
  outline-offset: 3px;
  border-radius: 8px;
}

.crm-modal-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.crm-modal-sidebar {
  width: 240px;
  background: #f8f9fa;
  border-right: 1px solid #edf2f7;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

.crm-sidebar-item {
  text-align: left;
  background: transparent;
  border: none;
  padding: 12px 24px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--crm-text-muted);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.crm-sidebar-item:hover {
  background: #edf2f7;
  color: var(--crm-text-main);
}

.crm-sidebar-item.active {
  background: #e6fffa;
  color: var(--crm-primary);
  border-left-color: var(--crm-primary);
  font-weight: 600;
}

.crm-modal-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

.crm-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #edf2f7;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #ffffff;
}

.crm-icon-btn.text-dark {
  color: var(--crm-text-muted);
}

.crm-icon-btn.text-dark:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--crm-text-main);
}

.crm-form-group {
  margin-bottom: 20px;
}

.crm-form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--crm-text-main);
}

.crm-form-grid {
  color: #333;
}

.skill-icon {
  color: #999;
}

.skill-score-block:hover .skill-circle {
  transform: scale(1.05);
}

/* Score Inputs */
.score-input-group {
  display: flex;
  gap: 24px;
  margin-bottom: 32px;
  justify-content: flex-start;
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.score-item label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--crm-text-main);
}

.score-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 0;
  display: flex;
  /* For alignment if we used div, but input text-align works */
  align-items: center;
  /* Vertical center not automatic for inputs, use padding/height */
  justify-content: center;
  border: 2px solid #e2e8f0;
}

.score-circle:focus {
  border-color: var(--crm-primary);
  box-shadow: 0 0 0 4px rgba(27, 138, 79, 0.1);
}

.text-muted {
  color: var(--crm-text-muted);
}

/* ============================================
   Course Management Helpers
   ============================================ */

.crm-inline-fields {
  display: flex;
  align-items: center;
  gap: 8px;
}

.crm-inline-fields .crm-input {
  flex: 1;
}

.crm-tag-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.crm-tag-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 0.85rem;
  color: var(--crm-text-main);
}

.crm-tag-remove {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--crm-text-muted);
  font-size: 0.8rem;
}

.crm-tag-remove:hover {
  color: #e53e3e;
}

.crm-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 12000;
  min-width: 240px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  color: #ffffff;
  background: #334155;
  font-size: 0.92rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.crm-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.crm-toast.success {
  background: #166534;
}

.crm-toast.error {
  background: #b91c1c;
}
