:root {
    /* New Palette: Sharp Navy & Pastels */
    --bg-color: #F0F4F8;          /* Very light pastel blue-grey for main background */
    --surface-color: #FFFFFF;     /* White surfaces for sidebar/modals */
    --border-color: #CBD5E1;      /* Crisp light grey border */
    
    /* Brand Colors */
    --primary-color: #0F2C59;     /* Sharp Navy Blue */
    --primary-hover: #1E4072;     /* Slightly lighter Navy for hovers */
    
    /* Text Colors - Switched to dark for light background */
    --text-primary: #0F172A;      /* Dark Slate for main text */
    --text-secondary: #475569;    /* Muted Slate for labels/secondary text */
    
    --toolbar-width: 250px;
    --header-height: 60px;
    --blue-surface-bg-color: #CCDBFD;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
}

.app-container {
    display: grid;
    grid-template-columns: 1fr var(--toolbar-width);
    grid-template-rows: var(--header-height) 1fr;
    height: 100vh;
}

/* Header */
.app-header {
    grid-column: 1 / -1;
    background-color: var(--primary-color); /* Navy Header */
    border-bottom: 1px solid rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    color: white; /* Force white text on Navy header */
}

/* Override button icons in header to be white */
.app-header .btn-icon {
    color: rgba(255,255,255,0.9);
    border-color: rgba(255,255,255,0.2);
}
.app-header .btn-icon:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.15);
    border-color: rgba(255,255,255,0.5);
    color: white;
}

.app-nav {
    display: flex;
    gap: 24px;
    order: 2;
}

.app-nav a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.app-nav a:hover {
    color: white;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
    order: 2;
}

.mobile-menu-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
    order: 1;
}

.logo span {
    /* White to Light Blue gradient for the logo text on Navy background */
    background: linear-gradient(to right, #FFFFFF, #93C5FD); 
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-icon {
    height: 32px;
    width: 32px;
    background-color: white;
    border-radius: 50%;
    padding: 2px;
}

/* Workspace */
.workspace {
    grid-column: 1;
    grid-row: 2;
    background-color: #DAE4F0; /* Deeper Pastel Blue for the "desk" area */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background-image: radial-gradient(#CBD5E1 1px, transparent 1px);
    background-size: 20px 20px; /* Subtle dot pattern */
}

.upload-zone {
    text-align: center;
    color: var(--text-secondary);
    border: 2px dashed var(--border-color);
    background-color: rgba(255,255,255,0.5); /* Semi-transparent white */
    border-radius: 12px;
    padding: 48px;
    transition: all 0.2s;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary-color);
    background-color: rgba(15, 44, 89, 0.05); /* Very faint Navy tint */
}

.upload-content svg {
    margin-bottom: 16px;
    color: var(--primary-color); /* Navy Icon */
}

.upload-content h2 {
    margin-bottom: 8px;
    color: var(--primary-color);
}

.upload-content p {
    margin-bottom: 24px;
}

/* Editor Area */
.editor-area {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.canvas-wrapper {
    position: relative;
    box-shadow: 0 20px 40px -5px rgba(15, 44, 89, 0.15); /* Navy-ish shadow */
    border: 4px solid white; /* Nice photo frame effect */
}

#main-canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

.drawing-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: all;
    cursor: crosshair;
}

/* Toolbar */
.toolbar {
    grid-column: 2;
    grid-row: 2;
    background-color: var(--blue-surface-bg-color);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    gap: 0;
    overflow-y: auto;
    box-shadow: -4px 0 15px rgba(0,0,0,0.02);
}

.tool-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-color);
    
}

.tool-group-sizes {
    background-color: #ABC4FF;
}

.tool-group-history {
    background-color: #A8DADC;
}

.tool-group-objectdraw {
    background-color: #B6CCFE;
}

.tool-group-edits {
    background-color: #C1D3FE;
}
/*
CCDBFD,
D7E3FC,
E2EAFC,
EDF2FB
*/

.tool-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

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

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

.tool-btn.active {
    background-color: rgba(15, 44, 89, 0.1);
    color: var(--primary-color);
    border-color: rgba(15, 44, 89, 0.2);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(15, 44, 89, 0.2);
}

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

