:root {
    /* Identidad Industrial Eléctrica: Carbono & Naranja Alto Voltaje */
    --bg-dark: #0a0c10;
    --card-bg: #121620;
    --card-border: #1f2738;
    --card-hover: #28334a;
    
    /* Acentos Eléctricos & Seguridad Industrial */
    --primary: #f97316;          /* Naranja Seguridad Industrial / Metrel */
    --primary-hover: #ea580c;
    --primary-gradient: linear-gradient(135deg, #f97316 0%, #c2410c 100%);
    --accent: #fbbf24;           /* Ámbar Arco Eléctrico */
    --accent-glow: rgba(251, 191, 36, 0.15);
    
    /* Tipografía y Contraste */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;          /* SEC Cumple Norma */
    --warning: #f59e0b;          /* Alerta */
    --danger: #ef4444;           /* Falla Crítica / Rechazo SEC */
    
    /* Fondos específicos */
    --header-bg: #0e1117;
    --input-bg: #07090d;
}

html {
    box-sizing: border-box;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

*, *:before, *:after {
    box-sizing: inherit;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    padding-bottom: 70px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Header Industrial */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--header-bg);
    border-bottom: 2px solid var(--primary);
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
    box-sizing: border-box;
}

.badge-status {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: rgba(249, 115, 22, 0.18);
    color: #fbbf24;
    border: 1px solid rgba(249, 115, 22, 0.5);
    padding: 2px 7px;
    border-radius: 4px;
    display: inline-block;
}

.logo-area h1 {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    margin-top: 2px;
}

.btn-voice-toggle {
    background: #1b202c;
    border: 1px solid #2d3748;
    color: #fff;
    padding: 7px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.btn-voice-toggle.listening {
    background: #dc2626;
    border-color: #ef4444;
    animation: pulse 1.5s infinite;
}

/* Tabs Mobile-First */
.nav-tabs {
    display: flex;
    background: #0e1117;
    border-bottom: 1px solid var(--card-border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    padding: 0 4px;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex: 1 0 auto;
    min-width: max-content;
    padding: 11px 13px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: color 0.15s, background 0.15s;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--primary);
    background: rgba(249, 115, 22, 0.1);
}

/* Contenido Principal */
.app-main {
    max-width: 680px;
    width: 100%;
    margin: 0 auto;
    padding: 12px;
    box-sizing: border-box;
}

.tab-content {
    display: none;
    width: 100%;
}

.tab-content.active {
    display: block;
}

/* Barra de Proyectos */
.project-manager-bar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-left: 3px solid var(--primary);
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
}

.project-selector-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    min-width: 0;
}

.project-selector-wrapper label {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.project-dropdown {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    background: var(--input-bg);
    border: 1px solid #2b3548;
    color: #fff;
    padding: 10px 36px 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23f97316' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: calc(100% - 12px) center;
    background-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

.project-dropdown:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2);
}

