/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color Palette */
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --info-color: #06b6d4;
    
    /* Neutral Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border-color: #e2e8f0;
    
    /* Dark Mode Colors */
    --dark-bg-primary: #0f172a;
    --dark-bg-secondary: #1e293b;
    --dark-bg-tertiary: #334155;
    --dark-text-primary: #f1f5f9;
    --dark-text-secondary: #cbd5e1;
    --dark-border-color: #475569;
    
    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    
    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 350ms ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: var(--spacing-xl);
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.logo i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

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

.nav-section {
    padding: var(--spacing-lg);
}

.nav-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: var(--spacing-md);
    letter-spacing: 0.05em;
}

.nav-list {
    list-style: none;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    margin-bottom: var(--spacing-xs);
}

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

.nav-link.active {
    background-color: var(--primary-color);
    color: white;
}

.nav-link i {
    width: 20px;
    margin-right: var(--spacing-sm);
}

.nav-link .count {
    margin-left: auto;
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.nav-link.active .count {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xl);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.content-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Content Sections */
.content-section {
    display: none;
    flex: 1;
    padding: var(--spacing-xl);
    overflow-y: auto;
}

.content-section.active {
    display: block;
}

/* Config List */
.config-list {
    display: grid;
    gap: var(--spacing-md);
}

.config-item {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    transition: all var(--transition-fast);
}

.config-item:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

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

.config-item-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.config-item-actions {
    display: flex;
    gap: var(--spacing-xs);
}

.config-item-details {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.config-detail {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.config-detail i {
    width: 16px;
    color: var(--text-tertiary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
}

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

.btn-secondary:hover {
    background-color: var(--secondary-hover);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background-color: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-sm {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.75rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--spacing-xl) * 2;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    color: var(--text-tertiary);
    margin-bottom: var(--spacing-md);
}

.empty-state h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

/* Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.required {
    color: var(--error-color);
}

/* Checkboxes */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-wide {
    max-width: 900px;
}

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

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

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

.modal-form {
    padding: var(--spacing-lg);
    overflow-y: auto;
    flex: 1;
}

.modal-form > * + * {
    margin-top: var(--spacing-lg);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-md);
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
}

/* Form Sections */
.form-section {
    padding: var(--spacing-lg);
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.form-section h4,
.form-section h5 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
}

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

/* Dynamic Lists */
.dynamic-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.dynamic-item {
    padding: var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

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

.dynamic-item-title {
    font-weight: 500;
    color: var(--text-primary);
}

.remove-item {
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    padding: var(--spacing-xs);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.remove-item:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

/* Badges */
.protocol-badge,
.transport-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

.protocol-badge {
    background-color: var(--info-color);
    color: white;
}

.transport-badge {
    background-color: var(--secondary-color);
    color: white;
}

/* Protocol-specific colors */
.protocol-http { background-color: #3b82f6; }
.protocol-socks { background-color: #8b5cf6; }
.protocol-shadowsocks { background-color: #10b981; }
.protocol-vmess { background-color: #f59e0b; }
.protocol-vless { background-color: #06b6d4; }
.protocol-trojan { background-color: #ef4444; }
.protocol-snell { background-color: #ec4899; }
.protocol-hysteria2 { background-color: #14b8a6; }
.protocol-tuicv5 { background-color: #6366f1; }
.protocol-forward { background-color: #64748b; }

/* Import/Export Section */
.import-export-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-xl);
}

.import-section,
.export-section {
    background-color: var(--bg-primary);
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.import-section h3,
.export-section h3 {
    margin-bottom: var(--spacing-lg);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.file-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl) * 2;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.file-upload-area:hover,
.file-upload-area.drag-over {
    border-color: var(--primary-color);
    background-color: var(--bg-secondary);
}

.file-upload-area i {
    font-size: 3rem;
    color: var(--text-tertiary);
    margin-bottom: var(--spacing-md);
}

.file-upload-area p {
    color: var(--text-secondary);
}

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

/* Validation Section */
.validation-container {
    background-color: var(--bg-primary);
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.validation-container h3 {
    margin-bottom: var(--spacing-md);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.validation-container p {
    margin-bottom: var(--spacing-lg);
    color: var(--text-secondary);
}

.validation-results {
    margin-top: var(--spacing-xl);
}

.validation-item {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-sm);
}

.validation-item.success {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.validation-item.error {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
}

.validation-item.warning {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.validation-item i {
    font-size: 1.25rem;
    margin-top: 2px;
}

.validation-item strong {
    display: block;
    margin-bottom: var(--spacing-xs);
}

.validation-item small {
    display: block;
    margin-top: var(--spacing-xs);
    opacity: 0.8;
}

/* YAML Preview */
.yaml-preview-container {
    flex: 1;
    overflow: auto;
    padding: var(--spacing-lg);
    background-color: var(--bg-secondary);
}

#yaml-preview-content {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre;
    margin: 0;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: var(--spacing-xl);
    right: var(--spacing-xl);
    background-color: var(--bg-primary);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    transform: translateY(100px);
    opacity: 0;
    transition: all var(--transition-base);
    z-index: 2000;
    border: 1px solid var(--border-color);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

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

.toast.error {
    border-color: var(--error-color);
}

.toast.warning {
    border-color: var(--warning-color);
}

.toast.info {
    border-color: var(--info-color);
}

.toast-icon {
    font-size: 1.25rem;
}

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

.toast.error .toast-icon {
    color: var(--error-color);
}

.toast.warning .toast-icon {
    color: var(--warning-color);
}

.toast.info .toast-icon {
    color: var(--info-color);
}

.toast-message {
    font-size: 0.875rem;
    color: var(--text-primary);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.loading-overlay.active {
    display: flex;
}

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

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

.loading-overlay p {
    color: white;
    font-size: 1rem;
    font-weight: 500;
}

/* PEM Field Components */
.pem-field-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.pem-select {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color var(--transition-base);
}

.pem-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.pem-extra-input {
    margin-top: var(--spacing-sm);
}

.pem-new-fields,
.pem-inline-field {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.pem-inline-textarea {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.8rem;
    background-color: var(--bg-tertiary);
    border: 2px dashed var(--warning-color);
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: var(--spacing-xs);
}

.help-text.warning {
    color: var(--warning-color);
    font-weight: 500;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .import-export-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        height: 100%;
        transition: left var(--transition-base);
        z-index: 100;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 95%;
        margin: var(--spacing-md);
    }
}