/* ============================================================
   VARIABLES Y RESET
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=Syne:wght@700;800&display=swap');

:root {
    --color-bg:         #F5F4F0;
    --color-surface:    #FFFFFF;
    --color-border:     #E2E0D8;
    --color-text:       #1A1916;
    --color-muted:      #7A7870;
    --color-primary:    #2D5016;
    --color-primary-h:  #3D6B1F;
    --color-accent:     #C8E06B;
    --color-danger:     #C0392B;
    --color-warning:    #E67E22;
    --color-success:    #27AE60;
    --color-info:       #2980B9;

    --radius:     10px;
    --radius-lg:  16px;
    --shadow-sm:  0 1px 4px rgba(0,0,0,0.06);
    --shadow-md:  0 4px 16px rgba(0,0,0,0.10);
    --shadow-lg:  0 8px 32px rgba(0,0,0,0.14);

    --font-body:    'DM Sans', sans-serif;
    --font-display: 'Syne', sans-serif;

    --transition: 0.2s ease;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
ul { list-style: none; }

/* ============================================================
   TIPOGRAFÍA
   ============================================================ */
h1, h2, h3, h4 {
    font-family: var(--font-display);
    line-height: 1.2;
}

h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { font-size: clamp(1.4rem, 3vw, 2rem); }
h3 { font-size: 1.2rem; }

/* ============================================================
   LAYOUT
   ============================================================ */
.app-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.main-content {
    flex: 1;
    padding: 2rem 0 4rem;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.header-brand {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--color-primary);
    letter-spacing: -0.5px;
}

.header-brand span {
    color: var(--color-accent);
    background: var(--color-primary);
    padding: 2px 8px;
    border-radius: 6px;
    margin-right: 6px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-user .user-info {
    text-align: right;
}

.header-user .user-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.header-user .user-role {
    font-size: 0.75rem;
    color: var(--color-muted);
    text-transform: capitalize;
}

.badge-role {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-role.superadmin { background: #1A1916; color: #C8E06B; }
.badge-role.admin     { background: #EAF5D8; color: var(--color-primary); }
.badge-role.supervisor { background: #D6EAF8; color: #154360; }
.badge-role.operario   { background: #FDEBD0; color: #784212; }

/* ============================================================
   PÁGINA: título de sección
   ============================================================ */
.page-title {
    margin-bottom: 2rem;
}

.page-title h1 {
    color: var(--color-text);
}

.page-title p {
    color: var(--color-muted);
    margin-top: 0.3rem;
    font-size: 0.95rem;
}

/* ============================================================
   CARDS DE MÓDULOS (index)
   ============================================================ */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
}

.module-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.75rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
}

.module-card::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--card-accent, var(--color-primary));
    transform: scaleX(0);
    transition: transform var(--transition);
}

.module-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--card-accent, var(--color-primary));
}

.module-card:hover::before {
    transform: scaleX(1);
}

.module-card .card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    background: var(--card-bg-icon, #EAF5D8);
}

.module-card .card-label {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
}

.module-card .card-desc {
    font-size: 0.82rem;
    color: var(--color-muted);
    line-height: 1.4;
}

/* Sección de módulos */
.modules-section {
    margin-bottom: 2.5rem;
}

.modules-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-muted);
    margin-bottom: 0.9rem;
    padding-left: 2px;
}

/* ============================================================
   ALERTAS Y MENSAJES
   ============================================================ */
.alert {
    padding: 0.85rem 1.2rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
    border: 1px solid transparent;
}

.alert-danger  { background: #FDEDEC; color: #922B21; border-color: #F1948A; }
.alert-success { background: #EAFAF1; color: #1E8449; border-color: #82E0AA; }
.alert-warning { background: #FEF9E7; color: #9A7D0A; border-color: #F7DC6F; }
.alert-info    { background: #EBF5FB; color: #1A5276; border-color: #85C1E9; }

/* ============================================================
   FORMULARIOS
   ============================================================ */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--color-text);
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: var(--font-body);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(45, 80, 22, 0.12);
}

.form-control::placeholder { color: var(--color-muted); }

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.4rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    border: none;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    text-decoration: none;
}

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

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}
.btn-primary:hover { background: var(--color-primary-h); box-shadow: var(--shadow-sm); }

