:root {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --accent: #22D3EE;
    --accent-hover: #06B6D4;
    --background: #0F172A;
    --surface: rgba(30, 41, 59, 0.7);
    --surface-border: rgba(99, 102, 241, 0.2);
    --text-main: #F8FAFC;
    --text-muted: #94A3B8;

    --node-frontend: rgba(99, 102, 241, 0.15);
    --node-backend: rgba(34, 197, 94, 0.15);
    --node-database: rgba(234, 179, 8, 0.15);
    --node-infra: rgba(239, 68, 68, 0.15);
    --node-border: rgba(248, 250, 252, 0.1);

    --border-radius: 12px;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --transition: all 0.2s ease;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--background);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

/* Layout */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.glass {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--surface-border);
}

/* Sidebar */
.sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.3);
    border-right: 1px solid var(--surface-border);
    border-top: none;
    border-bottom: none;
    border-left: none;
    border-radius: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem;
    border-bottom: 1px solid var(--surface-border);
}

.logo h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #FFF;
}

.logo-icon {
    width: 24px;
    height: 24px;
    color: var(--primary);
}

.sidebar-section {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--surface-border);
}

.sidebar-section h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-weight: 600;
}

.tools-section {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.search-input {
    width: 100%;
    padding: 0.6rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: var(--font-family);
    margin-bottom: 1rem;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.tech-categories {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.category-title {
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.tech-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.tech-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: grab;
    transition: var(--transition);
    user-select: none;
}

.tech-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

.tech-item:active {
    cursor: grabbing;
}

.tech-icon {
    width: 20px;
    height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
}

.tech-name {
    font-size: 0.8rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font-family);
}

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

.w-full {
    width: 100%;
}

.mt-2 {
    margin-top: 0.5rem;
}

.primary-btn {
    background: var(--primary);
    color: #FFF;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.accent-btn {
    background: rgba(239, 68, 68, 0.1);
    color: #EF4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.accent-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

.template-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.6rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.template-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Workspace */
.workspace {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-image:
        radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0);
    background-size: 30px 30px;
}

.toolbar {
    position: absolute;
    top: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1.5rem;
    padding: 0.5rem 1rem;
    border-radius: 30px;
    z-index: 20;
}

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

#zoom-level {
    font-size: 0.85rem;
    font-weight: 500;
    min-width: 45px;
    text-align: center;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    transition: var(--transition);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

/* Canvas Area */
.canvas-container {
    width: 100%;
    height: 100%;
    position: relative;
    cursor: grab;
    transform-origin: 0 0;
}

.canvas-container:active {
    cursor: grabbing;
}

.canvas-surface {
    position: absolute;
    top: 0;
    left: 0;
    width: 5000px;
    height: 5000px;
    transform-origin: 0 0;
}

/* Nodes */
.node {
    position: absolute;
    width: 140px;
    background: var(--surface);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--node-border);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.2s;
    z-index: 5;
}

.node:active {
    cursor: grabbing;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.node.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.4);
}

.node .icon {
    font-size: 2rem;
}

.node .label {
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
}

/* Category styles */
.node[data-category="frontend"] {
    border-top: 3px solid var(--primary);
}

.node[data-category="backend"] {
    border-top: 3px solid #22C55E;
}

.node[data-category="database"] {
    border-top: 3px solid #EAB308;
}

.node[data-category="infra"] {
    border-top: 3px solid #EF4444;
}

/* Ports for connecting */
.port {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--surface);
    border: 2px solid var(--text-muted);
    border-radius: 50%;
    cursor: crosshair;
    transition: var(--transition);
}

.port:hover {
    transform: scale(1.2);
    border-color: var(--primary);
}

.port.top {
    top: -6px;
    left: calc(50% - 6px);
}

.port.right {
    right: -6px;
    top: calc(50% - 6px);
}

.port.bottom {
    bottom: -6px;
    left: calc(50% - 6px);
}

.port.left {
    left: -6px;
    top: calc(50% - 6px);
}

/* Node Controls (Delete) */
.node-delete {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.node:hover .node-delete {
    opacity: 1;
}

/* SVG Connections layer */
.connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.connection-path {
    fill: none;
    stroke: var(--primary);
    stroke-width: 2;
    pointer-events: auto;
    /* Allow clicking path */
    cursor: pointer;
    transition: stroke 0.2s;
}

.connection-path:hover {
    stroke: var(--danger);
    stroke-width: 3;
}

/* Active drawing line */
.active-connection-line {
    position: absolute;
    pointer-events: none;
    border-top: 2px dashed var(--accent);
    transform-origin: 0 50%;
    z-index: 100;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 30px;
    font-weight: 500;
    z-index: 1000;
    transition: var(--transition);
}

.toast.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(20px);
}

/* Remove delete button internally when exporting */
.exporting .node-delete,
.exporting .port {
    display: none !important;
}

.exporting .node {
    box-shadow: none;
    border-color: var(--node-border);
}