/* --- DESIGN SYSTEM TOKENS --- */
:root {
    --bg-main: #0b1221;
    --bg-surface: rgba(17, 24, 39, 0.75);
    --bg-surface-hover: rgba(31, 41, 55, 0.85);
    --border-color: rgba(255, 255, 255, 0.075);
    --border-glow: rgba(89, 185, 232, 0.15);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    --accent-primary: #59b9e8;     /* Sky Blue */
    --accent-secondary: #3e92ba;   /* Blue Dark */
    --accent-purple: #818cf8;      /* Indigo Accent */

    --state-success: #10b981;      /* Emerald Green */
    --state-warning: #f59e0b;      /* Amber Orange */
    --state-error: #f43f5e;        /* Rose Red */
    
    --font-sans: "Google Sans Text", "Google Sans", "Roboto", "Outfit", sans-serif;
    --font-mono: 'Space Grotesk', monospace;
}

/* --- GENERAL RESET & BASE --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

body {
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(89, 185, 232, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(129, 140, 248, 0.08) 0px, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* --- LAYOUT WRAPPER --- */
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 104px 24px 24px 24px;
}

/* --- APP HEADER --- */
.app-header {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 1600px;
    z-index: 100;
    background: var(--bg-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-symbol {
    font-size: 32px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 10px rgba(6, 182, 212, 0.3));
}

.logo-text h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo-text h1 .accent {
    color: var(--accent-primary);
    text-shadow: 0 0 15px rgba(6, 182, 212, 0.4);
}

.logo-text .tagline {
    font-size: 13px;
    color: var(--text-secondary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 24px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-group label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* --- MAIN CONTENT LAYOUT --- */
.main-content-container {
    width: 100%;
    margin: 0 auto;
}

/* --- MAIN TABS NAVIGATION --- */
.main-tabs-nav {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding: 12px 0;
    /* Pinned flush below the fixed .app-header. The actual header height is
       measured in JS and exposed via --header-h to avoid the "rebote" caused
       by a hardcoded value that drifts a few pixels from the real layout. */
    position: sticky;
    top: var(--header-h, 84px);
    background: var(--bg-main);
    z-index: 99;
}

.main-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.25s ease;
}

.main-tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.15);
}

.main-tab-btn.active {
    color: #fff;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.15);
}

body.light-theme .main-tab-btn {
    background: rgba(0, 0, 0, 0.02);
}

body.light-theme .main-tab-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme .main-tab-btn.active {
    color: #fff;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}

/* --- MAIN TAB CONTENT --- */
.main-tab-content {
    display: none;
}

.data-table tr:hover td {
    background: rgba(255, 255, 255, 0.01);
}

body.light-theme .data-table tr:hover td {
    background: rgba(0, 0, 0, 0.01);
}

/* --- DECLARACIONES RESPONSABLES (DR) STYLE OVERRIDES --- */
.dr-modal-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
    padding-bottom: 2px;
}

body.light-theme .dr-modal-tabs {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

body.light-theme .dr-tab-btn {
    color: #475569 !important;
}

body.light-theme .dr-tab-btn.active {
    color: var(--text-primary) !important;
}

body.light-theme .dr-preview-text {
    background: #ffffff !important;
    color: #1e293b !important;
    border: 1px solid rgba(0,0,0,0.08) !important;
}

body.light-theme .dr-status-bar {
    background: rgba(0,0,0,0.02) !important;
    border-color: var(--accent-primary) !important;
}

body.light-theme .modal-footer {
    border-top-color: rgba(0, 0, 0, 0.08) !important;
}

/* Print Stylesheet for isolated printing of Declaraciones Responsables */
@media print {
    body * {
        visibility: hidden;
    }
    #declaracion-modal, #declaracion-modal *, .dr-tab-content:not(.hidden), .dr-tab-content:not(.hidden) * {
        visibility: visible;
    }
    #declaracion-modal {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background: white !important;
        color: black !important;
    }
    .modal-header, .modal-footer, .dr-modal-tabs, .dr-status-bar, .close-btn {
        display: none !important;
    }
    .dr-preview-text {
        background: transparent !important;
        color: black !important;
        border: none !important;
        font-size: 11pt !important;
        line-height: 1.5 !important;
        font-family: 'Courier New', Courier, monospace !important;
        white-space: pre-wrap !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 0 !important;
        margin: 0 !important;
    }
}