.btn-primary:disabled {
    background-color: #94A3B8;
    opacity: 0.7;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background-color: #E2E8F0; /* Light Grey/Blue for secondary */
    color: var(--text-primary);
    border: 1px solid transparent;
}

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

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* SVG Elements */
.svg-shape {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.svg-shape:hover {
    stroke-width: 3;
    filter: drop-shadow(0 0 4px rgba(15, 44, 89, 0.5));
}

/* Resize Handles for Shapes */
.resize-handle {
    fill: white;
    stroke: var(--primary-color);
    stroke-width: 2;
    cursor: nwse-resize;
    pointer-events: all;
}

/* Cursor directions for handles */
.resize-handle.se, .resize-handle.nw { cursor: nwse-resize; }
.resize-handle.ne, .resize-handle.sw { cursor: nesw-resize; }

/* Color Controls */
.color-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.color-control {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-primary);
    font-weight: 500;
}

.color-control label {
    min-width: 55px;
    color: var(--text-secondary);
}

.color-control input[type="color"] {
    width: 100%;
    height: 32px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    background: white;
    padding: 2px;
}

.color-control input[type="range"] {
    flex: 1;
    height: 4px;
    accent-color: var(--primary-color);
}

.filter-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-primary);
    font-weight: 500;
}

.filter-control input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--primary-color);
    width: 16px;
    height: 16px;
}

/* Image Filters */
.canvas-wrapper.bw-filter canvas {
    filter: grayscale(100%);
    opacity: 0.8;
}

.temp-poly-line {
    stroke: var(--primary-color);
    stroke-width: 2;
    stroke-dasharray: 4;
}

/* Crop Overlay */
.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 44, 89, 0.4); /* Navy tint overlay */
    z-index: 10;
    pointer-events: all;
}

.crop-box {
    position: absolute;
    border: 2px solid white;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    cursor: move;
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: white;
    border: 2px solid var(--primary-color);
    border-radius: 50%; /* Rounded handles */
}

/* Handle Positions */
.crop-handle.nw { top: -6px; left: -6px; cursor: nw-resize; }
.crop-handle.ne { top: -6px; right: -6px; cursor: ne-resize; }
.crop-handle.sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle.se { bottom: -6px; right: -6px; cursor: se-resize; }

/* Modal */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 44, 89, 0.7); /* Navy backdrop */
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-backdrop-filter: blur(2px); /* Safari & iOS */
    backdrop-filter: blur(2px);
}

/* Fallback for browsers without backdrop-filter support:
   a subtle blurred layer behind the modal using a pseudo-element */
.modal-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    background: inherit;
    filter: blur(8px);
    z-index: -1;
    pointer-events: none;
}

.modal-content {
    background-color: var(--surface-color);
    padding: 32px;
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
    width: 320px;
    text-align: center;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.resize-options {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

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

.custom-resize label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.custom-resize label .custom-resize-fs {
    align-items: flex-start;
}

.custom-resize input {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    width: 90px;
    font-family: inherit;
}

.custom-resize input:focus {
    outline: 2px solid var(--primary-color);
    border-color: transparent;
}

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

.svg-shape.selected {
    stroke: var(--primary-color);
    stroke-width: 3;
    stroke-dasharray: 5;
    animation: dash 1s linear infinite;
}

@keyframes dash {
    to { stroke-dashoffset: 10; }
}

/* Export Modal Styles */
.modal-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
    line-height: 1.5;
}

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

.export-options .btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    text-align: center;
    gap: 4px;
}

.option-hint {
    font-size: 0.75rem;
    font-weight: 400;
    opacity: 0.8;
}

.hidden {
    display: none !important;
}

/* Metadata Modal Styles */
#metadata-modal .modal-content {
    width: 400px;
}

#metadata-modal input[type="text"],
#metadata-modal textarea {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 6px;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    resize: vertical;
}

#metadata-modal input[type="text"]:focus,
#metadata-modal textarea:focus {
    border-color: transparent;
    outline: 2px solid var(--primary-color);
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    order: 3;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover:not(:disabled) {
    background-color: #F1F5F9;
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background-color: rgba(0,0,0,0.05);
}

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

/* Reset Button Danger Style */
#btn-reset-confirm {
    background-color: #EF4444 !important;
    color: white;
}

#btn-reset-confirm:hover {
    background-color: #DC2626 !important;
}

/* =========================================
   Call to Action (CTA) Button - Export SVG
   ========================================= */

