/* --- BASIS & LAYOUT --- */
body { 
    margin: 0; 
    overflow: hidden; 
    background-color: #f4f4f4; /* Das V8-Grau als Sicherheitsnetz */
    user-select: none; 
}

/* --- DAS QUADRAT (BASIS) --- */
.square {
    position: absolute;
    cursor: grab;
    background-color: #3498db;
    border-radius: 4px; /* Standard-Ecken */
    box-sizing: border-box;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); /* Von 5px auf 3px reduziert für einen feineren Look bei kleinen Quadraten    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);  */
    transform-origin: center center;
    z-index: 1;
    /* Nur Schatten und Farbe animieren, nicht die Bewegung/Größe! */
    transition: box-shadow 0.2s ease, background-color 0.3s ease;
}

/* Aktiv-Zustand */
.square.active {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 100;
    cursor: grabbing;
    outline: 2px solid #3498db; /* Fokus-Rahmen */
}

/* --- FORMEN --- */
.square.circle { 
    border-radius: 50% !important; 
}

.square.rounded { 
    border-radius: 20px !important; 
}

.square .controls {
    position: absolute;
    /* Wir nutzen 'top' und 'left' für die Grundposition */
    top: -65px; 
    left: 50%;
    
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 6px 12px;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1001;
    white-space: nowrap;
    min-width: 220px;

    /* Der Ankerpunkt muss exakt die Mitte der Unterkante sein */
    transform-origin: center bottom;
    
    /* Keine Transition auf 'transform', damit es nicht "nachwackelt" */
    transition: top 0.2s ease, opacity 0.2s;
}

.square.active .controls,
.square.selected .controls {
    display: flex;
}

/* Buttons & Picker im Menü */
.control-btn, .color-picker, .shape-picker {
    height: 28px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

.control-btn {
    width: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #555;
}

.control-btn:hover {
    background: #3498db;
    color: white;
    border-color: #2980b9;
}

.shape-picker {
    border-radius: 12px;
    padding: 0 8px;
    font-size: 12px;
    color: #333;
}

.color-picker {
    width: 28px;
    border-radius: 50%;
    padding: 0;
    overflow: hidden;
}

.color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker::-webkit-color-swatch { border: none; border-radius: 50%; }

/* --- RESIZE HANDLE (ZIEHECKE) --- */
.square .resizer {
    width: 10px;
    height: 10px;
    background: #3498db;
    border: 2px solid white;
    position: absolute;
    right: -7px;
    bottom: -7px;
    cursor: nwse-resize;
    display: none;
    z-index: 1003;
    border-radius: 3px;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

.square.active .resizer {
    display: block;
}

/* --- LÖSCH BUTTON --- */
.square .delete-btn {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 24px;
    height: 24px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    border: 2px solid white;
    font-size: 14px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1002;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.square.active .delete-btn, .square.selected .delete-btn,
.square.active .resizer, .square.selected .resizer {
    display: flex;
}

/* --- UI LAYER (HEADER) --- */
#ui-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(240, 240, 240, 0.95); /* Hellgrau aus V7 */
    padding: 0 20px;
    border-bottom: 2px solid #ccc;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

#addButton {
    padding: 8px 16px;
    font-size: 18px;
    cursor: pointer;
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle; /* Verhindert das Verspringen in Textzeilen */
}

#addButton:hover { background-color: #218838; }

#log {
    margin-left: 20px;
    font-family: monospace;
    color: #555;
}
#db-status { color: #888; font-size: 12px; margin-left: 10px; }

/* Spezifische Farben für die neuen Buttons innerhalb deines Designs */
.size-minus { 
    color: #e74c3c !important; /* Passend zu deinem Lösch-Rot */
}

.size-plus { 
    color: #27ae60 !important; /* Passend zu deinem Add-Grün */
}

/* Optional: Ein kleiner visueller Effekt beim Drücken */
.control-btn:active {
    transform: scale(0.9);
}

.square.line {
    height: 4px !important; /* Fixe Dicke der Linie */
    border-radius: 2px;
    border: none !important; /* Linien sind nie "hohl" im klassischen Sinne */
}

/* Verstecke den Resizer für Linien oder pass ihn an */
.square.line .resizer {
    height: 100%;
    top: 0;
    right: -5px;
    width: 10px;
    cursor: ew-resize; /* Nur horizontales Ziehen */
}

.selection-frame {
  position: absolute;
  border: 1px solid #007bff;
  background-color: rgba(0, 123, 255, 0.2);
  pointer-events: none; /* Wichtig: Der Rahmen darf keine Maus-Events abfangen! */
}

.lasso-selection {
    position: fixed;
    border: 1px dashed #3498db;
    background: rgba(52, 152, 219, 0.2);
    pointer-events: none; /* Wichtig: Das Lasso darf Maus-Events nicht blockieren */
    z-index: 9999;
}

#lasso-control {
    color: #000000 !important; /* Absolut Schwarz */
    margin-left: 15px;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    font-size: 14px;
    font-weight: 500; /* Etwas dicker für bessere Lesbarkeit */
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.08); /* Etwas dunklerer Hintergrund für Kontrast */
    padding: 5px 12px;
    border-radius: 4px;
    user-select: none;
}

