:root {
    /* Color Palette */
    --bg-color: #080808;
    --surface-color: #121212;
    --surface-light: #1e1e1e;
    --accent-color: #f2b90d;
    --accent-gradient: linear-gradient(135deg, #f2b90d 0%, #b88b0b 100%);
    --accent-hover: #ffffff;
    --text-primary: #ffffff;
    --text-secondary: #e6e6e6;
    --text-muted: #b3b3b3;

    /* Semantic Colors */
    --color-emergency: #ff4d4d;
    --color-functional: #ffcc00;
    --color-aesthetic: #00f2ff;

    /* Typography */
    --font-main: 'Inter', sans-serif;
    --font-heading: 'Outfit', sans-serif;

    /* Spacing & Borders */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --border-premium: 1px solid rgba(255, 255, 255, 0.08);
    --shadow-premium: 0 10px 30px rgba(0, 0, 0, 0.4);
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

input,
select,
textarea {
    background-color: var(--surface-light);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 15px;
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
}

select option {
    background-color: #1a1a1a;
    color: white;
}

h1,
h2,
h3,
h4 {
    font-family: var(--font-heading);
    font-weight: 700;
}

/* App Container */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Loader */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 20px;
}

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid var(--surface-light);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Layout Components */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    min-width: 0;
    /* Prevent overflow */
}

/* Cards & Buttons */
.card {
    background: var(--surface-color);
    border-radius: var(--radius-md);
    padding: 24px;
    border: var(--border-premium);
    box-shadow: var(--shadow-premium);
    margin-bottom: 24px;
    transition: var(--transition);
}

.card:hover {
    border-color: rgba(242, 185, 13, 0.4);
    background: #181818;
    transform: translateY(-2px);
}

/* KPI Active Status */
.card.active-kpi {
    background: rgba(42, 42, 42, 0.3) !important;
    border-color: var(--accent-color) !important;
    box-shadow: 0 0 20px rgba(242, 185, 13, 0.1), inset 0 0 10px rgba(242, 185, 13, 0.05);
    transform: translateY(-2px);
}

.card.active-kpi h2 {
    color: var(--accent-color);
}

/* Action Pill Bar */
.action-pill-bar {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    background: rgba(0, 0, 0, 0.3);
    padding: 12px 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.action-pill-label {
    font-size: 0.6rem;
    color: var(--accent-color);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border-right: 1px solid rgba(255, 255, 255, 0.15);
    padding-right: 15px;
    line-height: 1.2;
    white-space: nowrap;
}

.admin-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    width: 100%;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 22px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-size: 0.85rem;
    font-family: var(--font-heading);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.btn-full {
    width: 100%;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #000;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(242, 185, 13, 0.2);
}

.btn-outline {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
}

.btn-outline:hover {
    border-color: var(--accent-color);
    color: white;
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 255, 255, 0.05);
}

/* Header */
.header {
    margin-bottom: 48px;
}

