/* ============================================================
   Settlly — Admin Panel Styles
   ============================================================ */

/* ---- Keyframes ---- */

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

@keyframes pendingPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(245, 158, 11, 0);
  }
}

@keyframes pendingGlow {
  0%, 100% {
    border-color: rgba(245, 158, 11, 0.4);
  }
  50% {
    border-color: rgba(245, 158, 11, 0.9);
  }
}

/* ---- Page Layout ---- */

.admin-page {
  max-width: 1200px;
  margin: 0 auto;
  font-family: 'Outfit', sans-serif;
  color: var(--text-primary);
}

/* ---- Tabs ---- */

.admin-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 2rem;
}

.admin-tab {
  background: none;
  border: none;
  padding: 0.8rem 1.5rem;
  color: var(--text-secondary);
  font-family: 'Outfit', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.3s;
}

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

.admin-tab.active {
  color: var(--ink);
  border-bottom-color: var(--indigo-light);
}

/* ---- Stats Grid ---- */

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.admin-stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
}

.admin-stat-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.3rem;
  line-height: 1.2;
}

.admin-stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---- Pending Review Stat Card (Urgent) ---- */

.admin-stat-card.stat-pending {
  border: 2px solid var(--amber);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.06) 0%, rgba(245, 158, 11, 0.12) 100%);
  animation: pendingPulse 2.5s ease-in-out infinite;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.admin-stat-card.stat-pending:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.2);
}

.admin-stat-card.stat-pending .admin-stat-value {
  color: var(--amber);
}

.admin-stat-card.stat-pending .admin-stat-label {
  color: var(--amber);
  font-weight: 700;
}

.admin-stat-card.stat-pending .stat-pending-action {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--white);
  background: var(--amber);
  padding: 0.25rem 0.7rem;
  border-radius: 20px;
  letter-spacing: 0.3px;
}

/* ---- Tab Badge (Notification Count) ---- */

.admin-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--white);
  background: var(--amber);
  border-radius: 10px;
  margin-left: 6px;
  animation: pendingGlow 2s ease-in-out infinite;
  border: 1.5px solid var(--amber);
  line-height: 1;
}

/* ---- Pending Action Banner ---- */

.admin-pending-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, rgba(245, 158, 11, 0.15) 100%);
  border: 1.5px solid rgba(245, 158, 11, 0.35);
  border-left: 4px solid var(--amber);
  border-radius: 10px;
  margin-bottom: 2rem;
  animation: pendingGlow 2.5s ease-in-out infinite;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.admin-pending-banner:hover {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12) 0%, rgba(245, 158, 11, 0.2) 100%);
  transform: translateY(-1px);
}

.admin-pending-banner .pending-icon {
  font-size: 1.8rem;
  line-height: 1;
  flex-shrink: 0;
}

.admin-pending-banner .pending-info {
  flex: 1;
}

.admin-pending-banner .pending-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.15rem;
}

.admin-pending-banner .pending-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.admin-pending-banner .pending-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--white);
  background: var(--amber);
  padding: 0.45rem 1rem;
  border-radius: 8px;
  white-space: nowrap;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

.admin-pending-banner .pending-cta:hover {
  background: var(--amber-light);
}

/* ---- Revision Progress Overlay ---- */

@keyframes revisionProgress {
  0% { width: 0%; }
  15% { width: 15%; }
  40% { width: 40%; }
  65% { width: 58%; }
  80% { width: 72%; }
  90% { width: 85%; }
  100% { width: 95%; }
}

@keyframes revisionComplete {
  to { width: 100%; }
}

.revision-overlay {
  position: relative;
  padding: 1.5rem;
  background: var(--white);
  border: 1.5px solid var(--indigo-light);
  border-radius: 12px;
  text-align: center;
  animation: fadeInUp 0.3s ease;
}

.revision-overlay .revision-status {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.3rem;
}

.revision-overlay .revision-detail {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

.revision-progress-bar {
  width: 100%;
  height: 8px;
  background: var(--surface-alt);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.revision-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--indigo-light), var(--indigo));
  border-radius: 4px;
  animation: revisionProgress 25s ease-out forwards;
  transition: width 0.4s ease;
}

.revision-progress-fill.complete {
  animation: revisionComplete 0.4s ease forwards;
  background: linear-gradient(90deg, var(--green), #22c55e);
}

.revision-overlay .revision-steps {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 0.5rem;
}

.revision-step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  transition: color 0.3s;
}

.revision-step.active {
  color: var(--indigo-light);
  font-weight: 600;
}

.revision-step.done {
  color: var(--green);
  font-weight: 600;
}

.revision-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s;
}

.revision-step.active .revision-step-dot {
  background: var(--indigo-light);
}

.revision-step.done .revision-step-dot {
  background: var(--green);
}

/* ---- Pending Row Highlight in Tables ---- */

.admin-table tr.row-pending td {
  background: rgba(245, 158, 11, 0.06);
}