.main-tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

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

/* --- INTERNAL TWO-COLUMN LAYOUTS --- */
.simulator-layout, .companies-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media (min-width: 900px) {
    .simulator-layout, .companies-layout {
        display: grid;
        gap: 32px;
        align-items: start;
    }

    .simulator-layout {
        grid-template-columns: 1fr 1.5fr;
    }

    .companies-layout {
        grid-template-columns: 1.2fr 1fr;
    }

    /* Hide separators in desktop mode */
    .simulator-layout > hr.separator {
        display: none;
    }

    /* Sticky left rail: stays anchored under the fixed header + sticky tabs
       while the right column scrolls. The +70px buffer covers tab height
       (~52px) plus its bottom margin. The max-height keeps the left panel
       inside the viewport so its own scrollbar takes over if its content is
       taller than the visible area. */
    .simulator-layout > .simulator-left {
        position: sticky;
        top: calc(var(--header-h, 84px) + 70px);
        align-self: start;
        max-height: calc(100vh - var(--header-h, 84px) - 90px);
        overflow-y: auto;
        padding-right: 6px;
    }
}


/* --- PREMIUM CARDS --- */
.card {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    overflow: hidden;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.card:hover {
    border-color: var(--border-glow);
    box-shadow: 0 8px 32px 0 rgba(6, 182, 212, 0.05);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body {
    padding: 20px;
}

/* --- FORM CONTROLS --- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input, .form-select {
    width: 100%;
    background: rgba(10, 15, 28, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus, .form-select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 8px rgba(6, 182, 212, 0.2);
}

.form-row {
    display: flex;
    gap: 12px;
}

.col-6 {
    flex: 1;
}

.separator {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 20px 0;
}

/* --- SIMULATOR PROFILE BOX --- */
.profile-details {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.profile-details h3 {
    font-size: 12px;
    color: var(--accent-primary);
    text-transform: uppercase;
    margin-bottom: 8px;
    font-weight: 600;
}

.info-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 6px;
}

.info-row:last-child {
    margin-bottom: 0;
}

.info-row .label {
    color: var(--text-secondary);
}

.info-row .value {
    font-weight: 500;
}

.code {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent-purple);
}

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border: none;
    outline: none;
    transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #fff;
    box-shadow: 0 4px 14px rgba(6, 182, 212, 0.2);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #08c7e8, #4b93ff);
    box-shadow: 0 4px 20px rgba(6, 182, 212, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-info {
    background: rgba(6, 182, 212, 0.1);
    color: var(--accent-primary);
    border: 1px solid rgba(6, 182, 212, 0.2);
}

.btn-info:hover {
    background: rgba(6, 182, 212, 0.2);
}

.btn-danger {
    background: var(--state-error);
    color: #fff;
}

.btn-danger:hover {
    background: #e11d48;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    width: auto;
}

.btn:active {
    transform: scale(0.98);
}

.batch-section {
    margin-top: 16px;
}

.batch-section h3 {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.batch-buttons {
    display: flex;
    gap: 10px;
}

.batch-buttons .btn {
    flex: 1;
}

/* --- BADGES & LABELS --- */
.badge {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge-purple {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-purple);
    border: 1px solid rgba(139, 92, 246, 0.25);
}

/* --- QUEUE METRICS IN HEADER --- */
.monitor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.monitor-header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.metrics-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.metric-pill {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: border-color 0.3s ease;
}

.metric-pill .num {
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.metric-pill .label {
    font-size: 9px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.metric-pill.pending { border-color: rgba(245, 158, 11, 0.2); color: var(--state-warning); }
.metric-pill.processing { border-color: rgba(59, 130, 246, 0.2); color: var(--accent-secondary); }
.metric-pill.validated { border-color: rgba(16, 185, 129, 0.2); color: var(--state-success); }
.metric-pill.rejected { border-color: rgba(244, 63, 94, 0.2); color: var(--state-error); }

.queue-speed-indicator {
    font-size: 13px;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.queue-speed-indicator span {
    font-weight: 700;
    color: var(--accent-primary);
}

/* --- BLOCKCHAIN MAP (VERTICAL TIMELINE) --- */
.blockchain-section {
    margin-top: 10px;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-title-row h3 {
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.blockchain-flow {
    display: flex;
    flex-direction: column; /* JS feeds cards newest-first, so plain column = newest at top */
    gap: 8px;
    max-height: 560px;
    overflow-y: auto;
    padding-right: 8px;
    padding-left: 4px;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 40px 0;
}

/* CHAIN NODE CARD */
.node-card {
    background: rgba(10, 15, 28, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 12px;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.node-card:hover {
    transform: translateY(-2px);
    border-color: rgba(6, 182, 212, 0.4);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.node-card.selected {
    border-color: var(--accent-primary);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.25);
    background: rgba(6, 182, 212, 0.03);
}

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

.node-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.node-date {
    font-size: 10px;
    color: var(--text-muted);
}

.node-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}

.status-pending { background-color: var(--state-warning); box-shadow: 0 0 8px var(--state-warning); }
.status-processing { background-color: var(--accent-secondary); box-shadow: 0 0 8px var(--accent-secondary); }
.status-validated { background-color: var(--state-success); box-shadow: 0 0 8px var(--state-success); }
.status-rejected { background-color: var(--state-error); box-shadow: 0 0 8px var(--state-error); }

.node-body {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 4px;
}

.node-amount {
    font-weight: 600;
}

.node-type-label {
    font-family: var(--font-mono);
    background: rgba(255, 255, 255, 0.05);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
}

.node-hash-details {
    background: rgba(0, 0, 0, 0.3);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 10.5px;
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
    border: 1px solid rgba(255, 255, 255, 0.02);
    max-width: 100%;
}

.hash-row {
    display: flex;
    gap: 8px;
    font-family: var(--font-mono);
    line-height: 1.4;
}

.hash-row .lbl {
    color: var(--text-muted);
    min-width: 78px;
}

.hash-row .val {
    color: var(--text-secondary);
}

.node-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 4px;
    gap: 8px;
}

.tamper-btn {
    background: transparent;
    border: none;
    color: var(--state-error);
    opacity: 0.6;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: opacity 0.2s ease;
}

.tamper-btn:hover {
    opacity: 1;
}

/* Node flow link indicators */
.node-card::after {
    content: "↓";
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.15);
    pointer-events: none;
}

.node-card:last-child::after {
    display: none; /* No arrow below the oldest (now last in DOM order) */
}

/* Pagination bar (Verifactu hash chain) */
.chain-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.chain-pagination .page-info {
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.chain-pagination .page-info b {
    color: var(--text-primary);
    font-weight: 600;
}

.chain-pagination .page-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chain-pagination button {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    padding: 3px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.chain-pagination button:hover:not(:disabled) {
    background: rgba(6, 182, 212, 0.12);
    border-color: rgba(6, 182, 212, 0.3);
    color: var(--accent-cyan);
}

.chain-pagination button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* --- TABBED CONTAINER --- */
.tabbed-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 600px;
}

.tabs-nav {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: rgba(6, 182, 212, 0.02);
}

.tab-content {
    display: none;
    flex: 1;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* --- XML SOAP INSPECTOR --- */
.xml-inspect-subtabs {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.subtab-btn {
    padding: 4px 10px;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
}

.subtab-btn.active {
    background: rgba(6, 182, 212, 0.15);
    border-color: rgba(6, 182, 212, 0.3);
    color: var(--accent-primary);
}

.xml-editor-pane {
    background: #05070f;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    color: #38bdf8;
    flex: 1;
    max-height: 480px;
}

.xml-content {
    white-space: pre-wrap;
    word-break: break-all;
}

/* --- EVENT LOGS --- */
.log-console {
    background: #05070f;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px;
    flex: 1;
    overflow-y: auto;
    max-height: 520px;
}

.log-entries {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.log-entry {
    font-size: 12px;
    font-family: var(--font-mono);
    padding: 6px 8px;
    border-radius: 4px;
    border-left: 3px solid var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
}

.log-entry.startup { border-left-color: var(--accent-secondary); color: #93c5fd; }
.log-entry.error { border-left-color: var(--state-error); color: #fda4af; }
.log-entry.security { border-left-color: var(--state-error); background: rgba(244, 63, 94, 0.05); color: #f43f5e; font-weight: 500; }
.log-entry.register_invoice { border-left-color: var(--state-success); color: #a7f3d0; }

.log-time {
    color: var(--text-muted);
    margin-right: 6px;
}

/* --- AUDIT BANNER --- */
.audit-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
}

.audit-banner.healthy {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: var(--state-success);
}

.audit-banner.compromised {
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--state-error);
}

/* Yellow/amber state for "chain ok BUT there are rejected invoices"
   — drives the new `warning` apiStatus from /api/v1/system/audit. */
.audit-banner.warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--state-warning);
}

.audit-banner.healthy .audit-icon::before,
.audit-banner.warning .audit-icon::before,
.audit-banner.compromised .audit-icon::before {
    content: none;
}

/* --- MODAL DIALOGS --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.2s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    width: 480px;
    max-width: 90%;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

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

.modal-header h3 {
    font-size: 16px;
    color: var(--state-error);
    display: flex;
    align-items: center;
    gap: 8px;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.modal-body p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.modal-actions .btn {
    width: auto;
}

/* --- LUCIDE VECTOR ICONS --- */
.lucide {
    width: 18px;
    height: 18px;
    stroke-width: 2px;
    vertical-align: middle;
    display: inline-block;
}

.header-icon {
    width: 20px;
    height: 20px;
    stroke-width: 2px;
    vertical-align: middle;
    margin-right: 4px;
}

.icon-sm {
    width: 14px;
    height: 14px;
    stroke-width: 2px;
    vertical-align: middle;
}

.logo-symbol svg {
    width: 32px;
    height: 32px;
    stroke: var(--accent-primary);
    filter: drop-shadow(0 0 10px rgba(6, 182, 212, 0.3));
}

body.light-theme .logo-symbol svg {
    stroke: var(--accent-primary);
}

.anim-spin {
    animation: spin-anim 1s linear infinite;
}

@keyframes spin-anim {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* System header online pulse */
.status-indicator .pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--state-success);
    display: inline-block;
    box-shadow: 0 0 8px var(--state-success);
}

/* --- COMPANIES MANAGEMENT PANEL --- */
.companies-wrapper {
    height: 100%;
}

.company-admin-form {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
}

.company-admin-form h4 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--accent-primary);
}

.input-action-group {
    display: flex;
    gap: 8px;
}

.input-action-group .form-input {
    flex: 1;
}

.input-action-group .btn {
    width: auto;
    padding: 0 12px;
}

.form-actions-row {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

.form-actions-row .btn {
    width: auto;
}

.company-list-section h4 {
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.companies-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 4px;
}

/* Inside the clients modal there is plenty of vertical space, so let the list
   grow naturally. The surrounding .modal-body handles overflow at the modal
   level — having a 250px inner cap on top of that hid clients 3+ in plain
   sight (the inner scrollbar barely shows). */
#clients-modal .companies-list {
    max-height: none;
    overflow-y: visible;
}

.company-item-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    transition: all 0.2s ease;
}

.company-item-card:hover {
    border-color: rgba(6, 182, 212, 0.25);
    background: rgba(6, 182, 212, 0.03);
}

.company-item-card .card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.company-item-card .company-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.company-item-card .company-nif-badge {
    font-size: 10px;
    font-family: var(--font-mono);
    background: rgba(6, 182, 212, 0.15);
    color: var(--accent-primary);
    padding: 2px 6px;
    border-radius: 4px;
}

.company-item-card .detail-row {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.company-item-card .detail-row .value {
    font-family: var(--font-mono);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}

.btn-copy-api {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 11px;
    margin-left: 4px;
    transition: transform 0.1s ease;
}

.btn-copy-api:active {
    transform: scale(0.9);
}

.company-item-card .actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.company-item-card .invoice-indicator {
    font-size: 11px;
    color: var(--state-success);
    font-weight: 500;
}

.company-item-card .btn-edit {
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
}

.company-item-card .btn-edit:hover {
    background: rgba(6, 182, 212, 0.15);
    border-color: var(--accent-primary);
}

/* --- LIGHT THEME STYLE OVERRIDES --- */
body.light-theme {
    background-color: #f8fafc;
    background-image: 
        radial-gradient(at 0% 0%, rgba(89, 185, 232, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(129, 140, 248, 0.06) 0px, transparent 50%);
    
    --bg-main: #f8fafc;
    --bg-surface: rgba(255, 255, 255, 0.85);
    --bg-surface-hover: rgba(243, 244, 246, 0.95);
    --border-color: rgba(0, 0, 0, 0.08);
    --border-glow: rgba(89, 185, 232, 0.3);
    
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    --accent-primary: #59b9e8;     /* Sky Blue */
    --accent-secondary: #3e92ba;   /* Blue Dark */
    --accent-purple: #818cf8;      /* Indigo Accent */
}

body.light-theme .xml-editor-pane {
    background: #f8fafc;
    border-color: var(--border-color);
    color: #0369a1;
}

body.light-theme .log-console {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
}

body.light-theme .log-entries {
    color: #334155;
}

body.light-theme .form-input, 
body.light-theme .form-select,
body.light-theme #company-form-aeat-env {
    background: rgba(255, 255, 255, 0.8) !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    color: #1e293b !important;
}

body.light-theme .form-input:focus, 
body.light-theme .form-select:focus,
body.light-theme #company-form-aeat-env:focus {
    background: #fff !important;
    border-color: var(--accent-primary) !important;
}

body.light-theme .company-admin-form {
    background: rgba(0, 0, 0, 0.015);
}

body.light-theme .profile-details {
    background: rgba(0, 0, 0, 0.02);
}

body.light-theme .metric-pill {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0,0,0,0.08);
}

body.light-theme .separator {
    border-color: rgba(0, 0, 0, 0.08);
}

body.light-theme .node-card {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(0, 0, 0, 0.08);
}

body.light-theme .node-card:hover {
    background: #fff;
    border-color: var(--accent-primary);
}

body.light-theme .modal-content {
    background: #f8fafc;
    color: #1e293b;
    border-color: rgba(0,0,0,0.15);
}

body.light-theme .close-btn {
    color: #475569;
}

body.light-theme .audit-banner.healthy {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
    color: #065f46;
}

body.light-theme .btn-copy-api {
    filter: invert(0.2);
}

/* --- CREA Y CRECE (SPFE) EXTRA STYLES --- */
.subtabs-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 6px;
}

body.light-theme .subtabs-nav {
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

.monitor-subtab-btn {
    background: none;
    border: none;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
    border-radius: 4px 4px 0 0;
}

.monitor-subtab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
}

body.light-theme .monitor-subtab-btn:hover {
    background: rgba(0, 0, 0, 0.02);
}

.monitor-subtab-btn.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: rgba(6, 182, 212, 0.05);
}

body.light-theme .monitor-subtab-btn.active {
    background: rgba(6, 182, 212, 0.03);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.85rem;
}

.data-table th {
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.15);
}

body.light-theme .data-table th {
    background: rgba(0, 0, 0, 0.03);
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: rgba(255, 255, 255, 0.01);
}

body.light-theme .data-table tr:hover td {
    background: rgba(0, 0, 0, 0.01);
}

