:root {
    --primary-color: #0055ff;
    --primary-hover: #0044cc;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --bg-app: #f1f5f9;
    --bg-panel: #ffffff;
    --border-light: #e2e8f0;
    --border-strong: #cbd5e1;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --header-height: 56px;
    --sidebar-width: 280px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

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

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

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

.logo {
    font-weight: 800;
    color: var(--primary-color);
    font-size: 18px;
    letter-spacing: -0.02em;
    text-decoration: none;
    cursor: pointer;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-right: 32px;
}

.project-name-container {
    display: flex;
    align-items: center;
    border-left: 1px solid var(--border-light);
    padding-left: 16px;
}

#project-name-input {
    border: none;
    background: transparent;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-main);
    padding: 4px 8px;
    border-radius: 4px;
    width: 200px;
    transition: background 0.2s;
}

#project-name-input:hover {
    background: #f1f5f9;
}

#project-name-input:focus {
    background: white;
    box-shadow: 0 0 0 2px rgba(0, 85, 255, 0.1);
    outline: none;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

.label {
    color: var(--text-muted);
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 8px;
}

select,
input[type="number"],
input[type="text"] {
    padding: 6px 10px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    background: white;
    color: var(--text-main);
    transition: border-color 0.2s;
}

select:focus,
input:focus {
    border-color: var(--primary-color);
    outline: none;
}

.checkbox-group {
    background: transparent;
    border: none;
    gap: 16px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: default;
}

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

button {
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
    cursor: default;
    border: 1px solid transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border-light);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: var(--border-strong);
}

.btn-danger {
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #e11d48;
}

.btn-danger:hover {
    background: #ffe4e6;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 1px 2px 0 rgba(0, 85, 255, 0.2);
}

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

/* File Menu */
.file-menu-container {
    position: relative;
}

.btn-file-menu {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.file-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    min-width: 180px;
    display: none;
    flex-direction: column;
    padding: 6px;
    z-index: 1000;
}

.file-dropdown.show {
    display: flex;
}

.dropdown-item {
    padding: 10px 12px;
    border: none;
    background: transparent;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: #f1f5f9;
}

.dropdown-item svg {
    color: var(--text-muted);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-light);
    margin: 6px 0;
}

/* Main Layout */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

aside {
    width: var(--sidebar-width);
    background: var(--bg-panel);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 10;
}

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

.toolbox-header,
.properties-header {
    padding: 20px 24px;
    font-weight: 800;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-light);
    background: #f8fafc;
}

/* Canvas */
#canvas-container {
    flex: 1;
    background: #f1f5f9;
    position: relative;
    overflow: hidden;
    /* Container itself doesn't scroll */
    display: flex;
    flex-direction: column;
}

#canvas-viewport {
    flex: 1;
    overflow: auto;
    display: flex;
    padding: 0;
    background-image:
        linear-gradient(45deg, #f8fafc 25%, transparent 25%),
        linear-gradient(-45deg, #f8fafc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f8fafc 75%),
        linear-gradient(-45deg, transparent 75%, #f8fafc 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px 10px, 10px 0;
}

#canvas-wrapper {
    display: block;
    margin: auto;
    flex-shrink: 0;
    /* Allows text-align: center to work */
    text-align: left;
    /* Reset internal alignment */
    background: white;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    position: relative;
    transform-origin: top left;
    border-radius: 4px;
    border: 1px solid var(--border-light);
}

#canvas-wrapper.fitted {
    box-shadow: none;
    border-radius: 0;
    border: none;
    margin: 0;
}



/* Text editor overlay */
#text-editor {
    position: absolute;
    z-index: 1000;
    display: none;
    border: 2px solid var(--primary-color);
    outline: none;
    padding: 8px 12px;
    border-radius: 4px;
    font-family: var(--font-main);
    font-size: 14px;
    line-height: 1.4;
    background: white;
    color: var(--text-main);
    box-shadow: var(--shadow-md);
    resize: none;
    overflow: hidden;
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    padding: 6px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    z-index: 100;
}

.zoom-controls button {
    background: transparent;
    border: none;
    padding: 8px;
    border-radius: 8px;
    color: var(--text-muted);
}

.zoom-controls button:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-main);
}

