:root {
    --bg-color: #f0f2f5;
    --text-color: #333;
    --border-color: #333;
    --input-bg-color: #ffffff;
    --input-border-color: #aaa;
    --icon-fill-color: #333;
    --modal-bg: rgba(0, 0, 0, 0.4);
    --modal-content-bg: #fff;
    --sidebar-bg: #e8eaed;
    --sidebar-text: #212529;
    --icon-inner-color: #f0f2f5;
}
 body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --border-color: #e0e0e0;
    --input-bg-color: #2a2a2a;
    --input-border-color: #555;
    --icon-fill-color: #e0e0e0;
    --modal-bg: rgba(0, 0, 0, 0.7);
    --modal-content-bg: #2a2a2a;
    --sidebar-bg: #212529;
    --sidebar-text: #f8f9fa;
    --icon-inner-color: #121212;
}

* {
    box-sizing: border-box;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateY(-20px); }
    10% { opacity: 1; transform: translateY(0); }
    90% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-20px); }
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: row;
    min-height: 100vh;
    margin: 0;
    overflow: hidden; 
    transition: background-color 0.3s ease, color 0.3s ease;
}
 .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 72px;
    flex-shrink: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 10px 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
    z-index: 1000;
    overflow: visible;
    box-shadow: 0 -6px 20px rgba(0,0,0,0.15);
    transition: background-color 0.3s ease, color 0.3s ease;
}
 .sidebar-group {
    display: flex;
    flex-direction: row;
    gap: 12px;
    margin-bottom: 0;
    align-items: center;
}

.sidebar-spacer {
    flex-grow: 1;
}

.sidebar-group:last-child {
     margin-bottom: 0;
}
 .sidebar-header {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--sidebar-text);
    opacity: 0.6;
    text-transform: uppercase;
    padding-bottom: 0;
    white-space: nowrap;
    margin-right: 8px;
}
 .sidebar-item {
    padding: 8px 10px;
    font-size: 13px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s, color 0.2s;
    color: var(--sidebar-text);
    text-align: center;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(0, 0, 0, 0.1);
    white-space: nowrap;
    overflow: hidden;
    justify-content: center;
    min-width: 44px;
    height: 44px;
}

.sidebar-item:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background-color: rgba(0, 0, 0, 0.1);
}

.sidebar-item svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    flex-shrink: 0; 
}
 .sidebar-item span {
    display: none;
}
 .sidebar-item:not(:disabled):hover {
    background-color: rgba(0, 0, 0, 0.2);
}

.sidebar-item:active {
    transform: scale(0.98);
}
 #addButton { background-color: #2ecc71; color: white; }
#addButton:hover { background-color: #27ae60; }
#resetButton { background-color: #e74c3c; color: white; }
#resetButton:hover { background-color: #c0392b; }

#exportButton svg path:nth-child(2),
#importButton svg path:nth-child(2) {
    fill: var(--icon-inner-color) !important;
}
 #zoom-slider {
    width: 140px;
    height: 8px;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
    display: block;
    margin: 0 8px;
    background: transparent;
}
#zoom-slider::-webkit-slider-runnable-track { height:8px; background:#777; border-radius:999px; }
#zoom-slider::-webkit-slider-thumb { -webkit-appearance:none; width:16px; height:16px; background:#fff; border-radius:50%; margin-top:-4px; box-shadow:0 0 0 4px rgba(0,0,0,0.15);} 
#zoom-slider::-moz-range-track { height:8px; background:#777; border-radius:999px; }
#zoom-slider::-moz-range-thumb { width:16px; height:16px; background:#fff; border-radius:50%; border:none; }
  .main-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
        padding-bottom: calc(72px + 200px + 12px);
}
 #scale-title {
    width: 100%;
    border: none;
    background: none;
    color: var(--text-color);
    font-size: 2.5em;
    font-weight: bold;
    text-align: center;
    padding: 20px 40px 10px 40px;
    outline: none;
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 0;
}
#scale-title:empty:before {
    content: attr(data-placeholder);
    color: var(--input-border-color);
    font-weight: normal;
}
 .content-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow: hidden;
    transition: justify-content 0.4s ease;
}

.content-area.view-mode-center {
    justify-content: center;
}
 .scroll-wrapper {
    width: 100%;
    overflow-x: auto;
}

