/* Variables */
:root {
    --primary: #4a90d9;
    --success: #5cb85c;
    --danger: #d9534f;
    --secondary: #6c757d;
    --bg-dark: #1e1e2e;
    --bg-sidebar: #252536;
    --bg-canvas: #2d2d3f;
    --text: #e0e0e0;
    --text-muted: #888;
    --border: #3a3a4a;
    --highlight: #ffcc00;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 1.3rem;
    font-weight: 600;
}

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

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 500;
}

.sidebar-header .header-buttons {
    display: flex;
    gap: 4px;
}

.element-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.element-item {
    padding: 10px 12px;
    margin-bottom: 6px;
    background: var(--bg-canvas);
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.element-item:hover {
    background: #3a3a4f;
}

.element-item.selected {
    border-color: var(--primary);
    background: rgba(74, 144, 217, 0.15);
}

.element-item.child {
    margin-left: 14px;
    padding: 8px 10px;
    opacity: 0.95;
}

.element-item.child .item-id {
    color: #a9d6ff;
}

.element-item.not-selectable {
    cursor: default;
    opacity: 0.85;
}

.element-item.not-selectable:hover {
    background: var(--bg-canvas);
}

.element-item .item-id {
    font-weight: 600;
    color: var(--primary);
    font-size: 0.85rem;
}

.element-item .item-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.element-item .item-type {
    display: inline-block;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    margin-top: 5px;
}

.element-item .item-type.smiley {
    background: #ffc107;
    color: #000;
}

.element-item .item-type.checkbox {
    background: #17a2b8;
    color: #fff;
}

.element-item .item-type.text_area {
    background: #28a745;
    color: #fff;
}

.element-item .item-type.text {
    background: #475569;
    color: #fff;
}

.empty-message {
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
    font-size: 0.9rem;
}

/* Element sections */
.element-section {
    margin-bottom: 10px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-dark);
    border-radius: 5px;
    cursor: pointer;
    user-select: none;
    margin-bottom: 5px;
}

.section-header:hover {
    background: #2a2a3a;
}

.section-toggle {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.section-content {
    padding-left: 5px;
}

.section-content.collapsed {
    display: none;
}

/* Properties Panel */
.properties-panel {
    padding: 15px;
    border-top: 1px solid var(--border);
    background: var(--bg-canvas);
}

.tools-panel {
    padding: 15px;
    border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
}

.tools-panel h4 {
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.properties-panel h4 {
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.property-group {
    margin-bottom: 12px;
}

.property-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.property-group input,
.property-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-dark);
    color: var(--text);
    font-size: 0.9rem;
}

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

.coords-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.coords-inputs input {
    text-align: center;
}

.property-actions {
    display: flex;
    gap: 8px;
    margin-top: 15px;
}

/* Canvas */
.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: auto;
    background: var(--bg-canvas);
    display: grid;
    place-items: start center;
}

.canvas-wrapper > .canvas-container,
.canvas-wrapper > div {
    /* Fabric.js creates a wrapping div; let it take its natural size */
    width: max-content;
    margin: 16px auto;
}

.canvas-wrapper canvas {
    border: 1px solid var(--border);
    display: block;
}

.canvas-placeholder {
    position: absolute;
    text-align: center;
    color: var(--text-muted);
}

.canvas-placeholder p {
    font-size: 1.1rem;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    padding: 10px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
}

#pageIndicator {
    font-size: 0.9rem;
}

/* Footer */
.footer {
    display: flex;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-muted);
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: #3a7fc9;
}

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

.btn-success:hover:not(:disabled) {
    background: #4ca84c;
}

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

.btn-danger:hover:not(:disabled) {
    background: #c9433f;
}

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

.btn-info {
    background: #0ea5e9;
    color: white;
}

.btn-info:hover:not(:disabled) {
    background: #0284c7;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-sidebar);
    padding: 25px;
    border-radius: 10px;
    width: 400px;
    max-width: 90%;
}

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

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

/* Loading */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    margin-top: 15px;
    font-size: 1rem;
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #4a4a5a;
}

/* ============== New Styles for Questionnaire Editor ============== */

/* Right sidebar */
.sidebar-right {
    border-right: none;
    border-left: 1px solid var(--border);
    width: 320px;
}

/* Observations panel */
.observations-panel {
    border-top: 1px solid var(--border);
    max-height: 250px;
    display: flex;
    flex-direction: column;
}

.observations-panel .element-list {
    max-height: 200px;
}

/* Badges */
.badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--secondary);
    color: #fff;
    margin-right: 4px;
}

.badge-success {
    background: var(--success);
}

.badge-muted {
    background: var(--border);
    color: var(--text-muted);
}

.item-badges {
    margin-top: 5px;
}

/* Question item controls */
.question-item {
    padding: 8px 10px;
}

.question-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.question-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.question-controls {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.type-select {
    flex: 1;
    padding: 4px 6px;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-dark);
    color: var(--text);
}

/* Drop zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-dark);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(74, 144, 217, 0.1);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.drop-zone-icon {
    font-size: 2.5rem;
}

.drop-zone-filename {
    color: var(--primary);
    font-weight: 500;
}

/* Modal large */
.modal-large {
    width: 500px;
}

/* Observation edit modal */
.observation-questions {
    max-height: 300px;
    overflow-y: auto;
    margin: 15px 0;
}

.observation-question-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
}

.observation-question-item:hover {
    background: var(--bg-canvas);
}

.observation-question-item input {
    width: 16px;
    height: 16px;
}

/* Error state */
.empty-message.error {
    color: var(--danger);
}

/* Canvas placeholder improvements */
.canvas-placeholder {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Canvas toolbar */
.canvas-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.zoom-controls,
.pagination {
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-controls span,
.pagination span {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 100px;
    text-align: center;
}

/* Canvas wrapper scrollable - unified above */

.canvas-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* Confirmation Modal Styles */
.modal-confirm {
    width: 360px;
    text-align: center;
}

.modal-confirm h3 {
    margin-bottom: 10px;
}

.modal-confirm p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 0;
}

.modal-confirm .modal-actions {
    justify-content: center;
    margin-top: 25px;
}

.confirm-icon {
    font-size: 3rem;
    margin-bottom: 15px;
    line-height: 1;
}

/* Warning state */
.modal-confirm.warning .confirm-icon {
    filter: drop-shadow(0 0 10px rgba(255, 200, 0, 0.5));
}

/* Danger state */
.modal-confirm.danger .confirm-icon {
    filter: drop-shadow(0 0 10px rgba(217, 83, 79, 0.5));
}

/* Info state */
.modal-confirm.info .confirm-icon {
    filter: drop-shadow(0 0 10px rgba(74, 144, 217, 0.5));
}