#status-pill {
    position: absolute;
    bottom: 60px;
    /* Moved up to make room for tabs */
    left: 24px;
    background: var(--text-main);
    color: white;
    padding: 6px 16px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: var(--shadow-md);
}

/* Tabs Container */
#tabs-container {
    height: 40px;
    background: #ffffff;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    z-index: 100;
}

#tabs-list {
    display: flex;
    align-items: flex-end;
    height: 100%;
    gap: 2px;
    overflow-x: auto;
}

#tabs-list::-webkit-scrollbar {
    display: none;
}

.tab-item {
    height: 32px;
    padding: 0 20px;
    background: #f1f5f9;
    border: 1px solid var(--border-light);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    position: relative;
    margin-top: 8px;
}

.tab-item:hover {
    background: #e2e8f0;
    color: var(--text-main);
}

.tab-item.active {
    background: #ffffff;
    color: var(--primary-color);
    height: 36px;
    margin-top: 4px;
    border-top: 2px solid var(--primary-color);
    z-index: 2;
}

.tab-item .close-tab {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    opacity: 0;
    transition: opacity 0.2s;
}

.tab-item:hover .close-tab {
    opacity: 1;
}

.tab-item .close-tab:hover {
    background: rgba(0, 0, 0, 0.1);
}

#add-paper-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

#add-paper-btn:hover {
    background: #f1f5f9;
    color: var(--primary-color);
}

/* Properties Panel */
.property-section {
    padding: 24px;
    border-bottom: 1px solid var(--border-light);
}

.property-section h3 {
    font-size: 13px;
    margin-bottom: 20px;
    font-weight: 700;
    color: var(--text-main);
}

.property-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.property-row label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Toolbox Styles */
.toolbox-category {
    margin-bottom: 24px;
    padding: 0 24px;
}

.category-header {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    margin: 20px 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    padding: 4px 0;
}

.category-header:hover {
    color: var(--text-main);
}

.category-header .chevron {
    transition: transform 0.2s ease;
}

.toolbox-category.collapsed .chevron {
    transform: rotate(-90deg);
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.toolbox-item {
    aspect-ratio: 1;
    width: 100%;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
    color: var(--text-muted);
}

.toolbox-item:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #f0f7ff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.toolbox-item svg {
    width: 20px;
    height: 20px;
}

.toolbox-item.active {
    border-color: var(--primary-color);
    background: #eff6ff;
    color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 85, 255, 0.1);
}

/* Zoom Input */
#zoom-level {
    width: 56px;
    text-align: center;
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
}

/* Tool buttons in header */
.tool-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
}

.tool-btn:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

.tool-btn.active {
    background: white;
    color: var(--primary-color);
    border-color: var(--border-light);
    box-shadow: var(--shadow-sm);
}

/* Selection Styles */
.selection-rect {
    position: absolute;
    pointer-events: none;
    z-index: 9999;
    border: 1.5px dashed;
}

.selection-rect.blue {
    background: rgba(0, 85, 255, 0.08);
    border-color: var(--primary-color);
}

.selection-rect.green {
    background: rgba(34, 197, 94, 0.08);
    border-color: #22c55e;
}

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

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

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ================= PRINT SETTINGS ================= */
@media print {
    @page {
        margin: 0;
    }

    body {
        background: white;
        overflow: visible;
        margin: 0;
        padding: 0;
    }

    /* Hide UI */
    #header,
    #sidebar-left,
    #sidebar-right,
    .zoom-controls,
    #status-pill,
    #tabs-container,
    #text-editor,
    div[style*="position:fixed;bottom:10px;right:10px"] {
        display: none !important;
    }

    /* Full-width print area */
    #app {
        height: auto !important;
    }

    .main-container {
        display: block !important;
        height: auto !important;
    }

    #canvas-container {
        padding: 0;
        margin: 0;
        background: none;
        overflow: visible;
        width: 100% !important;
        height: auto !important;
    }

    #canvas-viewport {
        overflow: visible !important;
        width: 100% !important;
        height: auto !important;
    }

    #canvas-wrapper {
        box-shadow: none;
        border: none;
        margin: 0 auto;
        width: 100% !important;
        height: auto !important;
    }

    canvas {
        display: block;
        margin: 0 auto;
        max-width: 100%;
        height: auto !important;
    }
}