/* Status Badges */
.badge {
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-emergency {
    background: rgba(255, 59, 59, 0.15);
    color: #ff3b3b;
    border: 1px solid rgba(255, 59, 59, 0.2);
}

.badge-functional {
    background: rgba(255, 204, 0, 0.15);
    color: #ffcc00;
    border: 1px solid rgba(255, 204, 0, 0.2);
}

.badge-aesthetic {
    background: rgba(0, 242, 255, 0.15);
    color: #00f2ff;
    border: 1px solid rgba(0, 242, 255, 0.2);
}

/* UI Patterns */
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flex-center {
    display: flex;
    justify-content: center;
    align-items: center;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 32px;
}

.grid-1-2 {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 32px;
}

.user-management-grid {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.grid-3>*,
.grid-4>*,
.grid-2>*,
.grid-2-1>*,
.grid-1-2>*,
.user-management-grid>*,
.responsive-grid>* {
    min-width: 0;
    /* Critical for preventing grid item overflow */
}

.table-container {
    overflow-x: auto;
    background: var(--surface-color);
    border-radius: var(--radius-md);
    border: var(--border-premium);
    box-shadow: var(--shadow-premium);
}

/* Responsive Handling */
@media (max-width: 1024px) {

    .grid-3,
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {

    .responsive-grid,
    .user-management-grid,
    .grid-3,
    .grid-4,
    .grid-2,
    .grid-2-1,
    .grid-1-2 {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }

    /* Prevent iOS auto-zoom on focus */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    .container {
        padding: 16px;
    }

    h1 {
        font-size: 2rem !important;
    }

    h2 {
        font-size: 1.5rem !important;
    }

    .btn {
        padding: 8px 16px;
        font-size: 0.75rem;
    }

    /* Table Responsiveness */
    .table-ziel {
        display: block;
        width: 100%;
        max-width: calc(100vw - 32px);
        /* respect container padding */
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    /* Mobile Header/Nav Fixes */
    nav {
        padding: 20px 5% !important;
    }

    .hero-title {
        font-size: 2.2rem !important;
        line-height: 1.2 !important;
    }

    .landing-hero {
        height: auto !important;
        min-height: 100svh !important;
        padding: 100px 5% !important;
    }

    .header-title-section {
        margin-top: 20px !important;
        padding-left: 15px !important;
    }

    .header-title-section h1 {
        font-size: 1.5rem !important;
    }

    .header-title-section p {
        font-size: 0.65rem !important;
        letter-spacing: 1px !important;
    }

    /* Tabs handling for mobile */
    .tabs {
        overflow-x: auto;
        white-space: nowrap;
        gap: 20px;
        padding-bottom: 10px;
        scrollbar-width: none;
        /* Firefox */
    }

    .tabs::-webkit-scrollbar {
        display: none;
        /* Chrome/Safari */
    }

    .tab {
        padding: 10px 0;
        flex: 0 0 auto;
    }

    /* Header Mobile Optimization */
    .header-top {
        flex-direction: column;
        gap: 20px;
        align-items: flex-start !important;
        padding-bottom: 20px !important;
    }

    .header-nav-container {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 15px !important;
        width: 100%;
    }

    .header-nav-container nav {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px !important;
    }

    .header-nav-container nav .btn {
        width: 100%;
        font-size: 0.75rem;
        padding: 12px 10px;
        text-align: center;
    }

    .header-user-panel {
        width: 100%;
        justify-content: space-between !important;
        flex-wrap: wrap;
        border-top: 1px solid rgba(255, 255, 255, 0.05);
        padding-top: 15px;
    }

    .header-user-info {
        text-align: left !important;
    }

    /* Adjust Property Switcher for space */
    .property-switcher {
        max-width: 120px;
    }

    .action-pill-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .action-pill-label {
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.15);
        padding-right: 0;
        padding-bottom: 10px;
        text-align: center;
        white-space: normal;
    }

    .mobile-stack {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
    }
}

/* Modal Overlay Fix */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

.modal-content {
    background: var(--surface-color);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade {
    animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Tables */
.table-ziel {
    width: 100%;
    border-collapse: collapse;
}

.table-ziel th {
    text-align: left;
    padding: 16px;
    font-size: 0.75rem;
    color: #c0c0c0;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--surface-light);
}

.table-ziel td {
    padding: 16px;
    border-bottom: 1px solid var(--surface-light);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 32px;
    border-bottom: 1px solid var(--surface-light);
    margin-bottom: 32px;
}

.tab {
    padding: 16px 0;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}

.tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* Print Mode for Technical Reports */
@media print {
    @page {
        size: A4;
        margin: 1.5cm;
    }

    body {
        background: white !important;
        color: black !important;
        font-size: 11pt;
    }

    header,
    nav,
    .btn,
    .no-print,
    .action-pill-bar,
    aside {
        display: none !important;
    }

    .container {
        width: 100% !important;
        max-width: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .card {
        background: white !important;
        border: 1px solid #eee !important;
        box-shadow: none !important;
        break-inside: avoid;
        padding: 1.5rem !important;
        margin-bottom: 2rem !important;
    }

    h1,
    h2,
    h3 {
        color: #b88b0b !important;
        page-break-after: avoid;
    }

    .badge {
        border: 1px solid #000 !important;
        color: black !important;
        background: transparent !important;
    }

    img {
        max-width: 100% !important;
        height: auto !important;
        page-break-inside: avoid;
    }

    .tech-report-isotype {
        display: block !important;
        text-align: center;
        margin-bottom: 40px;
    }

    .footer-print {
        display: block !important;
        position: fixed;
        bottom: 0;
        width: 100%;
        font-size: 8pt;
        color: #999;
        text-align: center;
        border-top: 1px solid #eee;
        padding-top: 10px;
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(1.2);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Responsive Management Table */
.user-management-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    align-items: start;
}

@media (max-width: 768px) {
    .table-ziel thead {
        display: none;
    }

    .table-ziel tr {
        display: block;
        margin-bottom: 25px;
        background: rgba(255, 255, 255, 0.02);
        border-radius: 12px;
        padding: 15px;
        border: 1px solid rgba(255, 255, 255, 0.06);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }

    .table-ziel td {
        display: flex;
        flex-direction: column;
        align-items: flex-start !important;
        padding: 10px 0 !important;
        border: none;
        text-align: left;
        font-size: 0.85rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    }

    .table-ziel td:last-child {
        border-bottom: none;
        padding-top: 15px !important;
    }

    .table-ziel td::before {
        content: attr(data-label);
        font-weight: 800;
        color: var(--accent-color);
        text-transform: uppercase;
        font-size: 0.6rem;
        letter-spacing: 1px;
        margin-bottom: 8px;
        opacity: 0.7;
    }

    .table-ziel td>div,
    .table-ziel td>span {
        width: 100%;
    }

    .mobile-stack {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .mobile-stack .btn {
        width: 100% !important;
        padding: 12px !important;
    }
}

/* --- FIX DE IMPRESIÓN (EVITA PANTALLA NEGRA Y RESPETA COLORES) --- */
@media print {
    :root {
        --bg-color: #ffffff !important;
        --surface-color: #f7f7f7 !important;
        --surface-light: #ffffff !important;
        --text-primary: #000000 !important;
        --text-secondary: #333333 !important;
        --text-muted: #666666 !important;
    }

    html,
    body,
    #app {
        background-color: #ffffff !important;
        color: #000000 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .no-print {
        display: none !important;
    }

    .card,
    .container,
    .print-mode-fix {
        background: #ffffff !important;
        border: none !important;
        box-shadow: none !important;
        color: #000000 !important;
        page-break-inside: avoid;
    }

    h1,
    h2,
    h3,
    h4,
    p,
    span,
    div {
        text-shadow: none !important;
        box-shadow: none !important;
    }

    h1,
    h2,
    h3,
    h4 {
        color: #b88b0b !important;
    }

    table,
    tr,
    td,
    th {
        border-bottom: 1px solid #ddd !important;
        background: white !important;
        color: black !important;
    }

    img {
        filter: none !important;
        opacity: 1 !important;
    }

    /* Asegurar que las marcas (verde/rojo) en el canvas mantengan su color (las renderizadas por inline css prevalecen, esto evita que el texto se vuelva negro sobre ellas) */
    .print-mode-fix div[style*="border-radius"] {
        color: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        box-shadow: none !important;
    }
}