* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #1a1a2e;
    --bg2: #16213e;
    --bg3: #0f3460;
    --accent: #e94560;
    --text: #eee;
    --text2: #aaa;
    --green: #4ecca3;
    --red: #e94560;
    --orange: #f0a500;
    --blue: #4da6ff;
    --border: #333;
}

body.light {
    --bg: #eef0f4;
    --bg2: #ffffff;
    --bg3: #d8dce6;
    --text: #222;
    --text2: #666;
    --border: #c0c4cc;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---- HEADER ---- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
    z-index: 200;
}
.header h1 { font-size: 18px; font-weight: 600; }
.header h1 span { color: var(--accent); }
.header h1 .version { font-size: 11px; font-weight: 400; color: var(--text2); vertical-align: middle; }
/* ---- LOGO (TrixVision — alle sider) ---- */
.header-brand          { display: flex; align-items: center; }
.logo                  { font-size: 22px; font-weight: 900; color: #fff; letter-spacing: -0.5px;
                         line-height: 1; position: relative; display: inline-block; padding-bottom: 5px; }
.logo a                { color: inherit; text-decoration: none; }
.logo-accent           { color: #e94560; }
.logo-v5               { font-size: 10px; font-weight: 400; color: var(--text2);
                         margin-left: 4px; vertical-align: super; letter-spacing: 0; }
.logo::after           { content: ""; position: absolute; bottom: 0; left: 0;
                         height: 2px; width: 55%; background: linear-gradient(90deg, #e94560, transparent); }
.logo-sep              { color: var(--text2); font-size: 12px; margin: 0 8px; flex-shrink: 0; }
.logo-page             { color: var(--accent); font-size: 14px; font-weight: 600; white-space: nowrap; }
.btn-group { display: flex; gap: 4px; }
.header-right { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.header-sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; flex-shrink: 0; }
.sys-stats { display: flex; align-items: center; gap: 5px; font-size: 11px; white-space: nowrap; }
.sstat { display: flex; align-items: center; gap: 3px; color: var(--text2); }
.sstat-sep { color: var(--border); }
.sstat-val { font-weight: 700; min-width: 32px; text-align: right; }
.sstat-val.sstat-ok     { color: var(--green); }
.sstat-val.sstat-warn   { color: var(--orange); }
.sstat-val.sstat-danger { color: var(--red); }
.mobile-menu-btn { display: none; }
.sidebar-backdrop { display: none; }
.mobile-menu-backdrop { display: none; }

/* Grid selector — pill style */
.grid-selector {
    display: flex; gap: 2px;
    background: var(--bg3); border-radius: 6px; padding: 2px;
}
.grid-btn {
    padding: 4px 11px;
    border: none;
    background: transparent;
    color: var(--text2);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}
.grid-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.grid-btn.active { background: var(--accent); color: #fff; }

/* ---- DROPDOWNS ---- */
.dd-wrap { position: relative; }
.dd-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: transparent; color: var(--text);
    border-radius: 4px; cursor: pointer; font-size: 13px;
    transition: all 0.15s; white-space: nowrap; user-select: none;
}
.dd-btn:hover { border-color: var(--accent); background: rgba(233,69,96,0.07); }
.dd-btn.dd-open { border-color: var(--accent); background: rgba(233,69,96,0.07); }
.dd-caret { font-size: 8px; color: var(--text2); transition: transform 0.15s; margin-left: 2px; }
.dd-btn.dd-open .dd-caret { transform: rotate(180deg); }
.dd-badge-btn {
    background: var(--red); color: #fff; border-radius: 10px;
    font-size: 10px; font-weight: 700; padding: 1px 6px;
    min-width: 18px; text-align: center; line-height: 1.4;
}
.dd-menu {
    display: none; position: absolute; top: calc(100% + 5px); left: 0;
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 6px; min-width: 210px; z-index: 999;
    box-shadow: 0 8px 28px rgba(0,0,0,0.55); overflow: hidden;
}
.dd-menu.dd-open { display: block; }
.dd-menu.dd-right { left: auto; right: 0; }
.dd-section { padding: 4px 0; border-bottom: 1px solid var(--border); }
.dd-section:last-child { border-bottom: none; }
.dd-section-label {
    padding: 6px 14px 3px; font-size: 10px; font-weight: 700;
    color: var(--text2); letter-spacing: 0.8px; text-transform: uppercase;
}
.dd-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px; font-size: 13px; cursor: pointer;
    transition: background 0.1s; color: var(--text); white-space: nowrap;
    text-decoration: none;
}
.dd-item:hover { background: rgba(255,255,255,0.06); }
.dd-item a { color: var(--text); text-decoration: none; width: 100%; display: flex; align-items: center; gap: 8px; }
.dd-check { width: 14px; font-size: 11px; color: var(--green); flex-shrink: 0; text-align: center; }
.dd-item-badge {
    margin-left: auto; border-radius: 10px; font-size: 10px;
    font-weight: 700; padding: 1px 6px; min-width: 18px; text-align: center;
}
.dd-item-badge.red { background: var(--red); color: #fff; }
.dd-item-badge.green { background: var(--green); color: #000; }
.dd-item-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }

/* ---- SIDEBAR IP FILTER BAR ---- */
.sb-filter-bar {
    padding: 5px 10px; display: flex; align-items: center; gap: 6px;
    background: rgba(233,69,96,0.1); border-bottom: 1px solid var(--red);
    font-size: 11px; color: var(--accent);
}
.sb-filter-label { flex: 1; font-weight: 600; }
.sb-ip-vis {
    padding: 2px 6px; font-size: 16px; cursor: pointer; line-height: 1;
    border-radius: 3px; transition: all 0.15s; flex-shrink: 0;
    border: none; background: transparent; color: var(--text2);
}
.sb-ip-vis:hover { color: var(--text); }
.sb-ip-vis.active { color: var(--green); }
.sb-ip-vis.inactive { color: var(--border); }
.sb-filter-actions {
    padding: 4px 10px; display: flex; gap: 4px;
    border-bottom: 1px solid var(--border); flex-wrap: wrap;
}

.btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn:hover { background: var(--bg3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-accent { background: var(--accent); border-color: var(--accent); }
.btn-accent:hover { background: #c33; }
.btn-green { background: var(--green); border-color: var(--green); color: #000; }
.btn-green:hover { background: #3ba884; }
.btn-sm { padding: 3px 8px; font-size: 11px; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #c33; }
.btn-blue { background: var(--blue); border-color: var(--blue); color: #000; }
.btn-blue:hover { background: #3a8fd9; }
.btn-warn { background: var(--orange); border-color: var(--orange); color: #000; }
.btn-warn:hover { background: #d4831a; }
.btn-fav { background: transparent; border-color: var(--border); color: var(--text2); }
.btn-fav:hover { color: var(--orange); border-color: var(--orange); }
.btn-fav.active { color: var(--orange); border-color: var(--orange); }

/* ---- MAIN CONTENT ---- */
.main-content { flex: 1; display: flex; overflow: hidden; }

/* ---- SIDEBAR ---- */
.sidebar {
    width: 250px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: none;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}
.sidebar.show { display: flex; }
.sidebar-header {
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sidebar-list { flex: 1; overflow-y: auto; padding: 4px; }
.sb-group-label {
    padding: 6px 8px 2px;
    font-size: 10px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sb-group-label:hover { background: var(--bg3); border-radius: 4px; }
.sb-group-arrow { font-size: 8px; transition: transform 0.2s; margin-right: 4px; }
.sb-group-arrow.open { transform: rotate(90deg); }
.sb-group-detail {
    padding: 4px 8px 6px;
    font-size: 10px;
    color: var(--text2);
    background: rgba(0,0,0,0.15);
    border-radius: 4px;
    margin: 2px 4px 4px;
    display: none;
}
.sb-group-detail.show { display: block; }
.sb-group-detail .sb-detail-row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.sb-group-detail .sb-detail-flag { width: 16px; height: 16px; border-radius: 50%; vertical-align: middle; }
.sb-toggle-grp {
    font-size: 9px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text2);
    border-radius: 3px;
    cursor: pointer;
    margin-top: 4px;
}
.sb-toggle-grp:hover { border-color: var(--accent); color: var(--text); }
.sb-cam {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s;
}
.sb-cam:hover { background: var(--bg3); }
.sb-cam.active { background: var(--bg3); }
.sb-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sb-dot.live { background: var(--green); box-shadow: 0 0 4px var(--green); }
.sb-dot.dead { background: var(--red); }
.sb-dot.loading { background: var(--orange); }
.sb-dot.stale { background: var(--orange); }
.sb-dot.givenup { background: var(--border); }
.sb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-ip { font-size: 10px; color: var(--text2); }
.sb-cam-toggle {
    width: 28px; height: 14px; border-radius: 7px;
    background: var(--border); position: relative;
    cursor: pointer; flex-shrink: 0; transition: background 0.2s;
}
.sb-cam-toggle.on { background: var(--green); }
.sb-cam-toggle::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 10px; height: 10px; border-radius: 50%;
    background: #fff; transition: left 0.2s;
}
.sb-cam-toggle.on::after { left: 16px; }
.sb-stream-type {
    font-size: 9px; font-weight: 700; color: var(--green);
    background: rgba(78,204,163,0.15); padding: 1px 4px;
    border-radius: 3px; flex-shrink: 0;
}
.sb-cam-btns { display: flex; gap: 2px; flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.sb-cam:hover .sb-cam-btns { opacity: 1; }
.sb-btn-edit, .sb-btn-del {
    width: 18px; height: 18px; border: none; border-radius: 3px;
    cursor: pointer; font-size: 12px; line-height: 18px; text-align: center;
    background: transparent; color: var(--text2); padding: 0;
}
.sb-btn-edit:hover { color: var(--blue); background: rgba(77,166,255,0.15); }
.sb-btn-del:hover { color: var(--red); background: rgba(233,69,96,0.15); }
.sb-detail-btns { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.sb-scan-results { margin-top: 4px; }
.sb-cam-list { display: none; }
.sb-cam-list.show { display: block; }
.sb-btn-del-grp { color: var(--red) !important; border-color: var(--red) !important; }
.sb-btn-del-grp:hover { background: rgba(233,69,96,0.15) !important; }

/* Ping dots on IP groups */
.sb-ping-dot {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; margin-right: 4px; vertical-align: middle;
}
.sb-ping-dot.ping-online { background: var(--green); box-shadow: 0 0 4px var(--green); }
.sb-ping-dot.ping-slow { background: var(--orange); box-shadow: 0 0 4px var(--orange); }
.sb-ping-dot.ping-offline { background: var(--red); }
.sb-ping-dot.ping-unknown { background: var(--border); }
.sb-ping-ms { font-size: 9px; color: var(--text2); font-weight: 400; }
.sb-group-label.sb-dead { opacity: 0.5; }

/* Sidebar stats */
.sidebar-stats {
    padding: 4px 10px; font-size: 10px; color: var(--text2);
    border-bottom: 1px solid var(--border);
    display: flex; gap: 6px; align-items: center;
}
.stat-online { color: var(--green); }
.stat-offline { color: var(--red); }
.stat-fav { color: var(--orange); }

/* Sidebar action buttons */
.sidebar-actions {
    padding: 4px 10px; display: flex; gap: 4px;
    border-bottom: 1px solid var(--border);
}
.sb-action-btn {
    font-size: 9px; padding: 2px 6px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text2); border-radius: 3px; cursor: pointer;
}
.sb-action-btn:hover { border-color: var(--accent); color: var(--text); }

/* Favorite star in sidebar */
.sb-fav {
    cursor: pointer; font-size: 12px; color: var(--border);
    flex-shrink: 0; line-height: 1; margin-right: -4px;
}
.sb-fav.active { color: var(--orange); }
.sb-fav:hover { color: var(--orange); }

/* Favorite star in grid cell */
.cam-fav {
    position: absolute; top: 6px; right: 28px;
    font-size: 18px; color: rgba(255,255,255,0.3);
    cursor: pointer; z-index: 3; line-height: 1;
    transition: color 0.15s;
}
.cam-fav.active { color: var(--orange); }
.cam-fav:hover { color: var(--orange); }

/* View button active state */
.view-btn.active { background: var(--orange); border-color: var(--orange); color: #000; }
.btn-group .btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- CAMERA GRID ---- */
.grid-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.grid-container { flex: 1; display: grid; gap: 4px; padding: 4px; overflow: hidden; }
.grid-1  { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.grid-4  { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.grid-6  { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.grid-9  { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }
.grid-12 { grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }
.grid-24 { grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(4, 1fr); }
.grid-container.fav-mode { grid-template-rows: auto !important; overflow-y: auto; }
.grid-container.fav-mode .cam-cell { min-height: 200px; }

.cam-cell {
    position: relative; background: #000; border-radius: 4px;
    overflow: hidden; display: flex; align-items: center;
    justify-content: center; cursor: pointer;
}
.cam-cell video { width: 100%; height: 100%; object-fit: contain; }
.cam-label {
    position: absolute; top: 6px; left: 8px;
    background: rgba(0,0,0,0.7); padding: 2px 8px;
    border-radius: 3px; font-size: 12px; z-index: 2;
    pointer-events: none; display: flex; align-items: center; gap: 6px;
}
.cam-label .cam-ip-tag { font-size: 10px; color: var(--text2); opacity: 0.8; }
.cam-flag {
    position: absolute; top: 6px; right: 52px;
    width: 20px; height: 20px; border-radius: 50%;
    z-index: 3; pointer-events: none;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.cam-time-overlay {
    position: absolute; bottom: 6px; left: 8px;
    background: rgba(0,0,0,0.7); padding: 2px 8px;
    border-radius: 3px; font-size: 11px; color: var(--text2);
    z-index: 2; pointer-events: none;
}
.codec-badge {
    display: inline-block; padding: 1px 5px; border-radius: 3px;
    font-size: 9px; font-weight: 700; letter-spacing: 0.5px;
}
.codec-badge.h264 { background: var(--green); color: #000; }
.codec-badge.hevc { background: var(--orange); color: #000; }
.codec-badge.transcode { background: #c060e0; color: #fff; }
.codec-badge.unknown { background: var(--border); color: var(--text2); }

.cam-status {
    position: absolute; top: 8px; right: 8px;
    width: 10px; height: 10px; border-radius: 50%; z-index: 2;
}
.cam-status.live { background: var(--green); box-shadow: 0 0 6px var(--green); }
.cam-status.dead { background: var(--red); }
.cam-status.loading { background: var(--orange); animation: pulse 1s infinite; }
.cam-status.stale { background: var(--orange); }
@keyframes pulse { 50% { opacity: 0.4; } }

.cam-empty { color: var(--text2); font-size: 14px; text-align: center; cursor: default; }

/* ---- CAMERA PLACEHOLDER OVERLAYS ---- */
.cam-placeholder {
    position: absolute; inset: 0; z-index: 4;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,0.85); gap: 12px;
    pointer-events: none; transition: opacity 0.4s;
}
.cam-placeholder.hidden { opacity: 0; pointer-events: none; }
.cam-placeholder .ph-icon {
    width: 40px; height: 40px; display: flex;
    align-items: center; justify-content: center;
}
.cam-placeholder .ph-text {
    font-size: 12px; color: var(--text2); text-align: center;
    letter-spacing: 0.3px;
}
/* Loading state: pulsing spinner */
.cam-placeholder.loading .ph-icon {
    border: 3px solid var(--border); border-top-color: var(--orange);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
.cam-placeholder.loading .ph-text { color: var(--orange); }
/* Offline state: red camera icon */
.cam-placeholder.offline .ph-icon {
    border: none; animation: none;
}
.cam-placeholder.offline .ph-icon::before {
    content: '';
    display: block; width: 32px; height: 32px;
    background: var(--red); mask-size: contain; mask-repeat: no-repeat; mask-position: center;
    -webkit-mask-size: contain; -webkit-mask-repeat: no-repeat; -webkit-mask-position: center;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M18 10.48V6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4.48l4 3.98v-11l-4 3.98zm-2-.79V18H4V6h12v3.69zM10 8H5.09C6.47 10.64 8.58 12.76 11.23 14.15L10 8z'/%3E%3Cline x1='3' y1='3' x2='21' y2='21' stroke='white' stroke-width='2'/%3E%3C/svg%3E");
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M18 10.48V6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4.48l4 3.98v-11l-4 3.98zm-2-.79V18H4V6h12v3.69zM10 8H5.09C6.47 10.64 8.58 12.76 11.23 14.15L10 8z'/%3E%3Cline x1='3' y1='3' x2='21' y2='21' stroke='white' stroke-width='2'/%3E%3C/svg%3E");
}
.cam-placeholder.offline .ph-text { color: var(--red); }
/* Waiting state: yellow spinner */
.cam-placeholder.waiting .ph-icon {
    border: 3px solid var(--border); border-top-color: var(--green);
    border-radius: 50%; animation: spin 1s linear infinite;
}
.cam-placeholder.waiting .ph-text { color: var(--text2); }

.cam-cell .cam-actions {
    position: absolute; bottom: 6px; right: 8px;
    display: none; gap: 4px; z-index: 3;
}
.cam-cell:hover .cam-actions { display: flex; }

/* ---- PAGINATION ---- */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 4px; padding: 6px; background: var(--bg2);
    border-top: 1px solid var(--border); flex-shrink: 0;
}
.pagination.hidden { display: none; }
.page-btn {
    min-width: 32px; padding: 4px 10px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text2); border-radius: 4px; cursor: pointer;
    font-size: 12px; text-align: center;
}
.page-btn:hover { border-color: var(--accent); color: var(--text); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.page-info { font-size: 12px; color: var(--text2); margin: 0 8px; }

/* ---- FULLSCREEN OVERLAY ---- */
.fullscreen-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.85); z-index: 200;
    align-items: center; justify-content: center; cursor: pointer;
}
.fullscreen-overlay.show { display: flex; }
.fullscreen-overlay .fs-bg {
    position: absolute; inset: 0; cursor: pointer; z-index: 0;
}
.fullscreen-overlay .fs-viewport {
    position: relative; width: 90vw; height: 85vh;
    background: #000; border: 2px solid var(--border);
    border-radius: 8px; overflow: hidden;
    /* Ingen z-index: label/actions/nav er nu i overlay-stacking-context (z-index 210+) */
}
.fullscreen-overlay.is-native-fs .fs-viewport {
    width: 100vw; height: 100vh; border: none; border-radius: 0;
}
.fullscreen-overlay video {
    width: 100%; height: 100%; object-fit: contain; pointer-events: none;
}
.fullscreen-label {
    position: absolute; top: 12px; left: 16px;
    background: rgba(0,0,0,0.7); padding: 4px 12px;
    border-radius: 4px; font-size: 14px; z-index: 210;
    display: flex; align-items: center; gap: 8px; pointer-events: none;
}
.fullscreen-actions {
    position: absolute; top: 12px; right: 16px;
    display: flex; gap: 6px; z-index: 210; pointer-events: auto;
}
.fullscreen-actions .btn { pointer-events: auto; }
.fullscreen-hint {
    position: absolute; bottom: 16px; left: 50%;
    transform: translateX(-50%); background: rgba(0,0,0,0.6);
    padding: 4px 14px; border-radius: 4px; font-size: 12px;
    color: var(--text2); z-index: 210; opacity: 1;
    transition: opacity 2s; pointer-events: none;
}
.fullscreen-hint.fade { opacity: 0; }
.fs-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    z-index: 212; background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.2); color: #fff;
    font-size: 28px; width: 48px; height: 72px;
    border-radius: 6px; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    opacity: 0.4; transition: opacity 0.2s; pointer-events: auto;
}
.fs-nav:hover { opacity: 1; background: rgba(0,0,0,0.8); }
.fs-nav-left { left: 12px; }
.fs-nav-right { right: 12px; }

/* ---- SNAPSHOT OVERLAY ---- */
.snapshot-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.9); z-index: 250;
    align-items: center; justify-content: center;
    cursor: pointer; flex-direction: column;
}
.snapshot-overlay.show { display: flex; }
.snapshot-overlay img { max-width: 90vw; max-height: 85vh; object-fit: contain; border-radius: 4px; }
.snapshot-overlay .snap-info { margin-top: 10px; font-size: 13px; color: var(--text2); }
.snapshot-overlay .snap-loading { font-size: 14px; color: var(--text2); }

/* ---- MODAL ---- */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.7); z-index: 100;
    align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 8px; padding: 24px;
    min-width: 420px; max-width: 90vw; max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 16px; font-size: 16px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--text2); }
.form-group input, .form-group select {
    width: 100%; padding: 8px; border: 1px solid var(--border);
    border-radius: 4px; background: var(--bg); color: var(--text); font-size: 14px;
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---- TOGGLE SWITCH ---- */
.toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 0; font-size: 13px; border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-label { color: var(--text); }
.toggle-desc { font-size: 11px; color: var(--text2); }
.toggle {
    width: 40px; height: 22px; background: var(--border);
    border-radius: 11px; position: relative; cursor: pointer;
    transition: background 0.2s; flex-shrink: 0;
}
.toggle.on { background: var(--green); }
.toggle::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 16px; height: 16px; background: #fff;
    border-radius: 50%; transition: left 0.2s;
}
.toggle.on::after { left: 21px; }

/* ---- CAMERA LIST IN SETTINGS ---- */
.cam-list { margin: 12px 0; }
.cam-list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px; border: 1px solid var(--border); border-radius: 4px;
    margin-bottom: 6px; font-size: 13px;
}
.cam-list-item .cam-info { flex: 1; }
.cam-list-item .cam-info strong { color: var(--text); }
.cam-list-item .cam-info small { color: var(--text2); margin-left: 8px; }
.cam-list-item .cam-btns { display: flex; gap: 4px; }
.cam-list-item.sortable-ghost { background: var(--bg3); opacity: 0.5; }
.cam-list-item .drag-handle { cursor: grab; color: var(--text2); margin-right: 12px; font-size: 16px; }

/* ---- HEALTH CHECK ---- */
.health-results { margin-top: 12px; }
.health-row {
    display: flex; align-items: center; padding: 6px 10px;
    border: 1px solid var(--border); border-radius: 4px;
    margin-bottom: 4px; font-size: 12px; gap: 10px;
}
.health-row .h-name { flex: 1; font-weight: 600; }
.health-row .h-status { min-width: 80px; }
.health-row .h-status.ok { color: var(--green); }
.health-row .h-status.fail { color: var(--red); }

/* ---- LOG PANEL ---- */
.log-panel {
    display: none; position: fixed; bottom: 0; left: 0; right: 0;
    height: 250px; background: var(--bg2);
    border-top: 1px solid var(--border); z-index: 50; flex-direction: column;
}
.log-panel.show { display: flex; }
.log-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 12px; border-bottom: 1px solid var(--border);
}
.log-header span { font-size: 13px; font-weight: 600; }
.log-content {
    flex: 1; overflow-y: auto; padding: 8px 12px;
    font-family: 'Courier New', monospace; font-size: 12px;
    line-height: 1.5; color: var(--text2);
}
.log-content .log-warn { color: var(--orange); }
.log-content .log-err { color: var(--red); }

/* ---- TABS ---- */
.tabs { display: flex; gap: 0; margin-bottom: 16px; }
.tab {
    padding: 8px 16px; cursor: pointer;
    border-bottom: 2px solid transparent; font-size: 13px; color: var(--text2);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- SCANNER ---- */
.scan-row {
    display: flex; align-items: center; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: 4px;
    margin-bottom: 4px; font-size: 13px; gap: 12px;
}
.scan-row .ch-id { font-weight: 700; color: var(--accent); min-width: 44px; }
.scan-row .ch-info { flex: 1; color: var(--text2); }
.scan-row .ch-res { color: var(--green); font-family: monospace; min-width: 100px; }
.scan-row .ch-codec { font-size: 11px; font-weight: 700; min-width: 50px; text-align: center; }
.scan-row .ch-codec.hevc { color: var(--orange); }
.scan-row .ch-codec.h264 { color: var(--green); }
.scan-row .ch-added { color: var(--green); font-size: 12px; }
.scan-progress { padding: 16px; text-align: center; color: var(--text2); }
.scan-progress .spinner {
    display: inline-block; width: 20px; height: 20px;
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.8s linear infinite;
    vertical-align: middle; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.scan-summary {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 0; font-size: 13px; color: var(--text2);
    border-bottom: 1px solid var(--border); margin-bottom: 8px;
}

/* ---- DEVICE INFO ---- */
.device-info {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; padding: 10px 12px; margin-top: 10px; font-size: 12px;
}
.device-info h3 { font-size: 13px; margin-bottom: 6px; color: var(--accent); }
.device-info .di-row { display: flex; gap: 24px; flex-wrap: wrap; }
.device-info .di-item { margin-bottom: 3px; }
.device-info .di-label { color: var(--text2); }
.device-info .di-val { color: var(--text); margin-left: 4px; }

/* ---- NEDE VIEW ---- */
.nede-badge {
    display: inline-block; background: var(--red); color: #fff;
    font-size: 10px; font-weight: 700; padding: 1px 5px;
    border-radius: 8px; margin-left: 4px; vertical-align: middle;
    min-width: 16px; text-align: center;
}
.view-btn[data-view="nede"].active { background: var(--red); border-color: var(--red); color: #fff; }
.nede-cell .cam-placeholder { pointer-events: auto; }
.nede-cell .cam-actions { bottom: 12px; right: auto; left: 50%; transform: translateX(-50%); }
.nede-since { font-size: 10px; color: var(--text2); margin-top: 4px; }
.nede-precheck { margin-top: 6px; min-height: 16px; }

/* ---- RESPONSIVE: MOBILE (< 768px) ---- */
@media (max-width: 767px) {
    /* Allow page scrolling */
    body {
        height: auto;
        min-height: 100dvh;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Sticky header */
    .header {
        position: sticky;
        top: 0;
        z-index: 100;
        padding: 6px 10px;
        flex-wrap: nowrap;
        gap: 6px;
        justify-content: space-between;
    }
    .header h1 { font-size: 14px; flex: 1; white-space: nowrap; }
    .header h1 .version { font-size: 10px; }
    .header-right { gap: 4px; }
    .header-main { gap: 4px; }

    /* Grid selector: scrollable, no scrollbar */
    .grid-selector {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        max-width: 130px;
    }
    .grid-selector::-webkit-scrollbar { display: none; }
    .grid-btn { padding: 5px 8px; font-size: 12px; }

    /* Show mobile ⋮ button */
    .mobile-menu-btn { display: flex; padding: 6px 10px; }

    /* header-actions: hidden by default, slide-down drawer on mobile */
    .header-actions {
        display: none;
        position: fixed;
        top: 49px;
        right: 0;
        left: 0;
        background: var(--bg2);
        border-bottom: 2px solid var(--accent);
        padding: 10px 12px;
        z-index: 150;
        flex-direction: column;
        gap: 6px;
        box-shadow: 0 4px 16px rgba(0,0,0,0.5);
        max-height: calc(100dvh - 49px);
        overflow-y: auto;
    }
    .header-actions.mobile-open { display: flex; }
    .header-actions .btn {
        width: 100%;
        text-align: left;
        padding: 10px 14px;
        font-size: 14px;
    }
    .header-actions .btn-group { display: flex; width: 100%; gap: 4px; }
    .header-actions .btn-group .btn { flex: 1; text-align: center; }
    .header-actions a.btn { display: block; }

    /* Mobile menu backdrop */
    .mobile-menu-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 140;
        background: rgba(0,0,0,0.4);
    }
    .mobile-menu-backdrop.show { display: block; }

    /* Sidebar: slide-in overlay */
    .sidebar {
        position: fixed !important;
        left: -300px;
        top: 0;
        height: 100dvh;
        width: 280px !important;
        z-index: 300;
        transition: left 0.3s ease;
        display: flex !important;
        box-shadow: 4px 0 20px rgba(0,0,0,0.6);
    }
    .sidebar.show { left: 0; }

    /* Sidebar backdrop */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 290;
    }
    .sidebar-backdrop.show { display: block; }

    /* Main content + grid: scrollable */
    .main-content { overflow: visible; flex-direction: column; }
    .grid-wrapper { overflow: visible; flex: none; }
    .grid-container {
        overflow: visible !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
    }
    .cam-cell { min-height: 56vw; height: auto; }

    /* Always show cam actions (no hover on touch) */
    .cam-cell .cam-actions { display: flex !important; }

    /* Pagination: sticky at bottom */
    .pagination {
        position: sticky;
        bottom: 0;
        z-index: 50;
        background: var(--bg2);
        padding: 8px 6px;
        gap: 4px;
    }
    .page-btn { min-width: 36px; padding: 8px 10px; font-size: 13px; }

    /* Modal: full width */
    .modal { min-width: auto !important; width: 95vw; padding: 16px; }
    .modal h2 { font-size: 15px; }
    .form-row { flex-direction: column; gap: 6px; }
    .form-row .form-group { max-width: none !important; }

    /* Fullscreen */
    .fullscreen-actions { top: 8px; right: 8px; }
    .fs-nav { width: 40px; height: 60px; font-size: 24px; }
    .fullscreen-label { font-size: 12px; top: 8px; left: 8px; }

    /* Scanner + log */
    .scan-row { flex-wrap: wrap; gap: 6px; }
    .scan-row .ch-res { min-width: auto; }
    .scan-summary { flex-direction: column; gap: 6px; align-items: flex-start; }
    .log-panel { height: 200px; }
}

/* ---- RESPONSIVE: TABLET (768px - 1023px) ---- */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar { width: 200px; }
    .header { padding: 6px 12px; }
    .header h1 { font-size: 16px; }
    .grid-container.grid-12 { grid-template-columns: repeat(3, 1fr); }
    .grid-container.grid-24 { grid-template-columns: repeat(4, 1fr); }
    .modal { min-width: auto !important; width: 95vw; }
    .form-row { flex-direction: column; gap: 6px; }
    .form-row .form-group { max-width: none !important; }
}