.admin-table tr.row-pending:hover td {
  background: rgba(245, 158, 11, 0.12);
}

.admin-table tr.row-pending td:first-child {
  box-shadow: inset 3px 0 0 var(--amber);
}

/* ---- Kill Switch / Hold ---- */

.admin-table tr.row-held td {
  background: rgba(220, 38, 38, 0.05);
}

.admin-table tr.row-held:hover td {
  background: rgba(220, 38, 38, 0.1);
}

.admin-table tr.row-held td:first-child {
  box-shadow: inset 3px 0 0 var(--red-soft);
}

.admin-badge[data-status="on_hold"] {
  background: rgba(220, 38, 38, 0.12);
  color: #b91c1c;
  font-weight: 700;
  border: 1px solid rgba(220, 38, 38, 0.35);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-stat-card.stat-held {
  border: 2px solid var(--red-soft);
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.04) 0%, rgba(220, 38, 38, 0.1) 100%);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.admin-stat-card.stat-held:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(220, 38, 38, 0.15);
}

.admin-stat-card.stat-held .admin-stat-value {
  color: var(--red-soft);
}

.admin-stat-card.stat-held .admin-stat-label {
  color: var(--red-soft);
  font-weight: 700;
}

.hold-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.06) 0%, rgba(220, 38, 38, 0.12) 100%);
  border: 1.5px solid rgba(220, 38, 38, 0.3);
  border-left: 4px solid var(--red-soft);
  border-radius: 10px;
  margin-bottom: 1.5rem;
}

.hold-banner .hold-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.hold-banner .hold-info {
  flex: 1;
}

.hold-banner .hold-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #b91c1c;
  margin-bottom: 0.15rem;
}

.hold-banner .hold-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.btn-kill-switch {
  background: var(--red-soft);
  color: #fff;
  border: none;
  padding: 0.5rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.3px;
  transition: background 0.2s, transform 0.1s;
}

.btn-kill-switch:hover {
  background: #b91c1c;
  transform: translateY(-1px);
}

.btn-release-hold {
  background: var(--green);
  color: #fff;
  border: none;
  padding: 0.5rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.82rem;
  transition: background 0.2s;
}

.btn-release-hold:hover {
  background: #15803d;
}

/* ---- Filter Bar ---- */

.admin-filter-bar {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

/* ---- Sortable Column Headers ---- */

.admin-table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: color 0.2s;
}

.admin-table th.sortable:hover {
  color: var(--ink);
}

.admin-table th.sortable .sort-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.6rem;
  opacity: 0.3;
  transition: opacity 0.2s;
}

.admin-table th.sortable.sort-active .sort-arrow {
  opacity: 1;
  color: var(--indigo-light);
}

/* ---- Table ---- */

.admin-table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

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

.admin-table th {
  text-align: left;
  padding: 0.8rem 1rem;
  background: var(--surface-alt);
  color: var(--indigo-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.7rem;
  border-bottom: 2px solid rgba(79, 70, 229, 0.15);
  white-space: nowrap;
}

.admin-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.admin-table tr:hover td {
  background: var(--surface-alt);
}

/* ---- Status Badges ---- */

.admin-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-badge[data-status="draft"] {
  background: var(--surface-alt);
  color: var(--text-secondary);
}

.admin-badge[data-status="analyzing"] {
  background: rgba(91, 141, 239, 0.15);
  color: var(--indigo-light);
}

.admin-badge[data-status="analyzed"] {
  background: rgba(79, 70, 229, 0.06);
  color: var(--indigo-light);
}

.admin-badge[data-status="letter_generating"] {
  background: rgba(91, 141, 239, 0.15);
  color: var(--indigo-light);
}

.admin-badge[data-status="letter_ready"] {
  background: rgba(245, 158, 11, 0.18);
  color: #b45309;
  font-weight: 700;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* ---- Detail Panel ---- */

.admin-detail-panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  margin: 1rem 0 1.5rem;
  animation: fadeInUp 0.3s ease;
}

.admin-detail-section {
  margin-bottom: 1.5rem;
}

.admin-detail-section:last-child {
  margin-bottom: 0;
}

.admin-detail-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--indigo-light);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.admin-detail-text {
  color: var(--text-secondary);
  line-height: 1.6;
  font-size: 0.9rem;
}

/* ---- Letter Preview ---- */

.admin-letter-preview {
  background: var(--surface-alt);
  color: #1a1a2e;
  padding: 2rem;
  border-radius: 8px;
  max-height: 400px;
  overflow-y: auto;
  font-family: Georgia, serif;
  font-size: 0.9rem;
  line-height: 1.7;
}

/* ---- Notes ---- */

.admin-notes {
  margin-top: 1rem;
}