#btn-export {
    /* High-visibility Gradient */
    background: linear-gradient(135deg, #FF416C 0%, #FF4B2B 100%); 
    
    /* Text Styles */
    color: white;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    font-size: 0.85rem;
    
    /* Border & Shadow */
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 15px rgba(255, 75, 43, 0.4); 
    
    /* Positioning & Rendering Fixes */
    position: relative;
    z-index: 5;
    
    /* Prevents sub-pixel jitter/blurring */
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-font-smoothing: subpixel-antialiased;
    
    /* Only transition the properties that change to avoid layout reflows */
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease, border-color 0.2s ease;
}

#btn-export:hover:not(:disabled) {
    /* Removed scale(1.02) to fix text jitter */
    transform: translateY(-2px);
    
    /* Enhanced Glow */
    box-shadow: 0 0 25px rgba(255, 75, 43, 0.7);
    filter: brightness(1.1);
    border-color: white;
}

#btn-export:active:not(:disabled) {
    transform: translateY(1px);
    box-shadow: 0 0 10px rgba(255, 75, 43, 0.5);
    filter: brightness(1.0);
}

#btn-export:disabled {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
    color: rgba(255, 255, 255, 0.3);
    border-color: transparent;
    cursor: not-allowed;
    transform: none;
}

/* =========================================
   Responsive Design
   ========================================= */

/* Tablet and smaller screens */
@media (max-width: 1024px) {
    :root {
        --toolbar-width: 200px;
    }
    
    .app-container {
        grid-template-columns: 1fr var(--toolbar-width);
    }
    
    .editor-area {
        padding: 20px;
    }
    
    .upload-zone {
        padding: 32px;
    }
}

/* Mobile devices */
@media (max-width: 768px) {
    :root {
        --toolbar-width: 100%;
        --header-height: 50px;
    }
    
    .app-container {
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-height) 1fr auto;
    }
    
    .app-header {
        padding: 0 16px;
        position: relative;
        justify-content: space-between;
        align-items: center;
    }
    
    .logo {
        font-size: 1.1rem;
        gap: 8px;
        order: 1;
    }
    
    .mobile-menu-toggle {
        display: block;
        order: 2;
        margin: 0 auto;
    }
    
    .app-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background-color: var(--primary-color);
        flex-direction: column;
        gap: 0;
        padding: 16px 0;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        z-index: 1000;
    }
    
    .app-nav.mobile-open {
        display: flex;
    }
    
    .app-nav a {
        padding: 12px 24px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        font-size: 1rem;
    }
    
    .app-nav a:last-child {
        border-bottom: none;
    }
    
    .header-actions {
        position: static;
        order: 3;
    }
    
    .export-text::after {
        content: "Export";
        font-size: 0.85rem;
    }
    
    .export-text {
        font-size: 0;
    }
    
    .workspace {
        grid-column: 1;
        grid-row: 2;
    }
    
    .toolbar {
        grid-column: 1;
        grid-row: 3;
        border-left: none;
        border-top: 1px solid var(--border-color);
        max-height: 40vh;
        overflow-y: auto;
    }
    
    .editor-area {
        padding: 16px;
    }
    
    .upload-zone {
        padding: 24px 16px;
    }
    
    .upload-content h2 {
        font-size: 1.25rem;
    }
    
    .upload-content p {
        font-size: 0.9rem;
    }
    
    .tool-group {
        padding: 12px 0;
        gap: 8px;
    }
    
    .btn {
        min-height: 44px; /* Touch-friendly button size */
        padding: 8px 16px;
        font-size: 0.9rem;
    }
    
    .btn-icon {
        width: 40px;
        height: 40px;
    }
    
    /* .history-controls styles removed - now part of toolbar */
}

/* Small mobile devices */
@media (max-width: 480px) {
    .app-header {
        padding: 0 12px;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .logo span {
        display: none; /* Hide site name on very small screens */
    }
    
    .logo-icon {
        height: 24px;
        width: 24px;
    }
    
    .editor-area {
        padding: 12px;
    }
    
    .upload-zone {
        padding: 20px 12px;
    }
    
    .canvas-wrapper {
        border-width: 2px;
    }
    
    .tool-group {
        flex-direction: row;
        justify-content: space-around;
        padding: 8px;
    }
    
    .tool-group-history {
        flex-direction: column;
        gap: 8px;
    }
    
    .tool-group label {
        font-size: 0.8rem;
    }
}