.btn-new-project {
    width: 100%;
    box-sizing: border-box;
    background: var(--primary-gradient);
    color: #fff;
    border: none;
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(249, 115, 22, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: transform 0.1s, opacity 0.15s;
}

.btn-new-project:active {
    transform: scale(0.99);
    opacity: 0.9;
}

.card-new-project {
    background: #161b26;
    border: 1px solid var(--primary);
    margin-bottom: 14px;
    padding: 14px 12px;
    border-radius: 12px;
    width: 100%;
    box-sizing: border-box;
}

.new-project-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.new-project-header h3 {
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    margin: 0;
}

/* Banner de Caso Activo */
.banner-case {
    background: linear-gradient(135deg, #181d28 0%, #0e121a 100%);
    border: 1px solid #2d3748;
    border-left: 4px solid var(--primary);
    border-radius: 12px;
    padding: 14px 12px;
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
    word-break: break-word;
}

.tag-urgent {
    background: #ea580c;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.banner-header h2 {
    font-size: 15px;
    margin: 6px 0;
    color: #fff;
}

.banner-case p {
    font-size: 12px;
    color: var(--text-muted);
}

/* Acciones Multimodales Rápidas */
.quick-inputs-bar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
}

.btn-action-camera {
    display: block;
    text-align: center;
    background: linear-gradient(135deg, #242c3d 0%, #161b26 100%);
    border: 1px solid #f97316;
    color: #f8fafc;
    padding: 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(249, 115, 22, 0.2);
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.btn-action-camera:active {
    background: #1e2637;
}

.voice-status-box {
    background: #251608;
    border: 1px solid #c2410c;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 12px;
    color: #fed7aa;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.pulse-dot {
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 1s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0% { transform: scale(0.9); opacity: 0.7; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(0.9); opacity: 0.7; }
}

/* Tarjetas */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 14px 12px;
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.card h3 {
    font-size: 15px;
    margin-bottom: 12px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Formulario Mobile-First */
.grid-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
}

.form-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.form-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    background: var(--input-bg);
    border: 1px solid #2b3548;
    color: #fff;
    padding: 10px 8px;
    border-radius: 8px;
    font-size: 15px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2);
}

.form-group .hint {
    font-size: 10px;
    color: #64748b;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-primary {
    width: 100%;
    box-sizing: border-box;
    background: var(--primary-gradient);
    color: #fff;
    border: none;
    padding: 13px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    margin-top: 14px;
    box-shadow: 0 4px 14px rgba(249, 115, 22, 0.4);
    text-align: center;
    letter-spacing: 0.3px;
    transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:active {
    transform: scale(0.99);
    opacity: 0.9;
}

.btn-secondary {
    background: #1b2230;
    border: 1px solid var(--primary);
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    box-sizing: border-box;
}

/* Resultados */
.badge-verdict {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 800;
}

.badge-verdict.pasa { background: #15803d; color: #fff; }
.badge-verdict.falla { background: #b91c1c; color: #fff; }
.badge-verdict.alerta { background: #b45309; color: #fff; }

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

.verdict-desc {
    font-size: 13px;
    color: #e2e8f0;
}

.findings-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.finding-item {
    background: #171b26;
    border-left: 3px solid #ef4444;
    padding: 10px;
    border-radius: 4px;
    font-size: 12px;
    color: #f1f5f9;
    word-break: break-word;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.metric-item {
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    padding: 10px 8px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    box-sizing: border-box;
}

.metric-label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.metric-val {
    font-size: 16px;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.metric-item.highlight {
    border-color: var(--primary);
    background: rgba(249, 115, 22, 0.08);
}

.metric-item.highlight .metric-val {
    color: #fbbf24;
}

.plan-steps {
    padding-left: 20px;
    font-size: 13px;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.save-actions {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.save-actions input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    background: var(--input-bg);
    border: 1px solid #2b3548;
    color: #fff;
    padding: 10px 12px;
    border-radius: 8px;
}

.save-actions input:focus {
    outline: none;
    border-color: var(--primary);
}

.save-actions .btn-secondary {
    width: 100%;
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    background: var(--primary-gradient);
    border: none;
    font-weight: 700;
}

/* Spinner */
.loading-spinner {
    text-align: center;
    padding: 20px;
    background: #171b26;
    border-radius: 10px;
    margin-bottom: 16px;
    width: 100%;
    box-sizing: border-box;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 4px solid #2d3748;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    margin: 0 auto 10px auto;
}

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

/* Vision Card */
.vision-preview-card {
    background: #161b26;
    border: 1px solid var(--primary);
    border-radius: 10px;
    padding: 14px 12px;
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.btn-close-sm {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
}

/* Metrel Tab */
.test-selector-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
}

.btn-test-select {
    background: #161b26;
    border: 1px solid #28334a;
    color: #fff;
    padding: 10px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-test-select.active {
    background: #271a0e;
    border-color: var(--primary);
    color: #fbbf24;
}

.badge-rotary {
    background: var(--primary);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.settings-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 10px 0 14px 0;
    width: 100%;
}

.setting-row {
    background: var(--input-bg);
    padding: 8px 10px;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}

.setting-row .key { color: var(--text-muted); }
.setting-row .val { color: var(--accent); font-weight: 700; }

.wiring-steps, .field-tips-list {
    padding-left: 20px;
    font-size: 12px;
    color: #e2e8f0;
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.norm-reference {
    background: #0e121a;
    border-left: 3px solid #10b981;
    padding: 8px 10px;
    font-size: 12px;
    color: #a7f3d0;
}

/* RIC Grid */
.ric-cards-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.ric-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 12px;
    width: 100%;
    box-sizing: border-box;
}

.ric-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.ric-badge {
    background: #d97706;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

.ric-list {
    padding-left: 20px;
    font-size: 12px;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Historial */
.history-item-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.history-info {
    min-width: 0;
    flex: 1;
}

.history-info h4 {
    font-size: 13px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-info p {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-report {
    flex-shrink: 0;
    background: var(--primary-gradient);
    color: #fff;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

/* Media Query Tablet & Desktop */
@media (min-width: 640px) {
    .app-main {
        padding: 20px;
    }

    .project-manager-bar {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-end;
    }

    .project-selector-wrapper {
        flex: 1;
    }

    .btn-new-project {
        width: auto;
        height: 42px;
        padding: 0 18px;
    }

    .card {
        padding: 20px;
    }

    .save-actions {
        flex-direction: row;
    }

    .save-actions .btn-secondary {
        width: auto;
    }
}
