/* ============================================
   CHAOS NETWORK — Reusable Components
   ============================================ */

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-sm);
    font-weight: 600;
    border-radius: var(--radius-md);
    transition: all var(--transition-normal);
    position: relative;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: opacity var(--transition-fast);
    border-radius: inherit;
    pointer-events: none;
}
.btn:hover::before { opacity: 1; }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: var(--shadow-md), 0 0 20px var(--primary-glow);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--primary-glow);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary), var(--secondary-dark));
    color: white;
    box-shadow: var(--shadow-md), 0 0 20px var(--secondary-glow);
}
.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--secondary-glow);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #1a1a2e;
    box-shadow: var(--shadow-md), 0 0 20px var(--accent-glow);
}
.btn-accent:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-card);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #dc2626);
    color: white;
}
.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--danger-glow);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
}
.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--success-glow);
}

.btn-sm { padding: var(--space-2) var(--space-4); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-4) var(--space-8); font-size: var(--text-lg); }
.btn-icon {
    width: 38px; height: 38px;
    padding: 0;
    border-radius: var(--radius-md);
}
.btn-icon.btn-sm { width: 32px; height: 32px; }

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    transition: all var(--transition-normal);
}
.card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-lg);
}
.card-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}
.card-glow:hover {
    box-shadow: var(--shadow-glow-primary);
    border-color: rgba(230, 57, 70, 0.3);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}
.card-title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
}

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px 10px;
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: var(--radius-full);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.badge-primary { background: var(--primary-glow); color: var(--primary-light); }
.badge-secondary { background: var(--secondary-glow); color: var(--secondary-light); }
.badge-accent { background: var(--accent-glow); color: var(--accent-light); }
.badge-success { background: var(--success-glow); color: var(--success-light); }
.badge-danger { background: var(--danger-glow); color: var(--danger-light); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning-light); }
.badge-info { background: var(--info-glow); color: var(--info-light); }
.badge-ghost {
    background: rgba(100,116,139,0.15);
    color: var(--text-muted);
}

/* ── Online Status Dot ── */
.status-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px var(--success-glow);
    animation: pulse 2s infinite;
}
.status-dot.offline { background: var(--text-disabled); }
.status-dot.away { background: var(--warning); }

/* ── Form Controls ── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}
.form-label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.form-input {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}
.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: var(--bg-surface);
}
.form-input::placeholder { color: var(--text-disabled); }
.form-input.error { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-glow); }
.form-input.success { border-color: var(--success); box-shadow: 0 0 0 3px var(--success-glow); }

.form-select {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-textarea {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    resize: vertical;
    min-height: 100px;
    font-family: var(--font-ui);
}

/* ── Tables ── */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}
.data-table thead {
    background: var(--bg-surface);
    position: sticky;
    top: 0;
    z-index: 1;
}
.data-table th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: var(--text-xs);
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid rgba(45,45,68,0.5);
    color: var(--text-secondary);
    vertical-align: middle;
}
.data-table tbody tr {
    transition: background var(--transition-fast);
}
.data-table tbody tr:hover {
    background: var(--bg-card-hover);
}
.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6,6,11,0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-bg);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    padding: var(--space-4);
}
.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-spring);
    box-shadow: var(--shadow-xl);
}
.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-6);
    border-bottom: 1px solid var(--border);
}
.modal-title {
    font-size: var(--text-xl);
    font-weight: 700;
}
.modal-close {
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    transition: all var(--transition-fast);
    font-size: 18px;
}
.modal-close:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.modal-body { padding: var(--space-6); }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border);
}

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: var(--space-1);
    padding: var(--space-1);
    background: var(--bg-dark);
    border-radius: var(--radius-md);
    overflow-x: auto;
}
.tab {
    padding: var(--space-2) var(--space-5);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    cursor: pointer;
    white-space: nowrap;
    position: relative;
}
.tab:hover { color: var(--text-primary); background: var(--bg-surface); }
.tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px var(--primary-glow);
}
.tab .tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: rgba(255,255,255,0.2);
    border-radius: var(--radius-full);
    font-size: 10px;
    margin-left: var(--space-2);
}

/* ── Toast Notifications ── */
.toast-container {
    position: fixed;
    top: var(--space-6);
    right: var(--space-6);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: slideInRight 0.4s var(--transition-spring);
    min-width: 300px;
    max-width: 420px;
}
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; font-size: var(--text-sm); }
.toast-message { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.toast-close {
    padding: var(--space-1);
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition-fast);
}
.toast-close:hover { color: var(--text-primary); }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--info); }

