:root {
    --card-bg: #101415;
    --card-border: #2a2d2e;
    --card-border-active: #3a9bff;
    --danger: #ff4d4d;
    --success: #34d399;
    --grid-dot: rgba(255, 255, 255, 0.04);
    --snap-line: rgba(50, 152, 255, 0.25);
    --cols: 24;
    --rows: 18
}

@font-face {
    font-family: 'hyperlegible';
    src: url('../fonts/atkinson-regular.ttf');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'hyperlegible';
    src: url('../fonts/atkinson-bold.ttf');
    font-weight: bold;
    font-style: normal;
}

body {
    font-family: 'hyperlegible', sans-serif;
    background-color: black;
    color: white
}

.data-card {
    border: 1px solid #ccc;
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    width: 300px;
}

.value {
    font-size: 24px;
    font-weight: bold;
    color: #007bff;
}

/* Toolbar */
.toolbar {
    background: rgba(16, 20, 21, 0.88);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    display: flex;
    align-items: center;
    padding: 8px 16px;
    margin: 20px;
    gap: 12px;
    z-index: 1000;
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 12px;
    border: 1px solid var(--card-border);
}

.toolbar button {
    height: 32px;
    padding: 0 13px;
    border: none;
    border-radius: 7px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    white-space: nowrap;
}


.toolbar button.primary {
    background-color: rgba(255, 255, 255, 0.103);
}

.toolbar button.primary:hover {
    background: #4da8ff;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(50, 152, 255, 0.3);
}

.toolbar button.primary:active {
    transform: translateY(0);
}


/** CAMVAS!!! */

