:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --bg-color: #f4f4f4;
    --sidebar-bg: #ffffff;
    --primary-color: #333;
    --grid-color: #ddd;
    --grid-size: 96px; /* Default 1in = 96px */
    --active-color: #9b59b6; /* Ljubičasta boja */
    --active-text: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body, html {
    height: 100%;
    overflow: hidden;
}

.app-container {
    position: relative; /* Container je sada referenca za absolute pozicioniranje */
    height: 100vh;
    width: 100vw;
    background-color: #fff;
}

/* --- SIDEBAR --- */
.sidebar {
    position: absolute; /* Lebdeći efekat */
    top: 20px;
    left: 20px;
    height: auto;
    max-height: calc(100% - 40px); /* Visina minus margine */
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border: 1px solid #ccc; /* Border sa svih strana */
    border-radius: 12px; /* Zaobljene ivice */
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    z-index: 10;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1); /* Jača sjenka za lebdeći efekat */
}

/* Logo i Ikona */
.logo-container {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    border-bottom: 1px solid #eee;
    overflow: hidden;
    white-space: nowrap;
}

.app-icon {
    width: 40px;
    height: 40px;
    color: var(--primary-color);
    display: flex; /* Da centrira SVG unutar diva ako treba */
}

.logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
}

.app-name {
    font-weight: bold;
    font-size: 18px;
    color: var(--primary-color);
    margin-left: 10px;
    opacity: 1;
    transition: opacity 0.2s;
}

/* Kontrole */
.controls-container {
    padding: 20px;
    opacity: 1;
    transition: opacity 0.2s;
}

.control-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Button Groups */
/* Osigurava da su Imperial/Metric u istom redu */
.button-group {
    display: flex;
    flex-direction: row;
    gap: 5px;
}

.button-group.wrap {
    flex-wrap: wrap;
}

.toggle-btn {
    flex: 1;
    padding: 10px 5px;
    cursor: pointer;
    background: #eee;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
    color: #555;
}

.toggle-btn:hover {
    background: #e0e0e0;
    background: var(--active-color);
    color: #ffffff;
}

.toggle-btn.active {
    background: var(--active-color);
    color: var(--active-text);
}

/* Specifično za unit dugmad da budu manja */
#unit-buttons-container .toggle-btn {
    flex: 0 0 auto;
    width: 40px;
    padding: 5px;
    text-align: center;
}

/* Slider styling */
input[type=range] {
    cursor: pointer;
}

/* Opacity Control Row */
.opacity-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    font-size: 13px;
    color: #555;
}

/* Image Info Row */
.image-info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 13px;
    color: #555;
    background: #f9f9f9;
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #eee;
}

.delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #e74c3c;
    padding: 2px 5px;
    font-size: 16px;
    margin-left: auto; /* Push to right */
    opacity: 0.7;
    transition: opacity 0.2s;
}

.delete-btn:hover {
    opacity: 1;
}

/* Dugme za toggle sidebara (strelica) */
.sidebar-toggle-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%); /* Centriranje po visini */
    right: -15px; /* Centrirano na desnoj ivici (pola unutra, pola van) */
    width: 30px;
    height: 30px;
    background: var(--sidebar-bg);
    border: 1px solid #ccc;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.1);
    z-index: 20;
    font-size: 16px;
}

/* --- STANJE: ZATVOREN SIDEBAR --- */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    height: 62px; /* Visina ikonice (60) + borderi (2) */
    bottom: auto; /* Ukida dno da ne rasteže */
}

.sidebar.collapsed .app-name,
.sidebar.collapsed .controls-container {
    opacity: 0;
    pointer-events: none;
    display: none; /* Sakrij potpuno da ne smeta layoutu */
}

/* Uklonjena rotacija jer sada mijenjamo ikonicu u JS-u za "dva izdanja" */

/* --- CANVAS (MREŽA) --- */
#canvas-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    position: relative;
    cursor: default;
    overflow: hidden; /* Da SVG ne viri van */
}

#grid-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Klikovi prolaze kroz grid */
    z-index: 1; /* Iznad slike (0), ispod crteža (2) */
    /* Srafura / Grid */
    background-image: 
        linear-gradient(to right, var(--grid-color) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-color) 1px, transparent 1px);
    background-size: var(--grid-size) var(--grid-size);
}

/* Image States */
#background-image.calibrating {
    outline: 2px dashed var(--active-color);
    transition: outline 0.2s;
}

#background-image.dragging {
    outline: 2px solid var(--active-color);
    box-shadow: 0 0 15px var(--active-color);
    cursor: grabbing;
}

#canvas-area.grabbing {
    cursor: grabbing;
}

#canvas-area.tool-line {
    cursor: crosshair;
}

/* Drawing Layer */
#drawing-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Klikovi prolaze do canvas-area */
    z-index: 2; /* Iznad grida (1) i slike (0) */
}

