/* CSS Variables */
:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #383838;
    --bg-canvas: #191919;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent: #0d99ff;
    --accent-hover: #0077cc;
    --border: #404040;
    --selection: rgba(13, 153, 255, 0.3);
    --handle-fill: #ffffff;
    --handle-stroke: #0d99ff;
    --panel-width: 240px;
    --toolbar-height: 48px;
}

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

/* Base Styles */
html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    user-select: none;
    -webkit-user-select: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

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

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-section.align-tools {
    border-left: 1px solid var(--border);
    padding-left: 8px;
    margin-left: 4px;
}

.logo {
    font-weight: 600;
    font-size: 14px;
    gap: 8px;
}

.logo-icon {
    color: var(--accent);
    font-size: 20px;
}

.tool-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

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

.tool-btn.active {
    background: var(--accent);
    color: white;
}

.tool-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.zoom {
    gap: 8px;
}

.zoom button {
    width: 28px;
    height: 28px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 4px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 16px;
}

.zoom button:hover {
    background: var(--border);
}

#zoom-level {
    min-width: 50px;
    text-align: center;
}

.actions {
    gap: 8px;
}

.actions button {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 12px;
}

.actions button:hover {
    background: var(--border);
}

#export-btn {
    background: var(--accent) !important;
}

#export-btn:hover {
    background: var(--accent-hover) !important;
}

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

/* Panels */
#layers-panel, #properties-panel {
    width: var(--panel-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#properties-panel {
    border-right: none;
    border-left: 1px solid var(--border);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 500;
}

.panel-header button {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
}

.panel-header button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Layers List */
#layers-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.layer-item {
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    gap: 8px;
    margin-bottom: 2px;
}

.layer-item:hover {
    background: var(--bg-tertiary);
}

.layer-item.selected {
    background: var(--selection);
}

.layer-item.group {
    padding-left: 8px;
}

.layer-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.layer-icon svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.layer-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-visibility {
    opacity: 0.5;
    cursor: pointer;
}

.layer-visibility:hover {
    opacity: 1;
}

.layer-children {
    padding-left: 16px;
}

/* Properties Panel */
#properties-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.property-section {
    margin-bottom: 16px;
}

.property-section h4 {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.property-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.property-row label {
    min-width: 20px;
    color: var(--text-secondary);
}

.property-row input[type="number"],
.property-row input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 12px;
}

.property-row input:focus {
    outline: none;
    border-color: var(--accent);
}

.property-row input[type="color"] {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.property-row select {
    flex: 1;
    padding: 6px 8px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
}

.property-row select:focus {
    outline: none;
    border-color: var(--accent);
}

.property-row span {
    color: var(--text-secondary);
    min-width: 20px;
}

/* Canvas */
#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-canvas);
    background-image:
        radial-gradient(circle, #333 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Rulers */
.ruler {
    position: absolute;
    background: var(--bg-secondary);
    z-index: 10;
}

.ruler-horizontal {
    top: 0;
    left: 20px;
    right: 0;
    height: 20px;
    border-bottom: 1px solid var(--border);
}

.ruler-vertical {
    top: 20px;
    left: 0;
    bottom: 0;
    width: 20px;
    border-right: 1px solid var(--border);
}

.ruler-corner {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    z-index: 11;
}

.ruler-canvas {
    display: block;
}

#main-canvas, #overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

#overlay-canvas {
    pointer-events: none;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    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(--bg-secondary);
    border-radius: 8px;
    padding: 24px;
    min-width: 300px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    margin-bottom: 16px;
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.export-options label {
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
}

.export-options select {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 12px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

#export-cancel {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

#export-confirm {
    background: var(--accent);
    color: white;
}

/* Context Menu */
#context-menu {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    min-width: 160px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

#context-menu.hidden {
    display: none;
}

#context-menu button {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    font-size: 12px;
}

#context-menu button:hover {
    background: var(--bg-tertiary);
}

.context-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* Selection Handles */
.selection-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--handle-fill);
    border: 1.5px solid var(--handle-stroke);
    border-radius: 1px;
    transform: translate(-50%, -50%);
}

/* Cursor Styles */
.cursor-move { cursor: move; }
.cursor-nwse { cursor: nwse-resize; }
.cursor-nesw { cursor: nesw-resize; }
.cursor-ns { cursor: ns-resize; }
.cursor-ew { cursor: ew-resize; }
.cursor-crosshair { cursor: crosshair; }
.cursor-text { cursor: text; }
.cursor-grab { cursor: grab; }
.cursor-grabbing { cursor: grabbing; }

/* Text Input Overlay */
#text-input-overlay {
    position: absolute;
    border: 2px solid var(--accent);
    background: transparent;
    outline: none;
    font-family: inherit;
    resize: none;
    overflow: hidden;
    z-index: 50;
}

/* Guides */
.guide-line {
    position: absolute;
    background: var(--accent);
    pointer-events: none;
    z-index: 40;
}

.guide-line.horizontal {
    height: 1px;
    left: 0;
    right: 0;
}

.guide-line.vertical {
    width: 1px;
    top: 0;
    bottom: 0;
}

/* Loading Spinner */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Small Button */
.small-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

/* Shadow Item */
.shadow-item {
    background: var(--bg-tertiary);
    border-radius: 4px;
    padding: 6px;
    margin-bottom: 4px;
}

.shadow-item input[type="color"] {
    width: 24px;
    height: 24px;
}

.shadow-item input[type="number"] {
    width: 40px;
    padding: 4px 6px;
    font-size: 11px;
}

/* Gradient Controls */
#gradient-controls {
    background: var(--bg-tertiary);
    border-radius: 4px;
    padding: 8px;
    margin-top: 8px;
}

#gradient-controls .property-row {
    margin-bottom: 6px;
}

#gradient-controls .property-row:last-child {
    margin-bottom: 0;
}

/* Effects Section */
#effects-section .property-row label,
#gradient-section .property-row label {
    flex: 0 0 50px;
}

/* Responsive */
@media (max-width: 1200px) {
    :root {
        --panel-width: 200px;
    }
}

@media (max-width: 900px) {
    #layers-panel {
        display: none;
    }
}
