/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
    --sidebar-width: 320px;
    --header-height: 80px;
    --footer-height: 50px;
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1800px;
    margin: 0 auto;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

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

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

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

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

/* Panels */
.panel {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.panel h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary-color);
    border-radius: 10px;
}

/* Tabs */
.input-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    background: var(--surface-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

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

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

.tab-content {
    display: none;
}

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

/* Form Elements */
.form-group {
    margin-bottom: 0.875rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

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

.form-group input[type="text"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-primary);
    transition: var(--transition);
}

.form-group input[type="text"]:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.8125rem;
}

.form-group input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.checkbox-group label {
    margin-bottom: 0;
    cursor: pointer;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

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

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

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    margin-top: 0.5rem;
}

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

.btn-danger {
    background: var(--danger-color);
    color: white;
    margin-top: 0.5rem;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-export {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

.btn-link {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: underline;
}

/* Export Buttons */
.export-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.export-buttons .btn-export:last-child {
    grid-column: span 2;
}

/* Components List */
.components-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 0.5rem;
}

.component-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--surface-hover);
    border-radius: var(--radius);
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
}

.component-item:last-child {
    margin-bottom: 0;
}

.component-name {
    font-weight: 500;
    color: var(--text-primary);
}

.component-deps-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.component-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    line-height: 1;
    transition: var(--transition);
}

.component-remove:hover {
    color: var(--danger-color);
}

.empty-state {
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    padding: 1rem;
}

/* Graph Container */
.graph-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--background);
    overflow: hidden;
}

/* Graph Toolbar */
.graph-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.toolbar-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--primary-color);
}

.zoom-level {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

/* Circular Warning */
.circular-warning {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #fef3c7;
    border-bottom: 1px solid #fcd34d;
    color: #92400e;
    font-size: 0.875rem;
    font-weight: 500;
}

.circular-warning svg {
    color: var(--warning-color);
}

.circular-warning.hidden {
    display: none;
}

/* Graph Wrapper */
.graph-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#graph-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Graph Empty State */
.graph-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
}

.graph-empty-state svg {
    margin-bottom: 1rem;
    opacity: 0.5;
}

.graph-empty-state h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.graph-empty-state p {
    font-size: 0.875rem;
}

.graph-empty-state.hidden {
    display: none;
}

/* Node Details Panel */
.node-details {
    position: absolute;
    top: 60px;
    right: 1rem;
    width: 280px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.node-details.hidden {
    display: none;
}

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

.node-details-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

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

.node-details-content {
    padding: 1rem;
}

.detail-section {
    margin-bottom: 1rem;
}

.detail-section:last-child {
    margin-bottom: 0;
}

.detail-section h4 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.detail-section ul {
    list-style: none;
}

.detail-section li {
    font-size: 0.875rem;
    padding: 0.375rem 0.5rem;
    background: var(--surface-hover);
    border-radius: var(--radius-sm);
    margin-bottom: 0.25rem;
}

.detail-section .empty {
    color: var(--text-muted);
    font-style: italic;
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
}

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

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

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: 60vh;
}

.modal-body p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.modal-body ul {
    list-style: none;
}

.modal-body li {
    padding: 0.75rem 1rem;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #92400e;
}

/* Footer */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    text-align: center;
}

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

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.footer a:hover {
    text-decoration: underline;
}

/* SVG Graph Styles */
.node {
    cursor: pointer;
}

.node circle {
    fill: var(--primary-color);
    stroke: white;
    stroke-width: 2px;
    transition: var(--transition);
}

.node:hover circle {
    fill: var(--primary-hover);
    filter: drop-shadow(0 4px 6px rgba(99, 102, 241, 0.4));
}

.node.circular circle {
    fill: var(--warning-color);
}

.node.selected circle {
    stroke: var(--primary-hover);
    stroke-width: 3px;
}

.node text {
    font-size: 12px;
    font-weight: 500;
    fill: var(--text-primary);
    text-anchor: middle;
    pointer-events: none;
}

.link {
    stroke: var(--border-color);
    stroke-width: 2px;
    fill: none;
}

.link.circular {
    stroke: var(--warning-color);
    stroke-dasharray: 5, 5;
}

.link-arrow {
    fill: var(--border-color);
}

.link.circular .link-arrow,
.link-arrow.circular {
    fill: var(--warning-color);
}

/* Mobile Responsive */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        overflow-x: auto;
        padding: 0.75rem;
    }

    .panel {
        min-width: 280px;
        flex: 1;
    }

    .graph-container {
        min-height: 50vh;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
    }

    .header {
        padding: 0.75rem 1rem;
    }

    .header h1 {
        font-size: 1.125rem;
    }

    .subtitle {
        display: none;
    }

    .sidebar {
        flex-direction: column;
        max-height: none;
        overflow-x: visible;
    }

    .panel {
        min-width: auto;
    }

    .node-details {
        width: calc(100% - 2rem);
        right: 1rem;
        left: 1rem;
    }

    .graph-toolbar {
        padding: 0.5rem;
    }

    .toolbar-btn {
        width: 32px;
        height: 32px;
    }

    .export-buttons {
        grid-template-columns: 1fr;
    }

    .export-buttons .btn-export:last-child {
        grid-column: auto;
    }
}

@media (max-width: 480px) {
    .input-tabs {
        flex-direction: column;
    }

    .modal-content {
        width: 95%;
        margin: 1rem;
    }
}

/* Fullscreen Mode */
.fullscreen .graph-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
}

.fullscreen .sidebar,
.fullscreen .header,
.fullscreen .footer {
    display: none;
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Animation for nodes */
@keyframes nodeAppear {
    from {
        opacity: 0;
        transform: scale(0);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.node {
    animation: nodeAppear 0.3s ease-out;
}