.btn-outline {
    background: transparent;
    color: var(--color-primary);
    border: 1.5px solid var(--color-primary);
}
.btn-outline:hover { background: var(--color-primary); color: #fff; }

.btn-danger  { background: var(--color-danger);  color: #fff; }
.btn-danger:hover  { background: #A93226; }

.btn-sm { padding: 0.4rem 0.9rem; font-size: 0.82rem; }
.btn-full { width: 100%; }

/* ============================================================
   TABLAS
   ============================================================ */
.table-wrapper {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table thead th {
    background: var(--color-bg);
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--color-border);
    transition: background var(--transition);
}

.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--color-bg); }

.data-table tbody td {
    padding: 0.85rem 1rem;
    color: var(--color-text);
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.8rem;
    color: var(--color-muted);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}

/* ============================================================
   ALERTAS FLASH
   ============================================================ */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
    border: 1px solid transparent;
    animation: flashIn 0.3s ease;
}

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

.alert-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }

.alert-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.5;
    padding: 0 0 0 0.5rem;
    flex-shrink: 0;
    transition: opacity var(--transition);
}
.alert-close:hover { opacity: 1; }

.alert-success { background: #EAFAF1; color: #1E8449; border-color: #A9DFBF; }
.alert-error   { background: #FDEDEC; color: #922B21; border-color: #F1948A; }
.alert-warning { background: #FEF9E7; color: #9A7D0A; border-color: #F7DC6F; }
.alert-info    { background: #EBF5FB; color: #1A5276; border-color: #85C1E9; }

/* Auto-dismiss con JS — clase para animar salida */
.alert.hiding {
    animation: flashOut 0.3s ease forwards;
}

@keyframes flashOut {
    from { opacity: 1; transform: translateY(0); max-height: 100px; }
    to   { opacity: 0; transform: translateY(-8px); max-height: 0; margin: 0; padding: 0; }
}

/* ============================================================
   RESPONSIVE — módulos grid
   ============================================================ */
@media (max-width: 1024px) {
    .modules-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
    .modules-grid { grid-template-columns: repeat(2, 1fr); }
    .module-card  { padding: 1.25rem 1rem; }
    .module-card .card-icon { width: 40px; height: 40px; font-size: 1.2rem; }
    .module-card .card-label { font-size: 0.92rem; }
}
@media (max-width: 480px) {
    .modules-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
    .module-card  { padding: 1rem 0.85rem; gap: 0.5rem; }
    .module-card .card-desc { display: none; }
}

/* ============================================================
   PAGE HEADER (cabecera con botón volver)
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 2rem;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-muted);
    padding: 0.4rem 0;
    white-space: nowrap;
    margin-top: 0.35rem;
    transition: color var(--transition);
}
.btn-back:hover { color: var(--color-text); }

/* ============================================================
   SETTINGS CARD
   ============================================================ */
.settings-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.settings-card-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}

.settings-card-header .settings-icon {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
}

.settings-card-header h3 {
    font-size: 1.05rem;
    margin-bottom: 0.25rem;
}

.settings-card-header p {
    font-size: 0.85rem;
    color: var(--color-muted);
    line-height: 1.5;
}

.settings-card-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Toggle row */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.toggle-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle-label {
    font-weight: 500;
    font-size: 0.95rem;
}

.badge-status {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge-status.active   { background: #EAFAF1; color: #1E8449; }
.badge-status.inactive { background: #F2F3F4; color: var(--color-muted); }

/* Notice */
.settings-notice {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    font-size: 0.85rem;
    color: var(--color-muted);
    line-height: 1.5;
}

/* ============================================================
   FORMULARIOS — secciones y grid
   ============================================================ */
.form-section {
    padding: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.form-section:last-of-type { border-bottom: none; }

.form-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-muted);
    margin-bottom: 1.1rem;
}

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

.form-col-2 { grid-column: span 2; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
}

@media (max-width: 600px) {
    .form-grid-2  { grid-template-columns: 1fr; }
    .form-col-2   { grid-column: span 1; }
    .toggle-row   { flex-direction: column; align-items: flex-start; }
    .page-header  { flex-direction: column; gap: 0.5rem; }
}

/* ============================================================
   BADGE IGIC
   ============================================================ */
.badge-igic {
    display: inline-block;
    background: #EAF5D8;
    color: var(--color-primary);
    border: 1px solid #C5E0A0;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 700;
    font-family: var(--font-display);
    letter-spacing: 0.3px;
}

/* ============================================================
   MODALES
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

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

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal.modal-sm { max-width: 380px; }

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

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

.modal-header h3 {
    font-size: 1.05rem;
    font-family: var(--font-display);
}

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

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

.modal-body .form-group:last-child { margin-bottom: 0; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    flex-shrink: 0;
}

/* ============================================================
   ACCIONES EN TABLA
   ============================================================ */
.table-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: nowrap;
    white-space: nowrap;
}

/* Columna de acciones nunca hace wrap */
.data-table td:last-child {
    white-space: nowrap;
}

.btn-warning {
    background: #F39C12;
    color: #fff;
}
.btn-warning:hover { background: #D68910; }

/* ============================================================
   FILTROS / FILTER BAR
   ============================================================ */
.filter-bar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.filter-form {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 130px;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-muted);
}

.form-control-sm {
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding-top: 1.1rem;
}

/* ============================================================
   BADGES AUDITORÍA
   ============================================================ */
.badge-auditoria {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-modulo {
    display: inline-block;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: 2px 9px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 500;
}

/* ============================================================
   PAGINACIÓN
   ============================================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.6rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    transition: background var(--transition), border-color var(--transition), color var(--transition);
    text-decoration: none;
}

.page-btn:hover {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.page-btn.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    font-weight: 700;
}

.page-dots {
    color: var(--color-muted);
    font-size: 0.9rem;
    padding: 0 0.2rem;
}

/* ============================================================
   BADGE DÍAS (formas de pago)
   ============================================================ */
.badge-dias {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}
.badge-dias.inmediato { background: #EAFAF1; color: #1E8449; }
.badge-dias.diferido  { background: #FDEBD0; color: #784212; }

/* ============================================================
   RESPONSIVE GLOBAL — móvil
   ============================================================ */
@media (max-width: 600px) {
    /* Header compacto */
    .header-brand { font-size: 1.1rem; }
    .header-user .user-info { display: none; }
    .app-header { padding: 0 1rem; }

    /* Contenido */
    .container { padding: 0 1rem; }
    .main-content { padding: 1.25rem 0 3rem; }

    /* Page header apilado */
    .page-header {
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 1.25rem;
    }
    .page-header > div[style*="margin-left:auto"] {
        margin-left: 0 !important;
        width: 100%;
    }
    .page-header > div[style*="margin-left:auto"] .btn {
        width: 100%;
        justify-content: center;
    }

    /* Títulos */
    .page-title h1 { font-size: 1.4rem; }

    /* Filtros apilados */
    .filter-form { flex-direction: column; gap: 0.75rem; }
    .filter-group { min-width: 100%; }
    .filter-actions { width: 100%; }
    .filter-actions .btn { flex: 1; justify-content: center; }

    /* Formularios */
    .form-grid-2 { grid-template-columns: 1fr; }
    .form-col-2  { grid-column: span 1; }
    .form-actions { flex-direction: column-reverse; gap: 0.5rem; }
    .form-actions .btn { width: 100%; justify-content: center; }

    /* Modales */
    .modal { margin: 0.5rem; max-height: 95vh; }
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-width: 100%; }

    /* Tabla — ocultar columnas menos importantes */
    .data-table { min-width: 500px; }

    /* Paginación compacta */
    .pagination { gap: 0.25rem; }
    .page-btn { min-width: 32px; height: 32px; font-size: 0.8rem; }

    /* Toggle row en columna */
    .toggle-row { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
}

@media (max-width: 400px) {
    .modules-grid { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
    .module-card  { padding: 0.85rem 0.7rem; }
}

/* ============================================================
   BADGE CÓDIGO CONTABLE
   ============================================================ */
.badge-codigo {
    display: inline-block;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-primary);
    font-family: monospace;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 6px;
    letter-spacing: 0.5px;
}

/* Textarea en formularios */
textarea.form-control {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}

/* ============================================================
   BADGE STOCK
   ============================================================ */
.badge-stock {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-stock.ok   { background: #EAFAF1; color: #1E8449; }
.badge-stock.bajo { background: #FDEDEC; color: #C0392B; }

/* ============================================================
   BADGE STOCK
   ============================================================ */
.badge-stock {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}
.badge-stock.ok   { background: #EAFAF1; color: #1E8449; }
.badge-stock.bajo { background: #FDEDEC; color: #C0392B; }

/* ============================================================
   MARGEN DISPLAY (formulario producto)
   ============================================================ */
.margen-display {
    display: inline-flex;
    align-items: center;
    height: 42px;
    padding: 0 1rem;
    border-radius: var(--radius);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--color-muted);
    min-width: 160px;
}
.margen-display.positivo { background: #EAFAF1; color: #1E8449; border-color: #A9DFBF; }
.margen-display.negativo { background: #FDEDEC; color: #C0392B; border-color: #F1948A; }

/* ============================================================
   DOCUMENTOS (pedidos, albaranes, facturas)
   ============================================================ */

/* Estado badges */
.badge-doc-estado {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.badge-doc-estado.draft     { background:#F2F3F4; color:#616A6B; }
.badge-doc-estado.sent      { background:#EBF5FB; color:#1A5276; }
.badge-doc-estado.received  { background:#EAFAF1; color:#1E8449; }
.badge-doc-estado.cancelled { background:#FDEDEC; color:#C0392B; }
.badge-doc-estado.pending   { background:#FDEBD0; color:#784212; }
.badge-doc-estado.paid      { background:#EAFAF1; color:#1E8449; }
.badge-doc-estado.overdue   { background:#FDEDEC; color:#C0392B; }

/* Cabecera info documento */
.doc-info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem 2rem;
    padding: 1.5rem;
}
.doc-info-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-muted);
    margin-bottom: 0.2rem;
}
.doc-info-grid strong { display: block; font-size: 0.95rem; }
.doc-info-grid small  { color: var(--color-muted); font-size: 0.8rem; }

/* Totales vista */
.doc-totales-view {
    display: flex;
    justify-content: flex-end;
    padding: 1rem 0 0.5rem;
}
.totales-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.4rem 2rem;
    min-width: 260px;
    font-size: 0.9rem;
}
.totales-final {
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    border-top: 2px solid var(--color-border);
    padding-top: 0.4rem;
}

/* Editor de líneas */
.doc-lineas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding: 1.5rem 1.5rem 0;
}

.doc-lineas-tabla {
    width: 100%;
    padding: 0 1.25rem;
}

.lineas-head {
    display: grid;
    grid-template-columns: 1fr 90px 120px 150px 110px 36px;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.25rem;
}

.linea-row {
    display: grid;
    grid-template-columns: 1fr 90px 120px 150px 110px 36px;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    position: relative;
}
.linea-row:last-child { border-bottom: none; }

/* Buscador de proveedor */
.proveedor-search-wrap { position: relative; }
.proveedor-sugs {
    position: absolute;
    top: calc(100% + 2px);
    left: 0; right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-height: 260px;
    overflow-y: auto;
}
.prov-sug-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    font-size: 0.87rem;
    border-bottom: 1px solid var(--color-border);
    transition: background var(--transition);
}
.prov-sug-item:last-child { border-bottom: none; }
.prov-sug-item:hover { background: var(--color-bg); }

.col-desc  { position: relative; }
.col-cant  input,
.col-precio input { text-align: right; }
.col-sub   { display: flex; align-items: center; justify-content: flex-end; font-weight: 600; font-size: 0.9rem; padding-top: 0.5rem; }
.col-del   { display: flex; align-items: center; justify-content: center; padding-top: 0.3rem; }

.btn-linea-del {
    background: none;
    border: none;
    color: var(--color-muted);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color var(--transition), background var(--transition);
}
.btn-linea-del:hover { color: var(--color-danger); background: #FDEDEC; }

/* Totales editor */
.doc-totales {
    display: flex;
    justify-content: flex-end;
    padding: 1rem 1.5rem 0.5rem;
    border-top: 2px solid var(--color-border);
    margin-top: 0.5rem;
}

/* Autocompletado de productos */
.prod-sugerencias {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    max-height: 220px;
    overflow-y: auto;
}
.sug-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.87rem;
    border-bottom: 1px solid var(--color-border);
    transition: background var(--transition);
}
.sug-item:last-child { border-bottom: none; }
.sug-item:hover { background: var(--color-bg); }
.sug-codigo {
    font-size: 0.75rem;
    color: var(--color-muted);
    font-family: monospace;
    background: var(--color-bg);
    padding: 1px 6px;
    border-radius: 4px;
}
.sug-precio {
    margin-left: auto;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-primary);
}

/* Responsive líneas */
@media (max-width: 768px) {
    .lineas-head { display: none; }
    .linea-row {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto;
        gap: 0.4rem;
        padding: 0.75rem 0.25rem;
    }
    .col-desc   { grid-column: 1 / -1; }
    .col-sub    { justify-content: flex-start; }
    .doc-info-grid { grid-template-columns: repeat(2, 1fr); }
}

.lineas-head-albaran {
    grid-template-columns: 1fr 90px 75px 120px 150px 110px 36px;
    padding: 1.5rem 1.5rem 0.4rem 1.5rem;
}
.linea-row-albaran {
    grid-template-columns: 1fr 90px 75px 120px 150px 110px 36px;
    padding: 0.5rem 1.5rem;
}
.col-dto input { text-align: right; padding-right: 1.5rem; }

/* ============================================================
   STAT MINI (resumen rápido en listados)
   ============================================================ */
.stat-mini {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.75rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    min-width: 160px;
}
.stat-mini span { font-size: 0.75rem; color: var(--color-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-mini strong { font-size: 1.2rem; font-weight: 700; color: var(--color-text); }
.stat-mini-danger { border-color: #FADBD8; background: #FDEDEC; }
.stat-mini-danger strong { color: var(--color-danger); }

/* ============================================================
   VENTAS — clases adicionales
   ============================================================ */

/* Cabecera de documento (alias semántico de settings-card sin padding propio) */
.doc-cabecera {
    overflow: hidden;
}

/* Iconos y etiquetas del hub de ventas
   (el hub de compras usa card-icon/card-label pero ventas usa module-icon/module-label
    — se mapean a los mismos estilos) */
.module-icon {
    font-size: 2rem;
    line-height: 1;
    margin-bottom: 0.25rem;
}
.module-label {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}
.module-desc {
    font-size: 0.82rem;
    color: var(--color-muted);
    line-height: 1.4;
}

/* Columna IGIC en tabla de líneas */
.col-igic select {
    font-size: 0.82rem;
    padding: 0.3rem 0.5rem;
}
.col-igic input[type="hidden"] {
    display: none;
}

/* Subtotal inline en la fila de línea (formulario) */
.linea-subtotal {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-text);
    white-space: nowrap;
}

/* badge-igic — porcentaje en vista detalle */
.badge-igic {
    display: inline-block;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    color: var(--color-muted);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    white-space: nowrap;
}

/* Botón peligro */
.btn-danger {
    background: var(--color-danger);
    color: #fff;
    border: none;
}
.btn-danger:hover {
    background: #c0392b;
    color: #fff;
}

/* Precio en sugerencias de producto */
.sug-precio {
    margin-left: auto;
    font-weight: 700;
    color: var(--color-primary);
    font-size: 0.85rem;
}

/* ============================================================
   INFORMES — título de sección dentro de settings-card
   ============================================================ */
.settings-card-title {
    font-family: var(--font-display);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-muted);
    padding: 1.25rem 1.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.75rem;
}

/* ============================================================
   INFORMES — estilos específicos
   ============================================================ */

/* Las tarjetas de informes no deben cortar contenido */
.informe-stat {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-align: center;
    padding: 1.25rem 1rem;
}

.informe-stat-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--color-muted);
    font-weight: 600;
    margin-bottom: 0.5rem;
    white-space: nowrap;
}

.informe-stat-value {
    font-size: 1.25rem;
    font-weight: 900;
    font-family: var(--font-display);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Grid de stats en informes */
.informe-stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

/* Gráfico de barras CSS */
.informe-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
    height: 160px;
    padding: 0.25rem 0 0;
    overflow: visible;
}

.informe-chart-bar-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    justify-content: flex-end;
    min-width: 0;
}

.informe-chart-bar-value {
    font-size: 0.65rem;
    color: var(--color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.informe-chart-bar {
    width: 100%;
    border-radius: 3px 3px 0 0;
    transition: opacity 0.2s;
    min-height: 3px;
}
.informe-chart-bar:hover { opacity: 0.75; }

.informe-chart-label {
    font-size: 0.65rem;
    color: var(--color-muted);
    white-space: nowrap;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    height: 1.8rem;
    overflow: hidden;
}

/* Leyenda del gráfico */
.informe-chart-legend {
    display: flex;
    gap: 1.5rem;
    font-size: 0.8rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.informe-chart-legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.informe-chart-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* Tabla de top en informes */
.informe-top-table {
    width: 100%;
    font-size: 0.87rem;
    border-collapse: collapse;
}

.informe-top-table th {
    text-align: left;
    padding: 0.35rem 0.5rem;
    color: var(--color-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.informe-top-table td {
    padding: 0.5rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

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

/* Minibarra de progreso dentro de tabla */
.informe-mini-bar {
    background: var(--color-border);
    border-radius: 99px;
    height: 4px;
    margin-top: 4px;
    overflow: hidden;
}

.informe-mini-bar-fill {
    height: 100%;
    border-radius: 99px;
}

/* Badge de urgencia en pendientes */
.urgencia-vencida {
    background: var(--color-danger);
    color: #fff;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.74rem;
    font-weight: 700;
    white-space: nowrap;
}

.urgencia-pronto {
    background: #e67e22;
    color: #fff;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.74rem;
    font-weight: 700;
    white-space: nowrap;
}

.urgencia-normal {
    color: var(--color-muted);
    font-size: 0.82rem;
    white-space: nowrap;
}

/* Previsión tesorería */
.prevision-card {
    padding: 1.25rem;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.prevision-card-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--color-border);
}

.prevision-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.87rem;
    padding: 0.3rem 0;
}

.prevision-total {
    border-top: 2px solid var(--color-border);
    padding-top: 0.65rem;
    margin-top: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    font-weight: 700;
}

@media (max-width: 768px) {
    .informe-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .informe-chart { height: 100px; }
}

/* ============================================================
   AGENDA — Calendario
   ============================================================ */

.agenda-leyenda {
    color: var(--lc);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* Grid 7 columnas */
.agenda-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-top: 1px solid var(--color-border);
    border-left: 1px solid var(--color-border);
}

.agenda-dow {
    text-align: center;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-muted);
    padding: 0.5rem 0;
    background: var(--color-bg-alt);
    border-right: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}

.agenda-cell {
    min-height: 110px;
    padding: 0.4rem 0.4rem 0.3rem;
    border-right: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    vertical-align: top;
    position: relative;
    transition: background 0.15s;
}

.agenda-cell:hover { background: var(--color-bg-alt); }

.agenda-cell--vacia {
    background: var(--color-bg-alt);
    opacity: 0.5;
}

.agenda-cell--hoy {
    background: #f0faf4;
}

.agenda-cell--hoy .agenda-cell-num {
    background: var(--color-primary);
    color: #fff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.agenda-cell-num {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.3rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Evento dentro de celda */
.agenda-ev {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-bottom: 2px;
    border-radius: 3px;
    padding: 1px 4px;
    background: color-mix(in srgb, var(--ev-color) 12%, transparent);
    cursor: default;
    overflow: hidden;
}

.agenda-ev[onclick] { cursor: pointer; }
.agenda-ev[onclick]:hover { opacity: 0.8; }

.agenda-ev-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ev-color);
    flex-shrink: 0;
}

.agenda-ev-txt {
    font-size: 0.67rem;
    font-weight: 600;
    color: var(--ev-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.agenda-ev-imp {
    font-size: 0.63rem;
    color: var(--ev-color);
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.agenda-cell-more {
    font-size: 0.63rem;
    color: var(--color-muted);
    display: block;
    margin-top: 2px;
    text-decoration: underline;
}

.agenda-cell-more:hover { color: var(--color-primary); }

/* Vista día */
.agenda-dia-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.85rem 1rem;
    border-left: 3px solid var(--ev-color);
    background: color-mix(in srgb, var(--ev-color) 6%, var(--color-surface));
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 0.75rem;
}

.agenda-dia-titulo {
    font-weight: 700;
    font-size: 0.97rem;
}

.agenda-dia-titulo a {
    color: inherit;
    text-decoration: none;
}

.agenda-dia-titulo a:hover { text-decoration: underline; }

.agenda-dia-hora {
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--color-muted);
    margin-right: 0.25rem;
}

.agenda-dia-desc {
    font-size: 0.84rem;
    color: var(--color-muted);
}

.agenda-dia-importe {
    font-size: 0.88rem;
}

.agenda-dia-acciones {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

/* Botón xs */
.btn-xs {
    padding: 0.15rem 0.6rem;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

@media (max-width: 768px) {
    .agenda-cell { min-height: 60px; }
    .agenda-ev-imp { display: none; }
    .agenda-dow { font-size: 0.65rem; padding: 0.3rem 0; }
}

/* ============================================================
   VERIFACTÚ — estilos
   ============================================================ */

.badge-vf {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.85rem;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.badge-vf--activo {
    background: #eafaf1;
    color: #27ae60;
    border: 1px solid #27ae60;
}

.badge-vf--inactivo {
    background: var(--color-bg-alt);
    color: var(--color-muted);
    border: 1px solid var(--color-border);
}

.badge-vf-estado {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-vf-aceptado  { background: #eafaf1; color: #27ae60; }
.badge-vf-enviado   { background: #eaf4fd; color: #2980b9; }
.badge-vf-pendiente { background: #fef9ec; color: #e67e22; }
.badge-vf-rechazado { background: #fdf2f2; color: #c0392b; }
.badge-vf-error     { background: #f4f6f7; color: #7f8c8d; }

.badge-vf-tipo {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--color-bg-alt);
    color: var(--color-muted);
    border: 1px solid var(--color-border);
}

/* ============================================================
   FISCALIDAD — estilos
   ============================================================ */

.fiscal-periodo-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
}

.badge-fiscal {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge-fiscal--pendiente   { background: #fef9ec; color: #e67e22; }
.badge-fiscal--presentada  { background: #eaf4fd; color: #2980b9; }
.badge-fiscal--pagada      { background: #eafaf1; color: #27ae60; }
.badge-fiscal--domiciliada { background: #f5eef8; color: #8e44ad; }

.fiscal-vencida {
    display: inline-block;
    background: var(--color-danger);
    color: #fff;
    padding: 1px 7px;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 700;
}

.fiscal-urgente {
    display: inline-block;
    color: #e67e22;
    font-size: 0.72rem;
    font-weight: 700;
}

/* ============================================================
   BACKUPS — estilos
   ============================================================ */

.badge-backup {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.85rem;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 700;
}

.badge-backup--activo   { background: #eafaf1; color: #27ae60; border: 1px solid #27ae60; }
.badge-backup--inactivo { background: var(--color-bg-alt); color: var(--color-muted); border: 1px solid var(--color-border); }
.badge-backup--error    { background: #fdf2f2; color: #c0392b; border: 1px solid #c0392b; }

.badge-backup-tipo {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-backup-manual    { background: #eaf4fd; color: #2980b9; }
.badge-backup-automatica { background: #f5eef8; color: #8e44ad; }

.backup-tag {
    display: inline-block;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-muted);
}

/* ============================================================
   PDF — botones
   ============================================================ */
.pdf-botones {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
