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

:root {
    --toolbar-height: 56px;
    --bg-color: #e8e8e8;
    --toolbar-bg: #2c2c2c;
    --toolbar-text: #eee;
    --btn-hover: #444;
    --btn-active: #0066ff;
    --btn-active-text: #fff;
    --separator-color: #555;
    --modal-bg: rgba(0,0,0,0.5);
    --page-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-color);
}

/* === Toolbar === */
#toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--toolbar-height);
    background: var(--toolbar-bg);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    z-index: 100;
    overflow-x: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.toolbar-separator {
    width: 1px;
    height: 28px;
    background: var(--separator-color);
    margin: 0 6px;
}

/* Tool buttons */
.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 4px 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--toolbar-text);
    cursor: pointer;
    font-size: 11px;
    transition: background 0.15s, border-color 0.15s;
    min-width: 52px;
}

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

.tool-btn.active {
    background: var(--btn-active);
    color: var(--btn-active-text);
    border-color: rgba(255,255,255,0.3);
}

.tool-icon {
    font-size: 18px;
    line-height: 1;
}

.tool-label {
    font-size: 10px;
    white-space: nowrap;
}

/* Action buttons */
.action-btn {
    padding: 6px 10px;
    background: transparent;
    border: 1px solid #666;
    border-radius: 5px;
    color: var(--toolbar-text);
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    transition: background 0.15s;
}

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

.action-danger {
    border-color: #c44;
    color: #f88;
}

.action-danger:hover {
    background: #622;
}

/* Property controls */
.prop-label {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--toolbar-text);
    font-size: 12px;
    cursor: pointer;
}

.prop-label input[type="color"] {
    width: 30px;
    height: 28px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

.prop-label input[type="range"] {
    width: 70px;
    accent-color: var(--btn-active);
}

.prop-label input[type="number"] {
    background: #444;
    border: 1px solid #666;
    border-radius: 4px;
    color: #eee;
    padding: 3px 6px;
    font-size: 12px;
}

.prop-toggle {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid #666;
    border-radius: 4px;
    color: var(--toolbar-text);
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    min-width: 30px;
    transition: background 0.15s;
}

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

.prop-toggle.active {
    background: var(--btn-active);
    border-color: var(--btn-active);
}

/* Toolbar selects */
#toolbar select {
    padding: 5px 8px;
    background: #444;
    border: 1px solid #666;
    border-radius: 4px;
    color: #eee;
    font-size: 12px;
    cursor: pointer;
}

/* === Workspace === */
#workspace {
    position: fixed;
    top: var(--toolbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    background: var(--bg-color);
}

#canvas-container {
    position: relative;
    box-shadow: var(--page-shadow);
    flex-shrink: 0;
    overflow: visible;
}

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

#canvas-main {
    background: transparent;
}

#canvas-overlay {
    cursor: crosshair;
}

/* === Text editor overlay === */
#text-editor {
    position: fixed;
    z-index: 150;
    background: transparent;
    border: 2px dashed #0066ff;
    outline: none;
    resize: none;
    font-family: sans-serif;
    overflow: hidden;
    padding: 2px 4px;
    min-width: 100px;
    min-height: 30px;
}

#text-editor.hidden {
    display: none;
}

/* === Modals === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #2c2c2c;
    border-radius: 12px;
    padding: 0;
    min-width: 400px;
    max-width: 560px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #444;
}

.modal-header h2 {
    color: #eee;
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: #fff;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    color: #ccc;
    font-size: 14px;
}

.export-btn {
    display: block;
    width: 100%;
    margin-bottom: 8px;
    padding: 12px;
    font-size: 14px;
    text-align: center;
}

/* Shortcuts list */
.shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #3a3a3a;
}

.shortcut-action {
    color: #ddd;
    font-size: 13px;
}

.shortcut-key {
    background: #444;
    border: 1px solid #666;
    border-radius: 4px;
    padding: 4px 12px;
    color: #fff;
    font-size: 13px;
    font-family: monospace;
    cursor: pointer;
    min-width: 60px;
    text-align: center;
    transition: background 0.15s, border-color 0.15s;
}

.shortcut-key:hover {
    border-color: var(--btn-active);
}

.shortcut-key.listening {
    background: var(--btn-active);
    border-color: var(--btn-active);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* === Cursor styles per tool === */
.cursor-pencil { cursor: crosshair; }
.cursor-pen { cursor: crosshair; }
.cursor-highlighter { cursor: crosshair; }
.cursor-eraser { cursor: cell; }
.cursor-bucket { cursor: cell; }
.cursor-rect { cursor: crosshair; }
.cursor-roundRect { cursor: crosshair; }
.cursor-circle { cursor: crosshair; }
.cursor-text { cursor: text; }
.cursor-select { cursor: default; }
.cursor-move { cursor: move; }

/* === Scrollbar styling === */
#workspace::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

#workspace::-webkit-scrollbar-track {
    background: #ccc;
}

#workspace::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 5px;
}

/* === Document name input === */
.doc-name-input {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--toolbar-text);
    font-size: 15px;
    padding: 4px 8px;
    width: 180px;
    transition: border-color 0.15s, background 0.15s;
}

.doc-name-input:hover {
    border-color: #555;
}

.doc-name-input:focus {
    background: #444;
    border-color: var(--btn-active);
    outline: none;
}

.doc-name-input::placeholder {
    color: #888;
}

/* === Delete page button === */
.btn-delete-page {
    position: absolute;
    left: calc(100% + 12px);
    width: 32px;
    height: 32px;
    background: #3a3a3a;
    border: 1px solid #666;
    border-radius: 6px;
    color: #f88;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}

.btn-delete-page:hover {
    background: #622;
    border-color: #c44;
}

/* === Add page button === */
.btn-add-page {
    margin-top: 16px;
    padding: 10px 24px;
    background: #3a3a3a;
    border: 2px dashed #666;
    border-radius: 8px;
    color: #ccc;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    flex-shrink: 0;
}

.btn-add-page:hover {
    background: #4a4a4a;
    border-color: #999;
    color: #fff;
}

/* === Loading overlay === */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

#loading-overlay.hidden {
    display: none;
}

.loading-content {
    text-align: center;
    color: #eee;
    font-size: 16px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #555;
    border-top-color: var(--btn-active);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Responsive adjustments === */
@media (max-width: 1024px) {
    .tool-label {
        display: none;
    }
    .tool-btn {
        min-width: 36px;
        padding: 6px;
    }
}
