/* ==========================================================================
   SAEZ Cranes — Unified App Stylesheet
   Consolidates: control.css + portal.css + style.css
   All classes use `app-` prefix. Variables use `--app-` prefix.
   ========================================================================== */

/* === ROOT VARIABLES === */

:root {
    color-scheme: light;
    /* Layout */
    --app-sidebar-w: 240px;
    --app-topbar-h: 56px;
    --app-sidebar-bg: #1a2332;

    /* Brand */
    --app-saez-red: #e30613;
    --app-saez-red-dark: #c70512;
    --app-saez-dark: #373737;

    /* Blues */
    --app-blue: #1a3a5c;
    --app-blue-light: #3b82f6;
    --app-blue-hover: #2a5a8c;

    /* Palette */
    --app-bg: #f1f5f9;
    --app-card-bg: #ffffff;
    --app-text: #1e293b;
    --app-text-muted: #475569;
    --app-text-light: #94a3b8;
    --app-border: #e2e8f0;

    /* Semantic */
    --app-green: #28a745;
    --app-orange: #e87c1e;
    --app-red: #dc3545;
    --app-teal: #0d9488;
    --app-purple: #7c3aed;

    /* Extended palette */
    --app-card-bg-subtle: #f9fafb;
    --app-card-bg-alt: #f3f4f6;
    --app-border-light: #e5e7eb;
    --app-text-strong: #111827;
    --app-text-body: #374151;

    /* Badges */
    --app-badge-active-bg: #dcfce7;     --app-badge-active-text: #166534;
    --app-badge-inactive-bg: #f1f5f9;   --app-badge-inactive-text: #64748b;
    --app-badge-pending-bg: #fef3c7;    --app-badge-pending-text: #b45309;
    --app-badge-urgent-bg: #fee2e2;     --app-badge-urgent-text: #dc2626;
    --app-badge-root-bg: #fee2e2;       --app-badge-root-text: #dc2626;
    --app-badge-saez-bg: #dbeafe;       --app-badge-saez-text: #1d4ed8;
    --app-badge-cliente-bg: #dcfce7;    --app-badge-cliente-text: #166534;
    --app-badge-resolved-bg: #dcfce7;   --app-badge-resolved-text: #166534;
    --app-badge-available-bg: #d1fae5;  --app-badge-available-text: #065f46;
    --app-badge-missing-bg: #fef3c7;    --app-badge-missing-text: #92400e;
    --app-badge-searched-bg: #e5e7eb;   --app-badge-searched-text: #374151;

    /* Surfaces — sombras de 2 capas para profundidad (premium) */
    --app-shadow-sm: 0 1px 2px rgba(16,24,40,0.05);
    --app-shadow: 0 1px 2px rgba(16,24,40,0.06), 0 1px 3px rgba(16,24,40,0.10);
    --app-shadow-md: 0 2px 4px rgba(16,24,40,0.06), 0 4px 12px rgba(16,24,40,0.10);
    --app-shadow-lg: 0 8px 24px rgba(16,24,40,0.12);
    --app-radius-sm: 6px;
    --app-radius: 8px;
    --app-radius-lg: 14px;
    --app-radius-msg: 12px;

    /* Tokens de diseño (premium) — escala tipográfica modular (~1.2), spacing base 4px, motion */
    --fs-xs: 0.75rem;
    --fs-sm: 0.85rem;
    --fs-base: 0.95rem;
    --fs-md: 1.05rem;
    --fs-lg: 1.2rem;
    --fs-xl: 1.4rem;
    --fs-2xl: 1.7rem;
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --app-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --app-ease-snap: cubic-bezier(0.2, 0.8, 0.2, 1);  /* ease-out crujiente para hover de botones */
    --app-dur: 0.18s;
    /* alias usados por algunos módulos (catálogo) que no estaban definidos */
    --app-bg-card: var(--app-card-bg);
    --app-text-secondary: var(--app-text-muted);

    /* Chat */
    --app-bg-chat: #e8ecf0;
    --app-msg-bot: #f0f2f5;
    --app-msg-user: #1a3a5c;
    --app-msg-file: #e3f2fd;
}

/* === DARK MODE (P23) === */

[data-theme="dark"] {
    color-scheme: dark;
    --app-bg: #0f172a;
    --app-card-bg: #1e293b;
    --app-text: #e2e8f0;
    --app-text-muted: #94a3b8;
    --app-text-light: #64748b;
    --app-border: #334155;
    --app-shadow: 0 1px 3px rgba(0,0,0,0.3);
    --app-shadow-lg: 0 4px 12px rgba(0,0,0,0.3);

    /* Extended palette — dark */
    --app-card-bg-subtle: #162030;
    --app-card-bg-alt: #1a2536;
    --app-border-light: #334155;
    --app-text-strong: #f1f5f9;
    --app-text-body: #cbd5e1;

    /* Badges — dark */
    --app-badge-active-bg: #064e3b;     --app-badge-active-text: #6ee7b7;
    --app-badge-inactive-bg: #1e293b;   --app-badge-inactive-text: #94a3b8;
    --app-badge-pending-bg: #451a03;    --app-badge-pending-text: #fde68a;
    --app-badge-urgent-bg: #450a0a;     --app-badge-urgent-text: #fca5a5;
    --app-badge-root-bg: #450a0a;       --app-badge-root-text: #fca5a5;
    --app-badge-saez-bg: #172554;       --app-badge-saez-text: #93c5fd;
    --app-badge-cliente-bg: #064e3b;    --app-badge-cliente-text: #6ee7b7;
    --app-badge-resolved-bg: #064e3b;   --app-badge-resolved-text: #6ee7b7;
    --app-badge-available-bg: #064e3b;  --app-badge-available-text: #6ee7b7;
    --app-badge-missing-bg: #451a03;    --app-badge-missing-text: #fde68a;
    --app-badge-searched-bg: #334155;   --app-badge-searched-text: #94a3b8;

    --app-bg-chat: #1e293b;
    --app-msg-bot: #334155;
    --app-msg-file: #1e3a5f;
    --app-sidebar-bg: #0f172a;

    /* Messaging palette — used by messaging.js, forum.js */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #2a3548;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --bg-hover: rgba(255,255,255,0.06);
    --bg-active: rgba(33,150,243,0.15);
    --bg-accent-subtle: rgba(33,150,243,0.08);
}

[data-theme="dark"] .app-topbar { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .app-login-panel { background: #1e293b; }
[data-theme="dark"] .app-login-title { color: #e2e8f0; }
[data-theme="dark"] .app-input-icon-wrap input { background: #0f172a; border-color: #475569; color: #e2e8f0; }
[data-theme="dark"] .app-input-icon-wrap .app-input-icon { color: #94a3b8; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
    background: #334155; color: #e2e8f0; border-color: #475569;
}
[data-theme="dark"] .app-crane-card, [data-theme="dark"] .app-mon-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .app-kpi-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] table th,
[data-theme="dark"] .app-table th { background: #334155 !important; color: #e2e8f0 !important; }
[data-theme="dark"] table td { border-color: #334155; color: var(--app-text); }
[data-theme="dark"] table tbody tr:nth-child(even),
[data-theme="dark"] .app-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.03); }
[data-theme="dark"] table tbody tr:hover,
[data-theme="dark"] .app-table tbody tr:hover { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .app-modal-content { background: #1e293b; color: #e2e8f0; }

/* Dark mode — Calendar (grid/day now use variables; keep header contrast + interactive states) */
[data-theme="dark"] .app-calendar-header { background: #334155; }
[data-theme="dark"] .app-calendar-day:hover { background: #283548; }
[data-theme="dark"] .app-calendar-day.today { background: #1e3a5f; }
[data-theme="dark"] .app-calendar-day.other-month { background: #162030; color: #475569; }
[data-theme="dark"] .app-calendar-day.selected { background: #1e3a5f; }
[data-theme="dark"] .app-calendar-event { background: #283548; }

/* Dark mode — Scrollbars */
[data-theme="dark"] * {
    scrollbar-color: #475569 #1e293b;
}
[data-theme="dark"] ::-webkit-scrollbar { width: 8px; height: 8px; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: #1e293b; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #64748b; }
[data-theme="dark"] ::-webkit-scrollbar-corner { background: #1e293b; }

/* Dark mode — Catalog cards & load curves */
[data-theme="dark"] .app-catalog-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .app-catalog-card-img { background: #162030; }
[data-theme="dark"] .app-catalog-loadcurve td { color: #e2e8f0; }

/* Dark mode — Esquema cards (hover shadow only; base uses CSS variables) */
[data-theme="dark"] .app-esquema-model-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.3); }

/* Dark mode — PLC rows */
[data-theme="dark"] .plc-row-input { background: #0f2918; color: #86efac; }
[data-theme="dark"] .plc-row-output { background: #2d1215; color: #fca5a5; }
[data-theme="dark"] .plc-row-analog { background: #2d2305; color: #fde68a; }

/* Dark mode — CANopen stats */
[data-theme="dark"] .canopen-card-stats span { background: #334155; color: #e2e8f0; }

/* Dark mode toggle in sidebar */
.app-sidebar-theme {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    padding: 0.3rem 0;
    color: #94a3b8;
    font-size: 0.78rem;
    transition: color 0.2s;
}
.app-sidebar-theme:hover { color: #e2e8f0; }
.app-theme-toggle {
    position: relative;
    width: 36px; height: 20px;
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
    transition: background 0.3s;
    flex-shrink: 0;
}
.app-theme-toggle::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 16px; height: 16px;
    background: #cbd5e1;
    border-radius: 50%;
    transition: transform 0.3s;
}
[data-theme="dark"] .app-theme-toggle { background: var(--app-saez-red); }
[data-theme="dark"] .app-theme-toggle::after { transform: translateX(16px); }

/* === RESET === */

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

input, select, textarea {
    background: var(--app-card-bg);
    color: var(--app-text);
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Noto Sans CJK JP', 'Noto Sans CJK SC', 'PingFang SC', 'Hiragino Sans', 'Microsoft YaHei',
        'Noto Sans Hebrew', sans-serif;
    background: var(--app-bg);
    color: var(--app-text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Títulos grandes con tracking 'tight' (look premium) */
.app-section-title, .app-crane-header h2, .app-mon-detail-title,
.app-login-title, .app-card-title {
    letter-spacing: -0.011em;
}

/* ==========================================================================
   LOGIN — Split Screen
   ========================================================================== */

.app-login {
    display: none;
    min-height: 100vh;
}

.app-login.active {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    min-height: 100vh;
}

/* Hero panel (left) */
.app-login-hero {
    background: url('../assets/hero-login.jpg') center/cover no-repeat;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-login-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(26,35,50,0.85) 0%, rgba(26,58,92,0.75) 100%);
}

.app-login-hero-content {
    position: relative;
    z-index: 1;
    text-align: center;
    color: white;
    padding: 2rem;
}

.app-login-hero-logo {
    max-width: 200px;
    margin-bottom: 1.5rem;
    filter: brightness(0) invert(1);
}

.app-login-hero-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: 0.5px;
}

.app-login-hero-tagline {
    font-size: 0.95rem;
    opacity: 0.8;
    letter-spacing: 0.5px;
    font-style: italic;
}

/* Form panel (right) */
.app-login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--app-card-bg);
    padding: 2rem;
}

.app-login-container {
    max-width: 380px;
    width: 100%;
    animation: slideUp 0.5s ease-out;
}

.app-login-logo-mobile {
    display: none;
    text-align: center;
    margin-bottom: 1.5rem;
}

.app-login-logo-mobile img {
    max-width: 120px;
}

.app-login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--app-saez-dark);
    margin-bottom: 0.3rem;
}

.app-login-subtitle {
    font-size: 0.88rem;
    color: var(--app-text-muted);
    margin-bottom: 1.25rem;
}

.app-login-error {
    color: var(--app-red);
    font-size: 0.85rem;
    margin-top: 0.75rem;
    text-align: center;
}

.app-login-loading {
    color: var(--app-text-muted);
    font-size: 0.85rem;
    margin-top: 0.75rem;
    text-align: center;
}

/* Input with icon */
.app-input-icon-wrap {
    position: relative;
}

.app-input-icon-wrap .app-input-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--app-text-light);
    pointer-events: none;
}

.app-input-icon-wrap input {
    padding-left: 2.5rem !important;
}

/* ==========================================================================
   APP SHELL — Sidebar + Main layout
   ========================================================================== */

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */

.app-sidebar {
    width: var(--app-sidebar-w);
    height: 100vh;
    background: var(--app-sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    transition: transform 0.3s;
}

.app-sidebar-brand {
    padding: 1.25rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.app-sidebar-brand img {
    height: 32px;
    filter: brightness(2);
}

.app-sidebar-brand-text h2 {
    font-size: 1rem;
    font-weight: 700;
    color: #f8fafc;
    line-height: 1.2;
}

.app-sidebar-brand-text span {
    font-size: 0.7rem;
    color: var(--app-saez-red);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.app-sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.app-sidebar-nav::-webkit-scrollbar { width: 4px; }
.app-sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.app-sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
.app-sidebar-nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

.app-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.25rem;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
    position: relative;
}

.app-nav-item:hover {
    color: #e2e8f0;
    background: rgba(255,255,255,0.05);
}

.app-nav-item.active {
    color: #fff;
    background: rgba(255,255,255,0.08);
    border-left-color: var(--app-saez-red);
}

.app-nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.app-nav-item.active svg { opacity: 1; }

.app-nav-badge {
    margin-left: auto;
    background: var(--app-orange);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.app-nav-badge.green {
    background: var(--app-green);
    animation: pulse-badge 2s ease-in-out infinite;
}

.app-sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.78rem;
    flex-shrink: 0;
}

.app-sidebar-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    color: #94a3b8;
}

.app-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--app-green);
    flex-shrink: 0;
}

.app-sidebar-client {
    font-size: 0.68rem;
    color: #dbeafe;
    margin-bottom: 0.75rem;
    padding-left: 1rem;
}

.app-sidebar-guide {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.78rem;
    padding: 0.35rem 0;
    margin-bottom: 0.4rem;
    transition: color 0.15s;
}

.app-sidebar-guide:hover { color: #60a5fa; }

.app-sidebar-lang {
    margin-bottom: 0.6rem;
}

.app-lang-select {
    width: 100%;
    padding: 0.4rem 0.5rem;
    background: rgba(255,255,255,0.08);
    color: #cbd5e1;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}

.app-lang-select:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.25);
}

.app-lang-select:focus {
    border-color: var(--app-saez-red);
    background: rgba(255,255,255,0.15);
}

.app-lang-select option {
    background: var(--app-sidebar-bg);
    color: #cbd5e1;
}

.app-sidebar-clock {
    margin: 0.5rem 0;
    padding: 0.5rem 0;
    border-top: 1px solid rgba(255,255,255,0.08);
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.app-clock-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    color: #cbd5e1;
}
.app-clock-flag { font-size: 0.85rem; width: 1.1rem; text-align: center; }
.app-clock-label { flex: 1; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-clock-time { font-family: 'Courier New', monospace; font-weight: 600; letter-spacing: 0.5px; }
.app-clock-add {
    display: block;
    width: calc(100% - 1rem);
    margin: 0.3rem 0.5rem 0;
    background: rgba(255,255,255,0.05);
    border: 1px dashed rgba(255,255,255,0.15);
    color: #64748b;
    font-size: 0.75rem;
    padding: 0.2rem;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
}
.app-clock-add:hover { background: rgba(255,255,255,0.1); color: #94a3b8; }

.app-sidebar-mobile-status {
    display: none; /* shown only on mobile via media query */
}

.app-sidebar-logout {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 0.4rem 0;
    border: none;
    background: none;
    font-size: 0.8rem;
    width: 100%;
    text-align: left;
}

.app-sidebar-logout:hover { color: #f87171; }

/* Design mode toggle button */
.app-design-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--app-sidebar-border, #334155);
    color: var(--app-sidebar-fg, #94a3b8);
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    margin: 4px 16px 8px;
    transition: background .15s, color .15s;
}
.app-design-toggle:hover {
    background: var(--app-sidebar-hover, #1e293b);
    color: #e2e8f0;
}
.app-design-toggle svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Design mode sidebar */
.app-sidebar.design-mode { width: 320px; }

.app-design-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0;
}
.app-design-header {
    font-size: 14px;
    font-weight: 600;
    color: #e2e8f0;
    padding: 12px 16px 8px;
    border-bottom: 1px solid var(--app-sidebar-border, #334155);
}
.app-design-col-labels {
    display: flex;
    align-items: center;
    padding: 4px 16px 4px 48px;
    gap: 0;
    font-size: 10px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.app-design-col-spacer { flex: 1; }
.app-design-col-label { width: 28px; text-align: center; }

.app-design-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.app-design-item {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    gap: 8px;
    transition: background .1s;
    user-select: none;
}
.app-design-item:hover { background: var(--app-sidebar-hover, #1e293b); }
.app-design-item.dragging { opacity: .4; }
.app-design-item.drag-over { border-top: 2px solid #3b82f6; }

.app-design-handle {
    cursor: grab;
    font-size: 16px;
    color: #475569;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.app-design-handle:active { cursor: grabbing; }

.app-design-label {
    flex: 1;
    font-size: 13px;
    color: #cbd5e1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-design-checks {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.app-design-check {
    width: 16px;
    height: 16px;
    accent-color: #3b82f6;
    cursor: pointer;
}
.app-design-check:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.app-design-placeholder {
    background: rgba(59, 130, 246, .15);
    border: 1px dashed #3b82f6;
    border-radius: 4px;
    margin: 2px 16px;
}

.app-design-bar {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--app-sidebar-border, #334155);
    flex-shrink: 0;
}
.app-design-btn { font-size: 12px; padding: 6px 12px; }
.app-design-btn-reset { margin-left: auto; color: #f87171; }
.app-design-btn-reset:hover { color: #ef4444; }

/* Responsive design mode */
@media (max-width: 768px) {
    .app-sidebar.design-mode { width: 100%; }
}

/* ==========================================================================
   MAIN AREA
   ========================================================================== */

.app-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--app-sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   TOPBAR
   ========================================================================== */

.app-topbar {
    height: var(--app-topbar-h);
    background: var(--app-card-bg);
    border-bottom: 1px solid var(--app-border);
    border-top: 3px solid var(--app-saez-red);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
    overflow: hidden;
    min-width: 0;
}

.app-topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--app-text);
}

.app-topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.app-topbar-refresh {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: var(--app-text-muted);
}

.app-refresh-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--app-green);
    animation: pulse-badge 2s ease-in-out infinite;
}

.app-status-indicator {
    font-size: 0.78rem;
    color: var(--app-text-muted);
}

.app-topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--app-text);
    font-weight: 500;
}

.app-topbar-user .app-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--app-green);
    flex-shrink: 0;
}

/* === TOPBAR CENTER (info bar) === */

.app-topbar-center {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    margin: 0 1rem;
    overflow: hidden;
    min-width: 0;
    max-width: 500px;
}

.app-topbar-info-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--app-text-muted);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s;
}
.app-topbar-info-item:hover { color: var(--app-blue-light); }
.app-topbar-info-item svg { flex-shrink: 0; opacity: 0.7; }

.app-topbar-ticker {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--app-text-muted);
    cursor: pointer;
    overflow: hidden;
    max-width: 100%;
}
.app-topbar-ticker svg { flex-shrink: 0; opacity: 0.7; }

.app-ticker-track {
    flex: 1 1 0;
    overflow: hidden;
    position: relative;
    white-space: nowrap;
    min-width: 0;
    /* Fade en los bordes en vez de corte duro al entrar/salir el marquee */
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
}
.app-ticker-track span {
    display: inline-block;
    animation: ticker-scroll 35s linear infinite;
    padding-left: 100%;
}
.app-ticker-track span:hover {
    color: var(--app-blue-light);
    animation-play-state: paused;
}

@keyframes ticker-scroll {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

/* === NEWS SECTION === */

.app-news-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    padding: 0.5rem 0;
}

.app-news-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.15s;
    cursor: pointer;
}
.app-news-card:hover {
    box-shadow: var(--app-shadow-lg);
    transform: translateY(-2px);
}

.app-news-card-img-wrap {
    width: 100%;
    height: 160px;
    overflow: hidden;
    border-radius: 8px 8px 0 0;
}
.app-news-card-img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    background: var(--app-bg);
    display: block;
}
.app-news-card-img-placeholder {
    width: 100%;
    height: 160px;
    background: linear-gradient(135deg, var(--app-blue) 0%, var(--app-saez-red) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2rem;
    opacity: 0.6;
}

/* Cards without image: no image area, more space for text */
.app-news-card-noimg {
    border-left: 3px solid var(--app-saez-red);
}
.app-news-card-noimg .app-news-card-title {
    -webkit-line-clamp: 3;
}
.app-news-card-noimg .app-news-card-summary {
    -webkit-line-clamp: 5;
}

.app-news-card-body {
    padding: 0.75rem 1rem;
}

.app-news-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--app-text);
    margin-bottom: 0.4rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-news-card-summary {
    font-size: 0.78rem;
    color: var(--app-text-muted);
    margin-bottom: 0.5rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-news-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--app-text-light);
}

.app-news-card-source {
    font-weight: 600;
    color: var(--app-blue-light);
}

.app-news-card-actions {
    padding: 0.5rem 1rem 0.75rem;
    display: flex;
    gap: 0.5rem;
}

.app-news-loading,
.app-news-empty {
    text-align: center;
    padding: 2rem;
    color: var(--app-text-muted);
    font-size: 0.88rem;
}

.app-news-filters {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-news-ai-summary {
    margin-top: 0.5rem;
    padding: 0.6rem;
    background: var(--app-bg);
    border-radius: 6px;
    font-size: 0.78rem;
    color: var(--app-text);
    line-height: 1.5;
    border-left: 3px solid var(--app-blue-light);
}

/* ==========================================================================
   CONTENT
   ========================================================================== */

.app-content {
    flex: 1;
    min-width: 0;
    padding: 1.5rem;
}

.app-section { display: none; }
.app-section.active { display: block; }

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.app-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--app-border);
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    background: var(--app-card-bg);
    color: var(--app-text);
    font-family: inherit;
}

.app-btn:hover { background: var(--app-bg); }

.app-btn-primary {
    background: var(--app-saez-red);
    color: #fff;
    border-color: var(--app-saez-red);
}
.app-btn-primary:hover { background: var(--app-saez-red-dark); }

.app-btn-green {
    background: var(--app-green);
    color: #fff;
    border-color: var(--app-green);
}
.app-btn-green:hover { background: #218838; }

.app-btn-orange {
    background: var(--app-orange);
    color: #fff;
    border-color: var(--app-orange);
}
.app-btn-orange:hover { background: #d06c10; }

.app-btn-danger {
    background: var(--app-red);
    color: #fff;
    border-color: var(--app-red);
}
.app-btn-danger:hover { background: #c82333; }

.app-btn-ghost {
    background: transparent;
    color: var(--app-text-muted);
    border: 1px solid var(--app-border);
}
.app-btn-ghost:hover { background: var(--app-bg); color: var(--app-text); }

.app-btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
}

.app-btn-block {
    width: 100%;
    justify-content: center;
    padding: 0.8rem;
    font-size: 0.95rem;
    margin-top: 0.5rem;
}

.app-btn-icon {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.app-btn-icon:hover {
    background: rgba(0,0,0,0.06);
}

.app-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.app-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.app-action-group {
    display: flex;
    gap: 0.35rem;
}

/* ==========================================================================
   CARDS
   ========================================================================== */

.app-card {
    background: var(--app-card-bg);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.app-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--app-border);
}

.app-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--app-text);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--app-border);
}

/* When card-title is inside card-header, remove standalone bottom border/margin */
.app-card-header .app-card-title {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* ==========================================================================
   TABLES
   ========================================================================== */

.app-table-wrap {
    overflow-x: auto;
}

.app-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.app-table thead {
    background: var(--app-card-bg-subtle);
    color: var(--app-text-muted);
    border-bottom: 1px solid var(--app-border);
}

.app-table th {
    padding: 0.7rem 0.8rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.72rem;
    color: var(--app-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.app-table td {
    padding: 0.7rem 0.8rem;
    border-bottom: 1px solid var(--app-border);
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.app-table tbody tr {
    transition: background var(--app-dur) var(--app-ease);
}

.app-table tbody tr:nth-child(even) {
    background: var(--app-card-bg-subtle);
}

.app-table tbody tr:hover {
    background: var(--app-card-bg-alt);
}

/* ==========================================================================
   BADGES
   ========================================================================== */

.app-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 500;  /* escala contenida: clasifica sin gritar */
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.app-badge-root { background: var(--app-badge-root-bg); color: var(--app-badge-root-text); }
.app-badge-saez { background: var(--app-badge-saez-bg); color: var(--app-badge-saez-text); }
.app-badge-cliente { background: var(--app-badge-cliente-bg); color: var(--app-badge-cliente-text); }
.app-badge-active { background: var(--app-badge-active-bg); color: var(--app-badge-active-text); }
.app-badge-inactive { background: var(--app-badge-inactive-bg); color: var(--app-badge-inactive-text); }
.app-badge-pending { background: var(--app-badge-pending-bg); color: var(--app-badge-pending-text); }
.app-badge-urgente { background: var(--app-badge-urgent-bg); color: var(--app-badge-urgent-text); }
.app-badge-resolved { background: var(--app-badge-resolved-bg); color: var(--app-badge-resolved-text); }
.app-badge-available { background: var(--app-badge-available-bg); color: var(--app-badge-available-text); }
.app-badge-missing { background: var(--app-badge-missing-bg); color: var(--app-badge-missing-text); }
.app-badge-searched { background: var(--app-badge-searched-bg); color: var(--app-badge-searched-text); }
/* warning/info estilados con la misma escala (antes sueltos, sin fondo) */
.app-badge-warning { background: var(--app-badge-pending-bg); color: var(--app-badge-pending-text); }
.app-badge-info { background: var(--app-badge-saez-bg); color: var(--app-badge-saez-text); }
/* Status binario como punto + texto: más limpio que pill */
.app-status-dot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%;
    margin-right: 6px; vertical-align: middle; background: var(--app-text-muted);
}
.app-status-dot.is-on { background: var(--app-green); }
.app-status-dot.is-off { background: #cbd5e1; }
/* Celda de baja prioridad (auth Local/Legacy): texto tenue, sin badge */
.app-cell-soft { color: var(--app-text-muted); font-size: 0.78rem; }

/* ==========================================================================
   KPI CARDS
   ========================================================================== */

.app-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.app-kpi-card {
    background: var(--app-card-bg);
    border-radius: var(--app-radius);
    padding: 1.25rem;
    box-shadow: var(--app-shadow);
    border-left: 4px solid var(--app-blue);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.app-kpi-card.green { border-left-color: var(--app-green); }
.app-kpi-card.orange { border-left-color: var(--app-orange); }
.app-kpi-card.teal { border-left-color: var(--app-teal); }
.app-kpi-card.red { border-left-color: var(--app-red); }
.app-kpi-card.purple { border-left-color: var(--app-purple); }

.app-kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--app-text);
    line-height: 1;
}

.app-kpi-label {
    font-size: 0.82rem;
    color: var(--app-text-muted);
    font-weight: 500;
}

.app-kpi-detail {
    font-size: 0.75rem;
    color: var(--app-text-light);
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.app-kpi-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
    animation: pulse-badge 2s ease-in-out infinite;
}

/* ==========================================================================
   ACTIVITY FEED
   ========================================================================== */

.app-feed {
    list-style: none;
    max-height: 350px;
    overflow-y: auto;
}

.app-feed-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--app-border);
    font-size: 0.85rem;
}

.app-feed-item:last-child { border-bottom: none; }

.app-feed-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}

.app-feed-dot.green { background: var(--app-green); }
.app-feed-dot.red { background: var(--app-red); }
.app-feed-dot.orange { background: var(--app-orange); }
.app-feed-dot.blue { background: var(--app-blue-light); }
.app-feed-dot.purple { background: var(--app-purple); }

.app-feed-text {
    flex: 1;
    color: var(--app-text);
    line-height: 1.4;
}

.app-feed-text strong { font-weight: 600; }

.app-feed-time {
    font-size: 0.75rem;
    color: var(--app-text-light);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ==========================================================================
   SEARCH BAR
   ========================================================================== */

.app-search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.app-search-bar input,
.app-search-bar select {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    font-size: 0.88rem;
    background: var(--app-card-bg);
    outline: none;
    font-family: inherit;
}

.app-search-bar input {
    flex: 1;
}

.app-search-bar input:focus,
.app-search-bar select:focus {
    border-color: var(--app-saez-red);
    box-shadow: 0 0 0 3px rgba(227, 6, 19, 0.1);
}

/* ==========================================================================
   SELECTS
   ========================================================================== */

.app-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    font-size: 0.88rem;
    background: var(--app-card-bg);
    outline: none;
    font-family: inherit;
}

.app-select-sm {
    padding: 0.3rem 0.5rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    font-size: 0.78rem;
    background: rgba(255,255,255,0.15);
    color: inherit;
    outline: none;
    font-family: inherit;
}

.app-select-sm option {
    color: #000;
    background: #fff;
}

/* ==========================================================================
   PAGINATION
   ========================================================================== */

.app-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
    padding: 0.75rem;
    font-size: 0.88rem;
}

/* ==========================================================================
   GRID LAYOUTS
   ========================================================================== */

.app-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* ==========================================================================
   CHART CONTAINER
   ========================================================================== */

.app-chart-container {
    position: relative;
    width: 100%;
    height: 260px;
}

.app-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ==========================================================================
   FORM GROUPS
   ========================================================================== */

.app-form-group {
    margin-bottom: 1rem;
}

.app-form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--app-text-muted);
    margin-bottom: 0.3rem;
}

.app-form-group input,
.app-form-group select,
.app-form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: 6px;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.app-form-group input:focus,
.app-form-group select:focus,
.app-form-group textarea:focus {
    border-color: var(--app-saez-red);
    box-shadow: 0 0 0 3px rgba(227, 6, 19, 0.1);
}

.app-form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.app-form-group input[readonly] {
    background: #f8fafc;
    color: var(--app-text-muted);
}

/* ==========================================================================
   ACCORDION
   ========================================================================== */

.app-accordion {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-accordion-item {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    overflow: hidden;
}

.app-accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    background: var(--app-card-bg-subtle);
    transition: background 0.15s;
}

.app-accordion-header:hover {
    background: var(--app-card-bg-alt);
}

.app-accordion-header .count {
    background: var(--app-badge-saez-bg);
    color: var(--app-badge-saez-text);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
}

.app-accordion-header .arrow {
    transition: transform 0.2s;
    font-size: 0.75rem;
    color: var(--app-text-muted);
}

.app-accordion-item.open .app-accordion-header .arrow {
    transform: rotate(180deg);
}

.app-accordion-body {
    display: none;
    padding: 0 20px 16px;
}

.app-accordion-item.open .app-accordion-body {
    display: block;
}

/* ==========================================================================
   MODAL
   ========================================================================== */

.app-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.app-modal-overlay[hidden] { display: none; }

.app-modal {
    background: var(--app-card-bg);
    border-radius: 12px;
    width: 480px;
    max-width: 92vw;
    max-height: 85vh;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s ease;
}

.app-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--app-border);
}

