/*
 * Terminal43 Code - Shared Admin Components
 * Extracted from admin templates to eliminate duplication.
 * Uses design system variables from style.css.
 */


/* ============================================
   PAGE CONTAINERS
   ============================================ */

/* Generic admin page container with centered content */
.admin-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 24px 80px;
}

/* Narrower container for form-centric pages (edit user, single-entity forms) */
.form-page {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 24px 80px;
}


/* ============================================
   FORM HEADER (centered icon + gradient title)
   ============================================ */

.form-header {
  text-align: center;
  margin-bottom: 32px;
}

.form-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--primary-light);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.form-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.form-header p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}


/* ============================================
   FORM CARD
   ============================================ */

.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
}


/* ============================================
   FORM GROUP (label + input pair)
   ============================================ */

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

.form-group:last-child {
  margin-bottom: 0;
}

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

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="url"],
.form-group input[type="datetime-local"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 16px;
  font-size: 0.9375rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text);
  transition: all 0.2s ease;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

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

/* Alternative styling using named classes (for modal/non-.form-group contexts) */
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  color: var(--text);
  transition: all 0.2s ease;
  font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

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


/* ============================================
   FORM LABEL (standalone, with .required)
   ============================================ */

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

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


/* ============================================
   FORM LAYOUTS (multi-column grids)
   ============================================ */

/* 2-column grid row */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* 3-column grid row */
.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}


/* ============================================
   FORM CHECK (checkbox with label)
   ============================================ */

.form-check {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
}

.form-check input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.form-check label {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.form-check .hint {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 400;
  display: block;
  margin-top: 2px;
}


/* ============================================
   FORM HINT
   ============================================ */

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}


/* ============================================
   SUBMIT BUTTON (full-width gradient)
   ============================================ */

.submit-btn {
  width: 100%;
  padding: 14px 24px;
  background: var(--primary-gradient);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(124, 58, 237, 0.4);
}


/* ============================================
   PAGE HEADER (flex row: title + actions)
   ============================================ */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

/* Centered variant (used on admin_users, user_stats) */
.page-header.centered {
  display: block;
  text-align: center;
}

.page-header.centered h1 {
  display: block;
  font-size: 2rem;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Icon box above centered page headers */
.page-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--primary-light);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.header-actions {
  display: flex;
  gap: 12px;
}


/* ============================================
   ADD BUTTON (primary gradient, rounded)
   ============================================ */

.add-btn {
  padding: 10px 20px;
  background: var(--primary-gradient);
  color: white;
  font-size: 0.875rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.add-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

/* Alias for templates using btn-primary */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--primary-gradient);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}


/* ============================================
   ITEMS LIST (flex column list of rows)
   ============================================ */

.items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}


/* ============================================
   ITEM ROW (card-like row with info + actions)
   ============================================ */

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  transition: all 0.2s ease;
}

.item-row:hover {
  box-shadow: var(--shadow-md);
}

.item-info {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.item-info h3 {
  font-size: 1rem;
  font-weight: 700;
}

.item-info p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}


/* ============================================
   ITEM BADGE
   ============================================ */

.item-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 0.6875rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.item-badge.primary {
  background: var(--primary-light);
  color: var(--primary);
}

.item-badge.success {
  background: var(--success-light);
  color: var(--success);
}

.item-badge.danger {
  background: var(--danger-light);
  color: var(--danger);
}

.item-badge.secondary {
  background: var(--secondary-light);
  color: var(--secondary);
}

.item-badge.muted {
  background: var(--bg-subtle);
  color: var(--text-muted);
}


/* ============================================
   ITEM ACTIONS & ACTION BUTTONS
   ============================================ */

.item-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.action-btn {
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.action-btn.edit {
  background: var(--primary-light);
  color: var(--primary);
}

.action-btn.edit:hover {
  background: var(--primary);
  color: white;
}

.action-btn.stats {
  background: var(--secondary-light);
  color: var(--secondary);
}

.action-btn.stats:hover {
  background: var(--secondary);
  color: white;
}

.action-btn.delete {
  background: var(--danger-light);
  color: var(--danger);
}

.action-btn.delete:hover {
  background: var(--danger);
  color: white;
}

.action-btn.success {
  background: var(--success-light);
  color: var(--success);
}

.action-btn.success:hover {
  background: var(--success);
  color: white;
}

/* Icon-only action button (square) */
.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

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

.btn-icon.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-light);
}