.canvas {
    width: 100%;
    height: 70%;
    position: absolute;
    background:
        radial-gradient(circle 1px, #393b3c 0.8px, transparent 0.8px);
    background-size: calc(100% / var(--cols)) calc(100% / var(--rows));
}

/* ── Snap guides ───────────────────────────────────── */
.guide {
    position: absolute;
    background: var(--snap-line);
    z-index: 500;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.guide.visible {
    opacity: 1;
}

.guide.horizontal {
    height: 1px;
    left: 0;
    right: 0;
}

.guide.vertical {
    width: 1px;
    top: 0;
    bottom: 0;
}

/* CARDS */

.card {
    position: absolute;
    background-color: #101415;
    border: 2px dashed var(--card-border);
    border-radius: 15px;
    cursor: grab;
    transition: box-shadow 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94), border-color 0.25s ease;
    will-change: left, top, width, height;
    overflow: visible;
    /* Necessario per vedere i manigli di resize fuori bordo se necessario */
}

/* Stili Header Card */
.card-header {
    height: 32px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    user-select: none;
}

.card-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Path Picker Menu ────────────────────────────── */
.label-wrapper {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

.path-menu {
    display: none;
    position: absolute;
    top: 28px;
    left: -8px;
    background: rgba(26, 30, 31, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--card-border-active);
    border-radius: 8px;
    z-index: 2000;
    min-width: 180px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    padding: 5px 0;
    overflow: hidden;
}

.card.editable .label-wrapper:hover .path-menu {
    display: block;
    animation: spawnIn 0.2s ease-out;
}

.path-option {
    padding: 10px 15px;
    color: #aaa;
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    transition: all 0.2s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.path-option:last-child {
    border-bottom: none;
}

.path-option:hover {
    background: var(--card-border-active);
    color: white;
}

.card-close {
    background: none;
    border: none;
    color: rgba(255, 0, 0, 0.404);
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: all 0.2s;
}

.card-close:hover {
    color: var(--danger);
    text-decoration: underline;
}

.card:not(.editable) .card-close {
    display: none;
}

.card-body {
    padding: 12px;
    font-size: 70px;
    font-weight: bold;
    color: #ffffff;
    height: calc(100% - 33px);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* RESIZE HANDLERS (.rh) */
.rh {
    position: absolute;
    z-index: 10;
    transition: opacity 0.2s;
    border-radius: 40px;
}

.rh.corner {
    width: 12px;
    height: 12px;
    background: var(--card-border-active);
    border: 2px solid #101415;
    border-radius: 10px;
}

.rh.edge {
    background: transparent;
}

/* Corner alignment */
.rh.nw {
    top: -6px;
    left: -6px;
    cursor: nwse-resize;
}

.rh.ne {
    top: -6px;
    right: -6px;
    cursor: nesw-resize;
}

.rh.se {
    bottom: -6px;
    right: -6px;
    cursor: nwse-resize;
}

.rh.sw {
    bottom: -6px;
    left: -6px;
    cursor: nesw-resize;
}

/* Edge alignment */
.rh.n {
    top: -4px;
    left: 10px;
    right: 10px;
    height: 8px;
    cursor: ns-resize;
}

.rh.s {
    bottom: -4px;
    left: 10px;
    right: 10px;
    height: 8px;
    cursor: ns-resize;
}

.rh.e {
    right: -4px;
    top: 10px;
    bottom: 10px;
    width: 8px;
    cursor: ew-resize;
}

.rh.w {
    left: -4px;
    top: 10px;
    bottom: 10px;
    width: 8px;
    cursor: ew-resize;
}

.card:not(.selected) .rh.corner {
    opacity: 0;
}

.card.selected .rh.corner {
    opacity: 1;
}

@keyframes cardSpawn {
    0% {
        opacity: 0;
        transform: scale(0.92);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.card.spawning {
    animation: cardSpawn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes cardRemove {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    100% {
        opacity: 0;
        transform: scale(0.88);
    }
}

.card.removing {
    animation: cardRemove 0.2s ease forwards;
    pointer-events: none;
}

/* Stili per le classi dinamiche delle card */
.card.selected {
    border-color: var(--card-border-active);
    box-shadow: 0 0 15px rgba(50, 152, 255, 0.5);
}

.card.dragging,
.card.resizing {
    cursor: grabbing;
    opacity: 0.8;
}

/* Stili per gli elementi aggiunti da canvas.js */
.tooltip {
    position: fixed;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.1s ease;
    z-index: 2000;
}

.tooltip.visible {
    opacity: 1;
}

.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #aaa;
    font-size: 1.2em;
    text-align: center;
    pointer-events: none;
    z-index: 1;
}

.empty-state.hidden {
    display: none;
}

.unit-badge {
    position: fixed;
    top: 10px;
    right: 10px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    z-index: 1000;
}

.toast {
    position: fixed;
    bottom: 60px;
    /* Regola in base all'altezza della toolbar */
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 2000;
}

.toast.show {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 15px;
    padding: 20px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin-top: 0;
    color: white;
}

.modal-content textarea {
    width: calc(100% - 20px);
    min-height: 200px;
    background-color: #2a2d2e;
    border: 1px solid #3a3d3e;
    color: white;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 15px;
    resize: vertical;
}

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

.modal-actions button {
    height: 32px;
    padding: 0 13px;
    border: none;
    border-radius: 7px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    white-space: nowrap;
    background-color: rgba(255, 255, 255, 0.103);
    color: white;
}

.modal-actions button.primary {
    background-color: #4da8ff;
}

.modal-actions button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(50, 152, 255, 0.3);
}

/* ── Edit Mode & Animations ──────────────────────── */
@keyframes cardSpawn {
    0% { opacity: 0; transform: scale(0.92); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes cardRemove {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.88); }
}

.card.spawning {
    animation: cardSpawn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.card.removing {
    animation: cardRemove 0.2s ease forwards;
    pointer-events: none;
}

/* Canvas state during editing */
.canvas.edit-active {
    outline: 2px dashed rgba(58, 155, 255, 0.3);
    outline-offset: -10px;
    background-color: rgba(58, 155, 255, 0.02);
}

.card.editable {
    border-style: dashed;
}

.card.editable:not(.selected) {
    border-color: rgba(255, 255, 255, 0.1);
}

/* Hide handlers when not editing */
.card:not(.editable) .rh {
    display: none !important;
}

.card:not(.editable) {
    cursor: default;
    border-style: solid;
}

/* Rimuovi padding se la card contiene la mappa per farla aderire ai bordi */
.card[data-type="map"] .card-body {
    padding: 0;
    overflow: hidden;
}

.card-map-canvas {
    width: 100%;
    height: 100%;
    border-radius: 0 0 15px 15px;
    overflow: hidden;
}

/* Fix per Mapbox canvas che a volte non prende il 100% se il container è flex */
.card-map-canvas .mapboxgl-canvas-container,
.card-map-canvas .mapboxgl-canvas {
    width: 100% !important;
    height: 100% !important;
}

.hidden {
    display: none !important;
}

.toolbar button.primary {
    background-color: var(--card-border-active) !important;
    color: white;
}

/* ── Global Edit Mode Overrides ──────────────────── */
body.edit-mode {
    background-color: #0a0e0f;
    transition: background-color 0.4s ease;
}

body.edit-mode .toolbar {
    background: rgba(58, 155, 255, 0.15) !important;
    backdrop-filter: blur(25px);
    border: 2px dashed var(--card-border-active) !important;
    box-shadow: 0 0 20px rgba(58, 155, 255, 0.2);
}

body.edit-mode .toolbar p#cardCount {
    color: var(--card-border-active);
}

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

body.edit-mode .canvas.edit-active::after {
    content: "DASHBOARD EDITING";
    position: fixed;
    top: 20px;
    right: 20px;
    font-size: 10px;
    font-weight: 800;
    color: var(--card-border-active);
    letter-spacing: 2px;
    animation: editPulse 2s infinite ease-in-out;
    pointer-events: none;
}