/* ── Avatar ── */
.avatar {
    width: 40px; height: 40px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--text-sm);
    color: white;
    flex-shrink: 0;
    text-transform: uppercase;
    position: relative;
}
.avatar-sm { width: 32px; height: 32px; font-size: var(--text-xs); }
.avatar-lg { width: 56px; height: 56px; font-size: var(--text-xl); }
.avatar-xl { width: 72px; height: 72px; font-size: var(--text-2xl); }
.avatar .status-indicator {
    position: absolute;
    bottom: 0; right: 0;
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-card);
}
.avatar .status-indicator.online { background: var(--success); }
.avatar .status-indicator.offline { background: var(--text-disabled); }

/* ── Empty State ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) var(--space-8);
    text-align: center;
}
.empty-state-icon {
    font-size: 48px;
    margin-bottom: var(--space-4);
    opacity: 0.4;
}
.empty-state-title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}
.empty-state-desc {
    font-size: var(--text-sm);
    color: var(--text-muted);
    max-width: 400px;
}

/* ── Loading Spinner ── */
.spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }

/* ── Search Bar ── */
.search-bar {
    position: relative;
    width: 100%;
}
.search-bar input {
    width: 100%;
    padding: var(--space-3) var(--space-4) var(--space-3) 42px;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    background: var(--bg-dark);
    border: 1px solid var(--border);
}
.search-bar .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
    pointer-events: none;
}

/* ── Progress Bar ── */
.progress-bar {
    height: 6px;
    background: var(--bg-dark);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transition: width var(--transition-slow);
}

/* ── Dropdown ── */
.dropdown {
    position: relative;
    display: inline-flex;
}
.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
    padding: var(--space-1);
}
.dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    cursor: pointer;
    width: 100%;
    text-align: left;
}
.dropdown-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: var(--space-1) 0;
}

/* ── Tooltip ── */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 10px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: var(--text-xs);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    pointer-events: none;
    box-shadow: var(--shadow-md);
    z-index: 1000;
}
[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ── Role Colors ── */
.role-owner { color: #ff4d5a; }
.role-coowner { color: #ff6b81; }
.role-admin { color: #e63946; }
.role-manager { color: #f59e0b; }
.role-developer { color: #3b82f6; }
.role-srmod { color: #8b5cf6; }
.role-moderator { color: #10b981; }
.role-builder { color: #06b6d4; }
.role-helper { color: #84cc16; }

.role-bg-owner { background: rgba(255,77,90,0.15); }
.role-bg-coowner { background: rgba(255,107,129,0.15); }
.role-bg-admin { background: rgba(230,57,70,0.15); }
.role-bg-manager { background: rgba(245,158,11,0.15); }
.role-bg-developer { background: rgba(59,130,246,0.15); }
.role-bg-srmod { background: rgba(139,92,246,0.15); }
.role-bg-moderator { background: rgba(16,185,129,0.15); }
.role-bg-builder { background: rgba(6,182,212,0.15); }
.role-bg-helper { background: rgba(132,204,22,0.15); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .modal { max-width: 95vw; }
    .toast-container { left: var(--space-4); right: var(--space-4); }
    .toast { min-width: auto; }
}

/* ── UI Improvements (Module 1) ── */
/* Custom Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-dark); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: rgba(100,116,139,0.3); border-radius: 4px; border: 2px solid var(--bg-dark); }
::-webkit-scrollbar-thumb:hover { background: rgba(100,116,139,0.6); }

/* Focus States */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Skeleton Loaders */
@keyframes shimmer {
    0% { background-position: -1000px 0; }
    100% { background-position: 1000px 0; }
}
.skeleton {
    animation: shimmer 2s infinite linear;
    background: linear-gradient(to right, var(--bg-card) 4%, var(--bg-elevated) 25%, var(--bg-card) 36%);
    background-size: 1000px 100%;
    border-radius: var(--radius-md);
}

/* Enhanced Empty States */
.empty-state-svg { width: 120px; height: 120px; margin-bottom: 24px; opacity: 0.6; fill: var(--text-muted); }

/* Print Styles */
@media print {
    body * { visibility: hidden; }
    #trazModal, #trazModal * { visibility: visible; }
    #trazModal { position: absolute; left: 0; top: 0; width: 100%; box-shadow: none !important; border: none !important; }
    .modal-overlay { background: transparent !important; }
    .modal-close, .modal-footer, .btn, .doc-view-watermark { display: none !important; }
    .doc-view-inner { padding: 0 !important; color: black !important; }
}