.admin-note {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.admin-note:last-child {
  margin-bottom: 0;
}

.admin-note-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.admin-note-text {
  color: var(--text-primary);
  font-size: 0.9rem;
  line-height: 1.5;
}

.admin-note-input {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.admin-note-input input {
  flex: 1;
}

/* ---- Empty State ---- */

.admin-empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

/* ---- Letter Approval Badge Statuses ---- */

.admin-badge[data-status="letter_approved"] {
  background: rgba(78, 203, 113, 0.2);
  color: #4ecb71;
}

.admin-badge[data-status="letter_review"] {
  background: rgba(79, 70, 229, 0.15);
  color: var(--indigo-light);
}

.admin-badge[data-role="admin"] {
  background: rgba(79, 70, 229, 0.06);
  color: var(--indigo-light);
}

.admin-badge[data-role="legal"] {
  background: rgba(79, 70, 229, 0.06);
  color: var(--indigo);
}

.admin-badge[data-role="user"] {
  background: var(--surface-alt);
  color: var(--text-secondary);
}

/* ---- Letter Review Panel ---- */

.admin-letter-review {
  margin-top: 1rem;
}

.admin-review-actions {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.admin-review-textarea {
  width: 100%;
  min-height: 80px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  font-family: 'Outfit', sans-serif;
  font-size: 0.88rem;
  line-height: 1.5;
  resize: vertical;
  margin-bottom: 1rem;
}

.admin-review-textarea:focus {
  outline: none;
  border-color: var(--indigo-light);
}

.admin-review-textarea::placeholder {
  color: var(--text-secondary);
}

/* ---- Action Buttons ---- */

.btn-approve {
  background: rgba(78, 203, 113, 0.15);
  color: #4ecb71;
  border: 1px solid rgba(78, 203, 113, 0.3);
  padding: 0.5rem 1.25rem;
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-approve:hover {
  background: rgba(78, 203, 113, 0.25);
}

.btn-approve:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-revision {
  background: rgba(232, 168, 56, 0.15);
  color: #e8a838;
  border: 1px solid rgba(232, 168, 56, 0.3);
  padding: 0.5rem 1.25rem;
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-revision:hover {
  background: rgba(232, 168, 56, 0.25);
}

.btn-revision:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger {
  background: rgba(232, 93, 93, 0.15);
  color: #e85d5d;
  border: 1px solid rgba(232, 93, 93, 0.3);
  padding: 0.5rem 1.25rem;
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:hover {
  background: rgba(232, 93, 93, 0.25);
}

/* ---- Plan / Role Selectors ---- */

.admin-select {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  padding: 0.35rem 0.6rem;
  font-family: 'Outfit', sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  min-width: 140px;
}

.admin-select:focus {
  outline: none;
  border-color: var(--indigo-light);
}

.admin-select option {
  background: var(--white);
  color: var(--text-primary);
}

/* ---- Approval Info Display ---- */

.admin-approval-info {
  background: rgba(78, 203, 113, 0.08);
  border: 1px solid rgba(78, 203, 113, 0.2);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-top: 1rem;
}

.admin-approval-info .approval-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #4ecb71;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.admin-approval-info .approval-detail {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ---- User Detail Inline Controls ---- */

.admin-user-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.admin-control-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.admin-control-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* ---- Responsive: Tablet ---- */

@media (max-width: 1024px) {
  .admin-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---- Responsive: Mobile ---- */

@media (max-width: 640px) {
  .admin-stats {
    grid-template-columns: 1fr;
  }

  .admin-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .admin-tabs::-webkit-scrollbar {
    display: none;
  }

  .admin-tab {
    white-space: nowrap;
    flex-shrink: 0;
  }

  .admin-filter-bar {
    flex-wrap: wrap;
  }

  .admin-detail-panel {
    padding: 1.25rem;
  }

  .admin-letter-preview {
    padding: 1.25rem;
    max-height: 300px;
  }

  .admin-table th,
  .admin-table td {
    padding: 0.6rem 0.75rem;
  }

  .lh-editor-grid {
    grid-template-columns: 1fr !important;
  }

  .lh-preview-paper {
    position: static !important;
  }
}

/* ---- Letterhead Editor ---- */

.lh-editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: start;
}

.lh-logo-upload {
  width: 200px;
  height: 80px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  overflow: hidden;
}

.lh-logo-upload:hover {
  border-color: var(--indigo-light);
  background: rgba(99, 102, 241, 0.03);
}

.lh-logo-upload img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lh-preview-paper {
  background: #ffffff;
  border: 1px solid #e0ddd8;
  border-radius: 2px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  min-height: 500px;
  font-family: Georgia, 'Times New Roman', serif;
  color: #111;
  position: sticky;
  top: 6rem;
  overflow: hidden;
}

.lh-preview-paper::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(to right, #c9a227, #d4af37, #c9a227);
}

@media (max-width: 1024px) {
  .lh-editor-grid {
    grid-template-columns: 1fr;
  }

  .lh-preview-paper {
    position: static;
  }
}