.app-modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--app-text);
}

.app-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--app-text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0 0.25rem;
}

.app-modal-close:hover { color: var(--app-text); }

.app-modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.app-modal-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--app-border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Confirm dialog styling */
.app-confirm-text {
    font-size: 0.92rem;
    color: var(--app-text);
    text-align: center;
    padding: 0.5rem 0;
}

.app-btn-send {
    color: var(--app-blue);
    flex-shrink: 0;
}

.app-btn-send:hover {
    background: rgba(26, 58, 92, 0.08);
}

/* ==========================================================================
   MESSAGE BUBBLES
   ========================================================================== */

/* Row wrapper with avatar */
.app-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
}

.app-msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.app-msg-row.bot { align-self: flex-start; }
.app-msg-row .app-msg { max-width: 100%; align-self: auto; }

/* Avatar */
.app-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--app-blue);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-msg-row.bot .app-msg-avatar {
    background: var(--app-saez-red);
}

/* Bubble */
.app-msg {
    max-width: 85%;
    padding: 0.6rem 0.8rem;
    border-radius: var(--app-radius-msg);
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    position: relative;
}

.app-msg.bot {
    background: var(--app-msg-bot);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--app-saez-red);
}

.app-msg.user {
    background: var(--app-msg-user);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    color: #ffffff;
}

.app-msg.user .app-msg-time { color: rgba(255,255,255,0.7); }
.app-msg.user .app-btn-tts { color: rgba(255,255,255,0.7); }
.app-msg.user a { color: #b3d4ff; }

/* Time */
.app-msg-time {
    font-size: 0.65rem;
    color: var(--app-text-light);
    margin-top: 0.2rem;
    text-align: right;
}

/* Image in message */
.app-msg-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
}

/* File attachment */
.app-msg-file {
    background: var(--app-msg-file);
    border: 1px solid #bbdefb;
}

.app-msg-file a {
    color: var(--app-blue);
    text-decoration: none;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-msg-file a:hover { text-decoration: underline; }

/* HTML content inside messages */
.app-msg b, .app-msg strong { font-weight: 600; }
.app-msg hr { border: none; border-top: 1px solid var(--app-border); margin: 0.4rem 0; }

/* Bridge translation messages */
.app-msg-bridge-translation {
    background: #e8f4fd;
    border-left: 3px solid var(--app-orange);
}

/* ==========================================================================
   DATE SEPARATOR
   ========================================================================== */

.app-date-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 1rem 0 0.5rem;
    color: var(--app-text-light);
    font-size: 0.75rem;
}

.app-date-separator::before,
.app-date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--app-border);
}

/* ==========================================================================
   TYPING INDICATOR
   ========================================================================== */

.app-typing-indicator {
    font-size: 0.8rem;
    color: var(--app-text-muted);
    padding: 0.3rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.app-typing-dots span {
    animation: typingDot 1.4s infinite;
    animation-fill-mode: both;
    font-weight: bold;
    font-size: 1.2rem;
}

.app-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.app-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* ==========================================================================
   TTS BUTTON
   ========================================================================== */

.app-btn-tts {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0,0,0,0.06);
    border: none;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--app-text-muted);
    opacity: 0.5;
    transition: opacity 0.2s, background 0.2s;
}

.app-msg:hover .app-btn-tts,
.app-msg:active .app-btn-tts {
    opacity: 1;
}

.app-btn-tts:hover {
    background: rgba(0,0,0,0.12);
    color: var(--app-blue);
}

.app-btn-tts:active {
    background: var(--app-orange);
    color: white;
}

/* ==========================================================================
   CHAT CLASS ALIASES (chat-panel.js uses names without app- prefix)
   ========================================================================== */

/* Message row */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
}
.msg-row-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-row-bot { align-self: flex-start; }
.msg-row .msg { max-width: 100%; align-self: auto; }

/* Avatar */
.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--app-blue);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.msg-row-bot .msg-avatar {
    background: var(--app-saez-red);
}

/* Message bubble */
.msg {
    max-width: 85%;
    padding: 0.6rem 2rem 0.6rem 0.8rem;
    border-radius: var(--app-radius-msg);
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    position: relative;
}
.msg-bot {
    background: var(--app-msg-bot);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--app-saez-red);
}
.msg-user {
    background: var(--app-msg-user);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    color: #ffffff;
}
.msg-user .msg-time { color: rgba(255,255,255,0.7); }
.msg-user .btn-tts { color: rgba(255,255,255,0.7); }
.msg-user a { color: #b3d4ff; }

/* HTML inside messages */
.msg b, .msg strong { font-weight: 600; }
.msg hr { border: none; border-top: 1px solid var(--app-border); margin: 0.4rem 0; }

/* Time */
.msg-time {
    font-size: 0.65rem;
    color: var(--app-text-light);
    margin-top: 0.2rem;
    text-align: right;
}

/* Image */
.msg-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
}

/* Bridge */
.msg-bridge-translation {
    background: #e8f4fd !important;
    border-left: 3px solid var(--app-orange) !important;
}

/* Date separator */
.date-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 1rem 0 0.5rem;
    color: var(--app-text-light);
    font-size: 0.75rem;
}
.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--app-border);
}

/* TTS button */
.btn-tts {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0,0,0,0.06);
    border: none;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--app-text-muted);
    opacity: 0.5;
    transition: opacity 0.2s, background 0.2s;
}
.msg:hover .btn-tts { opacity: 1; }
.btn-tts:hover { background: rgba(0,0,0,0.12); color: var(--app-blue); }

/* Annotate hint on images */
.img-annotate-hint {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}
.msg-image:hover + .img-annotate-hint,
.img-annotate-hint:hover { opacity: 1; }

/* ==========================================================================
   RECORDING STATE
   ========================================================================== */

.recording-active {
    background: #fff3f3 !important;
    border-color: var(--app-red) !important;
    animation: recPulseInput 1.4s infinite;
}

.recording-active::placeholder {
    color: var(--app-red) !important;
    font-weight: 600;
    font-size: 1rem;
}

@keyframes recPulseInput {
    0%, 100% { border-color: var(--app-red); }
    50% { border-color: #ffaaaa; }
}

/* ==========================================================================
   INCOMING CALL BANNER
   ========================================================================== */

.app-incoming-call {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    animation: incomingCallFadeIn 0.3s ease;
}

.app-incoming-call[hidden] { display: none; }

@keyframes incomingCallFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.app-incoming-call-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1.2rem;
    text-align: center;
}

.app-incoming-call-caller {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.app-incoming-call-pulse {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--app-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: incomingRingPulse 1.5s infinite;
}

.app-incoming-call-pulse::after {
    content: '';
    width: 30px;
    height: 30px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpolygon points='23 7 16 12 23 17 23 7'/%3E%3Crect x='1' y='5' width='15' height='14' rx='2' ry='2'/%3E%3C/svg%3E") no-repeat center/contain;
}

@keyframes incomingRingPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); }
    50% { transform: scale(1.1); box-shadow: 0 0 0 20px rgba(59, 130, 246, 0); }
}

.app-incoming-call-actions {
    display: flex;
    gap: 2.5rem;
}

.app-btn-call-reject,
.app-btn-call-accept {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: transform 0.15s;
}

.app-btn-call-reject { background: var(--app-red); }
.app-btn-call-accept { background: var(--app-green); }

.app-btn-call-reject:active,
.app-btn-call-accept:active {
    transform: scale(0.92);
}

/* (Chat panel removed — using Messaging section now) */

/* Chat toggle button in topbar */
.app-btn-chat-toggle {
    position: relative;
}

.app-chat-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--app-saez-red);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 8px;
    min-width: 14px;
    text-align: center;
    line-height: 1.3;
}

/* ==========================================================================
   VIDEO CALL OVERLAY
   ========================================================================== */

.app-video-call {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    z-index: 300;
    display: flex;
    flex-direction: column;
}

.app-video-call[hidden] { display: none; }

.app-video-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #111;
}

#local-video {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 120px;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.3);
    z-index: 2;
    background: #222;
}

/* Multi-peer video grid */
.app-video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 4px;
    width: 100%;
    height: 100%;
    background: #111;
}
.app-video-grid[data-count="1"] { grid-template-columns: 1fr; }
.app-video-grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.app-video-grid[data-count="3"],
.app-video-grid[data-count="4"] { grid-template-columns: 1fr 1fr; }

.app-grid-cell {
    position: relative;
    background: #1a1a1a;
    overflow: hidden;
    border-radius: 6px;
}
.app-grid-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #111;
}
.app-grid-label {
    position: absolute;
    bottom: 6px;
    left: 6px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    pointer-events: none;
}
/* Participants overlay */
.app-participants-overlay {
    position: absolute;
    top: 40px;
    left: 8px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.75rem;
    z-index: 3;
    max-height: 200px;
    overflow-y: auto;
}
.app-participants-overlay ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.app-participants-overlay li {
    padding: 2px 0;
}
.app-participants-overlay li::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    margin-right: 6px;
}

.app-call-timer {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.5);
    color: white;
    padding: 2px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    z-index: 2;
}

/* Video controls - see dynamic toolbar styles at bottom */

.app-btn-vc {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}

.app-btn-vc:hover { background: rgba(255,255,255,0.25); }
.app-btn-vc:active { transform: scale(0.92); }
.app-btn-vc.muted { background: var(--app-red); }

.app-btn-vc-capture {
    width: 56px;
    height: 56px;
    border: 3px solid white;
    background: rgba(255,255,255,0.1);
}

.app-btn-vc-capture:hover { background: rgba(255,255,255,0.3); }

.app-btn-vc-hangup { background: var(--app-red); }
.app-btn-vc-hangup:hover { background: #c82333; }

/* Transparent mode — remote video off, show chat behind */
.app-video-call.video-call-transparent {
    background: transparent !important;
    pointer-events: none;
}

.app-video-call.video-call-transparent .app-video-container {
    background: transparent;
    pointer-events: none;
}

.app-video-call.video-call-transparent .app-video-controls {
    pointer-events: auto;
}

.app-video-call.video-call-transparent #local-video {
    pointer-events: auto;
}

/* ==========================================================================
   SUBTITLE OVERLAYS
   ========================================================================== */

.app-subtitle {
    pointer-events: none;
    z-index: 5;
    position: absolute;
    left: 5%;
    right: 5%;
    text-align: center;
    transition: opacity 0.3s;
    opacity: 0;
}

.app-subtitle-peer {
    bottom: 70px;
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
    background: rgba(0,0,0,0.55);
    padding: 6px 12px;
    border-radius: 8px;
}

.app-subtitle-self {
    top: 40px;
    left: 10%;
    right: 10%;
    color: rgba(255,255,255,0.6);
    font-size: 0.8rem;
    font-style: italic;
}

.app-video-call.video-call-transparent .app-subtitle-self {
    background: rgba(0,0,0,0.4);
    padding: 3px 10px;
    border-radius: 6px;
}

/* Subtitle language selector */
.app-subtitle-lang-select {
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.app-subtitle-lang-select option {
    color: #000;
    background: #fff;
}

/* ==========================================================================
   PORTAL — Crane Grid and Cards
   ========================================================================== */

.app-crane-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.app-crane-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 1.25rem;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.app-crane-card:hover {
    box-shadow: var(--app-shadow-lg);
    border-color: var(--app-saez-red);
}

.app-crane-card-model {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--app-text);
    margin-bottom: 4px;
}

.app-crane-card-serial {
    font-size: 0.88rem;
    color: var(--app-saez-red);
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.app-crane-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.82rem;
    color: var(--app-text-muted);
}

.app-crane-card-info span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-crane-card-info .label {
    font-weight: 500;
    color: var(--app-text);
    min-width: 60px;
}

/* Crane detail header */
.app-crane-header {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 1.5rem;
    margin: 1rem 0;
}

.app-crane-header h2 {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.app-crane-header .serial {
    color: var(--app-saez-red);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.app-crane-header-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}

.app-crane-header-item {
    font-size: 0.82rem;
}

.app-crane-header-item .label {
    color: var(--app-text-muted);
    display: block;
    margin-bottom: 2px;
}

.app-crane-header-item .value {
    font-weight: 600;
}

/* ==========================================================================
   BRIDGE CARDS (dashboard view)
   ========================================================================== */

.app-bridge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.75rem;
}

.app-bridge-card {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--app-radius);
    padding: 1rem;
}

.app-bridge-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.app-bridge-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--app-green);
    animation: pulse-badge 2s ease-in-out infinite;
}

.app-bridge-pair {
    font-size: 0.85rem;
    color: var(--app-text-muted);
    margin-bottom: 0.25rem;
}

.app-bridge-time {
    font-size: 0.75rem;
    color: var(--app-text-light);
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */

.app-toast-container {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-width: 90%;
    width: 360px;
    pointer-events: none;
}

.app-toast {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow-lg);  /* jerarquía de elevación #4: toasts = lg */
    font-size: 0.85rem;
    pointer-events: auto;
    animation: toastSlideIn 0.3s ease-out;
}

.app-toast-info {
    background: var(--app-blue);
    color: white;
}

.app-toast-warning {
    background: var(--app-orange);
    color: white;
}

.app-toast-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-toast-action {
    background: rgba(255,255,255,0.25);
    color: white;
    border: 1px solid rgba(255,255,255,0.4);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    cursor: pointer;
    flex-shrink: 0;
    font-weight: 600;
}

.app-toast-action:hover {
    background: rgba(255,255,255,0.4);
}

.app-toast-fade-out {
    animation: toastFadeOut 0.4s ease-in forwards;
}

/* Image toast during call */
.app-toast-image {
    background: #1a1a2e;
    color: white;
    border: 1px solid rgba(255,255,255,0.15);
}

.app-toast-thumbnail {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

/* ==========================================================================
   EMPTY STATE
   ========================================================================== */

.app-empty {
    text-align: center;
    padding: 2rem;
    color: var(--app-text-muted);
    font-size: 0.9rem;
}

.app-empty svg {
    width: 48px;
    height: 48px;
    color: var(--app-border);
    margin-bottom: 0.75rem;
}

.app-empty h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--app-text);
}

/* ==========================================================================
   HAMBURGER (mobile)
   ========================================================================== */

.app-hamburger {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--app-sidebar-bg);
    color: #fff;
    border: none;
    border-radius: 6px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.app-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
}

.app-sidebar-overlay.active { display: block; }

/* ==========================================================================
   ANNOTATIONS (image draw overlay)
   ========================================================================== */

.app-annotation-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.app-annotation-overlay[hidden] { display: none; }

.app-annotation-canvas-wrap {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    width: 100%;
}

.app-annotation-bg-canvas {
    position: absolute;
    pointer-events: none;
}

.app-annotation-draw-canvas {
    position: absolute;
    touch-action: none;
    cursor: crosshair;
}

.app-annotation-toolbar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.8rem;
    background: rgba(30,30,30,0.95);
    width: 100%;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: center;
}

.annotation-group {
    display: flex;
    align-items: center;
    gap: 4px;
}
.annotation-right-group {
    margin-left: auto;
}
.annotation-color-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.2s;
}
.annotation-color-btn.active {
    border-color: white;
    box-shadow: 0 0 6px rgba(255,255,255,0.5);
}
.annotation-width-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.annotation-width-btn.active {
    background: rgba(255,255,255,0.3);
}
.annotation-width-dot {
    display: block;
    border-radius: 50%;
    background: white;
}
.annotation-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.annotation-action-btn:hover {
    background: rgba(255,255,255,0.25);
}
.annotation-action-btn.active {
    background: var(--app-primary, #1976D2);
}
.annotation-cancel-btn {
    background: rgba(255,60,60,0.3);
}
.annotation-cancel-btn:hover {
    background: rgba(255,60,60,0.5);
}
.annotation-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--app-primary, #1976D2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: background 0.2s;
}
.annotation-send-btn:hover {
    background: #1565C0;
}

/* ==========================================================================
   IN-CALL IMAGE VIEWER
   ========================================================================== */

.app-image-viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.app-image-viewer-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2001;
    transition: background 0.2s;
}

.app-image-viewer-close:hover {
    background: rgba(255,255,255,0.3);
}

.app-image-viewer-img {
    max-width: 90%;
    max-height: 75vh;
    object-fit: contain;
    border-radius: 8px;
}

.app-image-viewer-bottom {
    display: flex;
    gap: 1.5rem;
    padding: 1rem;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes toastSlideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes toastFadeOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(-10px); }
}

/* ==========================================================================
   ESQUEMA VIEWER
   ========================================================================== */

