/* ============================================
           VARIABLES
        ============================================ */
:root {
    --bg-body: #09090b;
    --bg-surface: #18181b;
    --bg-hover: #27272a;
    --bg-raised: #1c1c1f;
    --border: #3f3f46;
    --border-subtle: #27272a;
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;
    --text-faint: #71717a;
    --accent: #8b5cf6;
    --accent-dim: rgba(139, 92, 246, 0.14);
    --accent-glow: rgba(139, 92, 246, 0.06);

    --ok-color: #22c55e;
    --warn-color: #f59e0b;
    --err-color: #ef4444;
    --pend-color: #a855f7;
    --repair-color: #f97316;

    --ok-bg: rgba(34, 197, 94, 0.1);
    --ok-tx: #86efac;
    --ok-bd: rgba(34, 197, 94, 0.3);
    --warn-bg: rgba(245, 158, 11, 0.1);
    --warn-tx: #fcd34d;
    --warn-bd: rgba(245, 158, 11, 0.3);
    --err-bg: rgba(239, 68, 68, 0.1);
    --err-tx: #fca5a5;
    --err-bd: rgba(239, 68, 68, 0.3);
    --pend-bg: rgba(168, 85, 247, 0.1);
    --pend-tx: #d8b4fe;
    --pend-bd: rgba(168, 85, 247, 0.3);
    --repair-bg: rgba(249, 115, 22, 0.1);
    --repair-tx: #fed7aa;
    --repair-bd: rgba(249, 115, 22, 0.3);
    color-scheme: dark;
}

[data-theme="light"] {
    --bg-body: #fafafa;
    --bg-surface: #ffffff;
    --bg-hover: #f4f4f5;
    --bg-raised: #f7f7f8;
    --border: #e4e4e7;
    --border-subtle: #f4f4f5;
    --text-main: #09090b;
    --text-muted: #71717a;
    --text-faint: #a1a1aa;
    --accent: #7c3aed;
    --accent-dim: rgba(124, 58, 237, 0.08);
    --accent-glow: rgba(124, 58, 237, 0.04);

    --ok-bg: rgba(34, 197, 94, 0.08);
    --ok-tx: #166534;
    --ok-bd: rgba(34, 197, 94, 0.25);
    --warn-bg: rgba(245, 158, 11, 0.08);
    --warn-tx: #92400e;
    --warn-bd: rgba(245, 158, 11, 0.25);
    --err-bg: rgba(239, 68, 68, 0.08);
    --err-tx: #7f1d1d;
    --err-bd: rgba(239, 68, 68, 0.25);
    --pend-bg: rgba(168, 85, 247, 0.08);
    --pend-tx: #4c1d95;
    --pend-bd: rgba(168, 85, 247, 0.25);
    --repair-bg: rgba(249, 115, 22, 0.08);
    --repair-tx: #7c2d12;
    --repair-bd: rgba(249, 115, 22, 0.25);
    color-scheme: light;
}

/* ============================================
           RESET & BASE
        ============================================ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-body);
    color: var(--text-main);
    font-family: "DM Sans", system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: clamp(16px, 3vw, 28px);
}

/* Barras de desplazamiento (Firefox) */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) var(--bg-body);
}

/* Barras de desplazamiento (Chromium, Safari, Edge) */
*::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

*::-webkit-scrollbar-track {
    background: var(--bg-body);
    border-radius: 99px;
}

*::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 99px;
    border: 2px solid var(--bg-body);
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
    border-color: var(--bg-body);
}

*::-webkit-scrollbar-thumb:active {
    background: var(--accent);
    border-color: var(--bg-body);
}

*::-webkit-scrollbar-corner {
    background: var(--bg-body);
}

/* Riel alineado con superficies elevadas (tabla, noticias) */
.news-sidebar-scroll,
.table-wrapper {
    scrollbar-color: var(--border) var(--bg-surface);
}

.news-sidebar-scroll::-webkit-scrollbar-track,
.table-wrapper::-webkit-scrollbar-track {
    background: var(--bg-surface);
}