.drawing-line {
    stroke: #333;
    /* stroke-width se postavlja u JS radi zooma */
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Fill for closed shapes */
.drawing-fill {
    fill: rgba(155, 89, 182, 0.1); /* Blaga ljubičasta */
    stroke: none;
}

/* Edit mode: dashed lines for unselected parts of the shape */
.drawing-line.edit-mode {
    stroke-dasharray: 5, 5;
    stroke: #666;
}

.drawing-line.dashed {
    stroke-dasharray: 5, 5;
    stroke: #666;
}

.drawing-point {
    fill: var(--active-color);
}

/* Edit mode: hollow points for unselected parts */
.drawing-point.edit-mode {
    fill: #fff;
    stroke: var(--active-color);
    /* stroke-width se postavlja u JS */
    /* r se postavlja u JS */
}

.drawing-point.anim {
    animation: point-pop 0.3s ease-out forwards;
}

@keyframes point-pop {
    0% { r: 0; }
    50% { r: 8; }
    100% { r: 5; }
}

/* Selected line style */
.drawing-line.selected {
    stroke: var(--active-color);
    /* stroke-width se postavlja u JS */
    stroke-dasharray: none; /* Solid */
    filter: drop-shadow(0 0 4px var(--active-color));
}

/* Selected point style */
.drawing-point.selected {
    fill: var(--active-color);
    stroke: none;
    filter: drop-shadow(0 0 4px var(--active-color));
} 

/* Selection Box */
.selection-box {
    position: absolute;
    border: 1px dashed var(--active-color);
    background-color: rgba(155, 89, 182, 0.1);
    pointer-events: none;
    z-index: 100;
}

/* Shape ID Badge */
.shape-id-group {
    cursor: pointer;
    pointer-events: all; /* To catch clicks */
}
.shape-id-bg {
    fill: var(--active-color);
    stroke: none;
}
.shape-id-text {
    /* font-size se postavlja u JS */
    fill: #fff;
    font-weight: bold;
    text-anchor: middle;
    dominant-baseline: central;
    user-select: none;
}
.shape-name-text {
    /* font-size se postavlja u JS */
    fill: #333;
    text-anchor: middle;
    user-select: none;
    pointer-events: all;
}

/* Calibration Popup */
#calibration-popup {
    font-size: 14px;
    color: #333;
}

/* Uklanjanje strelica (spinners) iz input type number u kalibraciji */
#calib-length::-webkit-outer-spin-button,
#calib-length::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
#calib-length {
    -moz-appearance: textfield;
}

/* Zoom Indicator */
#zoom-indicator {
    position: absolute;
    top: 70px; /* Ispod razmjere */
    right: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 5px;
    user-select: none;
}

#zoom-text {
    font-weight: bold;
    color: #555;
    cursor: pointer;
    padding: 5px;
}

/* Scale Indicator (Razmjera) */
#scale-indicator {
    position: absolute;
    top: 20px;
    right: 20px;
    bottom: auto;
    left: auto;
    transform: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none; /* Da ne smeta mišu */
    z-index: 5;
}

.zoom-reset-icon {
    width: 14px;
    height: 14px;
    box-sizing: content-box; /* Zbog paddinga */
    fill: #555;
    display: block;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 5px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: background 0.2s;
}

.zoom-reset-icon:hover {
    background: #f0f0f0;
    background: var(--active-color);
    fill: #ffffff;
}

.zoom-reset-icon:hover,
#zoom-text:hover + .zoom-reset-icon {
    background: #f0f0f0;
}

.scale-line {
    height: 2px;
    background-color: #333;
    position: relative;
    margin-top: 5px;
    /* Width se postavlja kroz JS */
}

/* Vertikalne crtice na krajevima linije */
.scale-line::before, .scale-line::after {
    content: '';
    position: absolute;
    top: -5px;
    width: 2px;
    height: 12px;
    background-color: #333;
}
.scale-line::before { left: 0; }
.scale-line::after { right: 0; }

.scale-text {
    font-size: 12px;
    color: #333;
    font-weight: bold;
    background: rgba(255,255,255,0.7);
    padding: 2px 5px;
    border-radius: 3px;
}

/* --- BOTTOM TOOLBAR --- */
#bottom-toolbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    gap: 10px;
    z-index: 20;
    border: 1px solid #ddd;
}

.tool-btn {
    width: 44px;
    height: 44px;
    border: 1px solid transparent;
    background: #f9f9f9;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    transition: all 0.2s;
}

.tool-btn:hover { background: #eee; }

.tool-group {
    display: flex;
    gap: 5px;
    align-items: center;
}

.tool-btn.sub-tool {
    width: 36px;
    height: 36px;
    opacity: 1;
    transition: all 0.3s ease;
}

.tool-btn.sub-tool.hidden {
    width: 0;
    padding: 0;
    opacity: 0;
    margin: 0;
    overflow: hidden;
    border: none;
}

.tool-btn.active { background: var(--active-color); color: white; border-color: var(--active-color); }

/* --- DRAWING TOOLTIP --- */
#draw-tooltip {
    position: absolute;
    bottom: 85px; /* Above the toolbar */
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 8px 15px;
    border-radius: 6px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 5px;
    z-index: 20;
    white-space: nowrap;
    transition: opacity 0.2s, transform 0.2s;
    flex-direction: column; /* Allow multi-line */
    align-items: center;
    text-align: center;
    line-height: 1.2;
}

#draw-tooltip.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 10px); /* Move down slightly when hidden */
}
.draw-tooltip .inline-svg {
    display: inline-block;
    vertical-align: middle;
}
/* --- MOBILNI PRIKAZ --- */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        transform: translateX(-100%); /* Sakriven skroz lijevo po defaultu */
        transition: transform 0.3s ease;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Na mobilnom, kad je otvoren, dugme je unutra ili na rubu */
    .sidebar-toggle-arrow {
        right: -15px;
    }
    
    /* Prilagodba logike za mobilni: collapsed klasa se ne koristi isto kao na desktopu */
}