/**
 * UltraGuard Pro — Real-Time Widget Styles
 * Version: 3.0.0
 *
 * Covers:
 *  - Status badges (active / inactive / scanning / warning / ok / error / critical / protected)
 *  - Progress bars
 *  - Live feed list
 *  - Live tables
 *  - Pulse / blink animations for scanning states
 *  - Responsive adjustments
 */

/* =====================================================================
   CSS Custom Properties
   ===================================================================== */
:root {
    --ug-rt-ok        : #22c55e;
    --ug-rt-good      : #4ade80;
    --ug-rt-warning   : #f59e0b;
    --ug-rt-danger    : #ef4444;
    --ug-rt-critical  : #b91c1c;
    --ug-rt-scanning  : #3b82f6;
    --ug-rt-inactive  : #94a3b8;
    --ug-rt-protected : #10b981;
    --ug-rt-info      : #6366f1;
    --ug-rt-text-dark : #1e293b;
    --ug-rt-text-mute : #64748b;
    --ug-rt-bg-card   : #ffffff;
    --ug-rt-border    : #e2e8f0;
    --ug-rt-radius    : 8px;
    --ug-rt-transition: 0.3s ease;
}

/* Utility: used by JS _cl() helper to show/hide realtime rows */
.ug-hidden { display: none !important; }

/* =====================================================================
   Status Badges  [data-rt="*-status"]
   ===================================================================== */
[data-rt$="-status"],
.ug-badge {
    display          : inline-flex;
    align-items      : center;
    gap              : 5px;
    padding          : 3px 10px;
    border-radius    : 20px;
    font-size        : 12px;
    font-weight      : 600;
    letter-spacing   : 0.02em;
    white-space      : nowrap;
    transition       : background var(--ug-rt-transition), color var(--ug-rt-transition);
}

