:root {
    --color-primary: #0f172a;
    --color-secondary: #b45309;
    --color-tertiary: #334155;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #dbe2ea;
    --color-text: #111827;
    --color-text-muted: #64748b;
    --color-danger: #dc2626;
    --color-warning: #c2410c;
    --color-success: #0f766e;
    --shadow-soft: 0 16px 40px rgba(15, 23, 42, 0.06);
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --sidebar-width: 288px;
    --font-sans: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
}

body {
    min-height: 100vh;
}

.auth-body {
    background:
        radial-gradient(circle at top left, rgba(180, 83, 9, 0.18), transparent 36%),
        linear-gradient(135deg, #eef3f7 0%, #f8fafc 48%, #eef2f7 100%);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.auth-shell {
    display: grid;
    grid-template-columns: minmax(320px, 1.15fr) minmax(320px, 520px);
    align-items: stretch;
    min-height: 100vh;
}

.auth-brand-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1.25rem;
    padding: 3rem 4rem;
    background: linear-gradient(180deg, #002b6b 0%, #001d4a 50%, #000d1f 100%);
    color: #fff;
}

.auth-brand-panel h1 {
    margin: 0;
    font-size: clamp(2.4rem, 4vw, 4.5rem);
    line-height: 0.95;
}

.auth-brand-panel p {
    margin: 0;
    max-width: 36rem;
    color: rgba(255, 255, 255, 0.78);
}

.auth-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 2.5rem;
}

.auth-form-header h2 {
    margin: 0;
    font-size: 2rem;
}

.auth-form-header p,
.auth-hint {
    color: var(--color-text-muted);
}

.auth-kpis {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.auth-kpis article {
    padding: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
}

.auth-kpis strong,
.auth-kpis span {
    display: block;
}


/* Logo en sidebar */
.sidebar-logo {
    padding: 1rem 0.75rem 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.25rem;
}
.sidebar-logo img {
    width: 100%;
    max-width: 133px;
    height: auto;
    display: block;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem 1rem;
    border-right: 1px solid rgba(219, 226, 234, 0.9);
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.25rem 0.5rem;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
}

.brand strong,
.brand span {
    display: block;
}

.sidebar-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 0.875rem 1rem;
    border-radius: 12px;
    background: #fb923c;
    color: #fff;
    font-weight: 700;
}

.sidebar-nav {
    display: grid;
    gap: 0.35rem;
}

.nav-item {
    padding: 0.9rem 1rem;
    border-radius: 12px;
    color: var(--color-text-muted);
    font-weight: 600;
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.15s ease;
}

.nav-item:hover:not(.nav-item-active) {
    background: rgba(37, 99, 235, 0.08);
    color: #1d4ed8;
    transform: translateX(4px);
    box-shadow: inset 3px 0 0 #2563eb;
}

