/**
 * Demi Database Optimization Dashboard - Scoped Styles
 * Reuses Demi's core CSS (.demi-stats-bar, .demi-sr-card, .demi-backup-table, .demi-btn-primary, etc.)
 *
 * @package Demi
 * @since 0.1.3
 */

.demi-opt-dashboard {
  font-family: var(--demi-font-family), sans-serif;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
}

/* -------------------------------------------------------------
   FULL-PAGE SCANNER LOADING STATE
------------------------------------------------------------- */
.demi-opt-loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  background: rgb(var(--demi-white));
  border: 1px solid rgb(var(--demi-border-light-color));
  border-radius: var(--demi-border-radius-lg, 12px);
  padding: 60px 24px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.demi-opt-loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.demi-opt-page-loader.demi-rays-loader {
  width: 38px;
  height: 38px;
}

.demi-opt-loading-text {
  font-size: 14px;
  font-weight: 500;
  color: rgb(var(--demi-secondary-font-color));
  margin: 0;
}

/* -------------------------------------------------------------
   SESSION FEEDBACK BANNER (Unified Success & Error Handler)
------------------------------------------------------------- */
.demi-opt-session-banner {
  padding: 14px 18px;
  border-radius: var(--demi-border-radius-lg, 12px);
  margin-bottom: 24px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.demi-opt-session-banner.is-success {
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.demi-opt-session-banner.is-error {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.demi-opt-session-banner-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
}

.demi-opt-session-banner-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.demi-opt-session-banner.is-success .demi-opt-session-banner-icon {
  color: #16a34a;
}

.demi-opt-session-banner.is-error .demi-opt-session-banner-icon {
  color: #dc2626;
}

.demi-opt-session-banner-content {
  flex: 1;
  min-width: 0;
}

.demi-opt-session-banner-text-wrap {
  line-height: 1.5;
  word-break: break-word;
}

.demi-opt-session-banner-text strong {
  font-weight: 700;
  color: #14532d;
}

.demi-opt-session-banner.is-error .demi-opt-session-banner-text strong {
  color: #7f1d1d;
}

.demi-opt-banner-expand-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  color: #b91c1c;
  text-decoration: underline;
  cursor: pointer;
  margin-left: 6px;
  transition: color 0.15s ease;
  vertical-align: baseline;
}

.demi-opt-banner-expand-btn:hover {
  color: #7f1d1d;
}

.demi-opt-session-banner-details {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.demi-opt-session-banner.is-error .demi-opt-session-banner-details {
  border-top-color: #fca5a5;
}

.demi-opt-session-banner-pre {
  margin: 0;
  padding: 10px 14px;
  background-color: #ffffff;
  border: 1px solid #fca5a5;
  border-radius: var(--demi-border-radius-md, 8px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  color: #7f1d1d;
  max-height: 180px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.demi-opt-session-banner-dismiss {
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
  border-radius: 4px;
}

.demi-opt-session-banner-dismiss:hover {
  opacity: 1;
}

/* -------------------------------------------------------------
   STATS BAR CUSTOM ICONS
------------------------------------------------------------- */
.demi-opt-stats-bar .demi-stat-icon.is-db-size {
  color: #0284c7;
  background-color: #e0f2fe;
}

.demi-opt-stats-bar .demi-stat-icon.is-overhead {
  color: #d97706;
  background-color: #fef3c7;
}

.demi-opt-stats-bar .demi-stat-icon.is-clean-items {
  color: #16a34a;
  background-color: #dcfce7;
}

.demi-opt-stats-bar .demi-stat-icon .hi {
  font-size: 20px;
}

.demi-opt-stats-bar .demi-stat-loader {
  display: inline-block;
  vertical-align: middle;
  width: 18px;
  height: 18px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    linear-gradient(
        0deg,
        rgba(var(--demi-primary-color), 0.5) 30%,
        #0000 0 70%,
        rgb(var(--demi-primary-color)) 0
      )
      50% / 8% 100%,
    linear-gradient(
        90deg,
        rgba(var(--demi-primary-color), 0.25) 30%,
        #0000 0 70%,
        rgba(var(--demi-primary-color), 0.75) 0
      )
      50% / 100% 8%;
  background-repeat: no-repeat;
  animation: demi-loader-spin 1s infinite steps(12);
}

#demi-opt-run-cleanup-btn .demi-rays-loader {
  --demi-loader-color-100: rgb(228 229 231);
  --demi-loader-color-75: rgb(233 233 233 / 75%);
  --demi-loader-color-50: rgb(216 216 217 / 50%);
  --demi-loader-color-25: rgb(255 255 255 / 25%);
  flex-shrink: 0;
  background:
    linear-gradient(
        0deg,
        var(--demi-loader-color-50) 30%,
        #0000 0 70%,
        var(--demi-loader-color-100) 0
      )
      50% / 8% 100%,
    linear-gradient(
        90deg,
        var(--demi-loader-color-25) 30%,
        #0000 0 70%,
        var(--demi-loader-color-75) 0
      )
      50% / 100% 8%;
  background-repeat: no-repeat;
  animation: demi-loader-spin 1s infinite steps(12);
}

/* -------------------------------------------------------------
   ACTION LINKS & DISABLED STATES (OPTIMIZATION TAB ONLY)
------------------------------------------------------------- */
.demi-opt-card .demi-sr-action-link {
  font-size: 13px;
  font-weight: 600;
  color: rgb(var(--demi-primary-color));
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.demi-opt-card .demi-sr-action-link:hover {
  text-decoration: underline;
}

.demi-opt-card .demi-sr-action-link.is-disabled,
.demi-opt-card .demi-sr-action-link[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed !important;
  text-decoration: none !important;
}

/* -------------------------------------------------------------
   CLEANUP TASK ROWS
------------------------------------------------------------- */
.demi-opt-tasks-body {
  display: flex;
  flex-direction: column;
}

.demi-opt-task-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid rgb(var(--demi-border-light-color));
  cursor: pointer;
  transition: background-color 0.15s ease;
  user-select: none;
}

.demi-opt-task-row:last-child {
  border-bottom: none;
}

.demi-opt-task-row:hover {
  background-color: #f8fafc;
}

.demi-opt-task-row.is-empty {
  opacity: 0.65;
  cursor: default;
}

.demi-opt-task-row.is-empty:hover {
  background-color: transparent;
}

.demi-opt-task-check {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.demi-opt-task-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  flex-shrink: 0;
}

.demi-opt-task-icon .hi {
  font-size: 18px;
}
.demi-sr-card-title .hi {
  font-size: 18px;
}

/* Task Icon pastel palettes */
.demi-opt-task-icon.is-revisions {
  background-color: #e0f2fe;
  color: #0284c7;
}
.demi-opt-task-icon.is-drafts {
  background-color: #f3e8ff;
  color: #9333ea;
}
.demi-opt-task-icon.is-trash-posts {
  background-color: #ffedd5;
  color: #ea580c;
}
.demi-opt-task-icon.is-spam-comments {
  background-color: #ffe4e6;
  color: #e11d48;
}
.demi-opt-task-icon.is-trash-comments {
  background-color: #fce7f3;
  color: #db2777;
}
.demi-opt-task-icon.is-unapproved-comments {
  background-color: #fef3c7;
  color: #d97706;
}
.demi-opt-task-icon.is-transients {
  background-color: #ccfbf1;
  color: #0d9488;
}
.demi-opt-task-icon.is-pingbacks {
  background-color: #ede9fe;
  color: #7c3aed;
}
.demi-opt-task-icon.is-orphans {
  background-color: #d1fae5;
  color: #059669;
}
.demi-opt-task-icon.is-terms {
  background-color: #e0f7fa;
  color: #00838f;
}

.demi-opt-task-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-grow: 1;
  min-width: 0;
}

.demi-opt-task-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.demi-opt-task-title {
  font-size: 14px;
  font-weight: 600;
  color: rgb(var(--demi-text-heading));
}

.demi-opt-task-desc {
  font-size: 13px;
  color: rgb(var(--demi-secondary-font-color));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Badge Review First */
.demi-opt-badge-review {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background-color: #fef3c7;
  color: #b45309;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  border: 1px solid #fde68a;
  line-height: 1.2;
}

.demi-opt-badge-icon {
  width: 12px;
  height: 12px;
}

.demi-opt-task-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
  min-width: 80px;
}

.demi-opt-task-count {
  font-size: 14px;
  font-weight: 700;
  color: rgb(var(--demi-text-heading));
}

.demi-opt-task-size {
  font-size: 12px;
  color: rgb(var(--demi-text-muted-light));
}

.demi-opt-task-cleaning {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #0284c7;
}

.demi-opt-task-cleaning .demi-rays-loader {
  width: 14px;
  height: 14px;
  vertical-align: middle;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    linear-gradient(
        0deg,
        rgba(2, 132, 199, 0.5) 30%,
        #0000 0 70%,
        rgb(2, 132, 199) 0
      )
      50% / 8% 100%,
    linear-gradient(
        90deg,
        rgba(2, 132, 199, 0.25) 30%,
        #0000 0 70%,
        rgba(2, 132, 199, 0.75) 0
      )
      50% / 100% 8%;
  background-repeat: no-repeat;
  animation: demi-loader-spin 1s infinite steps(12);
}

.demi-opt-task-cleaned-label {
  font-size: 13px;
  font-weight: 600;
  color: #16a34a;
}

.demi-opt-task-icon.is-completed {
  background-color: #dcfce7 !important;
  color: #16a34a !important;
}

.demi-opt-task-row.is-cleaned-row {
  cursor: default;
}

.demi-opt-task-row.is-cleaned-row:hover {
  background-color: transparent;
}

.demi-opt-task-row.is-cleaned-row .demi-opt-task-title {
  color: rgb(var(--demi-text-muted));
}

.demi-opt-task-row.is-cleaned-row .demi-opt-task-desc {
  color: rgb(var(--demi-text-muted-light));
}

/* -------------------------------------------------------------
   CARD FOOTER & ACTION BUTTONS
------------------------------------------------------------- */
.demi-opt-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
}

.demi-opt-footer-summary {
  font-size: 13px;
  font-weight: 500;
  color: rgb(var(--demi-text-muted));
}

/* Scoped button enhancements to avoid any global conflicts */
.demi-opt-action-btn {
  padding: 0 20px;
  min-height: 40px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--demi-border-radius-md, 8px);
  text-decoration: none;
  cursor: pointer;
}