/* Badge state colours */
.ug-badge-ok,
.ug-badge-clean,
.ug-badge-secure     { background: #dcfce7; color: #166534; }
.ug-badge-good       { background: #d1fae5; color: #065f46; }
.ug-badge-excellent  { background: #bbf7d0; color: #14532d; }
.ug-badge-protected  { background: #d1fae5; color: #065f46; }
.ug-badge-active     { background: #dbeafe; color: #1e40af; }
.ug-badge-scanning   { background: #dbeafe; color: #1e40af; animation: ug-blink 1.2s infinite; }
.ug-badge-warning    { background: #fef3c7; color: #92400e; }
.ug-badge-danger     { background: #fee2e2; color: #991b1b; }
.ug-badge-critical   { background: #fee2e2; color: #7f1d1d; }
.ug-badge-error      { background: #fee2e2; color: #991b1b; }
.ug-badge-inactive   { background: #f1f5f9; color: #64748b; }
.ug-badge-info       { background: #ede9fe; color: #5b21b6; }

/* Dot indicator prepended automatically via ::before */
.ug-badge-ok::before,
.ug-badge-clean::before,
.ug-badge-secure::before,
.ug-badge-protected::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ug-rt-ok); }

.ug-badge-active::before     { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ug-rt-scanning); }
.ug-badge-scanning::before   { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ug-rt-scanning); animation: ug-pulse 1s infinite; }
.ug-badge-warning::before    { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ug-rt-warning); }
.ug-badge-danger::before,
.ug-badge-critical::before   { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ug-rt-danger); }
.ug-badge-inactive::before   { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ug-rt-inactive); }

/* =====================================================================
   Progress Bars  [data-rt="*-progress"]
   ===================================================================== */
.ug-progress-wrap {
    width         : 100%;
    height        : 8px;
    background    : #e2e8f0;
    border-radius : 999px;
    overflow      : hidden;
    position      : relative;
}

[data-rt$="-progress"] {
    height           : 100%;
    border-radius    : 999px;
    background       : linear-gradient(90deg, var(--ug-rt-scanning), #60a5fa);
    transition       : width 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    min-width        : 0;
    position         : relative;
    overflow         : hidden;
}

/* Shimmer on active scanning */
.ug-scanning-active [data-rt$="-progress"]::after {
    content    : '';
    position   : absolute;
    top        : 0; left: -60%;
    width      : 60%; height: 100%;
    background : linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation  : ug-shimmer 1.5s infinite;
}

[data-rt-progress-label] {
    font-size   : 11px;
    color       : var(--ug-rt-text-mute);
    margin-left : 6px;
}

/* =====================================================================
   Alert Row  .ug-has-changes / .ug-alert-active
   ===================================================================== */
.ug-has-changes,
.ug-alert-active {
    border-left  : 3px solid var(--ug-rt-warning) !important;
    background   : #fffbeb !important;
    transition   : background var(--ug-rt-transition);
}

/* =====================================================================
   Score Arc / Radial Widget  [data-rt="security-score-arc"]
   ===================================================================== */
[data-rt="security-score-arc"] {
    position    : relative;
    display     : inline-flex;
    align-items : center;
    justify-content: center;
    flex-direction: column;
    transition  : all var(--ug-rt-transition);
}

[data-rt="security-score-arc"] .ug-score-number {
    font-size   : 42px;
    font-weight : 800;
    line-height : 1;
    transition  : color var(--ug-rt-transition);
}

[data-rt="security-score-arc"].ug-score-excellent .ug-score-number { color: var(--ug-rt-ok); }
[data-rt="security-score-arc"].ug-score-good      .ug-score-number { color: var(--ug-rt-good); }
[data-rt="security-score-arc"].ug-score-warning   .ug-score-number { color: var(--ug-rt-warning); }
[data-rt="security-score-arc"].ug-score-critical  .ug-score-number { color: var(--ug-rt-danger); }

/* =====================================================================
   Live Feed List  [data-rt="threat-feed-list"]
   ===================================================================== */
[data-rt="threat-feed-list"] {
    list-style    : none;
    margin        : 0;
    padding       : 0;
    max-height    : 320px;
    overflow-y    : auto;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

[data-rt="threat-feed-list"]::-webkit-scrollbar { width: 4px; }
[data-rt="threat-feed-list"]::-webkit-scrollbar-track { background: transparent; }
[data-rt="threat-feed-list"]::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* Scoped to threat-feed-list to avoid collision with admin-theme.css .ug-feed-item */
[data-rt="threat-feed-list"] .ug-feed-item,
.ug-rt-feed-item {
    display        : flex;
    align-items    : flex-start;
    gap            : 8px;
    padding        : 8px 10px;
    border-bottom  : 1px solid var(--ug-rt-border);
    font-size      : 12px;
    transition     : background 0.2s;
    border-left    : 3px solid transparent;
}

[data-rt="threat-feed-list"] .ug-feed-item:hover,
.ug-rt-feed-item:hover             { background: #f8fafc; }
[data-rt="threat-feed-list"] .ug-feed-item:last-child,
.ug-rt-feed-item:last-child        { border-bottom: none; }

/* Severity colours on left border */
[data-rt="threat-feed-list"] .ug-feed-item.ug-severity-critical,
[data-rt="threat-feed-list"] .ug-feed-item.ug-severity-high,
.ug-rt-feed-item.ug-severity-critical,
.ug-rt-feed-item.ug-severity-high    { border-left-color: var(--ug-rt-danger); }
[data-rt="threat-feed-list"] .ug-feed-item.ug-severity-warning,
[data-rt="threat-feed-list"] .ug-feed-item.ug-severity-medium,
.ug-rt-feed-item.ug-severity-warning,
.ug-rt-feed-item.ug-severity-medium  { border-left-color: var(--ug-rt-warning); }
[data-rt="threat-feed-list"] .ug-feed-item.ug-severity-info,
[data-rt="threat-feed-list"] .ug-feed-item.ug-severity-low,
.ug-rt-feed-item.ug-severity-info,
.ug-rt-feed-item.ug-severity-low     { border-left-color: var(--ug-rt-info); }

.ug-feed-time   { flex-shrink: 0; color: var(--ug-rt-text-mute); width: 68px; font-size: 11px; }
.ug-feed-type   { flex-shrink: 0; font-weight: 600; color: var(--ug-rt-text-dark); width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ug-feed-detail { color: var(--ug-rt-text-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* =====================================================================
   Live Tables  [data-rt="*-table"]
   ===================================================================== */
[data-rt$="-table"] { width: 100%; }

.ug-rt-table {
    width          : 100%;
    border-collapse: collapse;
    font-size      : 12px;
    table-layout   : auto;
}

.ug-rt-table thead tr {
    background : #f8fafc;
}

.ug-rt-table th {
    padding        : 7px 10px;
    text-align     : left;
    font-weight    : 600;
    color          : var(--ug-rt-text-mute);
    border-bottom  : 2px solid var(--ug-rt-border);
    white-space    : nowrap;
    text-transform : uppercase;
    font-size      : 10px;
    letter-spacing : 0.05em;
}

.ug-rt-table td {
    padding       : 7px 10px;
    border-bottom : 1px solid var(--ug-rt-border);
    color         : var(--ug-rt-text-dark);
    max-width     : 200px;
    overflow      : hidden;
    text-overflow : ellipsis;
    white-space   : nowrap;
}

.ug-rt-table tbody tr:hover { background: #f8fafc; }
.ug-rt-table tbody tr:last-child td { border-bottom: none; }

/* Alternating rows */
.ug-rt-table.striped tbody tr:nth-child(even) { background: #fafafa; }
.ug-rt-table.striped tbody tr:nth-child(even):hover { background: #f1f5f9; }

/* =====================================================================
   Realtime status card — shared wrapper
   ===================================================================== */
.ug-rt-card {
    background    : var(--ug-rt-bg-card);
    border        : 1px solid var(--ug-rt-border);
    border-radius : var(--ug-rt-radius);
    padding       : 16px 20px;
    display       : flex;
    flex-direction: column;
    gap           : 10px;
    transition    : box-shadow var(--ug-rt-transition);
}

.ug-rt-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.07); }

.ug-rt-card__header {
    display         : flex;
    align-items     : center;
    justify-content : space-between;
    gap             : 8px;
}

.ug-rt-card__title {
    font-size   : 13px;
    font-weight : 600;
    color       : var(--ug-rt-text-dark);
    margin      : 0;
}

.ug-rt-card__icon {
    font-size  : 18px;
    opacity    : 0.7;
}

.ug-rt-card__stats {
    display               : grid;
    grid-template-columns : repeat(auto-fit, minmax(80px, 1fr));
    gap                   : 8px;
}

.ug-rt-stat {
    display        : flex;
    flex-direction : column;
    align-items    : flex-start;
    gap            : 2px;
}

.ug-rt-stat__value {
    font-size   : 22px;
    font-weight : 700;
    color       : var(--ug-rt-text-dark);
    line-height : 1;
    transition  : color var(--ug-rt-transition);
}

.ug-rt-stat__label {
    font-size : 11px;
    color     : var(--ug-rt-text-mute);
}

/* =====================================================================
   Scanning state  .ug-scanning-active
   ===================================================================== */
.ug-scanning-active .ug-rt-card__header {
    border-bottom : 2px solid var(--ug-rt-scanning);
}

/* Scanning indicator row */
[data-rt="antivirus-scanning-row"] {
    display    : none;
    align-items: center;
    gap        : 8px;
    font-size  : 12px;
    color      : var(--ug-rt-scanning);
}

.ug-scanning-active [data-rt="antivirus-scanning-row"] {
    display : flex;
}

/* Spinner icon */
.ug-spinner {
    display         : inline-block;
    width           : 14px;
    height          : 14px;
    border          : 2px solid #bfdbfe;
    border-top-color: var(--ug-rt-scanning);
    border-radius   : 50%;
    animation       : ug-spin 0.8s linear infinite;
    flex-shrink     : 0;
}

/* =====================================================================
   Animations
   ===================================================================== */
@keyframes ug-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
}

@keyframes ug-pulse {
    0%    { transform: scale(1);    opacity: 1; }
    50%   { transform: scale(1.5);  opacity: 0.5; }
    100%  { transform: scale(1);    opacity: 1; }
}

@keyframes ug-shimmer {
    0%   { left: -60%; }
    100% { left: 120%; }
}

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

@keyframes ug-slide-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* New rows in live table animate in */
.ug-rt-table tbody tr {
    animation: ug-slide-in 0.25s ease both;
}

/* =====================================================================
   Dark-mode support (WordPress 6.4+ admin dark preference)
   ===================================================================== */
@media (prefers-color-scheme: dark) {
    :root {
        --ug-rt-bg-card  : #1e293b;
        --ug-rt-border   : #334155;
        --ug-rt-text-dark: #f1f5f9;
        --ug-rt-text-mute: #94a3b8;
    }
    .ug-rt-table th           { background: #0f172a; }
    .ug-rt-table tbody tr:hover { background: #1e293b; }
    .ug-has-changes,
    .ug-alert-active           { background: #451a03 !important; }
    .ug-feed-item:hover        { background: #0f172a; }
}

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 782px) {
    .ug-rt-card__stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .ug-rt-table th:nth-child(n+3),
    .ug-rt-table td:nth-child(n+3) {
        display: none;
    }

    [data-rt="threat-feed-list"] { max-height: 240px; }

    .ug-feed-type  { width: 90px; }
    .ug-feed-time  { width: 52px; }
}

@media (max-width: 480px) {
    .ug-rt-card { padding: 12px; }

    .ug-rt-stat__value { font-size: 18px; }

    [data-rt="security-score-arc"] .ug-score-number { font-size: 32px; }
}

/* ── Realtime — tablet (1024px) ────────────────────────────────────────── */
@media screen and (max-width: 1024px) {
  .ug-rt-layout {
    flex-direction: column;
  }

  .ug-rt-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--ug-border);
  }

  .ug-rt-card {
    min-width: 0;
  }

  .ug-rt-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ug-rt-table {
    min-width: 480px;
  }
}

@media screen and (max-width: 782px) {
  .ug-rt-header {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .ug-rt-controls {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  .ug-rt-controls .ultraguard-button {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* Show fewer columns on mobile — hide lower-priority ones */
  .ug-rt-table th:nth-child(n+4),
  .ug-rt-table td:nth-child(n+4) {
    display: none;
  }
}