.news-sidebar-scroll::-webkit-scrollbar-thumb,
.table-wrapper::-webkit-scrollbar-thumb {
    border-color: var(--bg-surface);
}

.news-sidebar-scroll::-webkit-scrollbar-thumb:hover,
.table-wrapper::-webkit-scrollbar-thumb:hover {
    border-color: var(--bg-surface);
}

.news-sidebar-scroll::-webkit-scrollbar-thumb:active,
.table-wrapper::-webkit-scrollbar-thumb:active {
    border-color: var(--bg-surface);
}

.news-sidebar-scroll::-webkit-scrollbar-corner,
.table-wrapper::-webkit-scrollbar-corner {
    background: var(--bg-surface);
}

/* ============================================
           CABECERA
        ============================================ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--accent-dim);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    flex-shrink: 0;
}

.brand-icon svg {
    width: 18px;
    height: 18px;
}

.brand-text h1 {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.brand-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.brand-sub {
    font-size: 0.72rem;
    color: var(--text-faint);
}

.count-pill {
    font-family: "DM Mono", monospace;
    font-size: 0.68rem;
    color: var(--accent);
    background: var(--accent-dim);
    border: 1px solid rgba(139, 92, 246, 0.25);
    padding: 1px 7px;
    border-radius: 9999px;
}
.count-pill:empty {
    display: none;
}

[data-theme="light"] .count-pill {
    border-color: rgba(124, 58, 237, 0.2);
}

.header-right {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ============================================
           STATS GRID
        ============================================ */
.stats-dashboard {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    margin-bottom: 14px;
}

@media (max-width: 900px) {
    .stats-dashboard {
        grid-template-columns: repeat(3, 1fr);
    }
}
@media (max-width: 500px) {
    .stats-dashboard {
        grid-template-columns: repeat(2, 1fr);
    }
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 14px 12px;
    border-left: 3px solid var(--dot-color, var(--accent));
    transition: box-shadow 0.18s;
}

.stat-card:hover {
    box-shadow:
        0 0 0 1px var(--dot-color, var(--accent)),
        0 4px 16px rgba(0, 0, 0, 0.3);
}

.stat-card[role="button"] {
    cursor: pointer;
}

.stat-card[role="button"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 10px;
}

.stat-card.stat-active {
    box-shadow:
        0 0 0 2px var(--dot-color, var(--accent)),
        0 4px 16px rgba(0, 0, 0, 0.3);
    background: color-mix(
        in srgb,
        var(--dot-color, var(--accent)) 8%,
        var(--bg-surface)
    );
}

.stat-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.stat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--dot-color, var(--accent));
    flex-shrink: 0;
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    color: var(--dot-color, var(--accent));
    margin-bottom: 10px;
}

.stat-bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    background: var(--dot-color, var(--accent));
    border-radius: 2px;
    opacity: 0.6;
    transition: width 0.4s ease;
}

/* ============================================
           BRAND CHART
        ============================================ */
.chart-section {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
    margin-bottom: 14px;
}