/* ============================================
   BACK LINK (pill-shaped nav link with arrow)
   ============================================ */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 32px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.back-link:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Compact back button variant (used in page headers) */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  transition: all 0.2s ease;
}

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


/* ============================================
   EMPTY STATE
   ============================================ */

.empty-state {
  text-align: center;
  padding: 60px 40px;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius-xl);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  color: var(--text-secondary);
  margin-bottom: 20px;
}


/* ============================================
   FLASH MESSAGES
   ============================================ */

.flash-messages {
  margin-bottom: 20px;
}

.flash-message {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.flash-message.success {
  background: var(--success-light);
  color: var(--success);
}

.flash-message.danger {
  background: var(--danger-light);
  color: var(--danger);
}

.flash-message.warning {
  background: var(--warning-light);
  color: var(--warning);
}


/* ============================================
   DATA TABLE (admin tables)
   ============================================ */

.data-table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

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

.data-table th {
  text-align: left;
  padding: 16px 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 16px 20px;
  font-size: 0.9375rem;
  border-bottom: 1px solid var(--border);
}

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

.data-table tr:hover td {
  background: var(--bg-subtle);
}


/* ============================================
   SECTION CARD (used in tabbed admin pages)
   ============================================ */

.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 24px;
}

.section-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.section-card-header h2 {
  font-size: 1.125rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-badge {
  padding: 4px 10px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}


/* ============================================
   FORM ACTIONS (right-aligned button row)
   ============================================ */

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  grid-column: 1 / -1;
  padding-top: 8px;
}

/* Cancel / secondary button */
.btn-cancel {
  padding: 12px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-cancel:hover {
  border-color: var(--text-muted);
}

/* Smaller button variant */
.btn-sm {
  padding: 8px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.btn-sm.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-light);
}


/* ============================================
   MODAL (shared overlay + content pattern)
   ============================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

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

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-backdrop.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2,
.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-subtle);
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

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

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}


/* ============================================
   STAT CARDS (quick stats row)
   ============================================ */

.quick-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

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

.stat-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.stat-icon.purple { background: linear-gradient(135deg, rgba(124, 58, 237, 0.15), rgba(124, 58, 237, 0.05)); }
.stat-icon.green  { background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.05)); }
.stat-icon.blue   { background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05)); }
.stat-icon.orange { background: linear-gradient(135deg, rgba(249, 115, 22, 0.15), rgba(249, 115, 22, 0.05)); }

.stat-info h3 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.stat-info p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}


/* ============================================
   TOGGLE SWITCH
   ============================================ */

.toggle-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 26px;
  transition: all 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

.toggle-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}


/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

@media (max-width: 640px) {
  /* Stack multi-column form rows */
  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr;
  }

  /* Stack item rows vertically */
  .item-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .item-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  /* Quick stats single column */
  .quick-stats {
    grid-template-columns: 1fr;
  }

  /* Tables scroll horizontally */
  .data-table-card {
    overflow-x: auto;
  }

  /* Reduce padding on containers */
  .admin-page,
  .form-page {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* Form card less padding */
  .form-card {
    padding: 20px;
  }

  /* Modal full width */
  .modal {
    max-width: 100%;
  }

  .modal-backdrop {
    padding: 12px;
  }
}

@media (max-width: 480px) {
  /* Even tighter spacing */
  .admin-page,
  .form-page {
    padding-left: 12px;
    padding-right: 12px;
  }

  .form-card {
    padding: 16px;
  }

  .section-card {
    padding: 16px;
  }

  /* Smaller page header */
  .page-header h1 {
    font-size: 1.375rem;
  }

  .form-header h1 {
    font-size: 1.5rem;
  }

  /* Action buttons wrap */
  .action-btn {
    padding: 6px 10px;
    font-size: 0.6875rem;
  }

  /* Back link compact */
  .back-link {
    padding: 10px 16px;
    font-size: 0.8125rem;
  }

  .empty-state {
    padding: 40px 20px;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 16px;
    padding-right: 16px;
  }
}