#demi-opt-optimize-tables-btn {
  color: #0073aa;
  border: 1px solid #0073aa;
}

.demi-opt-action-btn .hi {
  font-size: 16px;
}

.demi-opt-action-btn:disabled,
.demi-opt-action-btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* -------------------------------------------------------------
   DATABASE TABLES GRID
------------------------------------------------------------- */
.demi-opt-table-container {
  border: none;
  border-radius: 0;
  max-height: 340px;
  overflow-y: auto;
  overflow-x: auto;
  position: relative;
}

.demi-opt-data-table td {
  padding: 12px 20px;
  vertical-align: middle;
}

.demi-opt-data-table thead th {
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: #fafbfc;
  box-shadow: 0 1px 0 rgb(var(--demi-border-light-color));
}

.demi-opt-col-check {
  width: 44px;
  text-align: center !important;
}

.demi-opt-col-name code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  color: rgb(var(--demi-text-heading));
  background-color: #f1f5f9;
  padding: 3px 8px;
  border-radius: 4px;
}

.demi-opt-col-rows,
.demi-opt-col-size {
  color: rgb(var(--demi-secondary-font-color));
}

.demi-opt-col-overhead {
  color: rgb(var(--demi-secondary-font-color));
}

.demi-opt-col-overhead.is-gain {
  font-weight: 700;
  color: #d97706;
}

