/* ====================================================================
   SimpleSecurity Component Layer — "Elevated Refresh"
   Builds ON TOP of themes/unified-theme.css. Do not redefine tokens,
   .card, .btn*, .form-*, or .alert* here — they already exist there.

   Aesthetic: dark + depth (glass, layered blur, real shadow hierarchy).
   One accent (--primary / --accent-primary). success/warning/danger are
   STATUS ONLY — never used as brand decoration.
   ==================================================================== */

/* --------------------------------------------------------------------
   Accessibility — global focus ring (WCAG-AA)
   -------------------------------------------------------------------- */
*:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

/* Respect reduced-motion across every animation/transition in this file */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* --------------------------------------------------------------------
   .glass — elevated depth utility (layered bg + blur + hairline border)
   Use on top of .card, or standalone for panels/popovers/menus.
   -------------------------------------------------------------------- */
.glass {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
}

/* ====================================================================
   Badges / Pills / Status indicators
   ==================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: 600;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
    line-height: 1.6;
}

.pill {
    border-radius: 999px;
    padding: 4px var(--spacing-md);
}

/* Status badge — up/down/warn/critical/ok. Color = meaning, never decoration. */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px var(--spacing-md);
    border-radius: 999px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
    white-space: nowrap;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.status-badge.status-up,
.status-badge.status-ok {
    color: var(--accent-success);
    background: rgba(0, 220, 130, 0.1);
    border-color: rgba(0, 220, 130, 0.2);
}

.status-badge.status-warn {
    color: var(--accent-warning);
    background: rgba(255, 170, 0, 0.1);
    border-color: rgba(255, 170, 0, 0.2);
}

.status-badge.status-down,
.status-badge.status-critical {
    color: var(--accent-danger);
    background: rgba(255, 51, 51, 0.1);
    border-color: rgba(255, 51, 51, 0.2);
}

/* ====================================================================
   Modal — overlay + glass dialog. Markup:
   <div class="modal active"><div class="modal-content" role="dialog" aria-modal="true">
     <div class="modal-header"><h2>Title</h2><button class="modal-close">...</button></div>
     <div class="modal-body">...</div>
     <div class="modal-footer">...</div>
   </div></div>
   ==================================================================== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    overflow-y: auto;
    padding: var(--spacing-lg);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: modal-in 0.2s ease-out;
}

.modal-content:focus {
    outline: none;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h2,
.modal-header h3 {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-base);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--accent-danger);
    border-color: var(--accent-danger);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--spacing-xl);
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-footer {
    padding: var(--spacing-md) var(--spacing-xl);
    border-top: 1px solid var(--border-primary);
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
    position: sticky;
    bottom: 0;
    background: var(--bg-surface);
}

/* ====================================================================
   Data table — wrap the <table class="data-table"> in .table-responsive
   for horizontal scroll on narrow viewports.
   ==================================================================== */
.table-responsive {
    overflow-x: auto;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.data-table thead th {
    background: var(--bg-surface);
    text-align: left;
    padding: var(--spacing-md) var(--spacing-lg);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-primary);
    white-space: nowrap;
}

.data-table tbody td {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-secondary);
    color: var(--text-primary);
    vertical-align: middle;
}

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

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

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

/* Optional zebra striping */
.data-table.zebra tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.data-table.zebra tbody tr:nth-child(even):hover {
    background: var(--bg-surface);
}

/* ====================================================================
   Toast — top-right stack. Managed by navigation/ui-kit.js (UIKit.toast).
   ==================================================================== */
.toast-container {
    position: fixed;
    top: var(--spacing-lg);
    right: var(--spacing-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    max-width: 360px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-left: 3px solid var(--border-primary);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    animation: toast-in 0.2s ease-out;
}

.toast-icon {
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-close {
    margin-left: auto;
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: var(--font-size-sm);
    padding: 0;
    line-height: 1;
}

.toast-close:hover {
    color: var(--text-primary);
}

.toast-success { border-left-color: var(--accent-success); }
.toast-success .toast-icon { color: var(--accent-success); }

.toast-error { border-left-color: var(--accent-danger); }
.toast-error .toast-icon { color: var(--accent-danger); }

.toast-warn { border-left-color: var(--accent-warning); }
.toast-warn .toast-icon { color: var(--accent-warning); }

.toast-info { border-left-color: var(--accent-primary); }
.toast-info .toast-icon { color: var(--accent-primary); }

.toast.toast-hide {
    animation: toast-out 0.15s ease-in forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateX(16px); }
}

/* ====================================================================
   Tooltip — CSS-only, hover + focus
   Markup: <span class="tooltip" data-tooltip="Text">trigger</span>
   ==================================================================== */
.tooltip {
    position: relative;
    display: inline-flex;
}

.tooltip[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--font-size-xs);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-primary);
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    z-index: 1500;
}

.tooltip[data-tooltip]:hover::after,
.tooltip[data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ====================================================================
   Tabs — underline style (active = primary underline, not filled pill)
   ==================================================================== */
.tabs {
    display: flex;
    gap: var(--spacing-lg);
    border-bottom: 1px solid var(--border-primary);
    overflow-x: auto;
}

.tab {
    padding: var(--spacing-md) var(--spacing-xs);
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
    transition: color var(--transition-fast);
}

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

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

.tab.active::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--accent-primary);
}

/* ====================================================================
   Empty state — icon + title + hint, muted
   Markup: <div class="empty-state"><i class="fas fa-inbox"></i><h3>Title</h3><p>Hint</p></div>
   ==================================================================== */
.empty-state {
    text-align: center;
    padding: var(--spacing-3xl) var(--spacing-lg);
    color: var(--text-secondary);
}

.empty-state i,
.empty-state svg {
    font-size: 40px;
    margin-bottom: var(--spacing-md);
    opacity: 0.35;
    color: var(--text-tertiary);
}

.empty-state h2,
.empty-state h3 {
    color: var(--text-primary);
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

.empty-state p {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    max-width: 360px;
    margin: 0 auto;
}

/* ====================================================================
   Skeleton — the ONE acceptable pulse, loading placeholders only.
   Markup: <div class="skeleton" style="width:120px;height:16px;"></div>
   ==================================================================== */
.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    color: transparent !important;
}

.skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
    animation: skeleton-sweep 1.6s ease-in-out infinite;
}

@keyframes skeleton-sweep {
    from { transform: translateX(-100%); }
    to   { transform: translateX(100%); }
}

/* ====================================================================
   Responsive
   ==================================================================== */
@media (max-width: 768px) {
    .modal-content {
        max-width: 100%;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--spacing-md) var(--spacing-lg);
    }

    .modal-footer {
        flex-direction: column-reverse;
    }

    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }

    .toast-container {
        top: var(--spacing-md);
        right: var(--spacing-md);
        left: var(--spacing-md);
        max-width: none;
    }

    .data-table thead th,
    .data-table tbody td {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .tabs {
        gap: var(--spacing-md);
    }
}