.scale-panning-container {
    width: 100%;
    position: relative;
    transition: width 0.1s linear, padding 0.4s ease;
    padding-top: 80vh;
}


 .scale-bar {
    position: relative;
    width: auto;
    flex-grow: 1;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: linear-gradient(to right, #e74c3c, #f1c40f, #2ecc71);
    transition: border-color 0.3s ease;
    left: auto;
    right: auto;
    bottom: auto;
    transform: none;
    margin: 0;
}

.scale-bar::before,
.scale-bar::after {
    display: none;
}
.scale-bar::before { content: "0"; left: -28px; }
.scale-bar::after { content: "10"; right: -36px; }

@media (max-width: 600px) {
    .scale-bar::before { left: -20px; font-size: 0.95rem; }
    .scale-bar::after { right: -28px; font-size: 0.95rem; }
}

.content-area.view-mode-center .scale-row-container {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
}

.content-area.view-mode-center .scale-bar {
    top: auto;
    bottom: auto;
    transform: none;
}

.division-container {
    position: absolute;
    width: 120px;
    display: flex;
    align-items: center;
    transform: translateX(-50%);
    transition: left 0.3s ease, opacity 0.2s ease, top 0.4s ease, bottom 0.4s ease;
    pointer-events: none; 
}

.division-container.position-up {
    bottom: 10px;
    flex-direction: column;
}

.division-container.position-down {
    top: 10px;
    bottom: auto;
    flex-direction: column-reverse;
}
 .division-container.dragging {
    opacity: 0.5;
    cursor: grabbing;
    transition: none;
    z-index: 1000;
}

.division-btn-controls {
    position: absolute; 
    top: -15px; 
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    gap: 8px;
    height: 24px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none; 
}

.position-down .division-btn-controls {
    top: auto;
    bottom: -15px;
}

.division-container input[type="text"]:hover + .division-btn-controls,
.division-container input[type="text"]:focus + .division-btn-controls,
.division-btn-controls:hover { 
    opacity: 1;
    pointer-events: auto; 
}
 .division-btn-controls button {
    width: 24px;
    height: 24px;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    pointer-events: auto; 
}

#add-image-btn { 
    background-color: #007bff;
}

#add-image-btn:hover {
    background-color: #0056b3;
}

#remove-image-from-div-btn {
    background-color: #7f8c8d;
    display: none;
}

#remove-image-from-div-btn:hover {
    background-color: #95a5a6;
}

#move-to-staging-btn {
    background-color: #3498db;
}

#move-to-staging-btn:hover {
    background-color: #2980b9;
}

#remove-division-btn { 
    background-color: #e74c3c;
}

#remove-division-btn:hover {
    background-color: #c0392b;
}

.division-container.has-image #add-image-btn {
    display: none;
}

.division-container.has-image #remove-image-from-div-btn {
    display: flex;
}
 
.remove-division-btn {
    background-color: #e74c3c;
}

.division-stem {
    width: 3px;
    background-color: var(--border-color);
    transition: background-color 0.3s ease, height 0.3s ease;
    pointer-events: none; 
}

.division-container input[type="text"] {
    width: 100%;
    padding: 5px;
    background-color: var(--input-bg-color);
    color: var(--text-color);
    border: 1px solid var(--input-border-color);
    border-radius: 5px;
    text-align: center;
    box-sizing: border-box;
    font-size: 14px;
    margin-top: 5px;
    margin-bottom: 5px;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    position: relative;
    z-index: 2;
    order: 2;
    cursor: grab;
    pointer-events: auto; 
}

.division-container.dragging input[type="text"] {
    cursor: grabbing;
}
 .image-container {
    width: 100%;
    margin-bottom: 5px;
    position: relative;
    order: 0;
    pointer-events: none; 
}
   .division-container:hover {
    z-index: 100;
    transition-delay: 0s;
}
   .image-container img {
    width: 100%;
    height: auto;
    border-radius: 5px;
    border: 1px solid var(--input-border-color);
    display: block;
}

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--modal-bg); display: flex; align-items: center; justify-content: center; z-index: 2000;
}
.modal-content {
    background-color: var(--modal-content-bg); padding: 30px; border-radius: 10px; max-width: 600px; width: 90%; position: relative; line-height: 1.6;
}
.modal-close {
    position: absolute; top: 15px; right: 15px; font-size: 24px; font-weight: bold; cursor: pointer; color: var(--text-color);
}
.modal-content h2 {
    margin-top: 0; border-bottom: 1px solid var(--border-color); padding-bottom: 10px;
}

