/* Live Grid v2: layout mosaico + sidebar camere + overlay PTZ.
 * Palette allineata a verbatel.css (nero/oro).
 */

/* ------------------------------------------------------------ Modale root */
#live-grid-modal {
    /* di base display:none inline; quando aperto la modale usa display:flex */
    flex-direction: column;
}

.lg-toolbar {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 12px;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.lg-toolbar strong { color: #d4af37; }

.lg-toolbar select,
.lg-toolbar button {
    background: #111;
    color: #eee;
    border: 1px solid #444;
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
}

.lg-toolbar button:hover { border-color: #d4af37; }

.lg-status { color: #aaa; font-size: 12px; }

.lg-close {
    margin-left: auto;
    background: #333 !important;
    padding: 6px 14px !important;
}

/* ------------------------------------------------------------ Body split */
.lg-body {
    flex: 1;
    display: flex;
    min-height: 0; /* consente lo scroll interno */
}

.lg-mosaic {
    flex: 1;
    display: grid;
    gap: 6px;
    padding: 6px;
    min-width: 0;
    min-height: 0;
}

/* ------------------------------------------------------------ Cella */
.lg-cell {
    position: relative;
    background: #000;
    border: 1px solid #222;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.lg-cell.active {
    border-color: #d4af37;
    box-shadow: 0 0 0 1px #d4af37 inset;
}

.lg-cell.empty {
    background: #111;
    color: #555;
    cursor: default;
}

.lg-cell.drag-over {
    border-color: #d4af37;
    background: rgba(212, 175, 55, 0.1);
}

.lg-cell canvas {
    max-width: 100%;
    max-height: 100%;
}

.lg-cell-label {
    position: absolute;
    top: 4px;
    left: 6px;
    background: rgba(0, 0, 0, 0.6);
    color: #d4af37;
    padding: 2px 6px;
    font-size: 11px;
    border-radius: 2px;
    z-index: 2;
    pointer-events: none;
}

/* Overlay camera offline/segnale perso */
.lg-cell-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.72);
    color: #e57373;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.03em;
    z-index: 10;
    pointer-events: none;
    border-radius: inherit;
}

.lg-cell-remove {
    position: absolute;
    top: 4px;
    right: 6px;
    background: rgba(0, 0, 0, 0.7);
    color: #eee;
    border: 1px solid #555;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 3;
    padding: 0;
    line-height: 16px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.lg-cell:hover .lg-cell-remove { opacity: 1; }

.lg-cell-remove:hover { border-color: #e55; color: #e55; }

/* ------------------------------------------------------------ PTZ overlay */
.lg-ptz {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: grid;
    grid-template-columns: repeat(3, 28px);
    grid-template-rows: repeat(3, 28px);
    gap: 3px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #d4af37;
    border-radius: 6px;
    z-index: 4;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.lg-cell:hover .lg-ptz,
.lg-cell.active .lg-ptz {
    opacity: 1;
    pointer-events: auto;
}

.lg-ptz button {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 1px solid #555;
    background: rgba(0, 0, 0, 0.7);
    color: #d4af37;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.lg-ptz button:hover { border-color: #d4af37; background: rgba(212, 175, 55, 0.15); }
.lg-ptz button:active { background: rgba(212, 175, 55, 0.35); }

/* Riga extra sotto il d-pad per zoom + presets */
.lg-ptz-extra {
    position: absolute;
    bottom: 8px;
    right: 108px; /* accanto al d-pad (3x28 + 2x3 + padding) */
    display: flex;
    gap: 4px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #d4af37;
    border-radius: 6px;
    z-index: 4;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    align-items: center;
}

.lg-cell:hover .lg-ptz-extra,
.lg-cell.active .lg-ptz-extra {
    opacity: 1;
    pointer-events: auto;
}

.lg-ptz-extra button,
.lg-ptz-extra select {
    background: rgba(0, 0, 0, 0.7);
    color: #d4af37;
    border: 1px solid #555;
    border-radius: 4px;
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
    cursor: pointer;
}

.lg-ptz-extra button { width: 28px; padding: 0; font-size: 14px; }
.lg-ptz-extra button:hover,
.lg-ptz-extra select:hover { border-color: #d4af37; }
.lg-ptz-extra select { min-width: 100px; }

/* ------------------------------------------------------------ Sidebar */
.lg-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: #0d0d0d;
    border-left: 1px solid #333;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.lg-sidebar-header {
    padding: 10px 12px;
    border-bottom: 1px solid #222;
    color: #d4af37;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.lg-sidebar-filter {
    padding: 8px 10px;
    border-bottom: 1px solid #222;
}

.lg-sidebar-filter input {
    width: 100%;
    background: #111;
    border: 1px solid #333;
    color: #eee;
    padding: 5px 8px;
    border-radius: 3px;
    font-size: 12px;
    box-sizing: border-box;
}

.lg-sidebar-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    margin: 0;
    padding: 4px 0;
}

.lg-sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    color: #ddd;
    font-size: 12px;
    cursor: grab;
    border-left: 3px solid transparent;
}

.lg-sidebar-item:hover {
    background: rgba(212, 175, 55, 0.08);
    border-left-color: #d4af37;
}

.lg-sidebar-item:active { cursor: grabbing; }

.lg-sidebar-item.placed {
    opacity: 0.5;
    border-left-color: #444;
}

.lg-sidebar-item .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.lg-sidebar-item .dot.normal { background: #4caf50; }
.lg-sidebar-item .dot.alarm { background: #f0b429; }
.lg-sidebar-item .dot.fault { background: #e55; }
.lg-sidebar-item .dot.unknown { background: #888; }
.lg-sidebar-item .dot.disabled { background: #888; opacity: 0.7; }

.lg-sidebar-item .cam-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lg-sidebar-item .cam-ptz {
    font-size: 10px;
    color: #d4af37;
    border: 1px solid #d4af37;
    border-radius: 2px;
    padding: 0 3px;
}

/* ---------------------------------------------------------- Playback bar v3 */
.lg-playback-bar {
    display: none;
    flex-direction: column;
    gap: 12px;
    padding: 14px 20px 16px;
    background: linear-gradient(180deg, #0d0d0d 0%, #050505 100%);
    border-top: 1px solid #2a2a2a;
    flex-shrink: 0;
    color: #ddd;
    font-size: 13px;
}

#live-grid-modal.mode-playback .lg-playback-bar { display: flex; }

.lg-playback-bar label { color: #999; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

.lg-pb-row { display: flex; align-items: center; gap: 12px; }
.lg-pb-row-controls { flex-wrap: wrap; row-gap: 10px; }
.lg-pb-datetime,
.lg-pb-transport,
.lg-pb-info { display: flex; align-items: center; gap: 8px; }
.lg-pb-transport { justify-content: center; flex: 1 1 auto; }
.lg-pb-info { margin-left: auto; }

.lg-playback-bar input[type="date"],
.lg-playback-bar input[type="time"] {
    background: #1a1a1a;
    color: #eee;
    border: 1px solid #444;
    padding: 6px 8px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    color-scheme: dark;
}
.lg-playback-bar input:focus { outline: none; border-color: #d4af37; }

.lg-playback-bar button {
    background: #1a1a1a;
    color: #d4af37;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 14px;
    min-width: 36px;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.lg-playback-bar button:hover { border-color: #d4af37; background: #222; }
.lg-playback-bar button.active {
    background: #d4af37; color: #111; border-color: #d4af37;
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.15);
}

/* Transport (Play/Pause etc.) piu' visibile del resto */
.lg-pb-transport button { min-width: 42px; padding: 8px 12px; font-size: 16px; }
.lg-pb-transport button#lg-pb-play,
.lg-pb-transport button#lg-pb-pause { min-width: 52px; }

/* Time badge in stile "digital clock" */
#lg-pb-current.lg-pb-time {
    color: #d4af37;
    font-family: 'Consolas', 'Menlo', ui-monospace, monospace;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 1px;
    padding: 4px 12px;
    background: #000;
    border: 1px solid #333;
    border-radius: 4px;
    min-width: 175px;
    text-align: center;
}
#lg-pb-speed { color: #aaa; font-size: 12px; min-width: 66px; text-align: right; }

/* Separator inline nella toolbar transport */
.lg-pb-sep { display: inline-block; width: 1px; height: 22px; background: #2f2f2f; margin: 0 6px; }

/* --------- Timeline canvas 24h --------- */
.lg-pb-timeline-wrap {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.lg-pb-timeline {
    width: 100%;
    height: 56px;
    background:
        repeating-linear-gradient(45deg, #151515 0 6px, #101010 6px 12px);
    border: 1px solid #2b2b2b;
    border-radius: 6px;
    cursor: grab;
    display: block;
    box-shadow: inset 0 0 0 1px #000;
    user-select: none;
    touch-action: none;
}
.lg-pb-timeline.dragging { cursor: grabbing; }
.lg-pb-tooltip {
    position: absolute;
    pointer-events: none;
    background: #000;
    color: #d4af37;
    border: 1px solid #d4af37;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: 'Consolas', 'Menlo', ui-monospace, monospace;
    font-size: 11px;
    white-space: nowrap;
    transform: translate(-50%, -100%);
    top: -6px;
    display: none;
    z-index: 3;
}
.lg-pb-tooltip.visible { display: block; }
.lg-pb-tooltip.no-rec { color: #e57373; border-color: #e57373; }

.lg-pb-timeline-legend {
    display: flex;
    gap: 14px;
    color: #888;
    font-size: 11px;
    white-space: nowrap;
    padding: 0 2px;
    align-items: center;
    justify-content: flex-end;
}
.lg-pb-timeline-legend .dot {
    display: inline-block;
    width: 12px; height: 8px;
    margin-right: 5px;
    vertical-align: middle;
    border-radius: 2px;
}
.lg-pb-timeline-legend .dot.rec-block {
    background: linear-gradient(180deg, #ff4444, #c62828);
}
.lg-pb-timeline-legend .dot.rec-tick {
    background: repeating-linear-gradient(90deg, #ff4444 0 2px, #7a1515 2px 4px);
}
.lg-pb-timeline-legend .dot.none {
    background: repeating-linear-gradient(45deg, #151515 0 3px, #101010 3px 6px);
    border: 1px solid #2b2b2b;
}
.lg-pb-timeline-legend .dot.cursor { background: #e53935; box-shadow: 0 0 4px #e53935; }

/* --------- Zoom row (span presets + slider) --------- */
.lg-pb-row-zoom {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.lg-pb-zoom-presets {
    display: flex;
    gap: 4px;
    background: #0a0a0a;
    padding: 3px;
    border: 1px solid #2b2b2b;
    border-radius: 6px;
}
.lg-pb-zoom-presets button {
    background: transparent;
    color: #aaa;
    border: 1px solid transparent;
    padding: 4px 10px;
    min-width: 42px;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Consolas', ui-monospace, monospace;
}
.lg-pb-zoom-presets button:hover { color: #d4af37; background: #171717; }
.lg-pb-zoom-presets button.active {
    background: #d4af37;
    color: #111;
    border-color: #d4af37;
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.15);
    font-weight: 600;
}
.lg-pb-zoom-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 240px;
}
.lg-pb-zoom-slider input[type="range"] {
    flex: 1 1 auto;
    accent-color: #d4af37;
    background: transparent;
    height: 4px;
    cursor: pointer;
}
.lg-pb-zoom-ic {
    color: #888;
    font-family: 'Consolas', monospace;
    font-size: 14px;
    width: 12px;
    text-align: center;
}
.lg-pb-zoom-label {
    color: #d4af37;
    font-family: 'Consolas', monospace;
    font-size: 12px;
    min-width: 46px;
    text-align: right;
    letter-spacing: 0.5px;
}

/* --------- Mini calendario mensile --------- */
.lg-pb-row-calendar { flex-direction: column; align-items: stretch; gap: 6px; }
.lg-pb-cal-header {
    display: flex; align-items: center; justify-content: center; gap: 14px;
    color: #d4af37; font-size: 13px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 1px;
}
.lg-pb-cal-header button {
    background: #1a1a1a; color: #d4af37; border: 1px solid #3a3a3a; border-radius: 4px;
    padding: 4px 10px; cursor: pointer; min-width: 28px;
}
.lg-pb-cal-header button:hover { border-color: #d4af37; }

.lg-pb-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
    max-width: 460px;
    margin: 0 auto;
    width: 100%;
}
.lg-pb-cal-cell {
    background: #111;
    border: 1px solid #222;
    color: #aaa;
    text-align: center;
    padding: 8px 0 8px 0;
    font-size: 12px;
    cursor: pointer;
    position: relative;
    border-radius: 4px;
    transition: background 0.12s, border-color 0.12s, transform 0.06s;
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-variant-numeric: tabular-nums;
}
.lg-pb-cal-cell.head {
    background: transparent; border: 0; color: #666; cursor: default;
    padding: 2px 0; font-weight: 700; font-size: 10px; text-transform: uppercase;
    min-height: 0;
}
/* Giorno senza registrazioni: sfondo scuro con hatching sottile */
.lg-pb-cal-cell:not(.head):not(.has-rec) {
    background:
        repeating-linear-gradient(45deg, #0d0d0d 0 4px, #111 4px 8px);
    color: #555;
}
/* Giorno con registrazioni: sfondo verde tenue con accento */
.lg-pb-cal-cell.has-rec {
    background: linear-gradient(180deg, #1b3a1e, #14261a);
    color: #cdeacd;
    border-color: #2e7d32;
    font-weight: 600;
}
.lg-pb-cal-cell.other-month { opacity: 0.45; }
.lg-pb-cal-cell.today {
    outline: 2px solid #d4af37;
    outline-offset: -2px;
}
.lg-pb-cal-cell.selected {
    background: linear-gradient(180deg, #e0c04a, #b58a2a) !important;
    color: #111 !important;
    border-color: #d4af37 !important;
    font-weight: 700;
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.25);
}
.lg-pb-cal-cell:hover:not(.head) { transform: translateY(-1px); border-color: #d4af37; }

.lg-pb-cal-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    color: #888;
    font-size: 11px;
    padding-top: 2px;
}
.lg-pb-cal-legend .swatch {
    display: inline-block;
    width: 14px; height: 12px;
    margin-right: 5px;
    vertical-align: middle;
    border-radius: 2px;
    border: 1px solid #333;
}
.lg-pb-cal-legend .swatch.rec { background: linear-gradient(180deg, #1b3a1e, #14261a); border-color: #2e7d32; }
.lg-pb-cal-legend .swatch.empty { background: repeating-linear-gradient(45deg, #0d0d0d 0 4px, #111 4px 8px); }
.lg-pb-cal-legend .swatch.selected { background: linear-gradient(180deg, #e0c04a, #b58a2a); border-color: #d4af37; }

/* --------- Overlay "No recording" nella cella video --------- */
.lg-cell-no-rec {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(45deg, rgba(0,0,0,0.75) 0 10px, rgba(15,15,15,0.75) 10px 20px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #e57373;
    font-size: 13px;
    letter-spacing: 1px;
    text-transform: uppercase;
    z-index: 3;
    pointer-events: none;
    text-align: center;
    padding: 8px;
}
.lg-cell-no-rec::before {
    content: "⛔";
    font-size: 28px;
    margin-bottom: 6px;
    filter: grayscale(0.2);
}
.lg-cell-no-rec .sub {
    color: #999;
    font-size: 10px;
    letter-spacing: 0.5px;
    text-transform: none;
    margin-top: 3px;
}

/* ---------------------------------------------------------- Export modal */
.lg-export-modal {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 10000;
    display: flex; align-items: center; justify-content: center;
}
.lg-export-dialog {
    background: #1a1a1a; color: #eee;
    border: 1px solid #333; border-radius: 6px;
    width: 520px; max-width: 96vw;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    display: flex; flex-direction: column;
    font-size: 13px;
}
.lg-export-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #333;
    color: #d4af37;
}
.lg-export-x {
    background: transparent; color: #aaa; border: 0; cursor: pointer; font-size: 16px;
}
.lg-export-x:hover { color: #d4af37; }
.lg-export-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.lg-export-body label { color: #aaa; font-size: 11px; display: block; }
.lg-export-body input,
.lg-export-body select {
    background: #111; color: #eee;
    border: 1px solid #444; border-radius: 3px;
    padding: 5px 7px; font-family: inherit; font-size: 12px;
    width: 100%; box-sizing: border-box;
    color-scheme: dark;
}
.lg-export-row { display: flex; gap: 10px; }
.lg-export-row > label { flex: 1; }
.lg-export-cameras {
    border: 1px solid #333; border-radius: 4px;
    background: #0f0f0f;
    max-height: 140px; overflow-y: auto;
}
.lg-export-cameras-title {
    color: #d4af37; font-size: 11px; padding: 6px 8px;
    border-bottom: 1px solid #222;
}
#lg-export-cameras-list { list-style: none; margin: 0; padding: 4px 0; }
#lg-export-cameras-list li {
    padding: 4px 10px; color: #ddd; display: flex; gap: 6px; align-items: center;
}
#lg-export-cameras-list li input[type="checkbox"] { width: auto; }
.lg-export-status { color: #aaa; font-size: 12px; min-height: 16px; }
.lg-export-status.error { color: #e57373; }
.lg-export-status.ok { color: #81c784; }
.lg-export-footer {
    display: flex; align-items: center; justify-content: flex-end; gap: 8px;
    padding: 10px 14px; border-top: 1px solid #333;
}
.lg-export-footer button,
.lg-export-download {
    background: #111; color: #d4af37;
    border: 1px solid #444; border-radius: 4px;
    padding: 6px 14px; cursor: pointer; font-size: 12px;
    text-decoration: none;
}
.lg-export-footer button.primary { background: #d4af37; color: #111; border-color: #d4af37; font-weight: 600; }
.lg-export-footer button:hover:not(:disabled),
.lg-export-download:hover { border-color: #d4af37; }
.lg-export-footer button:disabled { opacity: 0.5; cursor: not-allowed; }
.lg-export-download { color: #81c784; border-color: #2e7d32; }


/* Toggle Live/Playback nella toolbar */
.lg-mode-toggle {
    display: inline-flex;
    border: 1px solid #444;
    border-radius: 3px;
    overflow: hidden;
}

.lg-mode-toggle button {
    background: #111;
    color: #aaa;
    border: 0;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 12px;
}

.lg-mode-toggle button.active {
    background: #d4af37;
    color: #111;
    font-weight: 600;
}

/* Overlay timestamp del frame corrente */
.lg-cell-timestamp {
    position: absolute;
    bottom: 4px;
    left: 6px;
    background: rgba(0, 0, 0, 0.6);
    color: #d4af37;
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 2px;
    z-index: 2;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- Mobile auth modal */
.lg-mobile-auth-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10020;
}

.lg-mobile-auth-dialog {
    width: min(420px, 92vw);
    background: #111;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.45);
}

.lg-mobile-auth-header {
    padding: 12px 14px;
    border-bottom: 1px solid #2f2f2f;
    color: #d4af37;
}

.lg-mobile-auth-body {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lg-mobile-auth-site {
    color: #9aa0a6;
    font-size: 12px;
}

.lg-mobile-auth-body label { color: #aaa; font-size: 11px; display: block; }
.lg-mobile-auth-body input {
    width: 100%;
    margin-top: 4px;
    background: #0c0c0c;
    border: 1px solid #333;
    color: #eee;
    border-radius: 3px;
    padding: 7px 8px;
    font-size: 13px;
}

.lg-mobile-auth-status {
    min-height: 16px;
    font-size: 12px;
    color: #e57373;
}

.lg-mobile-auth-footer {
    padding: 10px 14px;
    border-top: 1px solid #2f2f2f;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.lg-mobile-auth-footer button {
    min-width: 92px;
    background: #1a1a1a;
    border: 1px solid #3f3f3f;
    color: #ddd;
    border-radius: 3px;
    padding: 7px 10px;
    cursor: pointer;
}

.lg-mobile-auth-footer button.primary {
    background: #d4af37;
    border-color: #d4af37;
    color: #111;
    font-weight: 600;
}
