/* ================================================================
   Admin Page — AI AC/DC 통합 플랫폼
   Login, Program Builder, Step Builder, Competency Matrix, Stats
   ================================================================ */

/* ── Page Layout ── */
.page-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-xl);
  min-height: 100vh;
}

/* ── Login Overlay ── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-3xl) var(--space-2xl);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 400px;
  text-align: center;
}

.login-icon {
  font-size: 48px;
  margin-bottom: var(--space-lg);
}

.login-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin: 0 0 var(--space-2xl);
}

.login-error {
  margin-top: var(--space-md);
  color: var(--danger);
  font-size: var(--font-size-sm);
}

/* ── Admin Header ── */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border-default);
}

.admin-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.admin-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin: 0;
}

.admin-badge {
  padding: var(--space-xs) var(--space-md);
  background: var(--accent-gradient);
  color: var(--text-inverse);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
}

/* ── Section ── */
.section {
  margin-bottom: var(--space-2xl);
}

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-2xl);
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

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

.stat-icon {
  font-size: 32px;
  margin-bottom: var(--space-sm);
}

.stat-value {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.stat-label {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* ── Tab Navigation ── */
.admin-tabs {
  display: flex;
  gap: var(--space-xs);
  border-bottom: 2px solid var(--border-default);
  margin-bottom: var(--space-2xl);
}

.tab-btn {
  padding: var(--space-md) var(--space-xl);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  font-weight: var(--font-weight-medium);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 48px;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
  font-weight: var(--font-weight-semibold);
}

/* ── Tab Panels ── */
.tab-panel {
  display: none;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.panel-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin: 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: all var(--transition-base);
  text-decoration: none;
  line-height: 1;
  min-height: 48px;
}

.btn-sm {
  padding: var(--space-sm) var(--space-base);
  font-size: var(--font-size-sm);
  min-height: 36px;
}

.btn-primary {
  background: var(--accent-gradient);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-gradient-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

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

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

.btn-secondary:hover {
  background: var(--bg-card);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-inverse);
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-full {
  width: 100%;
}

.btn-icon-only {
  width: 36px;
  height: 36px;
  padding: 0;
  min-height: 36px;
}

/* ── Data Table ── */
.programs-table-wrapper,
.enrollments-table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

.data-table th,
.data-table td {
  padding: var(--space-md) var(--space-base);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--font-size-sm);
}

.data-table th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table td {
  color: var(--text-primary);
}

.data-table tbody tr {
  transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
  background: var(--bg-card);
}

.table-status {
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
}

.status-active { background: var(--success-bg); color: var(--success); }
.status-draft { background: var(--warning-bg); color: var(--warning); }
.status-archived { background: var(--bg-elevated); color: var(--text-muted); }
.status-in_progress { background: var(--info-bg); color: var(--info); }
.status-completed { background: var(--success-bg); color: var(--success); }

.table-actions {
  display: flex;
  gap: var(--space-xs);
}

.table-actions .btn {
  min-height: 32px;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-xs);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-modal-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  animation: fadeIn 0.2s ease;
  padding: var(--space-xl);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

.modal-card-lg {
  max-width: 800px;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xl);
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.modal-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.modal-body {
  padding: var(--space-xl);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-base) var(--space-xl);
  border-top: 1px solid var(--border-default);
  position: sticky;
  bottom: 0;
  background: var(--bg-secondary);
}

/* ── Form Elements ── */
.form-section {
  margin-bottom: var(--space-2xl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
}

.form-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.form-section-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin: 0 0 var(--space-lg);
}

.form-group {
  margin-bottom: var(--space-md);
}

.form-row {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 180px;
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.form-help {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin: 0 0 var(--space-lg);
}

.required {
  color: var(--danger);
}

.form-input {
  width: 100%;
  padding: var(--space-md) var(--space-base);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  box-sizing: border-box;
}

.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-glow);
}

.form-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.form-input-sm {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

select.form-input {
  appearance: auto;
}

.text-danger {
  color: var(--danger);
  font-weight: var(--font-weight-semibold);
}

/* ── Step Builder ── */
.step-builder {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.step-builder-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-base);
  transition: all var(--transition-fast);
}

.step-builder-item:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

.step-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: var(--font-size-md);
  padding: var(--space-xs);
  user-select: none;
  touch-action: none;
}

.step-drag-handle:active {
  cursor: grabbing;
}

.step-builder-item.dragging {
  opacity: 0.5;
  border-style: dashed;
}

.step-builder-item.drag-over {
  border-color: var(--accent-primary);
  background: rgba(37, 99, 235, 0.03);
}

.step-order {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  flex-shrink: 0;
}

.step-fields {
  flex: 1;
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  align-items: center;
}

.step-fields select,
.step-fields input {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  color: var(--text-primary);
  min-width: 140px;
}

.step-fields select:focus,
.step-fields input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.step-remove-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.step-remove-btn:hover {
  background: var(--danger);
  color: var(--text-inverse);
}

/* ── Competency Matrix Editor ── */
.competency-controls {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  align-items: center;
}

.competency-controls input {
  max-width: 200px;
}

.competency-matrix-wrapper {
  overflow-x: auto;
}

.competency-matrix {
  width: 100%;
  border-collapse: collapse;
  min-width: 400px;
}

.competency-matrix th,
.competency-matrix td {
  padding: var(--space-sm) var(--space-md);
  text-align: center;
  border: 1px solid var(--border-subtle);
  font-size: var(--font-size-sm);
}

.competency-matrix th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-xs);
}

.competency-matrix th:first-child {
  text-align: left;
  min-width: 120px;
}

.competency-matrix td:first-child {
  text-align: left;
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  background: var(--bg-card);
}

.competency-matrix input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.competency-matrix input[type="number"] {
  width: 60px;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  text-align: center;
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-family);
}

.competency-matrix input[type="number"]:focus {
  outline: none;
  border-color: var(--border-focus);
}

.competency-remove-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.competency-remove-btn:hover {
  background: var(--danger);
  color: var(--text-inverse);
}

/* ── Stats Detail ── */
.stats-detail {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-xl);
}

.program-stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
}

.program-stat-name {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin: 0 0 var(--space-md);
}

.program-stat-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--font-size-sm);
}

.program-stat-row:last-child {
  border-bottom: none;
}

.program-stat-label {
  color: var(--text-secondary);
}

.program-stat-value {
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
}

/* ── Theme Toggle ── */
.theme-toggle {
  position: fixed;
  top: var(--space-base);
  right: var(--space-base);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  font-size: 20px;
  cursor: pointer;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-xl);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  max-width: 360px;
  animation: toastIn 0.3s ease;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Loading Overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-loading-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border-default);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: var(--text-inverse);
  font-size: var(--font-size-sm);
  margin-top: var(--space-md);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .page-container {
    padding: var(--space-md) var(--space-base);
  }

  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-md);
  }

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

  .admin-tabs {
    overflow-x: auto;
  }

  .tab-btn {
    padding: var(--space-sm) var(--space-base);
    font-size: var(--font-size-sm);
    white-space: nowrap;
  }

  .modal-card-lg {
    max-width: 100%;
  }

  .step-fields {
    flex-direction: column;
    align-items: stretch;
  }

  .step-fields select,
  .step-fields input {
    min-width: auto;
    width: 100%;
  }

  .stats-detail {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