label#lasso-control, #lasso-control * {
    color: #000000 !important;
}

#lassoToggle {
    cursor: pointer;
}

.square.selected {
    outline: 3px solid #f1c40f !important; /* Goldener Rahmen */
    box-shadow: 0 0 15px rgba(241, 196, 15, 0.8);
    z-index: 100;
}

#selection-info {
    color: #333333 !important;
    margin: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #ddd;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

#selection-info input {
    width: 45px;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 2px;
    font-family: monospace;
}

.prop-group {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-family: 'Segoe UI', sans-serif;
}

.prop-label {
    font-weight: bold;
    color: #666;
}

.prop-input {
    width: 50px;
    border: 1px solid #eee;
    border-radius: 3px;
    padding: 2px 4px;
    font-family: monospace;
    font-size: 12px;
    outline: none;
}

.prop-input:focus {
    border-color: #3498db;
    background: #f0f7ff;
}

.prop-unit {
    font-size: 11px;
    color: #888;
    margin-left: -5px;
}

.prop-color {
    width: 25px;
    height: 25px;
    padding: 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: none;
}

.prop-color::-webkit-color-swatch {
    border: 1px solid #ddd;
    border-radius: 4px;
}

#btnShare {
    padding: 8px 16px;
    margin: 10px 20px;
    font-size: 18px;
    cursor: pointer;
    background-color: #fff;
    color: white;
    border: none;
    border: 1px solid #c0c0c0;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle; /* Verhindert das Verspringen in Textzeilen */
}

#btnShare:hover { background-color: #218838; }

#ui-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px; /* Nur oben der Streifen! */
    z-index: 1000;
    pointer-events: none; /* Das UI lässt Klicks durch... */
}

#ui-layer button, 
#ui-layer label, 
#ui-layer input,
#selection-info,
#zoom-info {
    pointer-events: auto; /* ...außer auf den eigentlichen Elementen! */
}

#zoom-info {
    background: white; 
    padding: 4px 10px; 
    border-radius: 6px; 
    border: 1px solid #ddd; 
    font-family: monospace; 
    font-size: 14px; 
    color: #333;
    display: flex;
    align-items: center;
    gap: 5px;
    user-select: none;
    cursor: pointer; /* Zeiger-Hand */
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

#zoom-info:hover {
    background-color: #f9f9f9;
    border-color: #3498db; /* Blauer Rahmen beim Drüberfahren */
}

#zoom-info:active {
    background-color: #f0f0f0;
    transform: translateY(1px); /* Kleiner Klick-Effekt */
}

#viewport {
    width: 100vw;
    height: 100vh;
    position: fixed;
    background-color: #e5e5e5; /* Die Tischfarbe */
    overflow: hidden;
    pointer-events: auto; /* Sicherstellen, dass Klicks hier landen */
    z-index: 1;
}

#canvas {
    position: absolute;
    width: 1200px; 
    height: 1600px;
    background-color: #ffffff;
    
    /* ABSTAND NACH UNTEN KORRIGIEREN */
    top: 0;  /* Von 100px auf 250px erhöht */
    left: 0; /* Etwas mehr Platz von links */
    
    border: 1px solid #ccc;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    transform-origin: 0 0; 
    z-index: 2;
    
    transform: translate(var(--pos-x, 0), var(--pos-y, 0)) scale(var(--zoom, 1));
}

:root {
    --zoom: 1;
    --pos-x: 0px;
    --pos-y: 0px;
}

/* Gitter auf dem Viewport (Hintergrund) */
body.grid-active #viewport {
  background-image: linear-gradient(to right, rgba(0,0,0,0.05) 1px, transparent 1px),
                    linear-gradient(to bottom, rgba(0,0,0,0.05) 1px, transparent 1px);
  background-size: calc(25px * var(--zoom, 1)) calc(25px * var(--zoom, 1)) !important;;
  background-position: var(--pos-x, 0) var(--pos-y, 0) !important;
}

/* Gitter auf dem Blatt (Canvas) - Etwas kräftiger, damit man es auf Weiß sieht */
/* Gitter auf dem Blatt (Canvas) */
body.grid-active #canvas {
  background-image: linear-gradient(to right, rgba(0,0,0,0.1) 1px, transparent 1px),
                    linear-gradient(to bottom, rgba(0,0,0,0.1) 1px, transparent 1px) !important;
  background-size: 25px 25px !important;
  background-position: 0 0 !important; 

}

#sync-indicator {
    display: inline-block; /* Damit sie in der Button-Reihe steht */
    width: 12px;
    height: 12px;
    background: #bbb;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 4px rgba(0,0,0,0.2);
    margin-right: 10px;
    transition: background 0.3s;
}














