/* ============================================================
   components.css — Reusable UI primitives
   ============================================================ */

/* ── Card ───────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: background-color var(--t), border-color var(--t), box-shadow var(--t);
}
.card-hover { transition: all var(--t); }
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.125rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.875rem;
    line-height: 1.25rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--t);
    white-space: nowrap;
    user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--brand-600);
    color: var(--text-inverse);
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) {
    background: var(--brand-700);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--bg-muted);
    color: var(--text-primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg-muted);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger-500);
    color: white;
}
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-sm { padding: 0.4rem 0.875rem; font-size: 0.8125rem; }
.btn-icon {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    transition: all var(--t);
}
.btn-icon:hover {
    background: var(--bg-muted);
    color: var(--text-primary);
}

/* ── Inputs ─────────────────────────────────────────────── */
.input, .select, .textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.25rem;
    transition: all var(--t);
    outline: none;
}
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.15);
}
.input::placeholder, .textarea::placeholder { color: var(--text-soft); }
.textarea { resize: vertical; min-height: 80px; }
.input-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75rem; }

.label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}
.label-req::after { content: ' *'; color: var(--danger-500); }
.help-text { font-size: 0.75rem; color: var(--text-soft); margin-top: 0.375rem; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.5;
}
.badge-free    { background: var(--success-bg); color: var(--success-fg); }
.badge-pro     { background: var(--warning-bg); color: var(--warning-fg); }
.badge-info    { background: var(--info-bg);    color: var(--info-fg); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-fg); }
.badge-neutral { background: var(--bg-muted);   color: var(--text-secondary); }

.dot {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 999px;
    background: currentColor;
}

/* ── Status pill ────────────────────────────────────────── */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}
.status-active { background: var(--success-bg); color: var(--success-fg); }
.status-active .dot { background: var(--success-500); }
.status-disabled { background: var(--danger-bg); color: var(--danger-fg); }
.status-disabled .dot { background: var(--danger-500); }

/* ── Toast ──────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 260px;
    max-width: 24rem;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity var(--t), transform var(--t);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success-500); }
.toast-error   { background: var(--danger-500); }
.toast-warning { background: var(--warning-500); }
.toast-info    { background: var(--brand-600); }

/* ── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--bg-backdrop);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.modal-panel {
    position: relative;
    width: 100%;
    max-width: 32rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-height: 90vh;
    overflow: auto;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-soft);
}
.modal-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--text-primary);
}
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-soft);
}

/* ── Image viewer (clean, full-bleed) ───────────────────── */
.image-viewer {
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 2rem;
}
.image-viewer-stage {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.image-viewer-img {
    max-width: 90vw;
    max-height: 88vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.7);
    display: block;
}
.image-viewer-actions {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    display: flex;
    gap: 0.375rem;
    opacity: 0;
    transition: opacity var(--t);
}
.image-viewer-stage:hover .image-viewer-actions,
.image-viewer-actions:focus-within {
    opacity: 1;
}
.image-viewer-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: white;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    cursor: pointer;
    text-decoration: none;
    font-size: 0.8125rem;
    transition: background var(--t-fast), transform var(--t-fast);
}
.image-viewer-btn:hover {
    background: rgba(0, 0, 0, 0.85);
    transform: scale(1.05);
}

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 4rem 1.5rem;
    color: var(--text-muted);
}
.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    border-radius: var(--radius-xl);
    background: var(--bg-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--text-faint);
}
.empty-state-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
}
.empty-state-desc {
    font-size: 0.875rem;
    margin-top: 0.25rem;
    margin-bottom: 1.25rem;
    color: var(--text-soft);
}

/* ── Loading ────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border-color);
    border-top-color: var(--brand-600);
    border-radius: 999px;
    animation: spin 0.7s linear infinite;
}
.loading-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 4rem 1rem;
    color: var(--text-soft);
    font-size: 0.875rem;
}

/* ── Switch ─────────────────────────────────────────────── */
.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 38px;
    height: 22px;
    border-radius: 999px;
    background: var(--border-strong);
    cursor: pointer;
    transition: background var(--t);
    flex-shrink: 0;
}
.switch.on { background: var(--brand-600); }
.switch-thumb {
    position: absolute;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: white;
    box-shadow: var(--shadow-sm);
    transition: left var(--t);
}
.switch.on .switch-thumb { left: 19px; }

/* ── Tables ─────────────────────────────────────────────── */
.data-table { width: 100%; font-size: 0.875rem; border-collapse: collapse; }
.data-table thead tr {
    background: var(--bg-surface-2);
    border-bottom: 1px solid var(--border-soft);
}
.data-table th {
    padding: 0.75rem 1.25rem;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.data-table td {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-soft);
}
.data-table tbody tr {
    transition: background var(--t-fast);
}
.data-table tbody tr:hover { background: var(--bg-surface-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }

/* ── Code chip ──────────────────────────────────────────── */
.code-chip {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: var(--bg-muted);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.6875rem;
}

/* ── Page header ────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.75rem;
}
.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.25;
}
.page-subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ── Stat card ──────────────────────────────────────────── */
.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.125rem 1.25rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    transition: all var(--t);
}
.stat-card:hover { border-color: var(--brand-200); box-shadow: var(--shadow-md); }
.dark .stat-card:hover { border-color: var(--brand-800); }
.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1rem;
    flex-shrink: 0;
}
.stat-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.stat-value {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin-top: 0.125rem;
}

/* ── Theme toggle ───────────────────────────────────────── */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--bg-muted);
    border-radius: var(--radius-full);
}
.theme-toggle-btn {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    color: var(--text-soft);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--t);
}
.theme-toggle-btn:hover { color: var(--text-primary); }
.theme-toggle-btn.active {
    background: var(--bg-surface);
    color: var(--brand-600);
    box-shadow: var(--shadow-sm);
}

/* ── Skeleton shimmer ───────────────────────────────────── */
@keyframes shimmer-flow {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.shimmer-wave {
    background: linear-gradient(90deg,
        var(--bg-muted) 0%,
        var(--bg-surface-2) 30%,
        var(--bg-surface) 50%,
        var(--bg-surface-2) 70%,
        var(--bg-muted) 100%);
    background-size: 200% 100%;
    animation: shimmer-flow 1.6s linear infinite;
}

/* ── Utility ────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border-soft); margin: 1rem 0; }
.text-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Range slider — default styling */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: var(--bg-muted);
    border-radius: 999px;
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    background: var(--brand-600);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(124,58,237,0.4);
    transition: transform var(--t);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
