/* ===== Design Tokens ===== */
:root {
    /* Teal Cyan Palette */
    --primary: #00CEC9;
    --primary-hover: #01b4b0;
    --secondary: #81ECEC;
    --accent: #FF7675;
    --accent-hover: #e06c6b;

    --bg-deep: #050a0a;
    --bg-base: #0A1A1A;
    --bg-panel: rgba(16, 36, 36, 0.7);
    --bg-input: rgba(5, 10, 10, 0.5);
    --bg-hover: rgba(0, 206, 201, 0.1);

    --border: rgba(129, 236, 236, 0.15);
    --border-focus: rgba(0, 206, 201, 0.5);
    --border-light: rgba(255, 255, 255, 0.1);

    --text-main: #E2E8F0;
    --text-muted: #94A3B8;
    --text-dim: #475569;

    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', 'Courier New', monospace;

    /* Layout */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-panel: 0 12px 40px rgba(0, 0, 0, 0.5);

    /* Node Colors */
    --type-api: #6C5CE7;
    --type-service: #0984E3;
    --type-db: #E17055;
    --type-cache: #FDCB6E;
    --type-queue: #00B894;
}

/* ===== Resets & Base ===== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

input,
textarea {
    user-select: text;
}

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

.code-font {
    font-family: var(--font-mono);
}

/* ===== Layout ===== */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.workspace-wrapper {
    display: flex;
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* ===== Toolbar ===== */
.toolbar {
    height: 60px;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.tools-center {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    padding: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.zoom-level {
    font-size: 0.85rem;
    font-family: var(--font-mono);
    width: 50px;
    text-align: center;
}

.tools-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    padding: 8px 16px;
    border: 1px solid transparent;
}

.btn-icon {
    padding: 6px;
    background: transparent;
    color: var(--text-muted);
}

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

.btn-sm {
    padding: 4px;
}

.btn-primary {
    background: var(--primary);
    color: var(--bg-deep);
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 16px rgba(0, 206, 201, 0.4);
}

.btn-outline {
    border-color: var(--border);
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.02);
}

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

.btn-danger {
    color: var(--accent);
}

.btn-danger:hover {
    background: rgba(255, 118, 117, 0.1);
    border-color: var(--accent);
}

.btn-block {
    width: 100%;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 280px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-section {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-section h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--secondary);
    margin-bottom: 16px;
}

.node-library {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.library-node {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: grab;
    color: var(--text-main);
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--transition);
}

.library-node:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

/* Node Icons logic */
.library-node.type-api svg {
    color: var(--type-api);
}

.library-node.type-service svg {
    color: var(--type-service);
}

.library-node.type-db svg {
    color: var(--type-db);
}

.library-node.type-cache svg {
    color: var(--type-cache);
}

.library-node.type-queue svg {
    color: var(--type-queue);
}

/* Radio buttons */
.conn-tools {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
}

.radio-label input {
    display: none;
}

.radio-custom {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.radio-label input:checked+.radio-custom {
    border-color: var(--primary);
}

.radio-label input:checked+.radio-custom::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}

.radio-label input:checked~span {
    color: var(--text-main);
}

.hints p {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.hints strong {
    color: var(--text-muted);
}

/* ===== Canvas Area ===== */
.canvas-container {
    flex: 1;
    background-color: var(--bg-base);
    position: relative;
    overflow: hidden;
    cursor: grab;
}

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

.workspace {
    position: absolute;
    top: 0;
    left: 0;
    width: 5000px;
    height: 5000px;
    transform-origin: 0 0;
    /* initial transform will be applied via js */
}

/* Background Grid */
.grid-bg {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
}

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

.conn-path {
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 2;
    cursor: pointer;
    pointer-events: auto;
    /* allow clicking to select */
    transition: stroke var(--transition);
}

.conn-path:hover {
    stroke: var(--secondary);
    stroke-width: 3;
}

.conn-path.selected {
    stroke: var(--primary);
    stroke-width: 3;
}

.conn-path.drawing {
    stroke: var(--primary);
    stroke-dasharray: 6 6;
    pointer-events: none;
}

/* Connection Type Styles */
.conn-path.sync {
    stroke-dasharray: 0;
}

.conn-path.async {
    stroke-dasharray: 6 6;
}

.conn-path.socket {
    stroke-dasharray: 2 4;
    stroke-width: 3;
}

/* Nodes Layer */
.nodes-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
}

/* Individual Node */
.node {
    position: absolute;
    width: 180px;
    background: rgba(15, 25, 25, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    cursor: grab;
    transition: box-shadow var(--transition);
}

.node.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary), 0 8px 24px rgba(0, 206, 201, 0.2);
}

.node-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

/* Color codes */
.node[data-type="API"] .node-header svg {
    color: var(--type-api);
}

.node[data-type="Service"] .node-header svg {
    color: var(--type-service);
}

.node[data-type="Database"] .node-header svg {
    color: var(--type-db);
}

.node[data-type="Cache"] .node-header svg {
    color: var(--type-cache);
}

.node[data-type="Queue"] .node-header svg {
    color: var(--type-queue);
}

.node-title {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.node-body {
    padding: 10px 14px;
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.node-body span {
    font-family: var(--font-mono);
}

/* Connection Ports */
.port {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--bg-deep);
    border: 2px solid var(--text-muted);
    border-radius: 50%;
    cursor: crosshair;
    z-index: 10;
    transition: all var(--transition);
}

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

/* 4 standard ports: top, right, bottom, left */
.port-t {
    top: -7px;
    left: calc(50% - 7px);
}

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

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

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

/* ===== Properties Panel ===== */
.properties-panel {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 320px;
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-panel);
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.properties-panel.hidden {
    display: none;
}

.panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    font-size: 1rem;
    color: var(--text-main);
}

.panel-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.form-control {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border var(--transition);
}

.form-control:focus {
    border-color: var(--primary);
}

/* ===== Modals ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 500px;
    max-width: 90vw;
    box-shadow: var(--shadow-panel);
}

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

.modal-header h2 {
    font-size: 1.1rem;
    color: var(--secondary);
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--secondary);
    color: var(--bg-deep);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition);
    box-shadow: 0 8px 24px rgba(129, 236, 236, 0.3);
    z-index: 9999;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}