/* FacturApp — Estilos principales */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--gray-900);
    background: var(--gray-50);
    line-height: 1.6;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* Logo */
.logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--gray-900);
    text-decoration: none;
}
.logo span { color: var(--primary); }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-lg { padding: 14px 32px; font-size: 1.1rem; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-xs { padding: 4px 10px; font-size: 0.8rem; }
.btn-block { display: block; width: 100%; }

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.95rem;
}
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #93c5fd; }
.alert a { color: inherit; font-weight: 600; }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-cobrada { background: #d1fae5; color: #065f46; }
.badge-cancelada { background: #f3f4f6; color: var(--gray-500); }
.badge-parcial { background: #ffedd5; color: #c2410c; }
.badge-borrador { background: #ede9fe; color: #6d28d9; }
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-pending { background: #fef3c7; color: #92400e; }

/* ========================
   LANDING PAGE
   ======================== */

.landing-header {
    padding: 16px 0;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
}
.landing-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.landing-header nav { display: flex; align-items: center; gap: 24px; }
.landing-header nav a { text-decoration: none; color: var(--gray-700); font-weight: 500; }
.landing-header nav a.btn { color: #fff; }
.landing-header nav a.btn-outline { color: var(--primary); }

.hero {
    padding: 80px 0;
    text-align: center;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}
.hero h1 { font-size: 3rem; font-weight: 800; line-height: 1.2; margin-bottom: 16px; }
.hero-sub { font-size: 1.2rem; color: var(--gray-500); max-width: 600px; margin: 0 auto 32px; }
.hero-note { font-size: 0.9rem; color: var(--gray-500); margin-top: 12px; }

.section { padding: 60px 0; }
.section-alt { background: #fff; }
.section h2 { text-align: center; font-size: 2rem; margin-bottom: 40px; }

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}
.feature-card {
    background: #fff;
    padding: 32px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}
.feature-icon { font-size: 2rem; margin-bottom: 12px; }
.feature-card h3 { margin-bottom: 8px; }
.feature-card p { color: var(--gray-500); font-size: 0.95rem; }

.verifactu-info { max-width: 700px; margin: 0 auto; }
.verifactu-info p { margin-bottom: 16px; color: var(--gray-700); }
.verifactu-info ul { list-style: none; padding: 0; }
.verifactu-info li { padding: 8px 0 8px 28px; position: relative; color: var(--gray-700); }
.verifactu-info li::before { content: "\2713"; position: absolute; left: 0; color: var(--success); font-weight: bold; }

.pricing-cards {
    display: flex;
    gap: 24px;
    justify-content: center;
    flex-wrap: wrap;
}
.pricing-card {
    background: #fff;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 40px 32px;
    width: 340px;
    text-align: center;
    position: relative;
}
.pricing-card.featured { border-color: var(--primary); }
.pricing-card .badge-feat {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    padding: 4px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
}
.pricing-card h3 { font-size: 1.2rem; margin-bottom: 8px; }
.price { font-size: 2.5rem; font-weight: 800; }
.price span { font-size: 1rem; font-weight: 400; color: var(--gray-500); }
.price-note { color: var(--gray-500); font-size: 0.9rem; margin-bottom: 24px; }
.pricing-card ul { list-style: none; text-align: left; margin: 24px 0; }
.pricing-card li { padding: 8px 0; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
.pricing-card .btn { margin-top: 16px; }
.pricing-card .badge {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    padding: 4px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    white-space: nowrap;
}

.landing-footer {
    padding: 24px 0;
    border-top: 1px solid var(--gray-200);
    background: #fff;
}
.landing-footer .container { display: flex; justify-content: space-between; align-items: center; }
.landing-footer nav { display: flex; gap: 24px; }
.landing-footer a { text-decoration: none; color: var(--gray-500); font-size: 0.9rem; }

/* ========================
   AUTH PAGES
   ======================== */

.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--gray-100);
}
.auth-container {
    background: #fff;
    padding: 48px 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    text-align: center;
}
.auth-container .logo { display: block; margin-bottom: 24px; }
.auth-container h1 { font-size: 1.5rem; margin-bottom: 8px; }
.auth-sub { color: var(--gray-500); margin-bottom: 24px; }

.auth-form { text-align: left; }
.auth-link { margin-top: 16px; font-size: 0.9rem; color: var(--gray-500); }
.auth-link a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ========================
   FORMS
   ======================== */

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.form-card {
    background: #fff;
    padding: 32px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.form-section { margin-bottom: 24px; }
.form-section h3 { font-size: 1.1rem; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--gray-200); }
.form-actions { margin-top: 24px; text-align: right; }

/* ========================
   APP LAYOUT
   ======================== */

.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--gray-900);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transition: width 0.2s ease;
}
.sidebar-logo {
    padding: 20px 24px;
    font-size: 1.3rem;
    font-weight: 800;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}
.sidebar-logo .logo-full > span { color: #60a5fa; }
.sidebar-logo .logo-mini { display: none; color: #60a5fa; font-size: 1.3rem; }
.sidebar-toggle {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    transition: all 0.15s;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* Modo colapsado */
.sidebar.collapsed { width: 64px; overflow: visible; }
.sidebar.collapsed .logo-full { display: none; }
.sidebar.collapsed .logo-mini { display: inline; }
.sidebar.collapsed .sidebar-logo { padding: 20px 0; justify-content: center; flex-direction: column; gap: 10px; }
.sidebar.collapsed .sidebar-search { display: none; }
.sidebar.collapsed .nav-item {
    padding: 12px 0;
    justify-content: center;
    width: 64px;
}
.sidebar.collapsed .nav-text { display: none; }
.sidebar.collapsed .nav-icon { font-size: 1.3rem; margin: 0; }

/* Tooltip nativo bonito en colapsado */
.sidebar.collapsed .nav-item { position: relative; }
.sidebar.collapsed .nav-item::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--gray-900);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, left 0.15s;
    z-index: 1000;
}
.sidebar.collapsed .nav-item::before {
    content: '';
    position: absolute;
    left: calc(100% + 4px);
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-right: 6px solid var(--gray-900);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 1000;
}
.sidebar.collapsed .nav-item:hover::after,
.sidebar.collapsed .nav-item:hover::before {
    opacity: 1;
}
.sidebar.collapsed .nav-item:hover::after {
    left: calc(100% + 14px);
}
.sidebar.collapsed .sidebar-trial {
    padding: 6px 4px;
    font-size: 0.65rem;
    margin: 0 8px 12px;
}
.sidebar.collapsed .sidebar-trial .trial-text { font-size: 0; }
.sidebar.collapsed .sidebar-trial .trial-text strong { font-size: 0.9rem; }
.sidebar.collapsed .sidebar-trial .trial-text::after { content: ' días'; font-size: 0.65rem; color: #93c5fd; }
.sidebar.collapsed .sidebar-trial a { display: none; }
.sidebar.collapsed .sidebar-footer { padding: 12px 8px; }
.sidebar.collapsed .sidebar-footer .user-info { display: none; }
.sidebar.collapsed .sidebar-footer .btn {
    font-size: 0;
    padding: 8px;
    width: 100%;
    display: flex;
    justify-content: center;
}
.sidebar.collapsed .sidebar-footer .btn::before {
    content: '⏻';
    font-size: 1rem;
    color: rgba(255,255,255,0.7);
}
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* Buscador en sidebar */
.sidebar-search { padding: 0 16px 12px 16px; position: relative; }
.sidebar-search input {
    width: 100%; padding: 8px 12px; background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15); border-radius: 6px;
    color: #fff; font-size: 0.85rem;
}
.sidebar-search input::placeholder { color: rgba(255,255,255,0.5); }
.sidebar-search input:focus { outline: none; background: rgba(255,255,255,0.15); border-color: var(--primary); }
#global-search-results {
    display: none; position: absolute; top: 100%; left: 16px; right: 16px;
    background: #fff; color: #333; border-radius: 6px; box-shadow: var(--shadow-lg);
    z-index: 200; max-height: 320px; overflow-y: auto; margin-top: 4px;
}
#global-search-results.visible { display: block; }

/* Trial en sidebar */
.sidebar-trial {
    background: rgba(96, 165, 250, 0.12);
    border: 1px solid rgba(96, 165, 250, 0.25);
    color: #93c5fd;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.78rem;
    text-align: center;
    margin-bottom: 12px;
}
.sidebar-trial .trial-text { white-space: nowrap; }
.sidebar-trial strong { color: #fff; font-weight: 700; }
.sidebar-trial a {
    display: inline-block;
    color: #fff;
    background: var(--primary);
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 5px;
    margin-top: 8px;
    text-decoration: none;
    font-size: 0.72rem;
    transition: background 0.15s;
}
.sidebar-trial a:hover { background: var(--primary-dark); }

.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
    min-height: 0; /* permite que flex shrink funcione */
}
/* Scrollbar fina y discreta */
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }
/* Firefox */
.sidebar-nav { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 24px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
.nav-item.active { color: #fff; background: rgba(255,255,255,0.1); border-right: 3px solid var(--primary); }
.nav-icon { font-size: 1.1rem; }

/* Submenú desplegable (ej. Modelos fiscales) */
.nav-group-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.nav-group.open .nav-group-items { max-height: 200px; }
.nav-group.open .nav-arrow { transform: rotate(90deg); }
.nav-group-toggle { cursor: pointer; }
.nav-sub {
    padding-left: 48px !important;
    padding-top: 6px !important;
    padding-bottom: 6px !important;
    font-size: 0.85rem;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.user-info { margin-bottom: 8px; }
.user-info strong { display: block; font-size: 0.9rem; }
.user-info small { color: rgba(255,255,255,0.5); font-size: 0.8rem; }
.sidebar-footer .btn { color: rgba(255,255,255,0.7); border-color: rgba(255,255,255,0.3); font-size: 0.8rem; padding: 4px 12px; }

.main-content { flex: 1; margin-left: 240px; padding: 24px 32px; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; transition: margin-left 0.2s ease; }
body.sidebar-collapsed .main-content { margin-left: 64px; }
.page-content { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.trial-banner {
    background: #fef3c7;
    color: #92400e;
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    font-size: 0.9rem;
}
.trial-banner a { color: #92400e; font-weight: 700; }

.page-content h1 { font-size: 1.8rem; margin-bottom: 8px; }
.page-subtitle { color: var(--gray-500); margin-bottom: 24px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card {
    background: #fff;
    padding: 20px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-label { font-size: 0.85rem; color: var(--gray-500); margin-bottom: 4px; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-value.warn { color: var(--warning); }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th { background: var(--gray-50); padding: 12px 16px; text-align: left; font-size: 0.8rem; text-transform: uppercase; color: var(--gray-500); font-weight: 600; }
.data-table td { padding: 12px 16px; border-top: 1px solid var(--gray-100); font-size: 0.9rem; }
.data-table tr:hover td { background: var(--gray-50); }
.data-table .actions { display: flex; gap: 6px; justify-content: flex-end; }

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.section-header h2 { font-size: 1.3rem; }

.filters { display: flex; gap: 8px; margin-bottom: 20px; }

/* Empty state bonito */
.empty-state { text-align: center; padding: 60px 24px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.empty-state p { color: var(--gray-500); margin-bottom: 16px; font-size: 1rem; }
.empty-icon { font-size: 4rem; margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 { font-size: 1.2rem; color: var(--gray-700); margin-bottom: 8px; }

/* Action buttons with icons */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--gray-300);
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
    color: var(--gray-500);
    line-height: 1;
    text-decoration: none;
}
.btn-icon svg { width: 13px; height: 13px; }
.btn-icon:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--gray-700); }
.btn-icon.primary { color: var(--primary); border-color: var(--primary); }
.btn-icon.primary:hover { background: var(--primary-light); }
.btn-icon.success { color: var(--success); border-color: var(--success); }
.btn-icon.success:hover { background: #d1fae5; }
.btn-icon.danger { color: var(--danger); border-color: var(--danger); }
.btn-icon.danger:hover { background: #fef2f2; }
.btn-icon.warning { color: #f59e0b; border-color: #f59e0b; }
.btn-icon.warning:hover { background: #fef3c7; }

/* Table scroll container — full height */
.table-scroll-container {
    flex: 1;
    overflow-y: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: #fff;
    max-height: calc(100vh - 280px);
}
.data-table-sticky { box-shadow: none; border-radius: 0; }
.data-table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--gray-100);
    box-shadow: 0 1px 0 var(--gray-200);
}

/* Filtros bar */
.filtros-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 12px;
}
.filtros-right {
    display: flex;
    gap: 8px;
    margin-left: auto;
    align-items: center;
}
.input-filtro {
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

/* Resumen bar */
.resumen-bar {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    align-items: center;
}
.resumen-stats {
    background: #fff;
    padding: 8px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.85rem;
}
.resumen-sep { color: var(--gray-300); margin: 0 2px; }

/* Factura form */
.lineas-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.lineas-table th { padding: 8px; text-align: left; font-size: 0.8rem; color: var(--gray-500); text-transform: uppercase; }
.lineas-table td { padding: 4px 8px; }
.lineas-table input { width: 100%; padding: 8px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 0.9rem; }
.linea-total { font-weight: 600; font-size: 0.95rem; }
.btn-remove-linea { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--danger); padding: 4px; }

.factura-totales {
    background: var(--gray-50);
    padding: 20px 24px;
    border-radius: var(--radius);
    margin-top: 16px;
    max-width: 350px;
    margin-left: auto;
}
.total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.95rem; }
.total-final { border-top: 2px solid var(--gray-300); padding-top: 10px; margin-top: 6px; font-size: 1.2rem; font-weight: 700; }

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
}
.modal-content {
    background: #fff;
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { font-size: 1.3rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--gray-500); }

/* ========================
   TRIAL EXPIRADO PAGE
   ======================== */

.trial-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--gray-100);
}
.trial-container {
    background: #fff;
    padding: 48px 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    text-align: center;
}
.trial-container h1 { margin-bottom: 12px; }
.trial-container .price-highlight { font-size: 2rem; font-weight: 800; color: var(--primary); margin: 16px 0; }

/* Header móvil de líneas: oculto en desktop */
.linea-mobile-header { display: none; }

/* ========================
   FULL-HEIGHT PAGE LAYOUT (facturas, clientes, presupuestos, gastos, recurrentes)
   ======================== */

.page-full { display: flex; flex-direction: column; height: calc(100vh - 48px); overflow: hidden; }
.page-full-header { flex-shrink: 0; }
.page-full-table { flex: 1; overflow-y: auto; border-radius: var(--radius); box-shadow: var(--shadow); background: #fff; }
.page-full-table table { border-collapse: collapse; width: 100%; }
.page-full-table thead th {
    position: sticky; top: 0; z-index: 10; background: var(--gray-100);
    box-shadow: 0 1px 0 var(--gray-200); padding: 10px 14px; text-align: left;
    font-size: 0.75rem; text-transform: uppercase; color: var(--gray-500); font-weight: 600;
}
.page-full-table td { padding: 10px 14px; border-top: 1px solid var(--gray-100); font-size: 0.88rem; }
.page-full-table tr:hover td { background: var(--gray-50); }
.page-full-table .actions { display: flex; gap: 4px; justify-content: flex-end; }
.page-full-table th:last-child, .page-full-table td.actions { text-align: right; }

/* Page topbar */
.page-topbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px; gap: 16px;
}
.page-topbar h1 { font-size: 1.4rem; margin: 0; white-space: nowrap; }
.page-topbar-right { display: flex; gap: 8px; align-items: center; }

/* Stats cards */
.page-stats { display: flex; gap: 10px; margin-bottom: 12px; }
.page-stat {
    background: #fff; padding: 10px 14px; border-radius: var(--radius);
    box-shadow: var(--shadow); flex: 1; min-width: 0;
}
.page-stat .ps-label { font-size: 0.7rem; text-transform: uppercase; color: var(--gray-500); letter-spacing: 0.5px; margin-bottom: 1px; }
.page-stat .ps-value { font-size: 1.15rem; font-weight: 700; }
.page-stat .ps-value.warn { color: var(--warning); }
.page-stat .ps-value.green { color: var(--success); }
.page-stat .ps-value.danger { color: var(--danger); }

/* Filters row */
.page-filters {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 14px; flex-wrap: nowrap; overflow-x: auto;
}
.page-filters::-webkit-scrollbar { height: 4px; }
.page-filters::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }
.year-select {
    padding: 6px 10px; border: 2px solid var(--primary); border-radius: var(--radius);
    font-size: 0.85rem; font-weight: 700; color: var(--primary); background: var(--primary-light);
    cursor: pointer; min-width: 80px;
}
.year-select:focus { outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.estado-pills { display: flex; gap: 0; border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; flex-shrink: 0; }
.estado-pill {
    padding: 6px 10px; font-size: 0.75rem; font-weight: 600; text-decoration: none;
    color: var(--gray-500); background: #fff; border-right: 1px solid var(--gray-200);
    transition: all 0.15s; white-space: nowrap;
}
.estado-pill:last-child { border-right: none; }
.estado-pill:hover { background: var(--gray-50); }
.estado-pill.active { background: var(--primary); color: #fff; }
.estado-pill .pill-count {
    display: inline-block; background: rgba(0,0,0,0.1); padding: 1px 5px;
    border-radius: 10px; font-size: 0.65rem; margin-left: 3px;
}
.estado-pill.active .pill-count { background: rgba(255,255,255,0.25); }
.tipo-select, .cat-select {
    padding: 6px 8px; border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: 0.78rem; font-weight: 500; cursor: pointer; min-width: 110px;
}
.tipo-badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 0.7rem; font-weight: 600; color: #fff; white-space: nowrap;
}
.search-box { display: flex; gap: 4px; margin-left: auto; flex-shrink: 0; }
.search-box input {
    padding: 6px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: 0.78rem; width: 140px;
}
.search-box input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

/* Batch bar */
.batch-bar {
    display: none; align-items: center; gap: 10px; background: var(--primary-light);
    padding: 8px 14px; border-radius: var(--radius); font-size: 0.85rem; flex-wrap: wrap;
    margin-bottom: 10px;
}
.batch-bar.visible { display: flex; }

/* Badge estados presupuestos */
.badge-borrador { background: #e5e7eb; color: #374151; }
.badge-enviado { background: #dbeafe; color: #1d4ed8; }
.badge-aceptado { background: #d1fae5; color: #065f46; }
.badge-rechazado { background: #fef2f2; color: #dc2626; }

/* Inactive row */
.row-inactive td { opacity: 0.5; }

/* ========================
   RESPONSIVE
   ======================== */

/* Botón hamburguesa móvil — siempre presente pero oculto en desktop */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--gray-900);
    color: #fff;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 49;
}

/* === RESPONSIVE TABLET === */
@media (max-width: 1024px) {
    .page-stats { flex-wrap: wrap; }
    .page-stat { min-width: 140px; flex: 1 1 140px; }
    .main-content { padding: 16px 20px; }
}

/* === RESPONSIVE MÓVIL === */
@media (max-width: 768px) {
    /* Landing */
    .hero h1 { font-size: 2rem; }
    .landing-header nav { gap: 12px; font-size: 0.85rem; }
    .form-row { grid-template-columns: 1fr; }
    .pricing-cards { flex-direction: column; align-items: center; }

    /* Sidebar móvil — oculto por defecto, slide-in con clase .open */
    .mobile-menu-btn { display: flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        width: 260px !important;
        z-index: 100;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.collapsed { width: 260px !important; transform: translateX(-100%); }
    .sidebar.collapsed.open { transform: translateX(0); }
    .sidebar-toggle { display: none; }
    .mobile-overlay.visible { display: block; }

    /* Main: sin margen */
    .main-content,
    body.sidebar-collapsed .main-content {
        margin-left: 0 !important;
        padding: 56px 12px 16px !important;
    }
    html.sidebar-pre-collapsed .main-content { margin-left: 0 !important; }

    /* Page layout */
    .page-full { height: calc(100vh - 70px); }
    .page-topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
    .page-topbar h1 { font-size: 1.2rem; }
    .page-topbar-right { width: 100%; flex-wrap: wrap; }
    .page-topbar-right .btn { font-size: 0.75rem; padding: 6px 10px; }

    /* Stats: grid de 2 o 3 columnas compactas */
    .page-stats {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
        margin-bottom: 10px;
    }
    .page-stat {
        min-width: 0;
        flex: none;
        padding: 6px 8px;
        text-align: center;
    }
    .page-stat .ps-label {
        font-size: 0.55rem;
        letter-spacing: 0;
        margin-bottom: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .page-stat .ps-value { font-size: 0.85rem; line-height: 1.2; }

    /* Filtros: scroll horizontal */
    .page-filters { gap: 4px; flex-wrap: nowrap; padding-bottom: 6px; }
    .estado-pill { padding: 5px 8px; font-size: 0.7rem; }
    .estado-pill .pill-count { font-size: 0.6rem; padding: 1px 4px; }
    .year-select, .tipo-select, .cat-select {
        padding: 5px 8px; font-size: 0.75rem; min-width: 0;
    }
    .search-box { margin-left: 0; }
    .search-box input { width: 110px; font-size: 0.72rem; }

    /* Tabla scroll horizontal */
    .page-full-table { overflow: auto; }
    .page-full-table table { font-size: 0.78rem; min-width: 600px; }
    .page-full-table th, .page-full-table td { padding: 8px 6px; }

    /* Stats grid (dashboard) */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px 14px; }
    .stat-value { font-size: 1.2rem; }

    /* Forms */
    .form-card { padding: 16px; }
    .form-section h3 { font-size: 1rem; }

    /* Modal */
    .modal-content { max-width: 95vw !important; padding: 20px 16px; max-height: 92vh; }

    /* Auth pages */
    .auth-container { padding: 28px 20px; max-width: 100%; }

    /* Tabla líneas factura/presupuesto: tarjetas plegables en móvil */
    .lineas-grid, .lineas-grid thead, .lineas-grid tbody, .lineas-grid tr, .lineas-grid td, .lineas-grid th {
        display: block;
    }
    .lineas-grid thead { display: none; }
    .lineas-grid tr {
        display: block !important;
        background: #f9fafb;
        border: 1px solid var(--gray-200);
        border-radius: 8px;
        padding: 0;
        margin-bottom: 10px;
        position: relative;
        overflow: hidden;
    }

    /* Fila colapsada (header siempre visible) */
    .linea-mobile-header {
        display: flex !important;
        align-items: center;
        gap: 10px;
        padding: 12px 14px;
        cursor: pointer;
        background: #fff;
        user-select: none;
    }
    .linea-mobile-header .lh-arrow {
        font-size: 0.7rem;
        color: var(--gray-400);
        transition: transform 0.2s;
        flex-shrink: 0;
    }
    .lineas-grid tr.expanded .linea-mobile-header .lh-arrow {
        transform: rotate(90deg);
    }
    .linea-mobile-header .lh-desc {
        flex: 1;
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--gray-900);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
    }
    .linea-mobile-header .lh-desc.empty { color: var(--gray-400); font-style: italic; font-weight: 400; }
    .linea-mobile-header .lh-total {
        font-weight: 700;
        color: var(--primary);
        font-size: 0.9rem;
        flex-shrink: 0;
    }

    /* Cuerpo plegable */
    .lineas-grid tr td {
        display: none !important;
        padding: 4px 0;
        width: auto !important;
        min-width: 0 !important;
    }
    .lineas-grid tr.expanded td {
        display: block !important;
    }
    .lineas-grid tr.expanded td.col-act { display: inline-block !important; }
    .lineas-grid tr.expanded {
        padding: 12px;
    }
    .lineas-grid tr.expanded .linea-mobile-header {
        background: transparent;
        padding: 0 0 10px 0;
        border-bottom: 1px solid var(--gray-200);
        margin-bottom: 10px;
    }

    .lineas-grid td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.65rem;
        font-weight: 600;
        text-transform: uppercase;
        color: var(--gray-500);
        margin-bottom: 3px;
        letter-spacing: 0.5px;
    }
    .lineas-grid td.col-desc::before { content: 'Descripción'; }
    .lineas-grid td.col-md::before { content: 'Precio unitario'; }
    .lineas-grid td.col-act {
        text-align: right;
        padding: 8px 0 0 0 !important;
    }
    .lineas-grid td.col-act::before { display: none; }
    .lineas-grid td.col-total {
        background: var(--primary-light);
        margin-top: 8px;
        padding: 8px 10px;
        border-radius: 6px;
        text-align: center;
    }
    .lineas-grid td.col-total::before { content: 'Total línea'; }
    .lineas-grid input, .lineas-grid select {
        padding: 8px 10px;
        font-size: 0.85rem;
    }
    .lineas-grid .line-total-val,
    .lineas-grid .line-total-val-p {
        text-align: center;
        font-size: 1rem;
        color: var(--primary);
    }
    .btn-rm {
        background: #fef2f2;
        color: var(--danger);
        border: 1px solid #fecaca;
        width: auto !important;
        height: auto !important;
        padding: 8px 14px;
        border-radius: 6px;
        font-size: 0.8rem;
        font-weight: 600;
        cursor: pointer;
        font-family: inherit;
    }
    .btn-rm:hover { background: #fee2e2; }

    /* Cantidad/precio en grid 2 columnas */
    .lineas-grid tr.expanded td.col-sm:nth-of-type(2),
    .lineas-grid tr.expanded td.col-md:nth-of-type(3) {
        display: inline-block !important;
        width: calc(50% - 4px) !important;
        vertical-align: top;
    }
    .lineas-grid tr.expanded td.col-sm:nth-of-type(2) { margin-right: 4px; }
    .lineas-grid tr.expanded td.col-sm:nth-of-type(2)::before { content: 'Cantidad'; }
    .lineas-grid tr.expanded td.col-sm:nth-of-type(4),
    .lineas-grid tr.expanded td.col-sm:nth-of-type(5) {
        display: inline-block !important;
        width: calc(50% - 4px) !important;
        vertical-align: top;
    }
    .lineas-grid tr.expanded td.col-sm:nth-of-type(4) { margin-right: 4px; }
    .lineas-grid tr.expanded td.col-sm:nth-of-type(4)::before { content: 'Dto %'; }
    .lineas-grid tr.expanded td.col-sm:nth-of-type(5)::before { content: 'IVA %'; }

    /* Sidebar dentro del móvil — full width text */
    .sidebar.collapsed .nav-text { display: inline; }
    .sidebar.collapsed .nav-item { padding: 12px 24px; justify-content: flex-start; }
    .sidebar.collapsed .sidebar-search,
    .sidebar.collapsed .sidebar-trial,
    .sidebar.collapsed .sidebar-footer .user-info { display: block; }
    .sidebar.collapsed .logo-mini { display: none; }
    .sidebar.collapsed .logo-full { display: inline; }
    .sidebar.collapsed .nav-item::after,
    .sidebar.collapsed .nav-item::before { display: none; }

}

/* === MUY PEQUEÑO === */
@media (max-width: 480px) {
    .main-content { padding: 56px 8px 12px !important; }
    .page-stats { grid-template-columns: repeat(2, 1fr); }
    .page-topbar h1 { font-size: 1.1rem; }
    .form-row { grid-template-columns: 1fr; gap: 12px; }
}