.chart-section-title {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.chart-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chart-row {
    display: grid;
    grid-template-columns: 80px 1fr 32px;
    align-items: center;
    gap: 10px;
}

.chart-brand-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-track {
    height: 8px;
    background: var(--bg-hover);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
}

.chart-segment {
    height: 100%;
    transition: width 0.4s ease;
}

.chart-segment:first-child {
    border-radius: 4px 0 0 4px;
}
.chart-segment:last-child {
    border-radius: 0 4px 4px 0;
}
.chart-segment:only-child {
    border-radius: 4px;
}

.chart-count {
    font-family: "DM Mono", monospace;
    font-size: 0.72rem;
    color: var(--text-faint);
    text-align: right;
}

/* ============================================
           BARRA DE CONTROLES
        ============================================ */
.controls-bar {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 14px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* ============================================
           INPUTS, SELECTS, BOTONES
        ============================================ */
input,
select,
.btn {
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: "DM Sans", sans-serif;
    outline: none;
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}

select {
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2371717a' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}

[data-theme="light"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a1a1aa' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

input:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

.btn:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.search-box {
    flex: 1;
    min-width: 180px;
    padding-left: 30px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 9px center;
}

[data-theme="light"] .search-box {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
}

.btn {
    cursor: pointer;
    font-weight: 500;
}

.btn:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
    color: var(--accent);
}

.btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

[data-theme="light"] .btn.active {
    color: #fff;
}

.icon-btn {
    padding: 6px 7px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn svg {
    width: 15px;
    height: 15px;
}

/* Edit button: hidden by default via CSS (belt+suspenders with inline style).
   Shown by JS toggling body.has-editor-token after token check. */
#editor-edit-btn {
    display: none;
}
body.has-editor-token #editor-edit-btn {
    display: flex;
}

.btn-group-actions,
.btn-group-views {
    display: flex;
    gap: 4px;
    padding-right: 8px;
    border-right: 1px solid var(--border);
}

.btn-group-theme {
    display: flex;
    gap: 4px;
}

.controls-filters {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.controls-right {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-left: auto;
    flex-wrap: wrap;
}

.group-by-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    padding-right: 8px;
    border-right: 1px solid var(--border);
}

.group-by-label input[type="checkbox"] {
    width: 13px;
    height: 13px;
    padding: 0;
    cursor: pointer;
    accent-color: var(--accent);
}

.group-by-label.hidden {
    display: none;
}

/* ============================================
           BADGES (pill con dot)
        ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px 2px 6px;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;
    border: 1px solid;
}

.badge::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.st-ok {
    background: var(--ok-bg);
    color: var(--ok-tx);
    border-color: var(--ok-bd);
}
.st-warn {
    background: var(--warn-bg);
    color: var(--warn-tx);
    border-color: var(--warn-bd);
}
.st-err {
    background: var(--err-bg);
    color: var(--err-tx);
    border-color: var(--err-bd);
}
.st-pend {
    background: var(--pend-bg);
    color: var(--pend-tx);
    border-color: var(--pend-bd);
}
.st-repair {
    background: var(--repair-bg);
    color: var(--repair-tx);
    border-color: var(--repair-bd);
}

/* ============================================
           TABLA
        ============================================ */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    white-space: nowrap;
}

thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
}

th {
    text-align: left;
    padding: 10px 14px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}

th:hover,
th.active {
    color: var(--accent);
}
th .sort-icon {
    margin-left: 3px;
    opacity: 0.35;
    font-size: 0.6rem;
}
th.active .sort-icon {
    opacity: 1;
}
th:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-main);
    font-size: 0.875rem;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--bg-hover);
}

tbody tr.urgent td:first-child {
    border-left: 3px solid var(--err-color);
}
tbody tr.has-film td:first-child {
    border-left: 3px solid var(--warn-color);
}

.col-brand {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
}

.col-model {
    font-weight: 500;
}

.col-serial {
    font-family: "DM Mono", monospace;
    font-size: 0.78rem;
    color: var(--text-faint);
}

.col-notes {
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: normal;
    min-width: 180px;
    max-width: 380px;
    line-height: 1.4;
}

/* ============================================
           VISTA CARDS
        ============================================ */
.view-table {
    display: block;
}
.view-cards {
    display: none;
}
body.cards-mode .view-table {
    display: none;
}
body.cards-mode .view-cards {
    display: block;
}

.cards-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
    gap: 14px;
}

@media (max-width: 640px) {
    .cards-view {
        grid-template-columns: 1fr;
    }
}

.camera-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition:
        transform 0.18s,
        box-shadow 0.18s;
    position: relative;
}

@media (hover: hover) {
    .camera-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }
}

.camera-card.urgent {
    border-color: var(--err-bd);
}
.camera-card.has-film {
    border-color: var(--warn-bd);
}

.card-status-stripe {
    height: 4px;
    width: 100%;
}

