/* ===== Design System Variables ===== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a24;
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(255, 255, 255, 0.08);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --sidebar-width: 260px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at 20% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.08) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
}

.hidden {
    display: none !important;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
}

/* Loading */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 9999;
}

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-screen p {
    margin-top: var(--space-md);
    color: var(--text-secondary);
}

/* Auth */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: var(--space-2xl);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.auth-header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.auth-header .logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    background: var(--accent-gradient);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    color: white;
}

.auth-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-header .subtitle {
    color: var(--text-secondary);
    margin-top: var(--space-xs);
}

.auth-form h2 {
    font-size: 1.25rem;
    margin-bottom: var(--space-lg);
}

.auth-hint {
    text-align: center;
    margin-top: var(--space-lg);
    color: var(--text-muted);
    font-size: 0.8rem;
}

.auth-hint code {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--accent-primary);
    font-family: monospace;
}

/* Form */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    font-family: inherit;
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

.form-actions {
    display: flex;
    gap: var(--space-md);
    justify-content: flex-end;
    margin-top: var(--space-xl);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--error);
    color: white;
}

/* Layout */
.main-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.logo-small {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    color: white;
}

.brand-name {
    font-weight: 600;
    font-size: 1.125rem;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-md);
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-xs);
    transition: all var(--transition-fast);
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-primary);
}

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.avatar {
    width: 36px;
    height: 36px;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: white;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: var(--space-xl);
    min-height: 100vh;
}

.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl);
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.page-header p {
    color: var(--text-secondary);
    margin-top: var(--space-xs);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.stat-card {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
}

.stat-icon {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
}

.stat-icon.running {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.stat-icon.total {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-primary);
}

.stat-icon.certs {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.stat-icon.system {
    background: rgba(59, 130, 246, 0.15);
    color: var(--info);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--space-lg);
}

/* Cards */
.card {
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    padding: var(--space-lg);
}

.quick-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.quick-actions .btn {
    justify-content: flex-start;
}

/* Detection */
.detection-loading {
    color: var(--text-secondary);
    font-style: italic;
}

.detection-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) 0;
    border-bottom: 1px solid var(--border-color);
}

.detection-item:last-child {
    border-bottom: none;
}

.detection-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    font-size: 1.25rem;
}

.detection-icon.installed {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.detection-icon.not-installed {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

.detection-name {
    font-weight: 500;
}

.detection-version {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.detection-recommendation {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--accent-primary);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Nodes */
.nodes-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-lg);
}

.node-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
}

.node-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.node-name {
    font-size: 1.125rem;
    font-weight: 600;
}

.node-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
}

.node-status.running {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.node-status.stopped {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

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

.node-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.node-info-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
}

.node-info-label {
    color: var(--text-secondary);
}

.node-info-value {
    font-weight: 500;
}

.node-actions {
    display: flex;
    gap: var(--space-sm);
}

.node-actions .btn {
    flex: 1;
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
    text-align: center;
}

.empty-state svg {
    opacity: 0.3;
    margin-bottom: var(--space-lg);
}

.empty-state p {
    margin-bottom: var(--space-lg);
    font-size: 1.125rem;
}

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--space-lg);
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-md) 0;
    border-bottom: 1px solid var(--border-color);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-secondary);
}

.info-value {
    font-weight: 500;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-lg);
}

.modal {
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: var(--radius-xl);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: var(--radius-md);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-lg);
}

/* Toast */
#toast-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    min-width: 280px;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--error);
}

.toast.warning {
    border-left: 3px solid var(--warning);
}

.toast.info {
    border-left: 3px solid var(--info);
}

.toast-message {
    flex: 1;
    font-size: 0.875rem;
}

.toast-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.25rem;
    line-height: 1;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
        padding: var(--space-md);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-grid,
    .settings-grid,
    .nodes-list {
        grid-template-columns: 1fr;
    }
}

/* Onboarding Guide */
.guide-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: var(--space-lg);
}

.guide-content {
    width: 100%;
    max-width: 500px;
    padding: var(--space-xl);
    border-radius: var(--radius-xl);
    animation: modalIn 0.4s ease;
}

.guide-header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.guide-header h2 {
    font-size: 1.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.guide-header p {
    color: var(--text-secondary);
    margin-top: var(--space-sm);
}

.guide-step {
    display: none;
    gap: var(--space-md);
}

.guide-step.active {
    display: flex;
}

.step-number {
    width: 40px;
    height: 40px;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.125rem;
    flex-shrink: 0;
}

.step-content h3 {
    font-size: 1.125rem;
    margin-bottom: var(--space-sm);
}

.step-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.step-info {
    background: var(--bg-tertiary);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-top: var(--space-md);
}

.step-info strong {
    display: block;
    margin-bottom: var(--space-sm);
    color: var(--accent-primary);
}

.step-info ul {
    list-style: none;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.step-info li {
    padding: 0.25rem 0;
}

.step-info li::before {
    content: '→';
    margin-right: 0.5rem;
    color: var(--accent-primary);
}

.step-tip {
    margin-top: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: rgba(99, 102, 241, 0.15);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--accent-primary);
}

.guide-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-color);
}

.guide-dots {
    display: flex;
    gap: var(--space-sm);
}

.guide-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    transition: all var(--transition-fast);
}

.guide-dot.active {
    background: var(--accent-primary);
    width: 24px;
    border-radius: 4px;
}

/* Protocol Description */
.protocol-desc {
    margin-top: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: none;
}

.protocol-desc.show {
    display: block;
}

.protocol-desc .recommended {
    color: var(--success);
    font-weight: 500;
}

/* Certificate Info Box */
.cert-info-box {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
}

.cert-info-box p {
    margin-bottom: var(--space-sm);
    color: var(--warning);
}

.cert-info-box ul {
    list-style: none;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.cert-info-box li {
    padding: 0.2rem 0;
}

.cert-info-box li::before {
    content: '•';
    margin-right: 0.5rem;
    color: var(--warning);
}

/* Show Guide Button */
.show-guide-btn {
    margin-top: var(--space-lg);
}

/* Share Modal Styles */
.share-tabs {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: var(--space-sm);
}

.share-tab {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.share-tab:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.share-tab.active {
    background: var(--primary);
    color: white;
}

.share-panel {
    display: none;
}

.share-panel.active {
    display: block;
}

.qrcode-container {
    display: flex;
    justify-content: center;
    padding: var(--space-lg);
    background: white;
    border-radius: var(--radius-md);
    margin: 0 auto;
    max-width: 220px;
}

.share-textarea {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: var(--space-md);
    resize: none;
    font-family: monospace;
    font-size: 0.8rem;
    margin-bottom: var(--space-md);
}

.share-json {
    background: var(--bg-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    color: var(--text);
    font-size: 0.75rem;
    max-height: 200px;
    overflow: auto;
    margin-bottom: var(--space-md);
}

.btn-block {
    width: 100%;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.text-success {
    color: var(--success);
}