@media (max-width: 600px) {
    :root { --scale-gap: 12px; }
    .sidebar { height: 56px; }
    .main-wrapper { padding-bottom: calc(56px + 8px); }
    .scale-bar { bottom: calc(56px + 8px); }
    #zoom-slider { width: 100px; }
    .scale-row-container { bottom: calc(56px + 8px); }
    .scale-label { font-size: 0.95rem; }
}

.scale-row-container {
    position: absolute;
    left: var(--scale-gap, 40px);
    right: var(--scale-gap, 40px);
    bottom: calc(36px + 6px);
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateY(0);
    transition: bottom 0.4s ease, transform 0.4s ease;
    z-index: 5;
}

.scale-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
    background: transparent;
    cursor: text;
    min-width: 10px;
    white-space: nowrap;
    outline: none;
    z-index: 6;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.2s;
}

.scale-label:hover, .scale-label:focus {
    border-bottom-color: var(--text-color);
}

::-webkit-scrollbar {
    width: 10px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--text-color);
    border: 2px solid var(--bg-color);
    border-radius: 10px;
}

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

/* Staging Menu Styles */
.staging-menu-container {
    position: fixed;
    bottom: 72px;
    left: 0;
    right: 0;
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
    border-radius: 12px 12px 0 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    max-height: 200px;
    transition: max-height 0.4s ease;
}

.staging-menu-container.expanded {
    max-height: 400px;
    z-index: 999;
}

.staging-menu-toggle {
    padding: 8px 16px;
    background-color: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 12px 12px 0 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    height: 36px;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

.staging-menu-toggle:hover {
    background-color: var(--input-bg-color);
}

.staging-menu-toggle svg {
    width: 20px;
    height: 20px;
    fill: var(--text-color);
    transition: transform 0.4s ease;
}

.staging-menu-container.expanded .staging-menu-toggle svg {
    transform: rotate(0deg);
}

.staging-menu-container:not(.expanded) .staging-menu-toggle svg {
    transform: rotate(180deg);
}

.staging-menu-content {
    flex-grow: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.staging-menu-scroll {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    padding: 12px;
    gap: 12px;
}

.staging-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100px;
    flex-shrink: 0;
    cursor: grab;
    pointer-events: all;
    gap: 0;
}

.staging-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.staging-item-image-container {
    width: 100%;
    height: 80px;
    background-color: var(--input-bg-color);
    border: 2px dashed var(--input-border-color);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 5px;
    overflow: visible;
    position: relative;
}

.staging-item-image-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 3px;
    pointer-events: none;
}

.staging-item-image-placeholder {
    font-size: 32px;
    color: var(--input-border-color);
}

.staging-item-text {
    width: 100%;
    padding: 4px;
    background-color: var(--input-bg-color);
    color: var(--text-color);
    border: 1px solid var(--input-border-color);
    border-radius: 3px;
    text-align: center;
    font-size: 12px;
    box-sizing: border-box;
    resize: none;
    max-height: 40px;
    overflow-y: auto;
    pointer-events: all;
}

.staging-item-controls {
    position: relative;
    display: flex;
    gap: 4px;
    justify-content: center;
    padding: 6px 0;
    pointer-events: auto;
}

.staging-item-btn {
    width: auto;
    min-width: 48px;
    height: 22px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    color: white;
    padding: 0 4px;
    pointer-events: auto;
    z-index: 10;
    transition: background-color 0.2s;
    flex: 1;
}

.staging-item-add-img-btn {
    background-color: #007bff;
}

.staging-item-add-img-btn:hover {
    background-color: #0056b3;
}

.staging-item-remove-img-btn {
    background-color: #7f8c8d;
    display: none;
}

.staging-item-remove-img-btn:hover {
    background-color: #95a5a6;
}

.staging-item-remove-btn {
    background-color: #e74c3c;
}

.staging-item-remove-btn:hover {
    background-color: #c0392b;
}

.staging-item.has-image .staging-item-add-img-btn {
    display: none;
}

.staging-item.has-image .staging-item-remove-img-btn {
    display: flex;
}

@media (max-width: 600px) {
    .staging-menu-container {
        bottom: 56px;
        max-height: 150px;
    }
    
    .staging-menu-container.expanded {
        max-height: 300px;
    }
    
    .staging-item {
        width: 80px;
    }
    
    .staging-item-image-container {
        height: 60px;
    }
}