.card-body {
    padding: 14px 15px 15px;
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.card-header {
    flex: 1;
    min-width: 0;
}

.card-brand {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    margin-bottom: 2px;
}

.card-model {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-serial {
    font-family: "DM Mono", monospace;
    font-size: 0.7rem;
    color: var(--text-faint);
    margin-top: 3px;
}

.card-status-badge {
    flex-shrink: 0;
    margin-left: 10px;
}

.card-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 12px 0;
}

.card-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.card-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
}

.card-info-row > span:first-child {
    font-size: 0.7rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.card-notes {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
}

/* ============================================
           GRUPOS POR MARCA
        ============================================ */
.brand-group {
    margin-bottom: 16px;
}

.brand-group-header {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 8px 8px 0 0;
    padding: 10px 14px;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.brand-group-header:hover {
    background: var(--bg-hover);
}
.brand-group-header:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.brand-group-count {
    font-family: "DM Mono", monospace;
    font-size: 0.7rem;
    color: var(--text-faint);
    font-weight: 400;
}

.brand-group-content {
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
}

.brand-group.collapsed .brand-group-content {
    display: none;
}
.brand-group-content thead {
    background: var(--bg-raised);
}

/* ============================================
           EMPTY STATE
        ============================================ */
.empty-state {
    text-align: center;
    padding: 52px 24px;
    color: var(--text-faint);
    font-size: 0.9rem;
}

/* En la vista de tarjetas (grid), el mensaje vacío debe ocupar todas las columnas */
.cards-view .empty-state {
    grid-column: 1 / -1;
}

/* ============================================
           RESPONSIVE
        ============================================ */
@media (max-width: 768px) {
    .controls-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .controls-right {
        margin-left: 0;
    }
    .search-box {
        min-width: 100%;
    }
}

/* ============================================
           ANIMACIONES
        ============================================ */
@media (prefers-reduced-motion: no-preference) {
    tbody tr {
        animation: rowIn 0.1s ease-out both;
    }
    .camera-card {
        animation: cardIn 0.12s ease-out both;
    }
    .chart-segment {
        animation: barIn 0.4s ease-out;
        transform-origin: left center;
    }

    @keyframes rowIn {
        from {
            opacity: 0;
            transform: translateY(-2px);
        }
        to {
            opacity: 1;
            transform: none;
        }
    }
    @keyframes cardIn {
        from {
            opacity: 0;
            transform: translateY(4px);
        }
        to {
            opacity: 1;
            transform: none;
        }
    }
    @keyframes barIn {
        from {
            transform: scaleX(0);
        }
        to {
            transform: scaleX(1);
        }
    }
}

/* ============================================
           PRINT
        ============================================ */
@media print {
    .controls-bar,
    .stats-dashboard,
    .chart-section,
    .app-header,
    #editor-panel,
    #editor-save-bar,
    #editor-settings-modal,
    aside,
    .view-cards,
    #activityPanel,
    #editor-edit-btn,
    #editor-settings-btn {
        display: none;
    }
    body {
        background: white;
        color: black;
    }
    .table-wrapper {
        border: 1px solid #000;
    }
}

/* ── PWA update banner ───────────────────────────────────────────────────── */
#pwa-update-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    font:
        500 14px system-ui,
        sans-serif;
    background: var(--bg-surface, #18181b);
    color: var(--text-main, #f4f4f5);
    border-top: 1px solid var(--border, #3f3f46);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

#pwa-update-banner button {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--accent, #8b5cf6);
    background: var(--accent, #8b5cf6);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

#pwa-update-banner button:focus-visible {
    outline: 2px solid var(--accent, #8b5cf6);
    outline-offset: 2px;
}

/* ── Search highlight ────────────────────────────────────────────────────── */
mark {
    background: rgba(251, 191, 36, 0.35);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

[data-theme="light"] mark {
    background: rgba(251, 191, 36, 0.5);
}

/* ── Editor ──────────────────────────────────────────────────────────────── */
/* Pending change indicator */
.editor-pending {
    outline: 2px solid var(--accent, #8b5cf6);
    outline-offset: -2px;
}

/* Edit mode: row/card cursor */
body.edit-mode #tableBody tr[data-serial] {
    cursor: pointer;
}

body.edit-mode #cardsContainer .camera-card[data-serial] {
    cursor: pointer;
    transition:
        transform 0.18s,
        box-shadow 0.18s,
        outline-color 0.15s;
}

body.edit-mode #cardsContainer .camera-card[data-serial]:hover {
    outline: 1px solid var(--accent);
    outline-offset: -1px;
    box-shadow:
        0 0 0 2px var(--accent-dim),
        0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Inline edit button on rows/cards */
.editor-row-btn,
.editor-card-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-hover);
    color: var(--text-muted);
    cursor: pointer;
    vertical-align: middle;
    margin-right: 6px;
    flex-shrink: 0;
}

.editor-row-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

.editor-card-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
    border-color: var(--accent);
}

.editor-row-btn:focus-visible,
.editor-card-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.camera-card .editor-card-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
}

/* Edit panel (slide-in) */
#editor-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(380px, 100vw);
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
    z-index: 9000;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

@media (prefers-reduced-motion: no-preference) {
    #editor-panel {
        animation: epSlideIn 0.2s ease-out;
    }
    @keyframes epSlideIn {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
}

.ep-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--border);
}