.app-esquema-type-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--app-border-light);
    margin-bottom: 1rem;
    overflow-x: auto;
}
.app-esquema-tab {
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--app-text-muted);
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}
.app-esquema-tab:hover { color: var(--app-saez-red); }
.app-esquema-tab.app-esquema-tab-active,
.app-esquema-tab.active {
    color: var(--app-saez-red);
    border-bottom-color: var(--app-saez-red);
}
.app-esquema-model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    padding: 0.5rem 0;
}
.app-esquema-model-card {
    background: var(--app-card-bg-subtle);
    border: 1px solid var(--app-border-light);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    text-align: center;
}
.app-esquema-model-card:hover {
    border-color: var(--app-saez-red);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.app-esquema-model-card h4 {
    margin: 0 0 0.3rem;
    font-size: 0.95rem;
}
.app-esquema-model-card .pages-count {
    font-size: 0.8rem;
    color: var(--app-text-muted);
}
.app-esquema-model-name {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}
.app-esquema-model-info {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: var(--app-text-muted);
}
.app-badge-green {
    background: #059669 !important;
}
.app-esquema-pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    padding: 1rem 0;
}
.app-esquema-page-card {
    border: 1px solid var(--app-border-light);
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
    background: var(--app-card-bg);
}
.app-esquema-page-card:hover {
    border-color: var(--app-saez-red);
    transform: translateY(-2px);
}
.app-esquema-page-card img.app-esquema-thumb {
    width: 100%;
    display: block;
    aspect-ratio: 4/3;
    object-fit: contain;
    background: var(--app-card-bg-subtle);
}
.app-esquema-page-label {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    text-align: center;
    color: var(--app-text-body);
    background: var(--app-card-bg-alt);
}

/* Lightbox */
.app-esquema-lightbox {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(0,0,0,0.92);
    display: flex;
    flex-direction: column;
}
.app-esquema-lightbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    color: #fff;
    background: rgba(0,0,0,0.6);
    flex-shrink: 0;
}
.app-esquema-lightbox-header .app-btn-ghost {
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}
.app-esquema-lightbox-header .app-btn-ghost:hover {
    background: rgba(255,255,255,0.1);
}
.app-esquema-lightbox-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 1rem;
}
.app-esquema-lightbox-body img {
    max-width: 95%;
    max-height: 90vh;
    object-fit: contain;
}

/* ==========================================================================
   RESPONSIVE — <= 768px
   ========================================================================== */

@media (max-width: 768px) {
    /* Login: single column */
    .app-login.active {
        grid-template-columns: 1fr;
    }

    .app-login-hero {
        display: none;
    }

    .app-login-logo-mobile {
        display: block;
    }

    .app-login-panel {
        background: linear-gradient(180deg, rgba(227,6,19,0.08) 0%, var(--app-card-bg) 35%);
        padding: 1.5rem;
    }

    .app-login-title {
        text-align: center;
    }

    .app-login-subtitle {
        text-align: center;
    }

    /* Sidebar: off-screen */
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .app-hamburger {
        display: flex;
    }

    .app-main {
        margin-left: 0;
    }

    .app-topbar {
        padding-left: 3.5rem;
    }

    .app-topbar-center {
        display: none;
    }

    /* Mobile: hide user info from topbar (moved to sidebar footer) */
    .app-topbar-refresh,
    .app-topbar-user,
    .app-status-indicator {
        display: none !important;
    }

    /* Mobile: show user status in sidebar footer */
    .app-sidebar-mobile-status {
        display: flex !important;
        flex-direction: column;
        gap: 0.3rem;
        padding: 0.5rem 0;
        border-top: 1px solid rgba(255,255,255,0.08);
        margin-bottom: 0.4rem;
        font-size: 0.75rem;
        color: #94a3b8;
    }
    .app-sidebar-mobile-status .app-mobile-status-row {
        display: flex;
        align-items: center;
        gap: 0.4rem;
    }

    /* Mobile: hamburger thinner when sidebar open */
    .app-hamburger {
        transition: all 0.3s;
    }
    .app-hamburger.sidebar-open {
        width: 18px;
        min-width: 18px;
        padding: 0.35rem 0;
        opacity: 0.3;
        z-index: 101;
    }

    .app-news-grid {
        grid-template-columns: 1fr;
    }

    .app-content {
        padding: 1rem;
    }

    /* KPIs: 2 columns */
    .app-kpi-row {
        grid-template-columns: 1fr 1fr;
    }

    /* Grids: single column */
    .app-grid-2 {
        grid-template-columns: 1fr;
    }

    /* Crane grid: single column */
    .app-crane-grid {
        grid-template-columns: 1fr;
    }

    .app-crane-header-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Search bar: wrap */
    .app-search-bar {
        flex-wrap: wrap;
    }

    .app-search-bar input {
        min-width: 0;
    }

    /* Modal: wider */
    .app-modal {
        width: 95vw;
    }

    /* Message avatars */
    .app-msg-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.65rem;
    }

    .app-msg-row {
        max-width: 92%;
    }

}

@media (max-width: 480px) {
    .app-kpi-row {
        grid-template-columns: 1fr;
    }
}

/* =====================================================================
   Diagnostico Section
   ===================================================================== */

.app-diag-model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    padding: 1rem 0;
}

.app-diag-model-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    text-align: center;
}
.app-diag-model-card:hover {
    border-color: var(--app-saez-red);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.app-diag-model-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}
.app-diag-model-type {
    font-size: 0.8rem;
    color: var(--app-text-muted);
}

.app-diag-tools-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 1rem 0;
    border-top: 1px solid var(--app-border);
    margin-top: 1rem;
}

.app-diag-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--app-border);
    padding-bottom: 0.5rem;
}
.app-diag-tab {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    color: var(--app-text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}
.app-diag-tab:hover { color: var(--app-text); }
.app-diag-tab.active {
    color: var(--app-saez-red);
    border-bottom-color: var(--app-saez-red);
    font-weight: 600;
}

.app-diag-content {
    min-height: 200px;
}

/* Document Analysis */
.app-doc-upload-zone {
    border: 2px dashed var(--app-border);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    margin-bottom: 1rem;
}
.app-doc-upload-zone:hover,
.app-doc-upload-zone.drag-over {
    border-color: var(--app-saez-red);
    background: rgba(227, 6, 19, 0.04);
}
.app-doc-upload-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}
.app-doc-upload-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.app-doc-upload-hint {
    font-size: 0.8rem;
    color: var(--app-text-muted);
    margin-bottom: 1rem;
}
.app-doc-file-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    margin-bottom: 1rem;
}
.app-doc-file-name {
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-doc-file-size {
    color: var(--app-text-muted);
    font-size: 0.85rem;
}
.app-doc-question-row {
    margin-bottom: 1rem;
}
.app-doc-question-row textarea {
    width: 100%;
    resize: vertical;
}
.app-doc-results {
    margin-top: 1rem;
}
.app-doc-terms {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--app-card-bg);
    border-radius: 8px;
}
.app-doc-term-tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: var(--app-saez-red);
    color: #fff;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}
.app-doc-matches-summary {
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    background: var(--app-card-bg);
    border-radius: 8px;
    border-left: 3px solid var(--app-saez-red);
}
.app-doc-analysis {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 1rem;
}
.app-doc-analysis h4 {
    margin: 0 0 0.75rem 0;
    color: var(--app-saez-red);
}
.app-doc-analysis-text {
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.app-diag-search-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.app-diag-search-row .app-input {
    flex: 1;
    min-width: 200px;
}

.app-diag-cadena-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.app-diag-cadena-card h4 {
    margin: 0 0 0.25rem 0;
    color: var(--app-saez-red);
}
.app-diag-cadena-card .cadena-desc {
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.app-diag-cadena-card .cadena-steps {
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
}

.app-diag-qf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.app-diag-qf-btn {
    padding: 0.75rem;
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    text-align: center;
    transition: border-color 0.2s;
}
.app-diag-qf-btn:hover {
    border-color: var(--app-saez-red);
    color: var(--app-saez-red);
}

.app-diag-ai-area {
    margin-top: 1rem;
}
.app-diag-ai-area textarea {
    width: 100%;
    min-height: 80px;
    padding: 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
}
.app-diag-ai-response {
    margin-top: 1rem;
    padding: 1rem;
    background: #f0f4f8;
    border-radius: 8px;
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 0.9rem;
}

.app-diag-troubleshoot-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.app-diag-troubleshoot-card h4 {
    margin: 0 0 0.25rem 0;
    color: var(--app-saez-red);
}
.app-diag-troubleshoot-card .ts-desc {
    color: var(--app-text-muted);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}
.app-diag-troubleshoot-card .ts-models {
    font-size: 0.8rem;
    color: var(--app-text-light);
    margin-bottom: 0.5rem;
}
.app-diag-troubleshoot-card .ts-steps {
    font-size: 0.9rem;
    line-height: 1.6;
}
.app-diag-troubleshoot-card .ts-steps .step {
    padding: 0.25rem 0;
    border-bottom: 1px dashed #e0e0e0;
}

/* PLC I/O Map & CANopen */
.app-diag-plc-note {
    background: #e8f4fd;
    border-left: 4px solid var(--app-primary);
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--app-text-muted);
    border-radius: 0 4px 4px 0;
}
.app-diag-plc-filters {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}
.app-diag-plc-filters select {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--app-border-light);
    border-radius: 4px;
    font-size: 0.85rem;
    background: var(--app-card-bg);
}
.app-diag-plc-filters input {
    flex: 1;
    min-width: 180px;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--app-border-light);
    border-radius: 4px;
    font-size: 0.85rem;
}
.app-diag-plc-count {
    font-size: 0.8rem;
    color: var(--app-text-muted);
    margin-bottom: 0.5rem;
}
.app-diag-canopen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
}
.app-diag-canopen-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border-light);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}
.app-diag-canopen-card:hover {
    border-color: var(--app-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.canopen-card-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}
.canopen-card-model {
    font-size: 0.85rem;
    color: var(--app-text-muted);
    margin-bottom: 0.5rem;
}
.canopen-card-stats {
    display: flex;
    gap: 0.75rem;
    font-size: 0.8rem;
}
.canopen-card-stats span {
    background: var(--app-card-bg-alt);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}
.plc-row-input { background: #f0fdf4; }
.plc-row-output { background: #fef2f2; }
.plc-row-analog { background: #fffbeb; }

/* Safety PLC Tab */
.app-diag-safety-diagram {
    margin-bottom: 1.5rem;
    text-align: center;
}
.app-diag-safety-img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--app-border-light);
    border-radius: 8px;
    cursor: zoom-in;
    transition: box-shadow 0.2s;
}
.app-diag-safety-img:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.safety-sil3 {
    background: #fecaca;
    color: #991b1b;
    font-weight: 700;
    text-align: center;
}
.safety-sil2 {
    background: #fed7aa;
    color: #9a3412;
    font-weight: 600;
    text-align: center;
}
.safety-sil1 {
    background: #fef08a;
    color: #854d0e;
    font-weight: 500;
    text-align: center;
}

/* =====================================================================
   Calendar Section
   ===================================================================== */

.app-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--app-border-light);
    border-radius: 8px;
    overflow: hidden;
}
.app-calendar-header {
    background: var(--app-card-bg-alt);
    padding: 8px;
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--app-text-muted);
}
.app-calendar-day {
    background: var(--app-card-bg);
    min-height: 80px;
    padding: 4px 6px;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
}
.app-calendar-day:hover { background: #f0f7ff; }
.app-calendar-day.today { background: #eff6ff; border: 2px solid var(--primary, #2563eb); }
.app-calendar-day.other-month { color: #9ca3af; background: #fafafa; }
.app-calendar-day.selected { background: #dbeafe; }
.app-calendar-day-num { font-weight: 600; font-size: 0.85rem; }
.app-calendar-dots { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 2px; }
.app-calendar-dot { width: 6px; height: 6px; border-radius: 50%; }
.app-calendar-dot.vis-private { background: #6b7280; }
.app-calendar-dot.vis-client_team { background: #8b5cf6; }
.app-calendar-dot.vis-team { background: #3b82f6; }
.app-calendar-dot.vis-client { background: #f59e0b; }
.app-calendar-dot.vis-public { background: #10b981; }
.app-calendar-event {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
    background: var(--app-card-bg-subtle);
    border-left: 3px solid var(--primary, #2563eb);
}
.app-calendar-event .time { font-weight: 600; white-space: nowrap; font-size: 0.85rem; }
.app-calendar-event .title { flex: 1; }
.app-calendar-event .vis-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    color: #fff;
    white-space: nowrap;
}
.app-calendar-event .vis-badge.vis-private { background: #6b7280; }
.app-calendar-event .vis-badge.vis-client_team { background: #8b5cf6; }
.app-calendar-event .vis-badge.vis-team { background: #3b82f6; }
.app-calendar-event .vis-badge.vis-client { background: #f59e0b; }
.app-calendar-event .vis-badge.vis-public { background: #10b981; }
.app-calendar-event .actions { display: flex; gap: 4px; }

@media (max-width: 640px) {
    .app-calendar-day { min-height: 50px; padding: 2px 3px; }
    .app-calendar-day-num { font-size: 0.75rem; }
    .app-calendar-header { padding: 4px; font-size: 0.7rem; }
    .app-calendar-event { flex-wrap: wrap; gap: 4px; }
}

/* =====================================================================
   Repuestos Section
   ===================================================================== */

.app-rep-model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1rem 0;
}
.app-rep-model-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 1.5rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    text-align: center;
    font-weight: 600;
    font-size: 1.1rem;
}
.app-rep-model-card:hover {
    border-color: var(--app-saez-red);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.app-rep-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: center;
}
.app-rep-filters .app-select,
.app-rep-filters .app-input {
    min-width: 150px;
}

/* --- Identify by Photo v2 --- */
.btn-identify-photo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0 1rem;
    padding: 0.75rem 1.25rem;
    background: var(--app-saez-red);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
}
.btn-identify-photo:hover {
    background: #b71c1c;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.btn-identify-photo svg { flex-shrink: 0; }

.identify-result {
    margin: 1rem 0;
    padding: 1rem;
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
}
.identify-preview {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.identify-preview img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 6px;
    object-fit: contain;
    border: 1px solid var(--app-border);
}
.identify-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--app-border);
    border-top-color: var(--app-saez-red);
    border-radius: 50%;
    animation: id-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 0.5rem;
}
@keyframes id-spin { to { transform: rotate(360deg); } }

.identify-vision-text {
    background: var(--app-bg);
    border: 1px solid var(--app-border);
    border-radius: 6px;
    padding: 0.75rem;
    font-size: 0.85rem;
    white-space: pre-wrap;
    margin-top: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}
.identify-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* Camera guidance */
.identify-camera-guide {
    padding: 1rem;
}
.identify-camera-guide h4 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}
.identify-camera-guide ul {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}
.identify-camera-guide li {
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    color: var(--app-text-secondary, var(--app-text-muted));
}

/* AI summary */
.identify-ai-summary {
    background: var(--app-bg);
    border: 1px solid var(--app-border);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    line-height: 1.5;
}
.identify-raw-toggle {
    background: none;
    border: none;
    color: var(--app-text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.25rem 0;
    text-decoration: underline;
}

/* Safety warning banners */
.identify-warning-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
}
.identify-warning-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}
.identify-warning-critical {
    background: #fde8e8;
    border: 1px solid #e74c3c;
    color: #b71c1c;
}
.identify-warning-warning {
    background: #fff8e1;
    border: 1px solid #f39c12;
    color: #e65100;
}
.identify-warning-info {
    background: #e3f2fd;
    border: 1px solid #2196f3;
    color: #0d47a1;
}
[data-theme="dark"] .identify-warning-critical {
    background: rgba(231,76,60,0.15);
    color: #ef9a9a;
}
[data-theme="dark"] .identify-warning-warning {
    background: rgba(243,156,18,0.15);
    color: #ffe082;
}
[data-theme="dark"] .identify-warning-info {
    background: rgba(33,150,243,0.15);
    color: #90caf9;
}

/* Confidence badges */
.identify-confidence-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-left: auto;
}
[dir="rtl"] .identify-confidence-badge { margin-left: 0; margin-right: auto; }
.identify-confidence-high { background: #e8f5e9; color: #2e7d32; border: 1px solid #66bb6a; }
.identify-confidence-medium { background: #fff8e1; color: #e65100; border: 1px solid #ffb74d; }
.identify-confidence-low { background: #fde8e8; color: #c62828; border: 1px solid #ef9a9a; }
[data-theme="dark"] .identify-confidence-high { background: rgba(46,125,50,0.2); color: #81c784; }
[data-theme="dark"] .identify-confidence-medium { background: rgba(230,81,0,0.2); color: #ffb74d; }
[data-theme="dark"] .identify-confidence-low { background: rgba(198,40,40,0.2); color: #ef9a9a; }

/* Safety critical icon */
.identify-safety-icon {
    color: #e74c3c;
    font-size: 1rem;
    margin: 0 0.25rem;
}

/* Match cards */
.identify-matches-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.identify-matches-title {
    margin: 0.75rem 0 0.5rem;
    font-size: 1rem;
}
.identify-match-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    transition: box-shadow 0.2s;
}
.identify-match-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.identify-match-critical {
    border-left: 3px solid #e74c3c;
}
[dir="rtl"] .identify-match-critical {
    border-left: 1px solid var(--app-border);
    border-right: 3px solid #e74c3c;
}
.identify-match-fallback {
    border-left: 3px solid #f59e0b;
}
[dir="rtl"] .identify-match-fallback {
    border-left: 1px solid var(--app-border);
    border-right: 3px solid #f59e0b;
}
.identify-match-fallback-warn {
    background: #fef3c7;
    color: #78350f;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin: 0.5rem 0;
    font-size: 0.875rem;
    line-height: 1.4;
}
[data-theme="dark"] .identify-match-fallback-warn {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
    border-color: #d97706;
}
.identify-match-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.identify-match-rank {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--app-text-muted);
    min-width: 1.5rem;
}
.identify-match-code {
    font-weight: 700;
    font-size: 1rem;
    color: var(--app-saez-red, #d32f2f);
}
.identify-match-desc {
    font-size: 0.85rem;
    color: var(--app-text-secondary, var(--app-text-muted));
    margin: 0.35rem 0 0.5rem;
    line-height: 1.4;
}
.identify-match-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.identify-match-tag {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    background: var(--app-bg);
    border: 1px solid var(--app-border);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--app-text-muted);
}
.identify-match-tag-ref {
    background: #e3f2fd;
    border-color: #90caf9;
    color: #1565c0;
    font-weight: 600;
}
[data-theme="dark"] .identify-match-tag-ref {
    background: rgba(21,101,192,0.2);
    color: #90caf9;
}
.identify-match-toggle {
    background: none;
    border: none;
    color: var(--app-saez-red, #d32f2f);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.35rem 0 0.15rem;
    text-decoration: underline;
}
.identify-match-details {
    padding: 0.5rem 0;
    font-size: 0.85rem;
    line-height: 1.6;
}
.identify-match-detail-line {
    color: var(--app-text-secondary, var(--app-text-muted));
}
.identify-match-ds-btn {
    display: inline-block;
    margin-top: 0.5rem;
    font-size: 0.8rem;
}

/* Contact SAEZ button */
.identify-contact-btn {
    display: block;
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--app-saez-red);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}
.identify-contact-btn:hover {
    background: #b71c1c;
}

/* Feedback */
.identify-feedback {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--app-border);
    font-size: 0.85rem;
    color: var(--app-text-muted);
    flex-wrap: wrap;
}
.identify-feedback-btn {
    font-size: 0.8rem;
    padding: 0.25rem 0.75rem;
}

/* Collapsed matches */
.identify-match-collapsed { display: none; }

/* User's cranes badge on identify result cards */
.identify-user-cranes-badge {
    margin: 0.5rem 0 0;
    padding: 0.5rem 0.75rem;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #2e7d32;
    line-height: 1.4;
}
[data-theme="dark"] .identify-user-cranes-badge {
    background: rgba(76, 175, 80, 0.15);
    border-color: rgba(76, 175, 80, 0.3);
    color: #81c784;
}

/* Multi-photo thumbnails */
.identify-multi-photos {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 0.75rem 0;
    min-height: 0;
}
.identify-photo-thumb {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid var(--app-border);
}
.identify-photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.identify-photo-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    padding: 0;
}
[dir="rtl"] .identify-photo-remove { right: auto; left: 2px; }
.identify-photo-label {
    font-size: 0.75rem;
    text-align: center;
    color: var(--app-text-muted);
    margin-top: 2px;
}

/* Comparison view */
.identify-comparison {
    background: var(--app-card-bg);
    border: 2px solid #ff9800;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.identify-comparison h4 {
    margin: 0 0 0.75rem;
    color: #e65100;
    font-size: 0.95rem;
}
[data-theme="dark"] .identify-comparison h4 { color: #ffb74d; }
.identify-comparison-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}
.identify-comparison-col {
    flex: 1;
    background: var(--app-bg);
    border: 1px solid var(--app-border);
    border-radius: 6px;
    padding: 0.75rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.identify-comparison-col:hover {
    border-color: var(--app-saez-red);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.identify-comparison-header {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--app-saez-red, #d32f2f);
    margin-bottom: 0.25rem;
}
.identify-comparison-desc {
    font-size: 0.8rem;
    color: var(--app-text-muted);
    line-height: 1.3;
}
.identify-comparison-vs {
    display: flex;
    align-items: center;
    font-weight: 700;
    color: #ff9800;
    font-size: 0.85rem;
    padding: 0 0.25rem;
}

/* Analytics dashboard */
.identify-analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.identify-stat-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}
.identify-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--app-saez-red, #d32f2f);
}
.identify-stat-label {
    font-size: 0.8rem;
    color: var(--app-text-muted);
    margin-top: 0.25rem;
}

/* Mobile responsive */
@media (max-width: 600px) {
    .identify-preview img { max-width: 120px; max-height: 120px; }
    .identify-match-header { flex-wrap: wrap; }
    .identify-match-code { font-size: 0.9rem; }
    .identify-comparison-row { flex-direction: column; }
    .identify-comparison-vs { justify-content: center; padding: 0.25rem 0; }
    .identify-analytics-grid { grid-template-columns: repeat(2, 1fr); }
    .identify-photo-thumb { width: 60px; height: 60px; }
}

/* =====================================================================
   Manuales Section
   ===================================================================== */

.app-man-category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    padding: 1rem 0;
}
.app-man-category-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 1.5rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.app-man-category-card:hover {
    border-color: var(--app-saez-red);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.app-man-category-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}
.app-man-category-count {
    color: var(--app-text-muted);
    font-size: 0.85rem;
}

.app-man-files {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.app-man-file-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 6px;
}
.app-man-file-name {
    font-weight: 500;
    flex: 1;
    margin-right: 1rem;
    word-break: break-word;
}
.app-man-file-size {
    color: var(--app-text-muted);
    font-size: 0.85rem;
    margin-right: 1rem;
    white-space: nowrap;
}

/* Manual groups (crane model sections in Despieces) */
.app-man-group {
    margin-bottom: 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    overflow: hidden;
}
.app-man-group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--app-card-bg);
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--app-border);
}
.app-man-group-header:hover {
    background: var(--app-hover-bg, rgba(255,255,255,0.05));
}
.app-man-group-arrow {
    font-size: 0.7rem;
    color: var(--app-text-muted);
    width: 1em;
    text-align: center;
}
.app-man-group-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--app-saez-red, #e74c3c);
}
.app-man-group-badge {
    font-size: 0.8rem;
    color: var(--app-text-muted);
    margin-left: auto;
}
.app-man-group-body {
    display: flex;
    flex-direction: column;
}
.app-man-group-body.collapsed {
    display: none;
}
.app-man-group-body .app-man-file-row {
    border: none;
    border-radius: 0;
    border-bottom: 1px solid var(--app-border);
}
.app-man-group-body .app-man-file-row:last-child {
    border-bottom: none;
}

/* Shared utility classes */
.app-btn-back {
    margin-bottom: 1rem;
}
.app-btn-outline {
    background: transparent;
    border: 1px solid var(--app-border);
    color: var(--app-text);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: border-color 0.2s, color 0.2s;
}
.app-btn-outline:hover {
    border-color: var(--app-saez-red);
    color: var(--app-saez-red);
}
.app-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: 6px;
    background: var(--app-card-bg);
    font-size: 0.9rem;
}
.app-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: 6px;
    font-size: 0.9rem;
}
.app-section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
}

.app-section-subtitle {
    font-size: 0.9rem;
    color: var(--app-text-muted);
    margin: 0 0 1rem 0;
    max-width: 520px;
    line-height: 1.4;
}

/* ==========================================================================
   POINTER OVERLAY (Plan 1)
   ========================================================================== */

.app-pointer-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    cursor: crosshair;
    z-index: 3;
}

/* ==========================================================================
   CALL RECORDING (Plan 2)
   ========================================================================== */

