/* CSS Variables */
:root {
    --primary-color: #4A90D9;
    --primary-hover: #3A7BC8;
    --secondary-color: #6B7280;
    --secondary-hover: #4B5563;
    --danger-color: #EF4444;
    --danger-hover: #DC2626;
    --background-color: #F3F4F6;
    --surface-color: #FFFFFF;
    --border-color: #E5E7EB;
    --text-primary: #1F2937;
    --text-secondary: #6B7280;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --sidebar-width: 240px;
    --header-height: 60px;
    --footer-height: 40px;
    --mobile-toolbar-height: 60px;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    overflow: hidden;
}

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

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 20px;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
}

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

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

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

.header-actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

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

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

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

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

.btn-small {
    padding: 4px 12px;
    font-size: 0.75rem;
}

.btn-full {
    width: 100%;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - var(--header-height) - var(--footer-height));
}

/* Sidebars */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

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

/* Shape Library */
.shape-library {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.shape-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background-color: var(--background-color);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

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

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

/* Tools */
.tools {
    display: flex;
    gap: 8px;
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background-color: var(--background-color);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

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

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

/* Property Groups */
.property-group {
    margin-bottom: 16px;
}

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

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

.property-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

.property-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.property-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.property-group select {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--surface-color);
    color: var(--text-primary);
    cursor: pointer;
}

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

/* Color Picker */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-picker-wrapper input[type="color"] {
    width: 40px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: none;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.color-text {
    flex: 1;
    padding: 6px 10px;
    font-size: 0.8125rem;
    font-family: monospace;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

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

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    background-color: var(--background-color);
    overflow: hidden;
}

.canvas-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    background:
        linear-gradient(90deg, var(--border-color) 1px, transparent 1px),
        linear-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: center center;
}

#mainCanvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: default;
}

/* Text Input Overlay */
.text-input-overlay {
    position: absolute;
    display: none;
    background-color: var(--surface-color);
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    z-index: 1000;
}

.text-input-overlay.active {
    display: block;
}

.text-input-overlay textarea {
    width: 200px;
    min-height: 60px;
    padding: 8px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    resize: both;
    font-family: inherit;
}

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

.text-input-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.zoom-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 1.25rem;
    background-color: var(--background-color);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

#zoomLevel {
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 50px;
    text-align: center;
}

/* Footer */
.footer {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--footer-height);
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

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

.footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Mobile Toolbar */
.mobile-toolbar {
    display: none;
    position: fixed;
    bottom: var(--footer-height);
    left: 0;
    right: 0;
    height: var(--mobile-toolbar-height);
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    justify-content: space-around;
    align-items: center;
    padding: 0 16px;
    z-index: 100;
}

.mobile-tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s ease;
}

.mobile-tool-btn.active {
    color: var(--primary-color);
}

/* Mobile Panels */
.mobile-panel {
    display: none;
    position: fixed;
    bottom: calc(var(--footer-height) + var(--mobile-toolbar-height));
    left: 0;
    right: 0;
    max-height: 60vh;
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    overflow-y: auto;
}

.mobile-panel.active {
    display: block;
}

.mobile-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background-color: var(--surface-color);
}

.mobile-panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.close-panel-btn {
    width: 32px;
    height: 32px;
    font-size: 1.5rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.mobile-panel-content {
    padding: 16px;
}

.mobile-shape-library {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 16px;
}

.mobile-shape-library .shape-btn {
    flex-direction: column;
    gap: 4px;
    padding: 16px 8px;
}

.mobile-shape-library .shape-btn span {
    font-size: 0.75rem;
}

/* Selected Actions */
.selected-actions {
    background-color: var(--background-color);
}

.selected-actions .btn {
    margin-bottom: 8px;
}

.selected-actions .btn:last-child {
    margin-bottom: 0;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .sidebar-left {
        width: 200px;
    }

    .sidebar-right {
        width: 220px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0 12px;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .btn-text {
        display: none;
    }

    .btn {
        padding: 8px;
    }

    .sidebar {
        display: none;
    }

    .main-content {
        height: calc(100vh - var(--header-height) - var(--footer-height) - var(--mobile-toolbar-height));
    }

    .mobile-toolbar {
        display: flex;
    }

    .zoom-controls {
        bottom: 80px;
    }

    .footer {
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0 8px;
    }

    .logo-img {
        width: 24px;
        height: 24px;
    }

    .logo h1 {
        font-size: 0.875rem;
    }

    .mobile-shape-library {
        grid-template-columns: repeat(3, 1fr);
    }

    .zoom-controls {
        padding: 6px 8px;
    }

    .zoom-btn {
        width: 28px;
        height: 28px;
    }
}

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

::-webkit-scrollbar-track {
    background: var(--background-color);
}

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

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

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.mobile-panel.active {
    animation: fadeIn 0.2s ease;
}

/* Canvas Cursor States */
#mainCanvas.cursor-crosshair {
    cursor: crosshair;
}

#mainCanvas.cursor-move {
    cursor: move;
}

#mainCanvas.cursor-grab {
    cursor: grab;
}

#mainCanvas.cursor-grabbing {
    cursor: grabbing;
}

#mainCanvas.cursor-pointer {
    cursor: pointer;
}

/* Selection Highlight */
.selection-box {
    position: absolute;
    border: 2px dashed var(--primary-color);
    background-color: rgba(74, 144, 217, 0.1);
    pointer-events: none;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background-color: var(--text-primary);
    color: var(--surface-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-secondary: #000000;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles */
@media print {
    .header, .sidebar, .footer, .mobile-toolbar, .zoom-controls {
        display: none !important;
    }

    .main-content {
        height: auto;
    }

    .canvas-container {
        position: static;
        width: 100%;
        height: auto;
    }

    #mainCanvas {
        position: static;
    }
}