.ep-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ep-brand {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
}

.ep-model {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
}

.ep-serial {
    font-family: "DM Mono", monospace;
    font-size: 0.72rem;
    color: var(--text-faint);
}

.ep-form {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
}

.ep-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ep-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.ep-select,
.ep-textarea {
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    padding: 7px 10px;
    font:
        0.875rem "DM Sans",
        sans-serif;
    width: 100%;
    outline: none;

    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}
.ep-textarea {
    resize: vertical;
}

.ep-select:focus,
.ep-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

.ep-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
    padding-top: 8px;
}

/* Inline confirmation widget (replaces native confirm()) */
.ep-inline-confirm {
    margin-top: 4px;
    padding: 12px 14px;
    background: var(--bg-raised);
    border: 1px solid var(--err-bd);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ep-inline-confirm-msg {
    font-size: 0.82rem;
    color: var(--text-main);
    line-height: 1.45;
    white-space: pre-line;
}

.ep-inline-confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.ep-inline-confirm-ok {
    color: var(--err-tx) !important;
    border-color: var(--err-bd) !important;
    font-weight: 600;
}

.ep-inline-confirm-ok:hover {
    background: var(--err-bg) !important;
}

.ep-inline-confirm-ok:focus-visible {
    outline: 2px solid var(--err-color);
    outline-offset: 2px;
}

.ep-inline-confirm-cancel:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.ep-save-btn {
    flex: 1;
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #fff !important;
    font-weight: 600;
}

.ep-save-btn:hover {
    opacity: 0.9;
}

/* Save bar */
/* When save bar is visible, push panel up so actions aren't hidden */
body.editor-has-save-bar #editor-panel {
    padding-bottom: 64px;
}

#editor-save-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 16px;
    background: var(--bg-raised);
    border-top: 1px solid var(--accent);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
    font:
        500 14px system-ui,
        sans-serif;
    color: var(--text-main);
}

#editor-save-msg {
    color: var(--accent);
    font-weight: 600;
}

#editor-save-commit-btn {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #fff !important;
    font-weight: 600;
}

#editor-discard-btn {
    color: var(--text-muted);
}

#editor-save-commit-btn:focus-visible,
#editor-discard-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Settings modal */
.editor-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.editor-modal-backdrop[hidden] {
    display: none;
}

.editor-modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: min(440px, 100%);
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

.editor-modal-title {
    font-size: 1rem;
    font-weight: 700;
}

.editor-modal-desc {
    font-size: 0.84rem;
    color: var(--text-muted);
    line-height: 1.55;
}

.editor-modal-desc a {
    color: var(--accent);
    text-decoration: underline;
}

.editor-modal-desc code {
    font-family: "DM Mono", monospace;
    font-size: 0.82em;
    background: var(--bg-hover);
    padding: 1px 4px;
    border-radius: 3px;
}