.app-recording-indicator {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    z-index: 5;
}

.app-recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--app-red);
    animation: app-rec-pulse 1s ease-in-out infinite;
}

@keyframes app-rec-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.app-peer-recording {
    position: absolute;
    top: 10px;
    right: 140px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(220,53,69,0.85);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 5;
    animation: app-rec-pulse 1.5s ease-in-out infinite;
}

.app-btn-vc-record {
    position: relative;
}
.app-btn-vc-record.recording,
.app-btn-vc-capture.recording {
    background: var(--app-red) !important;
    animation: recPulse 1.4s infinite;
}

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

/* ==========================================================================
   OFFLINE MODE (Plan 3)
   ========================================================================== */

.app-offline-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--app-orange);
    color: white;
    text-align: center;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.app-offline-count {
    background: rgba(255,255,255,0.3);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
}

/* ==========================================================================
   GUEST CALL (Plan 4)
   ========================================================================== */

.app-guest-body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #111;
    color: white;
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-guest-header {
    text-align: center;
    padding: 12px;
    background: rgba(0,0,0,0.5);
}

.app-guest-header img {
    height: 28px;
    vertical-align: middle;
    margin-right: 8px;
}

.app-guest-video-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.app-guest-remote {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #222;
}

.app-guest-local {
    position: absolute;
    bottom: 80px;
    right: 16px;
    width: 120px;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.3);
    background: #333;
}

.app-guest-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 16px;
    background: rgba(0,0,0,0.85);
}

.app-guest-status {
    text-align: center;
    padding: 40px 20px;
    font-size: 1.1rem;
    color: #ccc;
}

.app-guest-status .spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.app-guest-ended {
    text-align: center;
    padding: 60px 20px;
}

/* ==========================================================================
   MULTI-CALL VIDEO GRID (Plan 5)
   ========================================================================== */

.app-video-grid {
    flex: 1;
    display: grid;
    gap: 2px;
    background: #000;
    overflow: hidden;
}

.app-video-grid[data-count="1"] {
    grid-template-columns: 1fr;
}

.app-video-grid[data-count="2"] {
    grid-template-columns: 1fr 1fr;
}

.app-video-grid[data-count="3"],
.app-video-grid[data-count="4"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.app-video-grid video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #111;
}

.app-video-grid .app-video-cell {
    position: relative;
    overflow: hidden;
}

.app-video-cell-label {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    z-index: 2;
}

.app-local-pip {
    position: absolute;
    bottom: 70px;
    right: 10px;
    width: 120px;
    height: 90px;
    z-index: 4;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.3);
}

.app-local-pip video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #222;
}

/* ==========================================================================
   CALL TOOLBAR (Phase 0) - Dynamic toolbar layout
   ========================================================================== */

.app-video-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    background: rgba(0,0,0,0.85);
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.app-toolbar-core,
.app-toolbar-tools,
.app-toolbar-end {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-toolbar-core { order: 1; }
.app-toolbar-tools { order: 2; position: relative; }
.app-toolbar-end { order: 3; }

/* Separators between groups */
.app-toolbar-core::after,
.app-toolbar-tools::after {
    content: '';
    width: 1px;
    height: 28px;
    background: rgba(255,255,255,0.2);
    margin: 0 0.25rem;
}

/* Overflow menu */
.app-btn-vc-more.active {
    background: rgba(255,255,255,0.3);
}

.app-toolbar-overflow {
    position: fixed;
    z-index: 400;
    background: rgba(0,0,0,0.9);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
}

.app-toolbar-overflow[hidden] { display: none; }

/* Active toggle button */
.app-btn-vc.active {
    background: var(--app-primary);
    color: white;
}

/* Sub-toolbar (for drawing tools, colors, etc.) */
.app-sub-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(0,0,0,0.75);
    flex-shrink: 0;
}

.app-sub-toolbar[hidden] { display: none; }

.app-subtool-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.app-subtool-btn {
    width: 34px;
    height: 34px;
    border-radius: 6px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s;
}

.app-subtool-btn:hover { background: rgba(255,255,255,0.2); }
.app-subtool-btn.active { background: var(--app-primary); }

.app-subtool-separator {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,0.2);
    margin: 0 4px;
}

/* Color swatches */
.app-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.app-color-swatch:hover { transform: scale(1.15); }
.app-color-swatch.active { border-color: white; }

/* ==========================================================================
   LIVE ANNOTATE (Phase 1a)
   ========================================================================== */

.app-annotate-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
    touch-action: none;
}

/* ==========================================================================
   VIDEO ZOOM (Phase 1b)
   ========================================================================== */

.app-video-container #remote-video {
    transition: transform 0.1s ease-out;
    will-change: transform;
}

.app-zoom-indicator {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.app-zoom-indicator.visible { opacity: 1; }

/* ==========================================================================
   FACE BLUR (Phase 1c)
   ========================================================================== */

.app-face-blur-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    object-fit: contain;
    pointer-events: none;
}

/* ==========================================================================
   QR SCANNER (Phase 2a)
   ========================================================================== */

.app-qr-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 6;
    text-align: center;
    pointer-events: none;
}

.app-qr-viewfinder {
    width: 200px;
    height: 200px;
    border: 3px solid rgba(255,255,255,0.8);
    border-radius: 12px;
    margin: 0 auto 12px;
    position: relative;
    animation: app-qr-pulse 2s ease-in-out infinite;
}

.app-qr-viewfinder::before,
.app-qr-viewfinder::after {
    content: '';
    position: absolute;
    width: 30px;
    height: 30px;
    border-color: var(--app-primary);
    border-style: solid;
}

.app-qr-viewfinder::before {
    top: -2px;
    left: -2px;
    border-width: 3px 0 0 3px;
    border-radius: 6px 0 0 0;
}

.app-qr-viewfinder::after {
    bottom: -2px;
    right: -2px;
    border-width: 0 3px 3px 0;
    border-radius: 0 0 6px 0;
}

@keyframes app-qr-pulse {
    0%, 100% { border-color: rgba(255,255,255,0.8); }
    50% { border-color: rgba(255,255,255,0.4); }
}

.app-qr-label {
    color: white;
    font-size: 0.8rem;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.app-qr-result {
    color: #22c55e;
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(0,0,0,0.7);
    padding: 6px 16px;
    border-radius: 8px;
    margin-top: 8px;
    word-break: break-all;
    max-width: 280px;
}

.app-qr-result[hidden] { display: none; }

/* ==========================================================================
   GPS SHARING (Phase 2b) - Toast styles
   ========================================================================== */

.app-gps-toast {
    background: rgba(0,0,0,0.85);
    color: white;
    padding: 10px 16px;
    border-radius: 10px;
    position: absolute;
    top: 50px;
    right: 10px;
    z-index: 6;
    font-size: 0.8rem;
    max-width: 280px;
    pointer-events: auto;
}

.app-gps-toast a {
    color: #60a5fa;
    text-decoration: underline;
}

/* ==========================================================================
   HD CAPTURE (Phase 2c)
   ========================================================================== */

.app-hd-capture-flash {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 999;
    opacity: 0.8;
    animation: app-flash-fade 0.4s ease-out forwards;
    pointer-events: none;
}

@keyframes app-flash-fade {
    0% { opacity: 0.8; }
    100% { opacity: 0; }
}

/* ==========================================================================
   LOW DATA MODE (Phase 3a)
   ========================================================================== */

.app-btn-vc.low-data-active {
    background: var(--app-orange) !important;
}

.app-low-data-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(234,179,8,0.85);
    color: #000;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    z-index: 5;
}

/* ==========================================================================
   FILE SHARING (Phase 3b)
   ========================================================================== */

.app-file-progress {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 8px 20px;
    border-radius: 10px;
    font-size: 0.8rem;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-file-progress-bar {
    width: 120px;
    height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    overflow: hidden;
}

.app-file-progress-fill {
    height: 100%;
    background: var(--app-primary);
    border-radius: 3px;
    transition: width 0.2s;
}

/* ==========================================================================
   RESPONSIVE - Toolbar mobile adjustments
   ========================================================================== */

@media (max-width: 600px) {
    .app-video-controls {
        gap: 0.25rem;
        padding: 0.4rem;
        flex-wrap: wrap;
        justify-content: center;
        overflow-x: visible;
    }

    .app-btn-vc {
        width: 36px;
        height: 36px;
        min-width: 36px;
        flex-shrink: 0;
    }

    .app-btn-vc svg {
        width: 16px;
        height: 16px;
    }

    .app-toolbar-core,
    .app-toolbar-tools,
    .app-toolbar-end {
        gap: 0.25rem;
        flex-shrink: 0;
    }

    .app-sub-toolbar {
        padding: 4px 8px;
        gap: 3px;
        flex-wrap: wrap;
    }

    .app-subtool-btn {
        width: 30px;
        height: 30px;
    }

    .app-toolbar-overflow {
        flex-wrap: wrap;
        max-width: 200px;
    }

    .app-qr-viewfinder {
        width: 160px;
        height: 160px;
    }
}

/* ==========================================================================
   MONITORING SECTION
   ========================================================================== */

.app-mon-toolbar-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}
.app-mon-sync-status {
    font-size: 0.85rem;
    color: var(--app-muted);
}
.app-mon-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.app-mon-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.app-mon-search {
    display: flex;
    gap: 0.5rem;
    flex: 1;
    max-width: 400px;
}

.app-mon-search .app-input {
    flex: 1;
}

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

/* Monitoring grid */
.app-mon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

/* Monitoring card */
.app-mon-card {
    background: var(--app-card-bg);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    border-left: 4px solid var(--app-text-light);
    padding: 1rem;
    transition: transform 0.15s, box-shadow 0.15s;
}

.app-mon-card[data-crane-id] {
    cursor: pointer;
}

.app-mon-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--app-shadow-lg);
}

.app-mon-card.app-mon-online {
    border-left-color: var(--app-green);
}

.app-mon-card.app-mon-offline {
    border-left-color: var(--app-red);
}

.app-mon-card.app-mon-no-router {
    border-left-color: var(--app-text-light);
    opacity: 0.85;
}

.app-mon-no-router .app-mon-status-text {
    color: var(--app-text-light);
    font-style: italic;
}

.app-mon-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.app-mon-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.app-mon-online .app-mon-status-dot {
    background: var(--app-green);
    box-shadow: 0 0 6px rgba(40, 167, 69, 0.5);
    animation: app-mon-pulse 2s infinite;
}

.app-mon-offline .app-mon-status-dot {
    background: var(--app-red);
}

@keyframes app-mon-pulse {
    0%, 100% { box-shadow: 0 0 4px rgba(40, 167, 69, 0.4); }
    50% { box-shadow: 0 0 10px rgba(40, 167, 69, 0.8); }
}

.app-mon-status-text {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.app-mon-online .app-mon-status-text { color: var(--app-green); }
.app-mon-offline .app-mon-status-text { color: var(--app-red); }

.app-mon-card-body {
    margin-bottom: 0.5rem;
}

.app-mon-crane-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--app-text);
    margin-bottom: 0.2rem;
}

.app-mon-client {
    font-size: 0.85rem;
    color: var(--app-text-muted);
}

.app-mon-serial {
    font-size: 0.8rem;
    color: var(--app-text-light);
    font-family: monospace;
}

.app-mon-last-seen {
    font-size: 0.75rem;
    color: var(--app-text-light);
    margin-top: 0.3rem;
}

.app-mon-agents {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.app-mon-agent-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 3px;
    background: #e8f4fd;
    color: #1a6fb5;
    letter-spacing: 0.03em;
}

/* Telemetry badge on monitoring cards */
.app-mon-telemetry-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-radius: 3px;
    background: rgba(0, 188, 212, 0.15);
    color: #00838f;
    margin-bottom: 0.4rem;
}

/* KPI cards for monitoring */
.app-kpi-green .app-kpi-value { color: var(--app-green); }
.app-kpi-red .app-kpi-value { color: var(--app-red); }
.app-kpi-teal .app-kpi-value { color: var(--app-teal, #00bcd4); }

/* Detail view */
.app-mon-detail-header {
    margin-bottom: 1rem;
}

.app-mon-detail-header h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.3rem;
    color: var(--app-text);
}

.app-mon-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--app-text-muted);
}

.app-mon-detail-gm {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
}

.app-mon-sf-body { display: flex; flex-direction: column; gap: 0.6rem; font-size: 0.9rem; }
.app-mon-sf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.6rem;
}
.app-mon-sf-cell {
    background: var(--color-bg-alt, #f7f7f9);
    border: 1px solid var(--color-border, #e3e3e8);
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
}
.app-mon-sf-label { font-size: 0.75rem; opacity: 0.7; text-transform: uppercase; margin-bottom: 0.2rem; }
.app-mon-sf-value { font-weight: 600; word-break: break-word; }
.app-mon-sf-account { padding-top: 0.4rem; border-top: 1px solid var(--color-border, #e3e3e8); }
.app-mon-sf-subtitle { font-weight: 600; margin-top: 0.5rem; font-size: 0.9rem; }
.app-mon-sf-list { margin: 0.3rem 0; padding-left: 1.2rem; }
.app-mon-sf-list li { margin-bottom: 0.2rem; }
.app-mon-sf-meta { opacity: 0.7; font-size: 0.85rem; }
.app-mon-loading { opacity: 0.6; font-style: italic; padding: 0.4rem 0; }
.app-mon-empty { opacity: 0.6; font-style: italic; padding: 0.4rem 0; }

/* --- Skeleton loaders (P-B) --- */
.app-skel {
    background: linear-gradient(90deg,
        rgba(128,128,128,0.10) 0%,
        rgba(128,128,128,0.20) 50%,
        rgba(128,128,128,0.10) 100%);
    background-size: 200% 100%;
    animation: app-skel-shimmer 1.3s ease-in-out infinite;
    border-radius: 6px;
    display: block;
}
@keyframes app-skel-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.app-skel-line { height: 0.9rem; margin: 0.45rem 0; }
.app-skel-line.w-80 { width: 80%; }
.app-skel-line.w-60 { width: 60%; }
.app-skel-line.w-40 { width: 40%; }
.app-skel-title { height: 1.3rem; width: 40%; margin: 0.6rem 0 1rem; }
.app-skel-card  { height: 120px; margin: 0.6rem 0; }
.app-skel-row   { height: 2.2rem; margin: 0.4rem 0; }
.app-skel-avatar { width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0; }
.app-skel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.8rem;
    padding: 0.4rem 0;
}
.app-skel-list { padding: 0.4rem 0; }
@media (prefers-reduced-motion: reduce) {
    .app-skel { animation: none; }
}

/* --- Session expired banner (P7) --- */
.app-session-banner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    background: #fff4d6;
    color: #7a5a00;
    border-bottom: 1px solid #e5c270;
    font-size: 0.95rem;
    animation: app-session-slide-in 0.3s ease-out;
}
[data-theme="dark"] .app-session-banner {
    background: #5a4200;
    color: #ffe8a6;
    border-bottom-color: #8a6a00;
}
.app-session-banner-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}
.app-session-banner-text {
    flex: 1;
    font-weight: 500;
}
@keyframes app-session-slide-in {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .app-session-banner { animation: none; }
}

.app-mon-detail-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

/* Connection history event badges */
.app-mon-ev-online {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #d4edda;
    color: #155724;
}

.app-mon-ev-offline {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #f8d7da;
    color: #721c24;
}

@media (max-width: 768px) {
    .app-mon-grid {
        grid-template-columns: 1fr;
    }
    .app-mon-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .app-mon-search {
        max-width: none;
    }
}

/* ─── Telemetry Dashboard ─── */

.app-tel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--app-card-bg);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
}

.app-tel-crane-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--app-text);
}

.app-tel-live-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.app-tel-live {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    background: #d4edda;
    color: #155724;
}

.app-tel-live-ts {
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 500;
    white-space: nowrap;
}

.app-tel-live::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--app-green);
}

.app-tel-live-pulse::before {
    animation: pulse-badge 1s ease-in-out;
}

/* --- Live telemetry indicator states --- */

.app-tel-live-on {
    background: #d4edda;
    color: #155724;
}

.app-tel-live-on::before {
    background: #28a745;
    animation: pulse-dot 2s infinite;
}

.app-tel-live-idle {
    background: #e2e8f0;
    color: #64748b;
}

.app-tel-live-idle::before {
    background: #94a3b8;
}

.app-tel-live-activating {
    background: #fff3cd;
    color: #856404;
}

.app-tel-live-activating::before {
    background: #ffc107;
    animation: pulse-dot 1s infinite;
}

.app-tel-live-deactivating {
    background: #e2e8f0;
    color: #64748b;
}

.app-tel-live-deactivating::before {
    background: #94a3b8;
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.7); }
}

/* --- Live activation banner --- */

.app-tel-live-banner {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    border-radius: var(--app-radius);
    background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.app-tel-live-banner-activating {
    background: linear-gradient(135deg, #856404 0%, #a07a05 100%);
}

.app-tel-live-banner-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.app-tel-live-banner-text {
    flex: 1;
}

.app-tel-live-banner-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.app-tel-live-banner-desc {
    font-size: 0.85rem;
    opacity: 0.85;
}

.app-tel-live-btn {
    flex-shrink: 0;
    font-size: 0.9rem;
    padding: 0.6rem 1.5rem;
    background: #28a745;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.2s;
}

.app-tel-live-btn:hover {
    background: #218838;
}

@media (max-width: 600px) {
    .app-tel-live-banner {
        flex-wrap: wrap;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }
    .app-tel-live-banner-icon {
        font-size: 1.5rem;
    }
    .app-tel-live-banner-text {
        flex-basis: calc(100% - 3rem);
    }
    .app-tel-live-banner-title {
        font-size: 0.95rem;
    }
    .app-tel-live-banner-desc {
        font-size: 0.78rem;
    }
    .app-tel-live-banner-warn {
        font-size: 0.72rem;
    }
    .app-tel-live-btn {
        width: 100%;
        text-align: center;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}

/* --- Live activation spinner --- */

.app-tel-live-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

/* --- No telemetry data message --- */

.app-tel-no-data-msg {
    text-align: center;
    padding: 3rem 1rem;
    color: rgba(255, 255, 255, 0.6);
}

.app-tel-no-data-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.app-tel-no-data-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 0.5rem;
}

.app-tel-no-data-desc {
    font-size: 0.9rem;
    max-width: 400px;
    margin: 0 auto;
    line-height: 1.5;
}

/* --- SIM data warning in activation banner --- */

.app-tel-live-banner-warn {
    font-size: 0.78rem;
    color: rgba(255, 200, 50, 0.9);
    margin-top: 0.4rem;
    line-height: 1.4;
}

/* --- Live waiting for data spinner --- */

.app-tel-live-waiting {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    margin: 1rem 0;
    background: linear-gradient(135deg, #1a3a2a 0%, #1a4a3a 100%);
    border-radius: 10px;
    border-left: 4px solid #28a745;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.app-tel-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.app-tel-panel {
    background: var(--app-card-bg);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    padding: 1rem;
    min-height: 120px;
}

.app-tel-panel-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--app-blue);
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 2px solid var(--app-border);
}

.app-tel-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.app-tel-row:last-child {
    border-bottom: none;
}

.app-tel-label {
    font-size: 0.82rem;
    color: var(--app-text-muted);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-tel-value {
    font-size: 0.85rem;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
    padding-left: 0.5rem;
}

.app-tel-ok { color: var(--app-green); }
.app-tel-warn { color: var(--app-orange); }
.app-tel-fault { color: var(--app-red); font-weight: 700; }
.app-tel-on { color: var(--app-green); }
.app-tel-off { color: var(--app-text-muted); }

.app-tel-no-data {
    padding: 1rem 0;
    color: var(--app-text-muted);
    font-style: italic;
    font-size: 0.85rem;
}


.app-tel-loading {
    text-align: center;
    padding: 2rem;
    color: var(--app-text-muted);
}

.app-mon-detail-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

@media (max-width: 768px) {
    .app-tel-grid {
        grid-template-columns: 1fr;
    }
    .app-tel-header {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
}

/* ─── Telemetry Hero Dashboard ─── */

.app-tel-hero {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.app-tel-hero-card {
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    overflow: hidden;
}

.app-tel-hero-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}

.app-tel-hero-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.75rem;
    opacity: 0.85;
}

/* Hero Card 1: Load Gauge */
.app-tel-hero-load {
    background: linear-gradient(135deg, var(--app-blue), #0f2640);
    color: #fff;
}

.app-tel-gauge-wrap {
    width: 160px;
    height: 80px;
    overflow: hidden;
    position: relative;
    margin-bottom: 0.25rem;
}

.app-tel-gauge-arc {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
}

.app-tel-gauge-arc::after {
    content: '';
    position: absolute;
    inset: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--app-blue), #0f2640);
}

.app-tel-gauge-value {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
    text-align: center;
    line-height: 1.1;
}

.app-tel-gauge-value .big {
    font-size: 2rem;
    font-weight: 800;
    display: block;
}

.app-tel-gauge-value .max {
    font-size: 0.8rem;
    opacity: 0.7;
    display: block;
}

.app-tel-overload-bar {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
    margin-top: 0.5rem;
    overflow: hidden;
}

.app-tel-overload-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease, background 0.5s ease;
}

/* Hero Card 2: Wind */
.app-tel-hero-wind {
    background: var(--app-card-bg);
    border-top: 4px solid var(--app-green);
    transition: border-color 0.5s ease;
}

.app-tel-wind-val {
    font-size: 2.2rem;
    font-weight: 800;
    transition: color 0.5s ease;
    line-height: 1;
}

.app-tel-wind-unit {
    font-size: 0.85rem;
    color: var(--app-text-muted);
}

.app-tel-wind-bar-wrap {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
    height: 50px;
    width: 100%;
    justify-content: center;
}

.app-tel-wind-bar {
    width: 8px;
    border-radius: 4px;
    transition: height 0.5s ease, background 0.5s ease;
    min-height: 4px;
}

/* Hero Card 3: Status ON/OFF */
.app-tel-hero-status {
    transition: background 0.8s ease;
    color: #fff;
}

.app-tel-hero-status.on {
    background: linear-gradient(135deg, #28a745, #1e7e34);
}

.app-tel-hero-status.off {
    background: #374151;
}

.app-tel-status-big {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    line-height: 1;
}

.app-tel-status-sub {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 0.25rem;
}

/* KPI Row */
.app-tel-kpis {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.app-tel-kpi {
    background: var(--app-card-bg);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    padding: 1rem;
    border-left: 4px solid var(--app-border);
    transition: transform 0.2s ease;
}

.app-tel-kpi:hover {
    transform: translateY(-1px);
}

.app-tel-kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--app-text);
    line-height: 1.2;
}

.app-tel-kpi-label {
    font-size: 0.78rem;
    color: var(--app-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.15rem;
}

/* Hours Row */
.app-tel-hours-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.app-tel-hour-card {
    background: var(--app-card-bg);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    padding: 1rem;
}

.app-tel-hour-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.app-tel-hour-name {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--app-text-muted);
    font-weight: 600;
    letter-spacing: 0.03em;
}

.app-tel-hour-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--app-text);
}

.app-tel-hour-cycles {
    font-size: 0.8rem;
    color: var(--app-text-light);
    margin-top: 0.1rem;
}

.app-tel-hour-bar {
    height: 4px;
    background: #e2e8f0;
    border-radius: 2px;
    margin-top: 0.5rem;
    overflow: hidden;
}

.app-tel-hour-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
}

.app-tel-hour-indicator {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.4rem;
    font-size: 0.75rem;
}

.app-tel-hour-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--app-text-muted);
}

.app-tel-hour-dot.on {
    background: var(--app-green);
    animation: tel-dot-pulse 1.5s ease-in-out infinite;
}

@keyframes tel-dot-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Fault dot indicators */
.app-tel-fault-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.4rem;
    flex-shrink: 0;
}

.app-tel-fault-dot.ok { background: var(--app-green); }
.app-tel-fault-dot.fault { background: var(--app-red); }

/* Update flash animation */
@keyframes app-tel-flash {
    0% { background-color: rgba(59,130,246,0.15); }
    100% { background-color: transparent; }
}

.app-tel-value-updated {
    animation: app-tel-flash 0.8s ease-out;
    border-radius: 3px;
}

