:root {
    --bg-app: #f3f4f6;
    --bg-sidebar: #ffffff;
    --bg-canvas: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --grid-line-color: #d1d5db;
    --box-bg: #eff6ff;
    --box-border: #3b82f6;
    --box-handle: #2563eb;

    --font-heading: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    font-family: var(--font-heading);
    background-color: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

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

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

.control-group h2 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-weight: 600;
}

.input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.input-row.full-width {
    margin-top: -0.5rem;
    margin-bottom: 1rem;
}

.input-row input[type="text"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.input-row label {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.input-row input[type="number"] {
    width: 80px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* Tools */
.tool-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-app);
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s;
    user-select: none;
}

.tool-item:hover {
    border-color: var(--accent-color);
    background: #f0f9ff;
}

.tool-item .icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-color);
    color: white;
    border-radius: 4px;
    font-weight: bold;
}

/* Code Output */
.code-block {
    background: #1e293b;
    border-radius: 6px;
    padding: 1rem;
    overflow-x: auto;
    margin-bottom: 1rem;
}

code {
    font-family: var(--font-mono);
    color: #e2e8f0;
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-all;
}

.btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

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

/* Canvas Area */
.canvas-area {
    flex: 1;
    background-color: var(--bg-canvas);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    overflow: auto;
    position: relative;
}

.grid-canvas {
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    position: relative;
    /* Grid layout will be applied via inline styles from JS */
    display: grid;
    min-width: 600px;
    min-height: 400px;
    width: 80%;
    height: 80%;
    /* Default grid for initial render */
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 16px;
}

/* Layers inside canvas */
.grid-lines-layer,
.grid-items-layer,
.grid-preview-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through by default, items will re-enable */
}

.grid-lines-layer {
    display: grid;
    /* This will match the parent grid via JS or inheritance if possible, 
       but simplified: we might just use the parent's grid-gap to show background */
    z-index: 1;
}

/* We will implement grid lines using a different technique or just children divs 
   For now, let's assume we render 'cell' divs into the lines layer */
.grid-cell-marker {
    border: 1px dashed var(--grid-line-color);
    width: 100%;
    height: 100%;
}

.grid-items-layer {
    display: grid;
    grid-template-columns: inherit;
    grid-template-rows: inherit;
    gap: inherit;
    z-index: 10;
}

.grid-box {
    background-color: var(--box-bg);
    border: 2px solid var(--box-border);
    border-radius: 4px;
    pointer-events: auto;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    color: var(--accent-color);
    font-size: 0.8rem;
    user-select: none;
    cursor: default;
}

.delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: white;
    border: 1px solid var(--box-border);
    color: var(--box-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
}

.grid-box:hover .delete-btn {
    opacity: 1;
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 2px solid var(--box-handle);
    border-radius: 50%;
    z-index: 20;
    opacity: 0;
    transition: opacity 0.2s;
}

.grid-box:hover .resize-handle {
    opacity: 1;
}

/* Corner positions */
.handle-nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.handle-ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.handle-sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.handle-se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.grid-preview-layer {
    display: grid;
    grid-template-columns: inherit;
    grid-template-rows: inherit;
    gap: inherit;
    z-index: 100;
}

.preview-box {
    background-color: rgba(59, 130, 246, 0.2);
    border: 2px dashed var(--accent-color);
    border-radius: 4px;
}