.editor-modal-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.editor-modal-input {
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    padding: 8px 12px;
    font:
        0.875rem "DM Mono",
        monospace;
    width: 100%;
    outline: none;
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}

.editor-modal-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

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

/* Toast */
.editor-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 20px;
    border-radius: 8px;
    font:
        500 14px system-ui,
        sans-serif;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    white-space: nowrap;
}

.editor-toast-error {
    border-color: var(--err-color);
    color: var(--err-tx);
}
.btn-danger {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.35);
}
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: #ef4444;
}
[data-theme="light"] .btn-danger {
    color: #dc2626;
    border-color: rgba(220, 38, 38, 0.35);
}
[data-theme="light"] .btn-danger:hover {
    background: rgba(220, 38, 38, 0.08);
    border-color: #dc2626;
}
.editor-toast-reload {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 10px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.editor-toast-reload:hover {
    background: rgba(255, 255, 255, 0.22);
}
[data-theme="light"] .editor-toast-reload {
    border-color: rgba(0, 0, 0, 0.2);
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-main);
}
[data-theme="light"] .editor-toast-reload:hover {
    background: rgba(0, 0, 0, 0.1);
}

@media (prefers-reduced-motion: no-preference) {
    .editor-toast {
        animation: toastIn 0.2s ease-out;
    }
    @keyframes toastIn {
        from {
            opacity: 0;
            transform: translateX(-50%) translateY(8px);
        }
        to {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
    }
}

/* ============================================
   ETIQUETAS (tags) — visualización en tabla y tarjetas
============================================ */
.cam-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
}

.cam-tag {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 9999px;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    background: rgba(139, 92, 246, 0.12);
    color: var(--accent);
    border: 1px solid rgba(139, 92, 246, 0.25);
}

[data-theme="light"] .cam-tag {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: rgba(124, 58, 237, 0.25);
}

/* ============================================
   ETIQUETAS — panel de edición
============================================ */
.ep-tags-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ep-tag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.ep-tag-chip {
    padding: 4px 11px;
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
    transition:
        background 0.12s ease,
        color 0.12s ease,
        border-color 0.12s ease,
        box-shadow 0.12s ease;
    line-height: 1.4;
}

.ep-tag-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ep-tag-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.ep-tag-chip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.ep-new-tag-btn {
    padding: 3px 9px;
    border: 1px dashed var(--border);
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--text-faint);
    background: transparent;
    cursor: pointer;
    transition:
        background 0.12s ease,
        color 0.12s ease,
        border-color 0.12s ease;
    line-height: 1.4;
}

.ep-new-tag-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    border-style: solid;
}

.ep-new-tag-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 2px;
}

.ep-new-tag-input {
    flex: 1;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input, var(--bg-surface));
    color: var(--text-main);
    font: inherit;
    font-size: 0.8rem;
}

.ep-new-tag-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

.ep-new-tag-confirm,
.ep-new-tag-cancel {
    padding: 5px 10px;
    border-radius: 7px;
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition:
        background 0.12s,
        border-color 0.12s;
}

.ep-new-tag-confirm {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.ep-new-tag-confirm:hover {
    opacity: 0.85;
}

.ep-new-tag-cancel {
    background: transparent;
    color: var(--text-muted);
}

.ep-new-tag-cancel:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.ep-new-tag-confirm:focus-visible,
.ep-new-tag-cancel:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Tag item wrapper (chip + delete button) ── */
.ep-tag-item {
    display: inline-flex;
    align-items: center;
    gap: 1px;
}

.ep-tag-del {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    min-height: 24px;
    padding: 2px 4px;
    border: none;
    border-radius: 99px;
    background: transparent;
    color: var(--text-faint);
    font-size: 0.8rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.4;
    transition:
        opacity 0.12s,
        background 0.12s,
        color 0.12s;
}

.ep-tag-item:hover .ep-tag-del,
.ep-tag-del:focus-visible {
    opacity: 1;
}

.ep-tag-del:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    opacity: 1;
}

.ep-tag-del:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