.nav-item-active {
    background: #ffffff;
    color: var(--color-primary);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

.sidebar-footer {
    display: grid;
    gap: 0.85rem;
    margin-top: auto;
    padding: 1rem 0.5rem 0;
    border-top: 1px solid var(--color-border);
    color: var(--color-text-muted);
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.25rem 1.5rem 2rem;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.sidebar-toggle {
    display: none;
    min-height: 44px;
    padding: 0 0.95rem;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: #fff;
    color: var(--color-primary);
}

.search-box {
    flex: 1;
    max-width: 520px;
}

.search-box input {
    width: 100%;
    height: 48px;
    padding: 0 1rem;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: #fff;
    color: var(--color-text);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 42px;
    padding: 0 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: #fff;
    color: var(--color-primary);
    font-weight: 700;
}

.topbar-pill span {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 0.8rem;
}

.icon-button,
.profile-chip {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: #fff;
    color: var(--color-primary);
    cursor: pointer;
}

.profile-chip {
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
}

.eyebrow {
    margin: 0 0 0.35rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.page-header h1 {
    margin: 0;
    font-size: clamp(2rem, 3vw, 2.75rem);
    line-height: 1.05;
}

.page-copy {
    max-width: 760px;
    margin: 0.6rem 0 0;
    color: var(--color-text-muted);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 1.15rem;
    border: 1px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
}

.button-primary {
    background: #111111;
    color: #fff;
}

.button-secondary {
    background: #fff;
    border-color: var(--color-border);
    color: var(--color-primary);
}

.button-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.button-block {
    width: 100%;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.kpi-card,
.panel {
    padding: 1.2rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
}

.kpi-label {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.kpi-value {
    display: block;
    margin: 0.45rem 0;
    font-size: 2.15rem;
    line-height: 1;
}

.kpi-trend {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.kpi-principal {
    background: #dbeafe;
    color: #1d4ed8;
}

.kpi-critico {
    background: #fee2e2;
    color: #b91c1c;
}

.kpi-secundario {
    background: #ffedd5;
    color: #c2410c;
}

.kpi-terciario {
    background: #e2e8f0;
    color: #334155;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
    gap: 1rem;
}

.content-grid-bottom {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel-wide {
    min-width: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.panel-header a {
    color: var(--color-text-muted);
    font-weight: 600;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.9rem 0.65rem;
    text-align: left;
    border-bottom: 1px solid #edf2f7;
    vertical-align: middle;
}

.compact-table th,
.compact-table td {
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
}

.table-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.form-grid {
    display: grid;
    gap: 1rem;
}

.form-section {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.form-field {
    display: grid;
    gap: 0.45rem;
}

.form-field-full {
    grid-column: 1 / -1;
}

.form-field label {
    color: var(--color-text-muted);
    font-size: 0.92rem;
    font-weight: 700;
}

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    min-height: 48px;
    padding: 0.9rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: #fff;
    color: var(--color-text);
}

.form-field textarea {
    min-height: 128px;
    resize: vertical;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
}

.link-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--color-primary);
    cursor: pointer;
    font-weight: 700;
}

.danger {
    color: #b91c1c;
}

.text-muted {
    color: var(--color-text-muted);
}

.stack-lg {
    display: grid;
    gap: 1rem;
}

.alert {
    margin-bottom: 1rem;
    padding: 0.95rem 1rem;
    border-radius: 14px;
    border: 1px solid transparent;
    font-weight: 600;
}

.alert-success {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}

.alert-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.data-table th {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.28rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 800;
}

.badge-danger {
    background: #fee2e2;
    color: var(--color-danger);
}

.badge-warning {
    background: #ffedd5;
    color: var(--color-warning);
}

.badge-muted {
    background: #e5e7eb;
    color: #4b5563;
}

.metric-list {
    display: grid;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.metric-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 0;
    border-bottom: 1px solid #edf2f7;
}

.metric-list li:last-child {
    border-bottom: 0;
}

.metric-list span {
    color: var(--color-text-muted);
}


/* Auth: botón naranja */
.auth-card .button-primary {
    background: #f5821f;
    color: #ffffff;
}
.auth-card .button-primary:hover {
    background: #e0720e;
}

/* Auth: logo centrado */

.auth-form-logo span {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Auth: logo + nombre en panel izquierdo */
.auth-brand-logo-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}
.auth-brand-name strong,
.auth-brand-name span {
    display: block;
}
.auth-brand-name strong {
    font-size: 1.05rem;
    color: #fff;
}
.auth-brand-name span {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.65);
}







/* Logo centrado en panel derecho */
.auth-form-logo {
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 0;
    margin-bottom: 2rem;
}
.auth-form-logo img {
    width: 200px;
    max-width: 100%;
}

@media (max-width: 1100px) {
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .content-grid {
        grid-template-columns: 1fr;
    }

    .content-grid-bottom {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-brand-panel {
        padding: 2rem 1.25rem;
    }

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

    
/* Logo en sidebar */
.sidebar-logo {
    padding: 1rem 0.75rem 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.25rem;
}
.sidebar-logo img {
    width: 100%;
    max-width: 133px;
    height: auto;
    display: block;
}

.sidebar {
        gap: 1rem;
        border-right: 0;
        border-bottom: 1px solid var(--color-border);
        display: none;
    }

    .sidebar.sidebar-open {
        display: flex;
    }

    .page-header,
    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 580px) {
    .main-content {
        padding: 1rem;
    }

    
/* Logo en sidebar */
.sidebar-logo {
    padding: 1rem 0.75rem 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.25rem;
}
.sidebar-logo img {
    width: 100%;
    max-width: 133px;
    height: auto;
    display: block;
}

.sidebar {
        padding: 1rem;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 1rem;
    }

    .auth-kpis {
        grid-template-columns: 1fr;
    }

    .data-table {
        display: block;
        overflow-x: auto;
    }

    .form-section {
        grid-template-columns: 1fr;
    }

    .button-row,
    .table-actions {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Info cards normativas */
.info-card {
    background: var(--color-bg-subtle, #f8fafc);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1rem;
    font-size: 0.85rem;
}
.info-card strong {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    color: var(--color-text);
}
.info-card p {
    color: var(--color-text-muted);
    margin: 0;
    line-height: 1.5;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2em 0.55em;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
}
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-green  { background: #dcfce7; color: #166534; }

/* Normativa autodetectada en formulario activos */
.normativa-alert {
    border: 1px solid #bfdbfe;
    border-left: 4px solid #2563eb;
    border-radius: 10px;
    background: #eff6ff;
    padding: 0.875rem 1rem;
    font-size: 0.85rem;
}
.normativa-alert-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.normativa-alert-header strong {
    font-size: 0.9rem;
    color: #1e40af;
}
.normativa-alert-body > div {
    margin-bottom: 0.25rem;
    color: #374151;
}
.norm-label {
    font-weight: 600;
    color: #1e40af;
}
.norm-info {
    margin-top: 0.5rem;
    color: #6b7280;
    font-style: italic;
}

/* ============================
   CALENDARIO DE MANTENIMIENTO
   ============================ */
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-left: 1px solid var(--color-border);
    border-top: 1px solid var(--color-border);
}
.cal-header-cell {
    background: var(--color-bg-subtle, #f8fafc);
    padding: 0.5rem;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--color-text-muted);
    border-right: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cal-cell {
    min-height: 90px;
    padding: 0.35rem 0.4rem;
    border-right: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
    font-size: 0.78rem;
}
.cal-cell-empty {
    background: #fafafa;
}
.cal-today {
    background: #eff6ff;
}
.cal-has-events {
    background: #fefce8;
}
.cal-today.cal-has-events {
    background: #dbeafe;
}
.cal-day-num {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 0.25rem;
    line-height: 1;
}
.cal-day-today {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: #2563eb;
    color: #fff;
    border-radius: 50%;
    font-size: 0.78rem;
}
.cal-event {
    display: flex;
    flex-direction: column;
    border-radius: 5px;
    padding: 0.2rem 0.35rem;
    margin-bottom: 0.2rem;
    cursor: default;
    font-size: 0.72rem;
    line-height: 1.3;
}
.cal-event-pendiente  { background: #ffedd5; border-left: 3px solid #f97316; }
.cal-event-generada   { background: #dbeafe; border-left: 3px solid #2563eb; }
.cal-event-completada { background: #dcfce7; border-left: 3px solid #16a34a; }
.cal-event-omitida    { background: #f1f5f9; border-left: 3px solid #94a3b8; }
.cal-event-code {
    font-weight: 700;
    font-size: 0.68rem;
    color: #374151;
}
.cal-event-name {
    color: #4b5563;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-legend {
    display: flex;
    gap: 1.25rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    flex-wrap: wrap;
}
.cal-legend span {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.cal-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* Print styles para listado */
@media print {
    .sidebar, .topbar, .page-header .button, form { display: none !important; }
    .main-content { margin: 0 !important; padding: 0 !important; }
    .panel { box-shadow: none !important; border: 1px solid #ddd !important; }
    #tabla-listado { font-size: 0.75rem; }
}

/* ========================
   OFFLINE / PWA UI
   ======================== */
#offline-banner {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 9999;
    background: #92400e;
    color: #fff;
    padding: 0.55rem 1.25rem;
    font-size: 0.82rem;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
#offline-banner #offline-sync-btn {
    margin-left: auto;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.5);
    color: #fff;
    border-radius: 6px;
    padding: 0.25rem 0.75rem;
    cursor: pointer;
    font-size: 0.8rem;
}
#offline-banner #offline-sync-btn:hover {
    background: rgba(255,255,255,0.35);
}
body.app-offline {
    padding-top: 36px;
}

/* Dot de conexion en topbar */
.conn-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.25rem;
    flex-shrink: 0;
}
.conn-online  { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,0.25); }
.conn-offline { background: #ef4444; box-shadow: 0 0 0 2px rgba(239,68,68,0.25); animation: pulse-red 1.5s infinite; }

@keyframes pulse-red {
    0%,100% { box-shadow: 0 0 0 2px rgba(239,68,68,0.25); }
    50%      { box-shadow: 0 0 0 5px rgba(239,68,68,0.1); }
}

/* Botón sync en topbar */
#topbar-sync-btn {
    display: none;
    align-items: center;
    gap: 0.4rem;
    background: #f97316;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
#topbar-sync-btn:hover { background: #ea580c; }
#topbar-sync-badge {
    display: none;
    background: #fff;
    color: #f97316;
    border-radius: 50%;
    width: 17px;
    height: 17px;
    font-size: 0.68rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
}

/* Toast notifications */
.gmao-toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 10000;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 360px;
}
.gmao-toast.gmao-toast-show { transform: translateY(0); opacity: 1; }
.gmao-toast-success { background: #16a34a; }
.gmao-toast-warn    { background: #d97706; }
.gmao-toast-error   { background: #dc2626; }
.gmao-toast-info    { background: #2563eb; }