/* ─── Telemetry Hero Responsive ─── */

@media (max-width: 1024px) {
    .app-tel-hero {
        grid-template-columns: 1fr 1fr;
    }
    .app-tel-hero-load {
        grid-column: span 2;
    }
    .app-tel-kpis {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .app-tel-hero {
        grid-template-columns: 1fr;
    }
    .app-tel-hero-load {
        grid-column: span 1;
    }
    .app-tel-kpis {
        grid-template-columns: repeat(2, 1fr);
    }
    .app-tel-hours-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .app-tel-kpis {
        grid-template-columns: 1fr;
    }
}

/* ===== Catalog Section ===== */

.app-catalog-card {
    background: var(--app-bg-card, #fff);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
}
.app-catalog-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.app-catalog-card-img {
    width: 100%;
    aspect-ratio: 4/3;
    overflow: hidden;
    background: #f8f8f8;
}
.app-catalog-card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.app-catalog-card-body {
    padding: 12px 16px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app-catalog-card-header {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.app-catalog-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.app-catalog-badge-draft {
    background: #e0e0e0 !important;
    color: #555 !important;
}
.app-catalog-badge-sl {
    background: #fff8e1 !important;
    color: #f57f17 !important;
}

.app-catalog-card-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    color: var(--app-text, #1a1a1a);
}

.app-catalog-card-type {
    font-size: 12px;
    color: var(--app-text-secondary, #666);
    margin: 0;
}

.app-catalog-card-specs {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--app-border, #eee);
}

.app-catalog-spec {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}
.app-catalog-spec-label {
    color: var(--app-text-secondary, #666);
}
.app-catalog-spec-value {
    font-weight: 600;
    color: var(--app-text, #1a1a1a);
}

/* Filter row */
.app-filter-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* Detail view */
.app-catalog-detail-header {
    margin-bottom: 20px;
}
.app-catalog-detail-header h2 {
    font-size: 24px;
    font-weight: 800;
    margin: 0 0 8px;
}
.app-catalog-detail-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Hero product photo */
.app-catalog-hero {
    margin-bottom: 20px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    max-height: 400px;
}
.app-catalog-hero img {
    width: 100%;
    height: 100%;
    max-height: 400px;
    object-fit: cover;
    display: block;
    cursor: zoom-in;
}

/* Images gallery */
.app-catalog-images {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.app-catalog-image-item {
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.app-catalog-image-item img {
    width: 100%;
    cursor: zoom-in;
    display: block;
}
.app-catalog-image-label {
    text-align: center;
    font-size: 12px;
    padding: 6px;
    color: var(--app-text-secondary, #666);
    background: var(--app-bg-card, #fff);
}

/* Specs grid */
.app-catalog-specs-grid,
.app-catalog-extra-specs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 24px;
}
.app-catalog-spec-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--app-border, #f0f0f0);
    font-size: 14px;
}
.app-catalog-extra-specs {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--app-border, #eee);
}

/* Load curves */
.app-catalog-curve-title {
    font-weight: 600;
    font-size: 14px;
    margin: 12px 0 6px;
    color: var(--app-text-secondary, #666);
}
.app-catalog-loadcurve {
    font-size: 13px;
}
.app-catalog-loadcurve th {
    white-space: nowrap;
}
.app-catalog-lc-label {
    font-weight: 600;
    white-space: nowrap;
}

/* Mechanisms */
.app-catalog-mechanisms {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.app-catalog-mech-row {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--app-border, #f0f0f0);
    font-size: 14px;
}
.app-catalog-mech-label {
    font-weight: 600;
    min-width: 120px;
    flex-shrink: 0;
}
.app-catalog-mech-value {
    color: var(--app-text-secondary, #555);
}

/* Lightbox */
.app-catalog-lightbox {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.app-catalog-lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
}
.app-catalog-lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    font-size: 36px;
    color: #fff;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
    .app-catalog-images {
        grid-template-columns: 1fr;
    }
    .app-catalog-specs-grid,
    .app-catalog-extra-specs {
        grid-template-columns: 1fr;
    }
    .app-catalog-mech-row {
        flex-direction: column;
        gap: 2px;
    }
}

/* ==========================================================================
   HMI SIMULATOR
   ========================================================================== */

.app-hmi-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    flex-wrap: wrap;
}
.app-hmi-toolbar-right {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.app-hmi-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    color: var(--app-text-muted);
    flex-wrap: wrap;
}
.app-hmi-breadcrumb-item {
    cursor: pointer;
    color: var(--app-blue-light);
}
.app-hmi-breadcrumb-item:hover { text-decoration: underline; }
.app-hmi-breadcrumb-sep { color: var(--app-text-light); }
.app-hmi-breadcrumb-current { color: var(--app-text); font-weight: 600; }
.app-hmi-lang-select { width: 70px; padding: 0.3rem; font-size: 0.85rem; }

/* Layout */
.app-hmi-layout {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem;
    align-items: start;
}
.app-hmi-viewer {
    width: 100%;
    max-width: 360px;
}
.app-hmi-screen-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: var(--app-radius);
    border: 2px solid var(--app-border);
    background: #0a1628;
}
.app-hmi-screen-img {
    width: 100%;
    height: auto;
    aspect-ratio: 480 / 800;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}
.app-hmi-hotspots-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Hotspot zones */
.app-hmi-hotspot {
    position: absolute;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    pointer-events: auto;
    transition: border-color 0.2s, background 0.2s;
}
.app-hmi-hotspot:hover, .app-hmi-hotspot.active { background: rgba(255,255,255,0.12); }
.app-hmi-hotspot[data-type="value"]:hover,
.app-hmi-hotspot[data-type="value"].active,
.app-hmi-hotspot[data-type="value"].visible { border-color: #3b82f6; background: rgba(59,130,246,0.15); }
.app-hmi-hotspot[data-type="button"]:hover,
.app-hmi-hotspot[data-type="button"].active,
.app-hmi-hotspot[data-type="button"].visible { border-color: #10b981; background: rgba(16,185,129,0.15); }
.app-hmi-hotspot[data-type="navigation"]:hover,
.app-hmi-hotspot[data-type="navigation"].active,
.app-hmi-hotspot[data-type="navigation"].visible { border-color: #f59e0b; background: rgba(245,158,11,0.15); }
.app-hmi-hotspot[data-type="indicator"]:hover,
.app-hmi-hotspot[data-type="indicator"].active,
.app-hmi-hotspot[data-type="indicator"].visible { border-color: #8b5cf6; background: rgba(139,92,246,0.15); }
.app-hmi-hotspot[data-type="display"]:hover,
.app-hmi-hotspot[data-type="display"].active,
.app-hmi-hotspot[data-type="display"].visible { border-color: #06b6d4; background: rgba(6,182,212,0.15); }
.app-hmi-hotspot[data-type="info"]:hover,
.app-hmi-hotspot[data-type="info"].active,
.app-hmi-hotspot[data-type="info"].visible { border-color: #64748b; background: rgba(100,116,139,0.15); }
.app-hmi-hotspot.visible { border-style: dashed; }
.app-hmi-hotspot:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.app-hmi-hotspot:focus:not(:focus-visible) { outline: none; }
.app-hmi-hotspot:focus .app-hmi-hotspot-label { opacity: 1; }

/* Hotspot tooltip */
.app-hmi-hotspot-label {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.65rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
}
.app-hmi-hotspot:hover .app-hmi-hotspot-label,
.app-hmi-hotspot.active .app-hmi-hotspot-label { opacity: 1; }

/* Nav hotspot (bottom bar, arrows) */
.app-hmi-nav-hotspot {
    position: absolute;
    cursor: pointer;
    pointer-events: auto;
    border-radius: 4px;
}
.app-hmi-nav-hotspot:hover { background: rgba(255,255,255,0.1); }

/* Info panel */
.app-hmi-info-panel {
    background: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 1rem;
    max-height: 800px;
    overflow-y: auto;
    min-width: 260px;
}
.app-hmi-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.app-hmi-info-title { font-size: 1.05rem; font-weight: 700; color: var(--app-text); margin: 0; }
.app-hmi-info-content p { margin-bottom: 0.5rem; line-height: 1.5; }
.app-hmi-info-placeholder { color: var(--app-text-muted); text-align: center; padding: 1rem 0; font-style: italic; }
.app-hmi-info-desc { color: var(--app-text); }
.app-hmi-info-details { color: var(--app-text-muted); font-size: 0.9rem; border-left: 3px solid var(--app-border); padding-left: 0.75rem; }
.app-hmi-info-muted { color: var(--app-text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; }

/* Type badge */
.app-hmi-info-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.app-hmi-badge-value { background: rgba(59,130,246,0.15); color: #3b82f6; }
.app-hmi-badge-button { background: rgba(16,185,129,0.15); color: #10b981; }
.app-hmi-badge-navigation { background: rgba(245,158,11,0.15); color: #f59e0b; }
.app-hmi-badge-indicator { background: rgba(139,92,246,0.15); color: #8b5cf6; }
.app-hmi-badge-display { background: rgba(6,182,212,0.15); color: #06b6d4; }
.app-hmi-badge-info { background: rgba(100,116,139,0.15); color: #64748b; }

/* Nav link */
.app-hmi-info-nav-link {
    display: block;
    color: var(--app-blue-light);
    cursor: pointer;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}
.app-hmi-info-nav-link:hover { text-decoration: underline; }

/* Element list in overview */
.app-hmi-element-list { list-style: none; padding: 0; margin: 0; }
.app-hmi-element-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-radius: 4px;
}
.app-hmi-element-item:hover { background: var(--app-bg); }
.app-hmi-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.app-hmi-dot-value { background: #3b82f6; }
.app-hmi-dot-button { background: #10b981; }
.app-hmi-dot-navigation { background: #f59e0b; }
.app-hmi-dot-indicator { background: #8b5cf6; }
.app-hmi-dot-display { background: #06b6d4; }
.app-hmi-dot-info { background: #64748b; }

/* Screen overview separator */
.app-hmi-screen-overview {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--app-border);
}

/* Legend */
.app-hmi-legend {
    display: flex;
    gap: 1rem;
    padding: 0.5rem 0;
    flex-wrap: wrap;
}
.app-hmi-legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--app-text-muted);
}
.app-hmi-legend-item::before {
    content: '';
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 2px;
    border: 2px solid;
}
.app-hmi-legend-value::before { border-color: #3b82f6; background: rgba(59,130,246,0.15); }
.app-hmi-legend-button::before { border-color: #10b981; background: rgba(16,185,129,0.15); }
.app-hmi-legend-nav::before { border-color: #f59e0b; background: rgba(245,158,11,0.15); }
.app-hmi-legend-indicator::before { border-color: #8b5cf6; background: rgba(139,92,246,0.15); }
.app-hmi-legend-display::before { border-color: #06b6d4; background: rgba(6,182,212,0.15); }

/* Dark mode */
[data-theme="dark"] .app-hmi-info-panel { background: var(--app-card-bg); border-color: var(--app-border); }
[data-theme="dark"] .app-hmi-screen-container { border-color: var(--app-border); }
[data-theme="dark"] .app-hmi-element-item:hover { background: rgba(255,255,255,0.05); }

/* Responsive */
@media (max-width: 900px) {
    .app-hmi-layout { grid-template-columns: 1fr; }
    .app-hmi-viewer { max-width: 100%; margin: 0 auto; }
    .app-hmi-info-panel { max-height: none; }
}
@media (max-width: 480px) {
    .app-hmi-screen-container { border-radius: 0; }
    .app-hmi-viewer { max-width: 100%; }
}

/* =============================================
   CABINET VIEWER
   ============================================= */
.app-cabinet-toolbar {
    display: flex; gap: 0.5rem; align-items: center;
    padding: 0.5rem 0; flex-wrap: wrap;
}
.app-cabinet-view-tabs {
    display: flex; gap: 2px;
}
.app-cabinet-view-tab {
    padding: 0.3rem 0.7rem; font-size: 0.8rem; cursor: pointer;
    border: 1px solid var(--app-border, #444); border-radius: 4px;
    background: transparent; color: var(--app-text-secondary, #aaa);
    transition: background 0.15s, color 0.15s;
}
.app-cabinet-view-tab:hover { background: rgba(255,255,255,0.06); }
.app-cabinet-view-tab.active {
    background: var(--app-accent, #3b82f6); color: #fff;
    border-color: var(--app-accent, #3b82f6);
}
.app-cabinet-search {
    flex: 1; min-width: 160px; max-width: 300px;
}
.app-cabinet-layout {
    display: grid; grid-template-columns: 1fr 340px; gap: 1rem;
    align-items: start;
}
.app-cabinet-viewer {
    width: 100%; max-width: 540px;
}
.app-cabinet-container {
    position: relative; width: 100%;
    overflow: hidden;
    border-radius: var(--app-radius);
    border: 2px solid var(--app-border);
    background: #1a1a2e;
}
.app-cabinet-img {
    width: 100%; height: auto;
    display: block; user-select: none;
    -webkit-user-drag: none;
}
.app-cabinet-zones-overlay {
    position: absolute; inset: 0;
    pointer-events: none;
}

/* Cabinet zones */
.app-cabinet-zone {
    position: absolute; pointer-events: auto; cursor: pointer;
    border: 2px solid transparent; border-radius: 3px;
    transition: border-color 0.15s, background 0.15s;
    box-sizing: border-box;
}
.app-cabinet-zone:hover,
.app-cabinet-zone.active {
    border-color: var(--zone-border, #fff);
    background: var(--zone-bg, rgba(255,255,255,0.12));
}
.app-cabinet-zone.visible {
    border-color: var(--zone-border, #fff);
    background: var(--zone-bg, rgba(255,255,255,0.08));
    border-style: dashed;
}
.app-cabinet-zone.active {
    border-style: solid; border-width: 2px;
    box-shadow: 0 0 8px var(--zone-border, #fff);
}
.app-cabinet-zone:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.app-cabinet-zone:focus:not(:focus-visible) { outline: none; }

/* Zone label tooltip */
.app-cabinet-zone-label {
    position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.85); color: #fff; font-size: 0.7rem;
    padding: 2px 6px; border-radius: 3px; white-space: nowrap;
    opacity: 0; transition: opacity 0.15s; pointer-events: none;
    margin-bottom: 2px;
}
.app-cabinet-zone:hover .app-cabinet-zone-label,
.app-cabinet-zone.active .app-cabinet-zone-label,
.app-cabinet-zone:focus .app-cabinet-zone-label { opacity: 1; }

/* Info panel */
.app-cabinet-info-panel {
    background: var(--app-card-bg, #fff);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 1rem; max-height: 80vh; overflow-y: auto;
}
.app-cabinet-info-title { margin: 0 0 0.5rem; font-size: 1.1rem; }
.app-cabinet-info-desc { color: var(--app-text-secondary); font-size: 0.9rem; }
.app-cabinet-info-placeholder { color: var(--app-text-muted); font-style: italic; font-size: 0.85rem; }
.app-cabinet-info-muted { color: var(--app-text-muted); font-size: 0.8rem; }
.app-cabinet-info-function { font-weight: 500; margin: 0.5rem 0; }

/* Type badge */
.app-cabinet-type-badge {
    display: inline-block; padding: 2px 8px; border-radius: 12px;
    font-size: 0.75rem; font-weight: 600; border: 1px solid;
    margin-bottom: 0.5rem;
}

/* Detail table */
.app-cabinet-detail-table { margin: 0.75rem 0; }
.app-cabinet-detail-row {
    display: flex; gap: 0.5rem; padding: 4px 0;
    border-bottom: 1px solid var(--app-border);
    font-size: 0.85rem;
}
.app-cabinet-detail-label { color: var(--app-text-secondary); min-width: 90px; flex-shrink: 0; }
.app-cabinet-detail-value { font-weight: 500; word-break: break-word; }

/* Detail image */
.app-cabinet-detail-img-wrap { margin-top: 0.75rem; }
.app-cabinet-detail-img {
    width: 100%; border-radius: var(--app-radius);
    border: 1px solid var(--app-border);
}
.app-cabinet-detail-img-label { font-size: 0.8rem; color: var(--app-text-muted); text-align: center; margin-top: 4px; }

/* Legend */
.app-cabinet-legend {
    display: flex; flex-wrap: wrap; gap: 0.75rem;
    padding: 0.5rem 0; font-size: 0.8rem;
}
.app-cabinet-legend-item { display: flex; align-items: center; gap: 4px; }
.app-cabinet-legend-item::before {
    content: ''; display: inline-block; width: 14px; height: 14px;
    border: 2px dashed; border-radius: 3px;
}
.app-cabinet-legend-item[data-type="vfd"]::before { border-color: #3b82f6; background: rgba(59,130,246,0.15); }
.app-cabinet-legend-item[data-type="plc"]::before { border-color: #10b981; background: rgba(16,185,129,0.15); }
.app-cabinet-legend-item[data-type="safety"]::before { border-color: #ef4444; background: rgba(239,68,68,0.15); }
.app-cabinet-legend-item[data-type="protection"]::before { border-color: #f59e0b; background: rgba(245,158,11,0.15); }
.app-cabinet-legend-item[data-type="contactor"]::before { border-color: #8b5cf6; background: rgba(139,92,246,0.15); }
.app-cabinet-legend-item[data-type="relay"]::before { border-color: #06b6d4; background: rgba(6,182,212,0.15); }
.app-cabinet-legend-item[data-type="power"]::before { border-color: #f97316; background: rgba(249,115,22,0.15); }
.app-cabinet-legend-item[data-type="communication"]::before { border-color: #84cc16; background: rgba(132,204,22,0.15); }

/* Dark mode */
[data-theme="dark"] .app-cabinet-info-panel { background: var(--app-card-bg); border-color: var(--app-border); }
[data-theme="dark"] .app-cabinet-container { border-color: var(--app-border); }

/* Responsive */
@media (max-width: 900px) {
    .app-cabinet-layout { grid-template-columns: 1fr; }
    .app-cabinet-viewer { max-width: 100%; margin: 0 auto; }
    .app-cabinet-info-panel { max-height: none; }
}
@media (max-width: 480px) {
    .app-cabinet-container { border-radius: 0; }
    .app-cabinet-viewer { max-width: 100%; }
}

/* ===== Messaging Section (WhatsApp-style) ===== */

.msg-container {
    display: flex;
    height: calc(100vh - var(--app-topbar-h));
    height: calc(100dvh - var(--app-topbar-h));
    background: var(--bg-primary, #fff);
    overflow: hidden;
}

/* Messaging: cancel parent padding so container fills edge to edge */
#section-messaging.active {
    display: flex;
    flex-direction: column;
    margin: -1.5rem;
    flex: 1;
}

.msg-list-panel {
    width: 340px;
    min-width: 280px;
    border-right: 1px solid var(--border-color, #e0e0e0);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, #f5f5f5);
}

.msg-chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.msg-panel-hidden { display: none !important; }

/* List header */
.msg-list-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.msg-search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 20px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #222);
    font-size: 0.9rem;
    outline: none;
}
.msg-search-input:focus { border-color: var(--accent, #2196F3); }

/* Tabs */
.msg-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}
.msg-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary, #666);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.msg-tab.active {
    color: var(--accent, #2196F3);
    border-bottom-color: var(--accent, #2196F3);
}

/* List content */
.msg-list-content {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
}

.msg-list-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary, #999);
    font-size: 0.9rem;
}

/* List items */
.msg-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-color, #f0f0f0);
}
.msg-list-item:hover { background: var(--bg-hover, rgba(0,0,0,0.04)); }
.msg-list-item.active { background: var(--bg-active, rgba(33,150,243,0.08)); }
.msg-list-item.msg-bot-pinned { background: var(--bg-accent-subtle, rgba(33,150,243,0.04)); }

.msg-list-item-body { flex: 1; min-width: 0; }
.msg-list-item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.msg-list-item-name { font-weight: 500; font-size: 0.9rem; color: var(--text-primary, #222); }
.msg-list-item-time { font-size: 0.75rem; color: var(--text-secondary, #999); white-space: nowrap; }
.msg-list-item-bottom { display: flex; justify-content: space-between; align-items: center; }
.msg-list-item-preview { font-size: 0.8rem; color: var(--text-secondary, #888); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }

/* Close button on chat list items */
.msg-list-item { position: relative; }
.msg-list-item-close {
    flex-shrink: 0;
    width: 28px; height: 28px;
    border: none; background: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: var(--text-secondary, #999);
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.msg-list-item:hover .msg-list-item-close { opacity: 1; }
.msg-list-item-close:hover { color: #e53935; background: rgba(229,57,53,0.1); }
[data-theme="dark"] .msg-list-item-close:hover { background: rgba(229,57,53,0.2); }
@media (max-width: 768px) {
    .msg-list-item-close { opacity: 0.5; }
}

/* Avatar */
.msg-avatar {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: var(--accent, #2196F3);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.msg-avatar-bot {
    background: var(--accent-dark, #1565C0);
}

/* Online dot */
.msg-online-dot {
    display: inline-block;
    width: 8px; height: 8px;
    background: #4CAF50;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
}

/* Unread badge */
.msg-unread-badge {
    background: var(--accent, #2196F3);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* Contact group header */
.msg-contact-group-header {
    padding: 8px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary, #999);
    background: var(--bg-secondary, #f5f5f5);
    letter-spacing: 0.5px;
}

/* Chat panel header */
.msg-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    background: var(--bg-primary, #fff);
}
.msg-back-btn { display: none; }
.msg-chat-header-info { flex: 1; min-width: 0; }
.msg-chat-name { font-weight: 600; font-size: 1rem; display: block; }
.msg-chat-info-text { font-size: 0.8rem; color: var(--text-secondary, #888); }
.msg-chat-header-actions { display: flex; gap: 4px; }

/* Messages area */
.msg-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
}

.msg-empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary, #999);
}

/* Date separator */
.msg-date-sep {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary, #999);
    padding: 8px 0;
}

/* Message bubbles */
.msg-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    position: relative;
}
.msg-bubble-me {
    align-self: flex-end;
    background: var(--accent, #2196F3);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg-bubble-other {
    align-self: flex-start;
    background: var(--bg-secondary, #f0f0f0);
    color: var(--text-primary, #222);
    border-bottom-left-radius: 4px;
}
.msg-bubble-system {
    align-self: center;
    max-width: 80%;
    background: none;
    padding: 4px 0;
}
.msg-system-text {
    font-size: 0.75rem;
    color: var(--text-secondary, #999);
    font-style: italic;
}
.msg-sender-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent, #2196F3);
    margin-bottom: 2px;
}
.msg-text { font-size: 0.9rem; line-height: 1.4; white-space: pre-wrap; }
.msg-time {
    font-size: 0.65rem;
    text-align: right;
    opacity: 0.7;
    margin-top: 2px;
}
/* AI disclaimer on bot messages */
.msg-bot-disclaimer {
    font-size: 0.7rem;
    line-height: 1.3;
    color: #92600a;
    background: #fef9c3;
    border: 1px solid #fde68a;
    border-radius: 4px;
    padding: 3px 6px;
    margin-top: 6px;
}
[data-theme="dark"] .msg-bot-disclaimer {
    color: #fcd34d;
    background: rgba(253, 230, 138, 0.1);
    border-color: rgba(253, 230, 138, 0.25);
}

/* Translation inline */
.msg-translation {
    font-size: 0.85em;
    color: var(--text-muted, #64748b);
    padding-top: 4px;
    border-top: 1px solid rgba(0,0,0,0.08);
    margin-top: 4px;
    font-style: italic;
    white-space: pre-wrap;
}
[data-theme="dark"] .msg-translation {
    color: var(--text-muted, #94a3b8);
    border-top-color: rgba(255,255,255,0.1);
}
/* Translate toggle active state */
.msg-translate-active {
    color: var(--primary, #e30613) !important;
    background: rgba(227, 6, 19, 0.1) !important;
}
/* Bot action links */
.msg-action-link {
    color: var(--primary, #e30613);
    text-decoration: underline;
    cursor: pointer;
    font-weight: 500;
}
.msg-action-link:hover {
    opacity: 0.8;
}
/* Bot typing indicator */
.msg-bot-typing {
    opacity: 0.7;
    font-style: italic;
}
.msg-bot-typing .msg-typing-dots span {
    animation: msg-typing-dot 1.4s infinite both;
    font-size: 1.2em;
    font-weight: bold;
}
.msg-bot-typing .msg-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.msg-bot-typing .msg-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes msg-typing-dot {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}
.msg-media img {
    max-width: 250px;
    max-height: 250px;
    border-radius: 8px;
    cursor: pointer;
}
.msg-media audio { max-width: 220px; }
.msg-file-link {
    color: inherit;
    text-decoration: underline;
}

/* Input area */
.msg-chat-input-area {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color, #e0e0e0);
    background: var(--bg-primary, #fff);
}
.msg-chat-text-input {
    flex: 1;
    padding: 8px 14px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 20px;
    background: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #222);
    font-size: 0.9rem;
    outline: none;
}
.msg-chat-text-input:focus { border-color: var(--accent, #2196F3); }

/* Modal (shared messaging + forum) */
.msg-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.msg-modal {
    background: var(--bg-primary, #fff);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 440px;
    max-height: 80vh;
    overflow-y: auto;
}
.msg-modal h3 { margin: 0 0 16px; }
.msg-modal-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 12px;
    box-sizing: border-box;
    background: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #222);
}
.msg-modal-member-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 16px;
}
.msg-modal-member-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    cursor: pointer;
}
.msg-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Mobile */
@media (max-width: 767px) {
    #section-messaging.active { margin: -1rem; }
    .msg-container { flex-direction: column; height: calc(100vh - var(--app-topbar-h)); height: calc(100dvh - var(--app-topbar-h)); }
    .msg-list-panel { width: 100%; min-width: 0; border-right: none; }
    .msg-chat-panel { width: 100%; flex: 1; overflow: hidden; }
    .msg-back-btn { display: flex !important; }
    .msg-chat-messages { flex: 1; }
    .msg-chat-input-area { padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0.5rem)); }
}

/* Dark mode adjustments */
[data-theme="dark"] .msg-bubble-other { background: var(--bg-tertiary, #333); }
[data-theme="dark"] .msg-modal { background: var(--bg-secondary, #1e1e1e); }
[data-theme="dark"] .msg-search-input,
[data-theme="dark"] .msg-chat-text-input,
[data-theme="dark"] .msg-modal-input { background: var(--bg-tertiary, #2a2a2a); border-color: var(--border-color, #444); }

/* === Team Management === */
#team-content { padding: 1rem; max-width: 600px; }
.team-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.team-counter { font-size: 0.9rem; color: var(--app-text-muted, #666); }
.team-not-primary { padding: 2rem; text-align: center; color: var(--app-text-muted, #666); }
.team-empty { padding: 2rem; text-align: center; color: var(--app-text-muted, #666); }
.team-list { display: flex; flex-direction: column; gap: 0.75rem; }
.team-card { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; border: 1px solid var(--border-color, #e0e0e0); border-radius: 8px; background: var(--bg-secondary, #fff); }
.team-card-name { font-weight: 600; }
.team-card-username { font-size: 0.85rem; color: var(--app-text-muted, #666); font-family: monospace; }
.team-card-login { font-size: 0.8rem; color: var(--app-text-muted, #999); margin-top: 2px; }
.team-card-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.team-btn-delete { color: var(--danger, #e53935) !important; border-color: var(--danger, #e53935) !important; }
.team-form { display: flex; flex-direction: column; gap: 0.5rem; }
.team-form label { font-weight: 500; font-size: 0.9rem; margin-top: 0.25rem; }
.team-pw-row { display: flex; gap: 0.5rem; }
.team-pw-row .app-input { flex: 1; }
.team-error { color: var(--danger, #e53935); font-size: 0.85rem; padding: 0.25rem 0; }
.team-creds { text-align: center; }
.team-creds-box { background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 8px; padding: 1rem; margin: 0.75rem 0; font-family: monospace; text-align: left; }
.team-creds-label { color: var(--app-text-muted, #666); }
[data-theme="dark"] .team-card { background: var(--bg-secondary, #1e1e1e); border-color: var(--border-color, #333); }
[data-theme="dark"] .team-creds-box { background: #1a2a3a; border-color: #2a4a6a; }
@media (max-width: 600px) {
    .team-card { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .team-card-actions { width: 100%; }
}

/* ==========================================================================
   RTL (Right-to-Left) SUPPORT — Arabic, Hebrew
   Applied via [dir="rtl"] on <html>. Set automatically by i18n.js.
   ========================================================================== */

/* --- Sidebar: move to right side --- */
[dir="rtl"] .app-sidebar { left: auto; right: 0; }
[dir="rtl"] .app-main { margin-left: 0; margin-right: var(--app-sidebar-w); }

/* --- Nav items: border indicator on right --- */
[dir="rtl"] .app-nav-item { border-left: none; border-right: 3px solid transparent; }
[dir="rtl"] .app-nav-item.active { border-right-color: var(--app-saez-red); border-left-color: transparent; }
[dir="rtl"] .app-nav-badge { margin-left: 0; margin-right: auto; }

/* --- Sidebar logout --- */
[dir="rtl"] .app-sidebar-logout { text-align: right; }

/* --- Theme toggle knob --- */
[dir="rtl"] .app-theme-toggle::after { left: auto; right: 2px; }
[dir="rtl"][data-theme="dark"] .app-theme-toggle::after { transform: translateX(-16px); }

/* --- Input icons --- */
[dir="rtl"] .app-input-icon-wrap .app-input-icon { left: auto; right: 10px; }
[dir="rtl"] .app-input-icon-wrap input { padding-left: 1rem !important; padding-right: 2.5rem !important; }

/* --- Topbar: hamburger space on right --- */
[dir="rtl"] .app-hamburger { left: auto; right: 12px; }

/* --- KPI cards: border accent on right --- */
[dir="rtl"] .app-kpi-card { border-left: none; border-right: 4px solid var(--app-blue); }
[dir="rtl"] .app-kpi-card.green { border-right-color: var(--app-green); border-left-color: transparent; }
[dir="rtl"] .app-kpi-card.orange { border-right-color: var(--app-orange); border-left-color: transparent; }
[dir="rtl"] .app-kpi-card.teal { border-right-color: var(--app-teal); border-left-color: transparent; }
[dir="rtl"] .app-kpi-card.red { border-right-color: var(--app-red); border-left-color: transparent; }
[dir="rtl"] .app-kpi-card.purple { border-right-color: var(--app-purple); border-left-color: transparent; }

/* --- Tables --- */
[dir="rtl"] .app-table th { text-align: right; }
[dir="rtl"] .app-table td { text-align: right; }

/* --- Chat messages (main chat) --- */
[dir="rtl"] .app-msg.bot { border-left: none; border-right: 3px solid var(--app-saez-red); border-bottom-left-radius: var(--app-radius-msg); border-bottom-right-radius: 4px; }
[dir="rtl"] .app-msg.user { border-bottom-right-radius: var(--app-radius-msg); border-bottom-left-radius: 4px; }
[dir="rtl"] .app-msg-row.user { flex-direction: row; }
[dir="rtl"] .app-msg-time { text-align: left; }
[dir="rtl"] .app-msg-bridge-translation { border-left: none; border-right: 3px solid var(--app-orange); }

/* --- Chat messages (portal duplicate system) --- */
[dir="rtl"] .msg-bot { border-left: none; border-right: 3px solid var(--app-saez-red); border-bottom-left-radius: var(--app-radius-msg, 12px); border-bottom-right-radius: 4px; }
[dir="rtl"] .msg-user { border-bottom-right-radius: var(--app-radius-msg, 12px); border-bottom-left-radius: 4px; }
[dir="rtl"] .msg-row-user { flex-direction: row; }
[dir="rtl"] .msg-time { text-align: left; }
[dir="rtl"] .msg-bridge-translation { border-left: none !important; border-right: 3px solid var(--app-orange) !important; }

/* --- Chat panel (side panel messaging) --- */

/* --- News cards --- */
[dir="rtl"] .app-news-card-noimg { border-left: none; border-right: 3px solid var(--app-saez-red); }
[dir="rtl"] .app-news-ai-summary { border-left: none; border-right: 3px solid var(--app-blue-light); }

/* --- Diagnostico --- */
[dir="rtl"] .app-diag-plc-note { border-left: none; border-right: 4px solid var(--app-primary, #2563eb); padding-left: 0; padding-right: 0.75rem; }

/* --- Calendar events --- */
[dir="rtl"] .app-calendar-event { border-left: none; border-right: 3px solid var(--primary, #2563eb); }

/* --- Monitoring cards --- */
[dir="rtl"] .app-mon-card { border-left: none; border-right: 4px solid var(--app-text-light); }
[dir="rtl"] .app-mon-card.app-mon-online { border-right-color: var(--app-green); border-left-color: transparent; }
[dir="rtl"] .app-mon-card.app-mon-offline { border-right-color: var(--app-red); border-left-color: transparent; }
[dir="rtl"] .app-mon-card.app-mon-no-router { border-right-color: var(--app-text-light); border-left-color: transparent; }

/* --- Telemetry --- */
[dir="rtl"] .app-tel-value { text-align: left; padding-left: 0; padding-right: 0.5rem; }
[dir="rtl"] .app-tel-live-waiting { border-left: none; border-right: 4px solid #28a745; }
[dir="rtl"] .app-tel-kpi { border-left: none; border-right: 4px solid var(--app-border); }

/* --- HMI Virtual --- */
[dir="rtl"] .app-hmi-toolbar-right { margin-left: 0; margin-right: auto; }
[dir="rtl"] .app-hmi-info-details { border-left: none; border-right: 3px solid var(--app-border); padding-left: 0; padding-right: 0.75rem; }

/* --- Forum --- */
[dir="rtl"] .msg-list-panel { border-right: none; border-left: 1px solid var(--border-color, #e0e0e0); }

/* --- Manuales file list --- */
[dir="rtl"] .app-man-file-name { margin-right: 0; margin-left: 1rem; }
[dir="rtl"] .app-man-file-size { margin-right: 0; margin-left: 1rem; }

/* --- Misc margin-left:auto → margin-right:auto --- */
[dir="rtl"] .annotation-right-group { margin-left: 0; margin-right: auto; }
[dir="rtl"] .app-design-btn-reset { margin-left: 0; margin-right: auto; }

/* --- Participants list dot --- */
[dir="rtl"] .app-participants-overlay li::before { margin-right: 0; margin-left: 6px; }

/* --- Team credentials box --- */
[dir="rtl"] .team-creds-box { text-align: right; }

/* --- Sidebar footer text alignment + overflow containment --- */
[dir="rtl"] .app-sidebar-footer { text-align: right; overflow: hidden; }
[dir="rtl"] .app-sidebar-theme { max-width: 100%; overflow: hidden; }
[dir="rtl"] .app-sidebar-client { padding-left: 0; padding-right: 1rem; }
[dir="rtl"] .app-sidebar-status { direction: rtl; }
[dir="rtl"] .app-sidebar-status-text { padding-left: 0; padding-right: 1rem; }

/* --- News card text alignment --- */
[dir="rtl"] .app-news-card-body { text-align: right; }
[dir="rtl"] .app-news-card-meta { direction: rtl; }
[dir="rtl"] .app-news-card-actions { justify-content: flex-end; }

/* --- RTL Mobile (<=768px) --- */
@media (max-width: 768px) {
    [dir="rtl"] .app-sidebar { transform: translateX(100%); }
    [dir="rtl"] .app-sidebar.open { transform: translateX(0); }
    [dir="rtl"] .app-main { margin-right: 0; }
    [dir="rtl"] .app-topbar { padding-left: 0; padding-right: 3.5rem; }
}

/* ==========================================================================
   PRODUCTION MODULE
   ========================================================================== */
.prod-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.prod-header h2 { margin: 0; font-size: 1.5rem; color: var(--app-text); }
.prod-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.prod-btn { padding: 0.5rem 1rem; border: none; border-radius: 6px; cursor: pointer; font-size: 0.875rem; font-weight: 500; transition: background 0.2s; }
.prod-btn-primary { background: var(--app-saez-red); color: #fff; }
.prod-btn-primary:hover { background: var(--app-saez-red-dark); }
.prod-btn-secondary { background: var(--app-card-bg); color: var(--app-text); border: 1px solid var(--app-border); }
.prod-btn-secondary:hover { background: var(--app-card-bg-alt); }
.prod-btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.prod-last-sync { font-size: 0.78rem; color: var(--app-text-muted); white-space: nowrap; }

.prod-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.5rem; margin-bottom: 0.75rem; }
.prod-stat-card { background: var(--app-card-bg); border: 1px solid var(--app-border); border-radius: 6px; padding: 0.5rem 0.75rem; text-align: center; }
.prod-stat-card .stat-value, .prod-stat-card .prod-stat-num { font-size: 1.3rem; font-weight: 700; color: var(--app-text); display: block; }
.prod-stat-card .stat-label, .prod-stat-card .prod-stat-label { font-size: 0.75rem; color: var(--app-text-muted); margin-top: 0.1rem; display: block; }

/* .prod-filters removed — replaced by .prod-toolbar */

.prod-grid { max-width: 100%; overflow: hidden; }
.prod-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--app-card-bg); border-radius: 8px; border: 1px solid var(--app-border); }
.prod-table th { background: var(--app-card-bg-alt); padding: 0.6rem 0.75rem; text-align: left; font-size: 0.8rem; font-weight: 600; color: var(--app-text-muted); text-transform: uppercase; letter-spacing: 0.3px; border-bottom: 1px solid var(--app-border); white-space: nowrap; }
.prod-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--app-border-light); font-size: 0.875rem; color: var(--app-text); }
.prod-table tr:hover td { background: var(--app-card-bg-subtle); }
.prod-table tr { cursor: pointer; }

/* Top horizontal scrollbar (synced with table) */
.prod-scroll-top { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.prod-scroll-top-inner { height: 1px; }

/* Airtable-style CARGAS grid */
.prod-table-wrap { overflow-x: auto; max-width: 100%; }
.prod-table-cargas { table-layout: fixed; min-width: 100%; }
.prod-table-cargas td { padding: 0.4rem 0.6rem; font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-table-cargas td.prod-cell-check,
.prod-table-cargas td.prod-cell-progress,
.prod-table-cargas td.prod-cell-actions { text-overflow: clip; overflow: visible; }
.prod-table-cargas th { padding: 0.45rem 0.6rem; position: relative; }
.prod-th-sort { cursor: pointer; user-select: none; transition: background 0.15s; }
.prod-th-sort:hover { background: var(--app-card-bg); }
.prod-th-active { color: var(--app-text); }
.prod-sort-icon { font-size: 0.65rem; margin-left: 2px; }
.prod-cell-name { font-weight: 600; }
.prod-cell-extras { color: var(--app-text-muted); }

/* Attachment icon in grid */
.prod-att-icon { margin-left: 6px; font-size: 0.85em; opacity: 0.7; cursor: default; }

/* Attachments section in detail */
.prod-attachments-section { margin-bottom: 1rem; }
.prod-att-list { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0; }
.prod-att-item { display: flex; align-items: center; gap: 0.4rem; background: var(--app-card-bg); border: 1px solid var(--app-border); border-radius: 6px; padding: 0.4rem 0.75rem; }
.prod-att-pdf-icon { font-size: 1.1rem; }
.prod-att-link { color: var(--app-teal); text-decoration: none; font-weight: 500; font-size: 0.9rem; word-break: break-all; }
.prod-att-link:hover { text-decoration: underline; }
.prod-att-size { color: var(--app-text-muted); font-size: 0.8rem; white-space: nowrap; }

/* Delete order button */
.prod-btn-delete-order { background: none; border: none; color: var(--app-text-muted); font-size: 1.2rem; cursor: pointer; padding: 2px 6px; border-radius: 4px; line-height: 1; }
.prod-btn-delete-order:hover { color: #e74c3c; background: rgba(231,76,60,0.1); }

/* Column resize handles */
.prod-col-resize { position: absolute; top: 0; right: -2px; width: 5px; height: 100%; cursor: col-resize; z-index: 2; }
.prod-col-resize:hover, .prod-col-resize.active { background: var(--app-teal); opacity: 0.5; }
.prod-table-cargas.resizing { cursor: col-resize; user-select: none; }
.prod-table-cargas.resizing td, .prod-table-cargas.resizing th { pointer-events: none; }
.prod-table-cargas.resizing .prod-col-resize { pointer-events: auto; }

/* Frozen (sticky) columns */
.prod-table-cargas th.prod-col-frozen,
.prod-table-cargas td.prod-col-frozen { position: sticky; z-index: 2; background: var(--app-card-bg); }
.prod-table-cargas th.prod-col-frozen { z-index: 5; background: var(--app-card-bg-alt); }
.prod-col-frozen-last { border-right: 2px solid var(--app-teal) !important; }
.prod-table-cargas tr:hover td.prod-col-frozen { background: var(--app-card-bg-subtle); }
[dir="rtl"] .prod-col-frozen-last { border-right: none !important; border-left: 2px solid var(--app-teal) !important; }

/* Pin button in headers */
.prod-pin-btn { opacity: 0; position: absolute; top: 50%; right: 16px; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 0.7rem; padding: 2px 4px; border-radius: 3px; color: var(--app-text-muted); transition: opacity 0.15s; line-height: 1; }
th:hover .prod-pin-btn, .prod-pin-btn:focus { opacity: 1; }
.prod-pin-btn.prod-pin-active { opacity: 0.7; color: var(--app-teal); }
[dir="rtl"] .prod-pin-btn { right: auto; left: 16px; }

/* Weeks countdown badges */
.prod-weeks-badge { display: inline-block; padding: 0.15rem 0.45rem; border-radius: 4px; font-size: 0.78rem; font-weight: 600; min-width: 24px; text-align: center; }
.prod-weeks-green { background: #d1fae5; color: #065f46; }
.prod-weeks-yellow { background: #fef3c7; color: #92400e; }
.prod-weeks-orange { background: #ffedd5; color: #9a3412; }
.prod-weeks-red { background: #fee2e2; color: #991b1b; }

/* Country badge */
.prod-country-badge { display: inline-block; padding: 0.12rem 0.5rem; border-radius: 10px; font-size: 0.75rem; font-weight: 500; white-space: nowrap; }

/* Grid footer */
.prod-grid-footer { padding: 0.5rem 0.75rem; font-size: 0.8rem; color: var(--app-text-muted); text-align: right; }

/* Search filter wider */
.prod-filter-search { min-width: 180px; }

.prod-progress { width: 80px; height: 6px; background: var(--app-border); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; }
.prod-progress-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.prod-progress-fill.low { background: var(--app-red); }
.prod-progress-fill.mid { background: var(--app-orange); }
.prod-progress-fill.high { background: var(--app-green); }

.prod-badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 10px; font-size: 0.75rem; font-weight: 500; }
.prod-badge-pending { background: #fef3c7; color: #92400e; }
.prod-badge-in_progress { background: #dbeafe; color: #1e40af; }
.prod-badge-material_complete { background: #d1fae5; color: #065f46; }
.prod-badge-shipped { background: #e0e7ff; color: #3730a3; }
.prod-badge-ordered { background: #fef3c7; color: #92400e; }
.prod-badge-received { background: #d1fae5; color: #065f46; }

.prod-detail-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.prod-detail-header h2 { margin: 0; }
.prod-info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.prod-info-card { background: var(--app-card-bg); border: 1px solid var(--app-border); border-radius: 8px; padding: 1rem; }
.prod-info-card .info-label, .prod-info-label { font-size: 0.75rem; color: var(--app-text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.prod-info-card .info-value, .prod-info-value { font-size: 1rem; font-weight: 600; color: var(--app-text); margin-top: 0.25rem; }
.prod-info-field { display: flex; flex-direction: column; gap: 0.15rem; }

.prod-orders-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.prod-orders-header h3 { margin: 0; }

.prod-modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.prod-modal { background: var(--app-card-bg); border-radius: 12px; padding: 1.5rem; max-width: 600px; width: 90%; max-height: 80vh; overflow-y: auto; }
.prod-modal h3 { margin: 0 0 1rem; }
.prod-modal-form label { display: block; font-size: 0.85rem; font-weight: 500; margin: 0.75rem 0 0.25rem; color: var(--app-text); }
.prod-modal-form input, .prod-modal-form select { width: 100%; padding: 0.5rem; border: 1px solid var(--app-border); border-radius: 6px; font-size: 0.875rem; background: var(--app-card-bg); color: var(--app-text); box-sizing: border-box; }
.prod-modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

.prod-sync-list { max-height: 50vh; overflow-y: auto; }
.prod-sync-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem; border-bottom: 1px solid var(--app-border-light); }
.prod-sync-item label { flex: 1; font-size: 0.875rem; cursor: pointer; }

.prod-stock-info { font-size: 0.8rem; color: var(--app-teal); font-weight: 500; }
.prod-empty { text-align: center; padding: 3rem 1rem; color: var(--app-text-muted); }

@media (max-width: 768px) {
    .prod-header { flex-direction: column; align-items: flex-start; }
    .prod-stats { grid-template-columns: repeat(2, 1fr); }
    .prod-info-grid { grid-template-columns: 1fr; }
    .prod-table { font-size: 0.8rem; }
    .prod-table th, .prod-table td { padding: 0.4rem 0.5rem; }
}

[data-theme="dark"] .prod-badge-pending { background: #451a03; color: #fbbf24; }
[data-theme="dark"] .prod-badge-in_progress { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .prod-badge-material_complete { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .prod-badge-shipped { background: #312e81; color: #a5b4fc; }
[data-theme="dark"] .prod-badge-ordered { background: #451a03; color: #fbbf24; }
[data-theme="dark"] .prod-badge-received { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .prod-weeks-green { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .prod-weeks-yellow { background: #451a03; color: #fbbf24; }
[data-theme="dark"] .prod-weeks-orange { background: #7c2d12; color: #fdba74; }
[data-theme="dark"] .prod-weeks-red { background: #5c1616; color: #fca5a5; }

/* ── Toolbar (Airtable-style) ── */
.prod-toolbar { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; align-items: center; }
.prod-toolbar-item { position: relative; }
.prod-toolbar-btn { padding: 0.35rem 0.75rem; border: 1px solid var(--app-border); border-radius: 6px; background: var(--app-card-bg); color: var(--app-text); font-size: 0.82rem; cursor: pointer; display: flex; align-items: center; gap: 0.35rem; transition: border-color 0.15s, color 0.15s; }
.prod-toolbar-btn:hover { background: var(--app-card-bg-alt); }
.prod-toolbar-btn.active { border-color: var(--app-teal); color: var(--app-teal); }
.prod-toolbar-btn svg { flex-shrink: 0; }
.prod-toolbar-badge { background: var(--app-teal); color: #fff; font-size: 0.7rem; font-weight: 700; padding: 0.05rem 0.4rem; border-radius: 10px; margin-left: 0.15rem; }
.prod-toolbar-search-wrap { margin-left: auto; }
.prod-toolbar-search-input { padding: 0.35rem 0.6rem; border: 1px solid var(--app-border); border-radius: 6px; background: var(--app-card-bg); color: var(--app-text); font-size: 0.82rem; min-width: 180px; }

/* ── Dropdown panels ── */
.prod-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 50; background: var(--app-card-bg); border: 1px solid var(--app-border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); min-width: 380px; max-height: 70vh; overflow-y: auto; }
.prod-panel-header { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--app-border); font-weight: 600; font-size: 0.85rem; color: var(--app-text); }
.prod-panel-body { padding: 0.5rem 0.75rem; }
.prod-panel-footer { padding: 0.5rem 0.75rem; border-top: 1px solid var(--app-border); display: flex; gap: 0.5rem; align-items: center; }
.prod-panel-link { background: none; border: none; color: var(--app-teal); font-size: 0.82rem; cursor: pointer; padding: 0.25rem 0; font-weight: 500; }
.prod-panel-link:hover { text-decoration: underline; }
.prod-panel-btn-cancel { background: none; border: 1px solid var(--app-border); border-radius: 6px; padding: 0.3rem 0.7rem; font-size: 0.82rem; color: var(--app-text); cursor: pointer; }
.prod-panel-btn-apply { background: var(--app-teal); border: none; border-radius: 6px; padding: 0.3rem 0.7rem; font-size: 0.82rem; color: #fff; cursor: pointer; font-weight: 500; }
.prod-panel-btn-apply:hover { opacity: 0.9; }

/* ── Filter rows ── */
.prod-filter-row { display: flex; gap: 0.4rem; align-items: center; padding: 0.3rem 0; flex-wrap: wrap; }
.prod-filter-prefix { font-size: 0.8rem; color: var(--app-text-muted); min-width: 42px; text-align: right; flex-shrink: 0; }
.prod-filter-row select, .prod-filter-row input { padding: 0.3rem 0.45rem; border: 1px solid var(--app-border); border-radius: 4px; background: var(--app-card-bg); color: var(--app-text); font-size: 0.82rem; }
.prod-filter-field { width: 120px; }
.prod-filter-op { width: 120px; }
.prod-filter-val { flex: 1; min-width: 80px; }
.prod-filter-remove { background: none; border: none; color: var(--app-text-muted); cursor: pointer; font-size: 0.9rem; padding: 0.2rem 0.35rem; border-radius: 4px; }
.prod-filter-remove:hover { background: var(--app-card-bg-alt); color: var(--app-red); }

/* ── Fields panel ── */
.prod-field-toggle { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.5rem; cursor: pointer; border-radius: 4px; font-size: 0.85rem; }
.prod-field-toggle:hover { background: var(--app-card-bg-alt); }
.prod-field-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.prod-field-dot.visible { background: var(--app-green, #10b981); }
.prod-field-dot.hidden { background: var(--app-text-muted); }

/* ── Sort rows ── */
.prod-sort-row { display: flex; gap: 0.5rem; align-items: center; padding: 0.3rem 0; }
.prod-sort-row select { padding: 0.3rem 0.45rem; border: 1px solid var(--app-border); border-radius: 4px; background: var(--app-card-bg); color: var(--app-text); font-size: 0.82rem; flex: 1; }
.prod-sort-remove { background: none; border: none; color: var(--app-text-muted); cursor: pointer; font-size: 0.9rem; padding: 0.2rem 0.35rem; border-radius: 4px; }
.prod-sort-remove:hover { background: var(--app-card-bg-alt); color: var(--app-red); }

/* ── Dark mode for panels ── */
[data-theme="dark"] .prod-panel { box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
[data-theme="dark"] .prod-toolbar-badge { background: var(--app-teal); }

/* ── Mobile: toolbar + panels ── */
@media (max-width: 768px) {
    .prod-toolbar-search-wrap { margin-left: 0; width: 100%; }
    .prod-toolbar-search-input { width: 100%; min-width: unset; }
    .prod-panel { min-width: unset; left: 0; right: 0; width: calc(100vw - 2rem); }
    .prod-filter-row { flex-wrap: wrap; }
    .prod-filter-field, .prod-filter-op { width: calc(50% - 1.5rem); }
    .prod-filter-val { width: 100%; }
}

/* ── RTL ── */
[dir="rtl"] .prod-header { flex-direction: row-reverse; }
[dir="rtl"] .prod-table th { text-align: right; }
[dir="rtl"] .prod-detail-header { flex-direction: row-reverse; }
[dir="rtl"] .prod-modal-actions { flex-direction: row-reverse; }
[dir="rtl"] .prod-toolbar { flex-direction: row-reverse; }
[dir="rtl"] .prod-toolbar-search-wrap { margin-left: 0; margin-right: auto; }
[dir="rtl"] .prod-panel { left: auto; right: 0; }
[dir="rtl"] .prod-filter-prefix { text-align: left; }
[dir="rtl"] .prod-panel-footer { flex-direction: row-reverse; }

/* ── Stock Analysis (FASE 1) ── */
.prod-stock-analysis { margin: 1rem 0; }
.prod-stock-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }
.prod-stock-header .prod-subtitle { margin: 0; }
.prod-stock-summary { display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.prod-stock-sum-card { display: flex; flex-direction: column; align-items: center; padding: 0.5rem 1rem; border-radius: 8px; border: 1px solid var(--app-border); min-width: 70px; }
.prod-stock-sum-num { font-size: 1.3rem; font-weight: 700; }
.prod-stock-sum-lbl { font-size: 0.75rem; color: var(--app-text-muted); }
.prod-stock-ok { border-color: #16a34a; }
.prod-stock-ok .prod-stock-sum-num { color: #16a34a; }
.prod-stock-low { border-color: #d97706; }
.prod-stock-low .prod-stock-sum-num { color: #d97706; }
.prod-stock-miss { border-color: #dc2626; }
.prod-stock-miss .prod-stock-sum-num { color: #dc2626; }
.prod-stock-svc { border-color: #6b7280; }
.prod-stock-svc .prod-stock-sum-num { color: #6b7280; }
.prod-stock-no-bom { padding: 1rem; color: var(--app-text-muted); font-style: italic; }
.prod-stock-table { margin-top: 0.5rem; }
.prod-stock-row-ok { }
.prod-stock-row-low td { background: rgba(217, 119, 6, 0.06); }
.prod-stock-row-miss td { background: rgba(220, 38, 38, 0.06); }
.prod-stock-row-svc td { opacity: 0.6; }
.prod-stock-status-ok { background: #d1fae5; color: #065f46; }
.prod-stock-status-low { background: #fef3c7; color: #92400e; }
.prod-stock-status-missing { background: #fee2e2; color: #991b1b; }
.prod-stock-status-service { background: #f3f4f6; color: #6b7280; }
[data-theme="dark"] .prod-stock-status-ok { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .prod-stock-status-low { background: #451a03; color: #fbbf24; }
[data-theme="dark"] .prod-stock-status-missing { background: #5c1616; color: #fca5a5; }
[data-theme="dark"] .prod-stock-status-service { background: #374151; color: #9ca3af; }
[data-theme="dark"] .prod-stock-row-low td { background: rgba(217, 119, 6, 0.12); }
[data-theme="dark"] .prod-stock-row-miss td { background: rgba(220, 38, 38, 0.12); }
[data-theme="dark"] .prod-stock-ok { border-color: #22c55e; }
[data-theme="dark"] .prod-stock-ok .prod-stock-sum-num { color: #22c55e; }
[data-theme="dark"] .prod-stock-low { border-color: #f59e0b; }
[data-theme="dark"] .prod-stock-low .prod-stock-sum-num { color: #f59e0b; }
[data-theme="dark"] .prod-stock-miss { border-color: #ef4444; }
[data-theme="dark"] .prod-stock-miss .prod-stock-sum-num { color: #ef4444; }

/* ── Availability Queue (FASE 2) ── */
.prod-avail-snapshot-info { margin-bottom: 0.75rem; font-size: 0.85rem; color: var(--app-text-muted); }
.prod-avail-no-snapshot { color: #d97706; font-weight: 500; }
.prod-avail-summary { display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.prod-avail-badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 10px; font-size: 0.78rem; font-weight: 600; }
.prod-avail-ready { background: #d1fae5; color: #065f46; }
.prod-avail-partial { background: #fef3c7; color: #92400e; }
.prod-avail-blocked { background: #fee2e2; color: #991b1b; }
.prod-avail-no_bom { background: #f3f4f6; color: #6b7280; }
.prod-avail-ready-card { border-left: 3px solid #16a34a; }
.prod-avail-partial-card { border-left: 3px solid #d97706; }
.prod-avail-blocked-card { border-left: 3px solid #dc2626; }
.prod-avail-ready-row td:first-child { border-left: 3px solid #16a34a; }
.prod-avail-partial-row td:first-child { border-left: 3px solid #d97706; }
.prod-avail-blocked-row td:first-child { border-left: 3px solid #dc2626; }
.prod-avail-no_bom-row td:first-child { border-left: 3px solid #9ca3af; }
.prod-avail-name { font-weight: 500; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-avail-missing-cell { font-size: 0.78rem; color: var(--app-text-muted); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-avail-table { cursor: default; }
.prod-avail-row { cursor: pointer; }
.prod-avail-row:hover td { background: var(--app-card-bg-subtle); }
[data-theme="dark"] .prod-avail-ready { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .prod-avail-partial { background: #451a03; color: #fbbf24; }
[data-theme="dark"] .prod-avail-blocked { background: #5c1616; color: #fca5a5; }
[data-theme="dark"] .prod-avail-no_bom { background: #374151; color: #9ca3af; }
[data-theme="dark"] .prod-avail-ready-card { border-left-color: #22c55e; }
[data-theme="dark"] .prod-avail-partial-card { border-left-color: #f59e0b; }
[data-theme="dark"] .prod-avail-blocked-card { border-left-color: #ef4444; }
[data-theme="dark"] .prod-avail-ready-row td:first-child { border-left-color: #22c55e; }
[data-theme="dark"] .prod-avail-partial-row td:first-child { border-left-color: #f59e0b; }
[data-theme="dark"] .prod-avail-blocked-row td:first-child { border-left-color: #ef4444; }
[dir="rtl"] .prod-avail-ready-card, [dir="rtl"] .prod-avail-partial-card, [dir="rtl"] .prod-avail-blocked-card { border-left: none; border-right-width: 3px; border-right-style: solid; }
[dir="rtl"] .prod-avail-ready-row td:first-child, [dir="rtl"] .prod-avail-partial-row td:first-child, [dir="rtl"] .prod-avail-blocked-row td:first-child, [dir="rtl"] .prod-avail-no_bom-row td:first-child { border-left: none; border-right-width: 3px; border-right-style: solid; }

/* ── Production: Checkbox & Bulk ─────────────────────────────────────── */
.prod-th-check { width: 30px; text-align: center; padding: 4px; }
.prod-cell-check { text-align: center; padding: 4px; cursor: default; }
.prod-row-check, .prod-select-all { cursor: pointer; width: 16px; height: 16px; }
.prod-row-selected { background: rgba(14, 165, 233, 0.08); }
[data-theme="dark"] .prod-row-selected { background: rgba(14, 165, 233, 0.15); }

.prod-bulk-bar {
    position: sticky; bottom: 0; left: 0; right: 0; z-index: 20;
    display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    background: var(--app-card-bg, #fff); border-top: 2px solid var(--app-primary, #0ea5e9);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1); border-radius: 8px 8px 0 0;
}
.prod-bulk-count { font-weight: 600; white-space: nowrap; }
.prod-bulk-status-sel { padding: 4px 8px; border-radius: 4px; border: 1px solid var(--app-border); font-size: 0.85rem; }

/* ── Production: Progress Bar ────────────────────────────────────────── */
.prod-cell-progress { text-align: center; padding: 4px; }
.prod-progress-mini { height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; min-width: 40px; }
[data-theme="dark"] .prod-progress-mini { background: #374151; }
.prod-progress-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.prod-progress-green { background: #16a34a; }
.prod-progress-yellow { background: #d97706; }
.prod-progress-red { background: #dc2626; }
.prod-progress-text { font-size: 0.72rem; color: var(--app-text-muted); }
.prod-cell-progress.prod-progress-na { opacity: 0.4; }
.prod-cell-progress.prod-progress-na .prod-progress-text { color: var(--app-text-muted); font-size: 0.9rem; }
.prod-cell-progress.prod-progress-urgent { background: rgba(220, 38, 38, 0.18); animation: prod-urgent-pulse 2.5s infinite; }
.prod-cell-progress.prod-progress-urgent .prod-progress-text { color: #dc2626; font-weight: 700; }
[data-theme="dark"] .prod-cell-progress.prod-progress-urgent { background: rgba(220, 38, 38, 0.25); }
[data-theme="dark"] .prod-cell-progress.prod-progress-urgent .prod-progress-text { color: #fca5a5; }
@keyframes prod-urgent-pulse { 0%, 100% { background: rgba(220, 38, 38, 0.18); } 50% { background: rgba(220, 38, 38, 0.32); } }

/* ── Production: Quick Actions ───────────────────────────────────────── */
.prod-cell-actions { padding: 2px 4px; }
.prod-quick-status {
    width: 100%; padding: 2px 4px; font-size: 0.78rem;
    border: 1px solid var(--app-border); border-radius: 4px;
    background: var(--app-card-bg); color: var(--app-text);
    cursor: pointer;
}

/* ── Production: Inline Editing ──────────────────────────────────────── */
.prod-inline-input, .prod-inline-select {
    width: 100%; padding: 2px 6px; font-size: 0.85rem;
    border: 2px solid var(--app-primary, #0ea5e9); border-radius: 4px;
    background: var(--app-card-bg); color: var(--app-text);
    outline: none;
}

/* ── Production: View Toggle (in toolbar, right-aligned) ────────────── */
.prod-view-toggle { display: flex; gap: 0; border: 1px solid var(--app-border); border-radius: 6px; overflow: hidden; margin-left: auto; flex-shrink: 0; }
.prod-view-btn {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 28px; border: none; cursor: pointer;
    background: var(--app-card-bg); color: var(--app-text-muted);
    transition: background 0.15s, color 0.15s;
}
.prod-view-btn:hover { color: var(--app-text); }
.prod-view-btn.active { background: var(--app-primary, #0ea5e9); color: #fff; }
.prod-view-btn svg { pointer-events: none; }

/* ── Production: Kanban ──────────────────────────────────────────────── */
.prod-kanban {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
    min-height: 400px; padding: 8px 0;
}
@media (max-width: 900px) { .prod-kanban { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .prod-kanban { grid-template-columns: 1fr; } }

.prod-kanban-lane {
    background: var(--app-bg-subtle, #f9fafb); border-radius: 8px;
    display: flex; flex-direction: column; min-height: 200px;
}
[data-theme="dark"] .prod-kanban-lane { background: #1e293b; }

.prod-kanban-header {
    padding: 8px 12px; font-weight: 600; font-size: 0.88rem;
    border-radius: 8px 8px 0 0; text-align: center;
}
.prod-kanban-header-pending { background: #e5e7eb; color: #374151; }
.prod-kanban-header-in_progress { background: #dbeafe; color: #1e40af; }
.prod-kanban-header-material_complete { background: #d1fae5; color: #065f46; }
.prod-kanban-header-shipped { background: #f3f4f6; color: #6b7280; }
[data-theme="dark"] .prod-kanban-header-pending { background: #374151; color: #d1d5db; }
[data-theme="dark"] .prod-kanban-header-in_progress { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .prod-kanban-header-material_complete { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .prod-kanban-header-shipped { background: #1f2937; color: #9ca3af; }

.prod-kanban-body { flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 70vh; }

.prod-kanban-card {
    background: var(--app-card-bg, #fff); border-radius: 6px; padding: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1); cursor: pointer;
    border-left: 3px solid transparent; transition: box-shadow 0.15s;
}
.prod-kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.prod-kanban-overdue { border-left-color: #dc2626; }
.prod-kanban-dragging { opacity: 0.5; }
.prod-kanban-dragover { background: rgba(14, 165, 233, 0.08); }

.prod-kanban-title { font-weight: 600; font-size: 0.88rem; margin-bottom: 4px; }
.prod-kanban-sub { font-size: 0.78rem; color: var(--app-text-muted); margin-bottom: 6px; }
.prod-kanban-card .prod-progress-mini { margin-bottom: 6px; }
.prod-kanban-move { display: none; width: 100%; font-size: 0.78rem; padding: 2px; margin-top: 4px; border: 1px solid var(--app-border); border-radius: 4px; }
@media (max-width: 768px) { .prod-kanban-move { display: block; } }
[dir="rtl"] .prod-kanban-card { border-left: none; border-right: 3px solid transparent; }
[dir="rtl"] .prod-kanban-overdue { border-left-color: transparent; border-right-color: #dc2626; }

/* ── Production: Stock Adjustments ───────────────────────────────────── */
.prod-stock-adjusted { background: rgba(234, 179, 8, 0.06) !important; }
[data-theme="dark"] .prod-stock-adjusted { background: rgba(234, 179, 8, 0.1) !important; }
.prod-adjustment-badge {
    display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 0.78rem; font-weight: 600;
    background: #fef3c7; color: #92400e;
}
[data-theme="dark"] .prod-adjustment-badge { background: #451a03; color: #fbbf24; }
.prod-adjustment-manual-badge {
    display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 0.7rem;
    background: #fef3c7; color: #92400e; margin-left: 4px;
}
[data-theme="dark"] .prod-adjustment-manual-badge { background: #451a03; color: #fbbf24; }
.prod-adj-effective { font-weight: 600; }
.prod-adj-cell { position: relative; white-space: nowrap; }
.prod-adj-edit-btn {
    background: none; border: none; cursor: pointer; padding: 0 4px;
    font-size: 0.85rem; color: var(--app-text-muted); opacity: 0.5;
}
.prod-adj-edit-btn:hover { opacity: 1; }
.prod-adj-form {
    position: absolute; top: 100%; left: 0; z-index: 10;
    background: var(--app-card-bg); border: 1px solid var(--app-border);
    border-radius: 6px; padding: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex; gap: 6px; align-items: center; white-space: nowrap;
}
[dir="rtl"] .prod-adj-form { left: auto; right: 0; }
.prod-adj-delta-input { width: 60px; padding: 4px; border: 1px solid var(--app-border); border-radius: 4px; font-size: 0.85rem; }
.prod-adj-reason-input { width: 140px; padding: 4px; border: 1px solid var(--app-border); border-radius: 4px; font-size: 0.85rem; }

/* ── Production: Audit Panel ─────────────────────────────────────────── */
.prod-audit-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: 100;
    display: flex; justify-content: flex-end;
}
.prod-audit-panel {
    width: min(420px, 90vw); height: 100%;
    background: var(--app-card-bg, #fff); box-shadow: -4px 0 16px rgba(0,0,0,0.15);
    display: flex; flex-direction: column; overflow: hidden;
}
[dir="rtl"] .prod-audit-overlay { justify-content: flex-start; }
[dir="rtl"] .prod-audit-panel { box-shadow: 4px 0 16px rgba(0,0,0,0.15); }
.prod-audit-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px; border-bottom: 1px solid var(--app-border);
}
.prod-audit-header h3 { margin: 0; font-size: 1.1rem; }
.prod-audit-timeline { flex: 1; overflow-y: auto; padding: 12px 16px; }
.prod-audit-item {
    display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0;
    border-bottom: 1px solid var(--app-border-subtle, #f3f4f6);
    font-size: 0.85rem;
}
.prod-audit-time { color: var(--app-text-muted); font-size: 0.78rem; flex-shrink: 0; }
.prod-audit-user { font-weight: 600; flex-shrink: 0; }
.prod-audit-desc { color: var(--app-text); word-break: break-word; }
.prod-audit-empty { text-align: center; padding: 40px; color: var(--app-text-muted); }

/* ========================================================================
   Admin editors (cabinet, components, files, diagnostics)
   ======================================================================== */
.admin-btn { display: inline-block; padding: 0.4rem 0.85rem; border-radius: 6px; border: 1px solid var(--app-border, #d1d5db); background: #fff; color: var(--app-text, #1f2937); cursor: pointer; font-size: 0.85rem; font-weight: 500; margin: 0 0.2rem; transition: all 0.15s; }
.admin-btn:hover { background: #f3f4f6; }
.admin-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.admin-btn-primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.admin-btn-primary:hover { background: #1d4ed8; }
.admin-btn-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.admin-btn-danger:hover { background: #b91c1c; }
.admin-btn-ghost { background: transparent; }
.admin-btn-sm { padding: 0.25rem 0.55rem; font-size: 0.78rem; }
.admin-btn-inline { display: inline-block; }
.admin-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 10000; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow-y: auto; }
.admin-modal-box, .admin-confirm-box { background: #fff; border-radius: 10px; box-shadow: 0 8px 40px rgba(0,0,0,0.25); max-width: 720px; width: 100%; max-height: calc(100vh - 4rem); display: flex; flex-direction: column; overflow: hidden; }
.admin-confirm-box { max-width: 420px; padding: 1.25rem; }
.admin-modal-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; background: #1e40af; color: #fff; font-weight: 600; }
.admin-modal-close { background: transparent; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; line-height: 1; padding: 0 0.5rem; }
.admin-modal-body { padding: 1rem; overflow-y: auto; flex: 1; }
.admin-confirm-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.admin-field { margin-bottom: 0.75rem; }
.admin-field label { display: block; font-size: 0.78rem; font-weight: 600; color: #6b7280; margin-bottom: 0.25rem; }
.admin-field input { width: 100%; padding: 0.4rem 0.6rem; border: 1px solid #d1d5db; border-radius: 5px; font-size: 0.85rem; }
.admin-list { list-style: none; padding: 0; margin: 0; }
.admin-list li { padding: 0.5rem 0.6rem; border: 1px solid #e5e7eb; border-radius: 6px; margin-bottom: 0.4rem; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.admin-list-meta { color: #6b7280; font-size: 0.8rem; flex: 1; }
.admin-section { margin: 1.2rem 0; padding: 0.75rem; border: 1px solid #e5e7eb; border-radius: 8px; }
.admin-section h5 { margin: 0 0 0.5rem 0; color: #1e40af; font-size: 1rem; }
.admin-image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.5rem; margin-bottom: 0.5rem; }
.admin-image-card { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 0.3rem; text-align: center; font-size: 0.72rem; }
.admin-image-card img { max-width: 100%; max-height: 80px; border-radius: 3px; display: block; margin: 0 auto 0.2rem; }
.admin-zones-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; margin-bottom: 0.5rem; }
.admin-zones-table th { background: #1f2937; color: #fff; padding: 0.4rem 0.5rem; text-align: left; font-weight: 600; font-size: 0.72rem; text-transform: uppercase; }
.admin-zones-table td { border-bottom: 1px solid #e5e7eb; padding: 0.3rem 0.4rem; vertical-align: middle; }
.admin-zones-table input, .admin-zones-table select { padding: 0.2rem 0.4rem; border: 1px solid #d1d5db; border-radius: 3px; font-size: 0.78rem; max-width: 100%; box-sizing: border-box; }
.admin-toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: #1f2937; color: #fff; padding: 0.7rem 1.2rem; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 10001; font-size: 0.88rem; transition: opacity 0.3s; max-width: 360px; }
.admin-toast-success { background: #16a34a; }
.admin-toast-error { background: #dc2626; }
.admin-toast-warn { background: #d97706; }

/* ---- Admin components editor (Sprint P0.2) ---- */
.admin-components-editor { display: flex; flex-direction: column; gap: 0.75rem; }
.admin-toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; padding: 0.4rem 0; }
.admin-input { padding: 0.35rem 0.55rem; border: 1px solid #d1d5db; border-radius: 4px; font-size: 0.85rem; background: #fff; color: #111; }
.admin-input-sm { padding: 0.2rem 0.4rem; font-size: 0.78rem; width: 100%; box-sizing: border-box; }
.admin-table-wrap { overflow-x: auto; max-height: 60vh; border: 1px solid #e5e7eb; border-radius: 6px; }
.admin-components-table { font-size: 0.78rem; }
.admin-components-table tr:nth-child(even) { background: #f9fafb; }
.admin-components-table tr:hover { background: #fef3c7; }
.admin-cell-readonly { color: #6b7280; font-family: monospace; text-align: center; }
.admin-cell-actions { white-space: nowrap; text-align: center; }
.admin-cell-actions button { margin: 0 0.1rem; }
.admin-pagination { display: flex; gap: 0.5rem; align-items: center; justify-content: center; padding-top: 0.5rem; }
.admin-pagination-info { font-size: 0.85rem; color: #6b7280; min-width: 130px; text-align: center; }
.admin-field-row { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.6rem; }
.admin-field-label { font-size: 0.85rem; color: #374151; font-weight: 500; }
.admin-form-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1rem; padding-top: 0.6rem; border-top: 1px solid #e5e7eb; }
[data-theme="dark"] .admin-input { background: #1f2937; color: #f3f4f6; border-color: #4b5563; }
[data-theme="dark"] .admin-components-table tr:nth-child(even) { background: #1f2937; }
[data-theme="dark"] .admin-components-table tr:hover { background: #374151; }
[data-theme="dark"] .admin-cell-readonly { color: #9ca3af; }
[data-theme="dark"] .admin-pagination-info { color: #9ca3af; }
[data-theme="dark"] .admin-field-label { color: #d1d5db; }

/* ---- Dark mode admin (cabinet/diagnostics/all editors) ---- */
[data-theme="dark"] .admin-modal-box,
[data-theme="dark"] .admin-confirm-box { background: #111827; color: #e5e7eb; }
[data-theme="dark"] .admin-modal-header { background: #1e3a8a; }
[data-theme="dark"] .admin-modal-body { background: #111827; color: #e5e7eb; }
[data-theme="dark"] .admin-btn { background: #1f2937; color: #e5e7eb; border-color: #4b5563; }
[data-theme="dark"] .admin-btn:hover { background: #374151; }
[data-theme="dark"] .admin-btn-primary { background: #2563eb; border-color: #2563eb; color: #fff; }
[data-theme="dark"] .admin-btn-primary:hover { background: #1d4ed8; }
[data-theme="dark"] .admin-btn-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
[data-theme="dark"] .admin-btn-ghost { background: transparent; color: #e5e7eb; }
[data-theme="dark"] .admin-list li { background: #1f2937; border-color: #374151; color: #e5e7eb; }
[data-theme="dark"] .admin-list-meta { color: #9ca3af; }
[data-theme="dark"] .admin-section { border-color: #374151; background: #1f2937; }
[data-theme="dark"] .admin-section h5 { color: #93c5fd; }
[data-theme="dark"] .admin-field label { color: #d1d5db; }
[data-theme="dark"] .admin-field input { background: #1f2937; color: #f3f4f6; border-color: #4b5563; }
[data-theme="dark"] .admin-image-card { background: #1f2937; border-color: #374151; color: #e5e7eb; }
[data-theme="dark"] .admin-zones-table th { background: #0b1220; color: #e5e7eb; }
[data-theme="dark"] .admin-zones-table td { border-color: #374151; background: #111827; color: #e5e7eb; }
[data-theme="dark"] .admin-zones-table input,
[data-theme="dark"] .admin-zones-table select,
[data-theme="dark"] .admin-zones-table textarea { background: #1f2937; color: #f3f4f6; border-color: #4b5563; }
[data-theme="dark"] .admin-table-wrap { border-color: #374151; }
[data-theme="dark"] .admin-form-actions { border-top-color: #374151; }
[data-theme="dark"] .admin-diag-info strong { color: #e5e7eb; }

/* ---- Admin Zone Editor (visual drag/resize) ---- */
.admin-zone-modal { background: #16213e !important; color: #e5e7eb; }
.admin-zone-modal .admin-modal-header { background: #0f3460; }
.admin-zone-body { padding: 0.6rem; background: #1a1a2e; color: #e5e7eb; display: flex; flex-direction: column; gap: 0.6rem; height: calc(100vh - 8rem); }
.admin-zone-toolbar { display: flex; gap: 0.5rem; align-items: center; padding: 0.4rem 0.6rem; background: #0b1220; border-radius: 6px; flex-wrap: wrap; }
.admin-zone-info { color: #9ca3af; font-size: 0.82rem; margin-left: auto; }
.admin-zone-layout { display: flex; gap: 0.6rem; flex: 1; min-height: 0; }
.admin-zone-canvas-wrap { flex: 1; overflow: auto; background: #111; display: flex; justify-content: center; align-items: flex-start; padding: 1rem; min-height: 0; }
.admin-zone-container { position: relative; background: #222; box-shadow: 0 0 20px rgba(0,0,0,0.5); user-select: none; }
.admin-zone-container img { display: block; width: 100%; height: auto; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.admin-zone-canvas-overlay { position: absolute; inset: 0; cursor: default; }
.admin-zone-rect { position: absolute; border: 2px solid #3b82f6; background: rgba(59,130,246,0.15); cursor: move; box-sizing: border-box; }
.admin-zone-rect.selected { border-color: #f59e0b; background: rgba(245,158,11,0.2); z-index: 10; }
.admin-zone-rect.zone-type-button { border-color: #10b981; background: rgba(16,185,129,0.15); }
.admin-zone-rect.zone-type-button.selected { border-color: #f59e0b; background: rgba(245,158,11,0.2); }
.admin-zone-rect.zone-type-indicator { border-color: #8b5cf6; background: rgba(139,92,246,0.15); }
.admin-zone-rect.zone-type-indicator.selected { border-color: #f59e0b; background: rgba(245,158,11,0.2); }
.admin-zone-rect.zone-type-value { border-color: #06b6d4; background: rgba(6,182,212,0.15); }
.admin-zone-rect.zone-type-value.selected { border-color: #f59e0b; background: rgba(245,158,11,0.2); }
.admin-zone-rect.zone-type-nav { border-color: #f97316; background: rgba(249,115,22,0.15); }
.admin-zone-rect.zone-type-nav.selected { border-color: #f59e0b; background: rgba(245,158,11,0.2); }
.admin-zone-rect.zone-type-display { border-color: #94a3b8; background: rgba(148,163,184,0.15); }
.admin-zone-label { position: absolute; top: 0; left: 2px; font-size: 10px; color: #fff; background: rgba(0,0,0,0.7); padding: 1px 4px; border-radius: 0 0 3px 0; pointer-events: none; white-space: nowrap; overflow: hidden; max-width: calc(100% - 4px); }
.admin-zone-resize { position: absolute; width: 10px; height: 10px; background: #f59e0b; border: 1px solid #fff; z-index: 11; }
.admin-zone-resize.nw { top: -5px; left: -5px; cursor: nw-resize; }
.admin-zone-resize.ne { top: -5px; right: -5px; cursor: ne-resize; }
.admin-zone-resize.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.admin-zone-resize.se { bottom: -5px; right: -5px; cursor: se-resize; }
.admin-zone-preview { position: absolute; border: 2px dashed #f59e0b; background: rgba(245,158,11,0.1); pointer-events: none; box-sizing: border-box; }
.admin-zone-side { width: 320px; background: #16213e; border-radius: 6px; padding: 0.8rem; overflow-y: auto; flex-shrink: 0; color: #e5e7eb; }
.admin-zone-side h4 { margin: 0 0 0.6rem 0; color: #93c5fd; font-size: 1rem; }
.admin-zone-hint { color: #9ca3af; font-size: 0.82rem; line-height: 1.4; }
.admin-zone-coords { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.4rem; margin-bottom: 0.5rem; }
.admin-zone-coord-row { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.4rem; }
.admin-zone-coord-row label { font-size: 0.78rem; color: #d1d5db; font-weight: 500; }
.admin-zone-coord-row input,
.admin-zone-coord-row select { background: #1a1a2e; color: #e5e7eb; border: 1px solid #334; border-radius: 4px; padding: 0.3rem 0.4rem; font-size: 0.8rem; }
.admin-zone-custom-props label.admin-zone-field-label { display: block; font-size: 0.78rem; color: #d1d5db; margin: 0.4rem 0 0.2rem; }
.admin-zone-custom-props input,
.admin-zone-custom-props textarea { background: #1a1a2e !important; color: #e5e7eb !important; border: 1px solid #334; border-radius: 4px; padding: 0.3rem 0.4rem; font-size: 0.8rem; }

/* ---- Stock Alerts dashboard ---- */
.app-stock-alerts { padding: 1rem 1.4rem; max-width: 100%; }
.app-stock-header h2 { margin: 0 0 0.3rem 0; font-size: 1.4rem; }
.app-stock-subtitle { color: #6b7280; font-size: 0.88rem; margin: 0 0 1rem 0; }
.app-stock-stats { display: flex; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.app-stock-kpi { padding: 0.7rem 1.1rem; border-radius: 8px; min-width: 130px; border: 1px solid #e5e7eb; background: #fff; display: flex; flex-direction: column; gap: 0.2rem; }
.app-stock-kpi-val { font-size: 1.6rem; font-weight: 700; color: #111827; }
.app-stock-kpi-lbl { font-size: 0.75rem; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; }
.app-stock-kpi-danger { border-color: #dc2626; background: #fef2f2; }
.app-stock-kpi-danger .app-stock-kpi-val { color: #dc2626; }
.app-stock-kpi-warning { border-color: #d97706; background: #fef3c7; }
.app-stock-kpi-warning .app-stock-kpi-val { color: #d97706; }
.app-stock-tabs { display: flex; gap: 0.4rem; border-bottom: 2px solid #e5e7eb; margin-bottom: 0.8rem; flex-wrap: wrap; }
.app-stock-tab { padding: 0.5rem 0.9rem; background: transparent; border: none; cursor: pointer; font-size: 0.92rem; color: #6b7280; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.app-stock-tab.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 600; }
.app-stock-tab:hover { background: #f3f4f6; }
.app-stock-toolbar { display: flex; gap: 0.6rem; margin-bottom: 0.8rem; align-items: center; flex-wrap: wrap; }
.app-stock-chk { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; cursor: pointer; }
.app-stock-content { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 0.8rem; overflow-x: auto; }
.app-stock-loading { color: #6b7280; padding: 1rem; text-align: center; }
.app-stock-empty { color: #6b7280; padding: 1rem; text-align: center; font-style: italic; }
.app-stock-error { color: #dc2626; padding: 1rem; }
.app-stock-rowcount { color: #6b7280; font-size: 0.85rem; margin: 0 0 0.4rem 0; }
.app-stock-help { background: #f0f9ff; border-left: 3px solid #0284c7; padding: 0.5rem 0.8rem; font-size: 0.85rem; color: #075985; border-radius: 4px; margin-bottom: 0.6rem; }
.app-stock-table-wrap { overflow-x: auto; max-height: 65vh; }
.app-stock-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.app-stock-table th { background: #1e40af; color: #fff; padding: 0.5rem 0.6rem; text-align: left; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; position: sticky; top: 0; }
.app-stock-table td { border-bottom: 1px solid #f3f4f6; padding: 0.4rem 0.6rem; vertical-align: middle; }
.app-stock-table tr:hover { background: #f9fafb; }
.app-stock-table td.mono { font-family: monospace; font-size: 0.82rem; }
.app-stock-table td.num { text-align: right; font-family: monospace; }
.app-stock-table td.small { font-size: 0.78rem; }
.app-stock-table td.bal-bad { color: #dc2626; font-weight: 600; background: #fef2f2; }
.app-stock-table td.bal-warn { color: #d97706; font-weight: 600; }
.app-stock-table td.bal-ok { color: #16a34a; }
.app-stock-row-lack { background: rgba(220, 38, 38, 0.04); }
.app-stock-row-late { background: rgba(217, 119, 6, 0.04); }
.app-stock-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 10000; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow-y: auto; }
.app-stock-modal-box { background: #fff; border-radius: 10px; max-width: 1100px; width: 100%; max-height: calc(100vh - 4rem); display: flex; flex-direction: column; overflow: hidden; }
.app-stock-modal-header { display: flex; justify-content: space-between; padding: 0.8rem 1rem; background: #1e40af; color: #fff; font-weight: 600; }
.app-stock-modal-close { background: transparent; border: none; color: #fff; font-size: 1.6rem; cursor: pointer; line-height: 1; }
.app-stock-modal-body { padding: 1rem; overflow-y: auto; flex: 1; }
.app-stock-summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; margin-bottom: 1rem; }
.app-stock-summary-cell { padding: 0.5rem; background: #f9fafb; border-radius: 6px; }
.app-stock-summary-lbl { font-size: 0.72rem; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; }
.app-stock-summary-val { font-size: 1.1rem; font-weight: 600; color: #111827; }
.app-stock-rule-actions { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.app-stock-subtable { width: 100%; font-size: 0.82rem; border-collapse: collapse; margin-bottom: 1rem; }
.app-stock-subtable td { border-bottom: 1px solid #f3f4f6; padding: 0.3rem 0.5rem; }
.app-stock-rule-item { padding: 0.4rem 0.6rem; background: #f9fafb; border-radius: 4px; margin-bottom: 0.3rem; display: flex; align-items: center; gap: 0.5rem; }
.app-stock-rule-type { font-family: monospace; font-size: 0.78rem; background: #1e40af; color: #fff; padding: 0.1rem 0.4rem; border-radius: 3px; }
[data-theme="dark"] .app-stock-kpi { background: #1f2937; border-color: #374151; }
[data-theme="dark"] .app-stock-kpi-val { color: #f3f4f6; }
[data-theme="dark"] .app-stock-kpi-lbl { color: #9ca3af; }
[data-theme="dark"] .app-stock-kpi-danger { background: #4c1d24; border-color: #dc2626; }
[data-theme="dark"] .app-stock-kpi-warning { background: #4a2e0c; border-color: #d97706; }
[data-theme="dark"] .app-stock-tabs { border-bottom-color: #374151; }
[data-theme="dark"] .app-stock-tab { color: #9ca3af; }
[data-theme="dark"] .app-stock-tab.active { color: #93c5fd; border-bottom-color: #2563eb; }
[data-theme="dark"] .app-stock-tab:hover { background: #1f2937; }
[data-theme="dark"] .app-stock-content { background: #111827; border-color: #374151; }
[data-theme="dark"] .app-stock-help { background: #1e3a5f; color: #93c5fd; border-left-color: #38bdf8; }
[data-theme="dark"] .app-stock-table th { background: #0b1220; }
[data-theme="dark"] .app-stock-table td { border-color: #1f2937; color: #e5e7eb; }
[data-theme="dark"] .app-stock-table tr:hover { background: #1f2937; }
[data-theme="dark"] .app-stock-table td.bal-bad { background: #4c1d24; }
[data-theme="dark"] .app-stock-modal-box { background: #111827; color: #e5e7eb; }
[data-theme="dark"] .app-stock-modal-body { background: #111827; }
[data-theme="dark"] .app-stock-summary-cell { background: #1f2937; }
[data-theme="dark"] .app-stock-summary-val { color: #f3f4f6; }
[data-theme="dark"] .app-stock-summary-lbl { color: #9ca3af; }
[data-theme="dark"] .app-stock-rule-item { background: #1f2937; }
[data-theme="dark"] .app-stock-subtable td { border-color: #1f2937; color: #e5e7eb; }
[data-theme="dark"] .app-stock-empty, [data-theme="dark"] .app-stock-loading, [data-theme="dark"] .app-stock-rowcount { color: #9ca3af; }
[data-theme="dark"] .app-stock-subtitle { color: #9ca3af; }

/* === GADDA Calibration Videos Modal === */
.app-gadda-videos-modal { position: fixed; inset: 0; z-index: 9000; display: flex; align-items: center; justify-content: center; }
.app-gadda-videos-modal[hidden] { display: none; }
.app-gadda-videos-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.app-gadda-videos-dialog { position: relative; background: #fff; border-radius: 8px; width: min(1100px, 95vw); height: min(720px, 90vh); display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,0.3); overflow: hidden; }
.app-gadda-videos-header { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; border-bottom: 1px solid #e5e7eb; }
.app-gadda-videos-header h3 { margin: 0; font-size: 1.1rem; }
.app-gadda-videos-body { display: flex; flex: 1; min-height: 0; }
.app-gadda-videos-list { width: 280px; border-right: 1px solid #e5e7eb; padding: 0.75rem; overflow-y: auto; background: #f9fafb; }
.app-gadda-videos-cat { font-size: 0.8rem; text-transform: uppercase; color: #6b7280; margin: 0.75rem 0 0.35rem; letter-spacing: 0.5px; }
.app-gadda-videos-cat:first-child { margin-top: 0; }
.app-gadda-videos-cat-items { list-style: none; padding: 0; margin: 0; }
.app-gadda-videos-cat-items li { margin-bottom: 0.25rem; }
.app-gadda-videos-item { display: block; width: 100%; text-align: left; padding: 0.45rem 0.6rem; border: 1px solid transparent; background: transparent; border-radius: 4px; cursor: pointer; font-size: 0.9rem; color: #374151; }
.app-gadda-videos-item:hover { background: #e5e7eb; }
.app-gadda-videos-item.active { background: #2563eb; color: #fff; }
.app-gadda-videos-player { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1rem; background: #000; overflow: hidden; }
.app-gadda-videos-placeholder { color: #9ca3af; font-size: 0.95rem; }
.app-gadda-videos-video, .app-gadda-videos-image { max-width: 100%; max-height: calc(100% - 2.5rem); background: #000; border-radius: 4px; }
.app-gadda-videos-caption { color: #f3f4f6; font-size: 0.9rem; margin: 0.5rem 0 0; text-align: center; }
[dir="rtl"] .app-gadda-videos-list { border-right: none; border-left: 1px solid #e5e7eb; }
[dir="rtl"] .app-gadda-videos-item { text-align: right; }
[data-theme="dark"] .app-gadda-videos-dialog { background: #111827; color: #e5e7eb; }
[data-theme="dark"] .app-gadda-videos-header { border-color: #1f2937; }
[data-theme="dark"] .app-gadda-videos-list { background: #0b1220; border-color: #1f2937; }
[data-theme="dark"] .app-gadda-videos-item { color: #d1d5db; }
[data-theme="dark"] .app-gadda-videos-item:hover { background: #1f2937; }
[data-theme="dark"] .app-gadda-videos-cat { color: #9ca3af; }
@media (max-width: 700px) {
    .app-gadda-videos-body { flex-direction: column; }
    .app-gadda-videos-list { width: auto; max-height: 35%; border-right: none; border-bottom: 1px solid #e5e7eb; }
}

/* ============================================================
   Toast — completa el sistema existente (.app-toast-container / _appToast):
   ya define info (azul) + warning (naranja); faltaban success/error + fade-out.
   API JS: window.toast(msg, kind) delega en window._appToast.
   ============================================================ */
.app-toast-success {
    background: var(--app-green, #28a745);
    color: #fff;
}
.app-toast-error {
    background: var(--app-red, #dc3545);
    color: #fff;
}
.app-toast-fade-out {
    opacity: 0;
    transition: opacity 0.4s ease;
}

/* ============================================================
   Empty states (global) — API JS: window.emptyState(el, opts)
   ============================================================ */
.app-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.5rem;
    padding: 2.5rem 1.25rem;
    color: var(--app-text-muted, #64748b);
}
.app-empty-icon { font-size: 2.4rem; line-height: 1; opacity: 0.55; }
.app-empty-title { font-size: 1.02rem; font-weight: 600; color: var(--app-text, #1e293b); }
.app-empty-msg { font-size: 0.9rem; max-width: 38ch; }
.app-empty-action { margin-top: 0.6rem; }

@media (prefers-reduced-motion: reduce) {
    .app-toast { animation: none; }
    .app-toast-fade-out { transition: opacity 0.01ms; }
}

/* ============================================================
   Batch 2 — refinamientos móvil / RTL / accesibilidad (campo)
   ============================================================ */

/* a11y: foco visible por teclado en TODOS los controles interactivos.
   :focus-visible solo muestra el anillo en navegación por teclado, no al click. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
.app-btn:focus-visible,
.app-nav-item:focus-visible {
    outline: 2px solid var(--app-accent, #3b82f6);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Touch targets accesibles (WCAG 2.5.5 / iOS HIG = 44px) para botones-icono y hamburguesa */
.app-btn-icon,
.app-hamburger {
    min-width: 44px;
    min-height: 44px;
}

/* RTL: flechas direccionales literales (← →) se espejan en árabe/hebreo */
[dir="rtl"] .app-arrow,
[dir="rtl"] .app-back-arrow,
[dir="rtl"] .app-btn-back .app-icon-arrow { transform: scaleX(-1); display: inline-block; }

/* RTL: labels pequeños un punto más grandes (he/ar necesitan más cuerpo) */
[dir="rtl"] .app-form-group label { font-size: 0.85rem; }

/* Móvil: las celdas de tabla dejan de truncar con ellipsis (corta mal CJK) y permiten wrap */
@media (max-width: 640px) {
    .app-table td {
        max-width: 160px;
        white-space: normal;
        word-break: break-word;
        overflow: visible;
        text-overflow: clip;
    }
    /* hint visual de scroll horizontal en tablas anchas */
    .app-table-wrap { scrollbar-gutter: stable; }
}

/* ============================================================
   Presentación premium — pulido (botones, hover de cards, motion)
   ============================================================ */

/* Feedback :active en botones (estaba ausente salvo en llamadas) */
.app-btn { transition: background var(--app-dur) var(--app-ease-snap), box-shadow var(--app-dur) var(--app-ease-snap), transform var(--app-dur) var(--app-ease-snap), filter var(--app-dur) var(--app-ease-snap), border-color var(--app-dur) var(--app-ease-snap); }
.app-btn:active { transform: translateY(0) scale(0.99); }

/* Hover consistente en TODAS las cards interactivas (translateY + sombra) */
.app-crane-card, .app-mon-card, .app-catalog-card, .app-rep-model-card,
.app-diag-card, .app-esquema-card, .app-news-card, .app-cabinet-card {
    transition: box-shadow var(--app-dur) var(--app-ease), transform var(--app-dur) var(--app-ease), border-color var(--app-dur) var(--app-ease);
}
.app-crane-card:hover, .app-mon-card:hover, .app-catalog-card:hover, .app-rep-model-card:hover,
.app-diag-card:hover, .app-esquema-card:hover, .app-news-card:hover, .app-cabinet-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--app-shadow-lg);
}

/* Scrollbars finas también en light (antes solo en dark) */
* { scrollbar-width: thin; scrollbar-color: rgba(100,116,139,0.35) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: rgba(100,116,139,0.35); border-radius: 6px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(100,116,139,0.55); }
*::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
    .app-btn, .app-crane-card, .app-mon-card, .app-catalog-card, .app-rep-model-card,
    .app-diag-card, .app-esquema-card, .app-news-card, .app-cabinet-card,
    .app-table tbody tr { transition: none; }
    .app-btn:active { transform: none; }
}

/* === Pulido estético v2 — sidebar + elevación de botones (2026-06-13) === */
/* Sidebar: micro-desplazamiento al hover; ítem activo más legible (peso + degradado de acento rojo SAEZ) */
.app-nav-item {
    transition: color var(--app-dur) var(--app-ease), background var(--app-dur) var(--app-ease),
        border-left-color var(--app-dur) var(--app-ease), padding-left var(--app-dur) var(--app-ease);
}
.app-nav-item:hover { padding-left: 1.45rem; }
.app-nav-item.active {
    font-weight: 600;
    background: linear-gradient(90deg, rgba(227,6,19,0.16), rgba(255,255,255,0.04));
}

/* Botones (diseño): hover lift + shadow-md + brillo +3%; active hunde a shadow-sm; glow de color SOLO en primary */
.app-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--app-shadow-md); filter: brightness(1.03); }
.app-btn:active:not(:disabled) { box-shadow: var(--app-shadow-sm); filter: none; }
.app-btn-primary:hover:not(:disabled) { box-shadow: var(--app-shadow-md), 0 6px 18px rgba(227,6,19,0.22); }  /* glow de acento premium (sólido, no flashy — calibrado), solo la acción primaria */
.app-btn-ghost:hover:not(:disabled) { transform: translateY(-1px); box-shadow: none; }
.app-btn-icon:hover { transform: scale(1.06); }  /* icon-buttons: leve escala en vez de lift */

@media (prefers-reduced-motion: reduce) {
    .app-nav-item, .app-nav-item:hover { padding-left: 1.25rem; transition: none; }
    .app-btn:hover:not(:disabled), .app-btn-ghost:hover:not(:disabled) { transform: none; box-shadow: none; filter: none; }
    .app-btn-icon:hover { transform: none; }
}

/* === Pulido estético v3 — focus ring unificado + modales (2026-06-13) === */
/* Transición suave del ring en todos los controles de texto */
input, select, textarea {
    transition: border-color var(--app-dur) var(--app-ease), box-shadow var(--app-dur) var(--app-ease);
}
/* Mismo ring de acento que .app-form-group, ahora también en admin/búsqueda/inputs sueltos */
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):focus,
select:focus, textarea:focus, .app-input:focus, .admin-input:focus {
    outline: none;
    border-color: var(--app-saez-red);
    box-shadow: 0 0 0 3px rgba(227,6,19,0.12);
}

/* Modales: backdrop con desenfoque + elevación más rica + botón cerrar con hover circular */
.app-modal-overlay { background: rgba(15,23,42,0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.app-modal { box-shadow: var(--app-shadow-lg); }
.app-modal-close {
    width: 32px; height: 32px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background var(--app-dur) var(--app-ease), color var(--app-dur) var(--app-ease);
}
.app-modal-close:hover { background: rgba(127,127,127,0.14); }