.demi-opt-col-status {
  text-align: right !important;
}

/* Status Badges */
.demi-opt-status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 9999px;
  line-height: 1.2;
}

.demi-opt-status-badge.is-needs-opt {
  background-color: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}

.demi-opt-status-badge.is-optimal {
  background-color: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
  letter-spacing: 0.05em;
}

.demi-opt-status-badge.is-optimizing {
  background-color: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.demi-opt-status-badge.is-optimizing .demi-rays-loader {
  width: 12px;
  height: 12px;
}

.demi-opt-table-row.is-optimizing-row {
  background-color: #f8fafc;
}

.demi-opt-table-row.is-optimal-row .demi-opt-table-checkbox:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* -------------------------------------------------------------
   RESPONSIVE ADJUSTMENTS
------------------------------------------------------------- */
@media (max-width: 640px) {
  .demi-opt-card-footer {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    text-align: center;
  }

  .demi-opt-task-row {
    padding: 12px 16px;
  }

  .demi-opt-task-desc {
    white-space: normal;
  }
}

/* -------------------------------------------------------------
   CONFIRMATION MODAL
------------------------------------------------------------- */
.demi-opt-modal .demi-btn-confirm-danger {
  padding: 0 20px;
  min-height: 38px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--demi-font-family);
  color: #ffffff;
  background: #b91c1c;
  border: 1px solid #b91c1c;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.demi-opt-modal .demi-btn-confirm-danger:hover {
  background: #991b1b;
  border-color: #991b1b;
}

.demi-opt-modal .demi-btn-cancel {
  padding: 0 16px;
  min-height: 38px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--demi-font-family);
  color: #475569;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.demi-opt-modal .demi-btn-cancel:hover {
  background: #f8fafc;
  color: #1e293b;
  border-color: #94a3b8;
}
