/* ============================================================
   PORTAL PROVEEDORES AGROCENTRO — DESIGN SYSTEM
   Paleta: #7DA13D #669149 #4CAF50 #0D7C66 #1d6f3c #0E1E14
           #282828 #F2EEE7 #EBEBEB
   ============================================================ */

/* ---------- Variables ---------- */
:root {
    --green-lime:   #7DA13D;
    --green-mid:    #669149;
    --green-bright: #4CAF50;
    --teal:         #0D7C66;
    --primary:      #1d6f3c;
    --dark-bg:      #0E1E14;
    --dark-text:    #282828;
    --cream:        #F2EEE7;
    --gray-light:   #EBEBEB;
    --white:        #ffffff;
    --shadow-sm:    0 2px 8px rgba(0,0,0,0.07);
    --shadow-md:    0 4px 20px rgba(0,0,0,0.12);
    --shadow-lg:    0 8px 32px rgba(0,0,0,0.16);
    --radius-sm:    6px;
    --radius-md:    12px;
    --radius-lg:    20px;
    --transition:   all 0.25s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--dark-text);
    line-height: 1.6;
    /* Sin overflow-x para que los wrappers de tablas funcionen */
}

/* ---------- TABLE CONTAINER (usado en vistas de contabilidad/finanzas) ---------- */
.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #1d6f3c #f0f0f0;
    margin-bottom: 16px;
}
.table-container::-webkit-scrollbar { height: 5px; }
.table-container::-webkit-scrollbar-track { background: #f0f0f0; }
.table-container::-webkit-scrollbar-thumb { background: #1d6f3c; border-radius: 4px; }

/* Overrides para grids con inline styles — hacer responsivos */
.resumen-cards {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
}

/* ---------- TABLE SCROLL WRAPPER (inyectado por JS) ---------- */
.table-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    /* Scrollbar visible pero discreta */
    scrollbar-width: thin;
    scrollbar-color: var(--teal) #f0f0f0;
}

.table-scroll-wrapper::-webkit-scrollbar {
    height: 5px;
}
.table-scroll-wrapper::-webkit-scrollbar-track { background: #f0f0f0; }
.table-scroll-wrapper::-webkit-scrollbar-thumb {
    background: var(--teal);
    border-radius: 4px;
}

/* La tabla dentro del wrapper no necesita overflow propio */
.table-scroll-wrapper .data-table {
    margin-bottom: 0;
    border-radius: 0;   /* el wrapper ya tiene radius */
}

/* ---------- WELCOME / DASHBOARD ---------- */
.dashboard-container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
}

.welcome-section {
    background: linear-gradient(135deg, var(--primary) 0%, var(--teal) 100%);
    color: var(--white);
    padding: 28px 32px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}

.welcome-section::after {
    content: '';
    position: absolute;
    right: -40px;
    top: -40px;
    width: 200px;
    height: 200px;
    background: rgba(255,255,255,0.04);
    border-radius: 50%;
    pointer-events: none;
}

.welcome-section h1 {
    font-size: clamp(1.3rem, 3vw, 1.9rem);
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--white);
}

.welcome-section p {
    opacity: 0.85;
    margin-bottom: 4px;
    font-size: 0.95rem;
}

.welcome-section small {
    display: inline-block;
    background: rgba(255,255,255,0.15);
    padding: 4px 12px;
    border-radius: 20px;
    margin-top: 8px;
    font-size: 0.8rem;
}

/* Recordatorio */
.Recordatorio {
    background: linear-gradient(135deg, #b8960c, #d4a914);
    color: var(--white);
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    box-shadow: var(--shadow-sm);
}

.Recordatorio::before {
    content: '⚠️';
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.Recordatorio h2 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 4px;
}

.Recordatorio p { font-size: 0.88rem; opacity: 0.95; margin: 0; }

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}

.card {
    background: var(--white);
    padding: 24px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    text-align: center;
    transition: var(--transition);
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--teal), var(--green-bright));
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
    border-color: #d4edda;
}

.card-icon { font-size: 2.2rem; margin-bottom: 10px; display: block; }

.card h3 {
    color: var(--dark-text);
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.65;
}

.big-number {
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    font-weight: 800;
    color: var(--teal);
    margin: 4px 0;
    line-height: 1;
}

.card small { color: var(--green-mid); font-weight: 600; font-size: 0.88rem; }

/* Actions Section */
.actions-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.btn-action {
    padding: 15px 18px;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-size: 0.93rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
    border: 2px solid transparent;
    box-shadow: var(--shadow-sm);
    word-break: break-word;
}

.btn-action.primary {
    background: linear-gradient(135deg, var(--primary), var(--teal));
    color: var(--white);
}

.btn-action.secondary {
    background: var(--white);
    color: var(--dark-text);
    border-color: var(--gray-light);
}

.btn-action.admin-btn {
    background: linear-gradient(135deg, var(--dark-bg), #1a3a22);
    color: var(--white);
}

.btn-action:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn-action.primary:hover  { background: linear-gradient(135deg, var(--teal), var(--green-bright)); }
.btn-action.secondary:hover { border-color: var(--teal); color: var(--teal); }

.btn-icon { font-size: 1.3rem; flex-shrink: 0; }

/* ---------- SECTIONS ---------- */
.section, .page-container {
    width: 100%;
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
}

.section h2,
.page-container > h1,
.page-container > h2 {
    color: var(--dark-bg);
    font-size: 1.2rem;
    font-weight: 700;
    margin: 28px 0 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--gray-light);
    display: flex;
    align-items: center;
    gap: 8px;
}

.section h2::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: linear-gradient(180deg, var(--teal), var(--green-bright));
    border-radius: 2px;
    flex-shrink: 0;
}

/* ---------- TABLAS ---------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    box-shadow: var(--shadow-sm);
    /* sin overflow aquí; el wrapper .table-scroll-wrapper lo maneja */
}

.data-table thead tr { background: #1d6f3c !important; }

.data-table th {
    padding: 12px 14px;
    text-align: left;
    color: #ffffff !important;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    white-space: nowrap;
    background: transparent;
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gray-light);
    font-size: 0.88rem;
    color: var(--dark-text);
    /* Permite que el contenido largo haga wrap, no overflow */
    word-break: break-word;
    min-width: 80px;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f4fbf6; }
.data-table tbody tr:nth-child(even) { background: #f9fdf9; }
.data-table tbody tr:nth-child(even):hover { background: #edf7f0; }

.no-data {
    text-align: center;
    padding: 40px;
    color: #aaa;
    font-style: italic;
    font-size: 0.9rem;
}

/* ---------- STATUS BADGES ---------- */
.status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.status.reportada           { background: #fff8e1; color: #e65100; border: 1px solid #ffe082; }
.status.validada            { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.status.en_sap              { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }
.status.pagada              { background: #e0f2f1; color: var(--teal); border: 1px solid #80cbc4; font-weight: 700; }
.status.pendiente           { background: #fff8e1; color: #e65100; border: 1px solid #ffe082; }
.status.abierta             { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.status.cerrada             { background: #f5f5f5; color: #555;    border: 1px solid #ddd; }
.status.cancelada,
.status.rechazada           { background: #fce4ec; color: #c62828; border: 1px solid #ef9a9a; }
.status.aprobada,
.status.aprobado_para_pago  { background: #e0f2f1; color: var(--teal); border: 1px solid #80cbc4; }

/* ---------- COMPARACIÓN FACTURA VS ORDEN DE COMPRA ---------- */
.badge-comparacion {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-comparacion.igual        { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.badge-comparacion.orden-mayor  { background: #fffde7; color: #f57f17; border: 1px solid #ffe082; }
.badge-comparacion.factura-mayor{ background: #fce4ec; color: #c62828; border: 1px solid #ef9a9a; }

/* ---------- FORMS ---------- */
.form-container {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    background: var(--white);
    padding: 32px 36px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.form-container h1 {
    color: var(--dark-bg);
    font-size: 1.5rem;
    margin-bottom: 24px;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--gray-light);
}

.form-group { margin-bottom: 20px; }

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.88rem;
    color: #444;
}

.form-group input,
.form-group select,
.form-group textarea,
.form-select {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid var(--gray-light);
    border-radius: var(--radius-sm);
    font-size: 0.93rem;
    font-family: inherit;
    color: var(--dark-text);
    background: #fafafa;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--teal);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(13,124,102,0.1);
}

/* ---------- BUTTONS ---------- */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--primary), var(--teal));
    color: var(--white);
    padding: 12px 26px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.93rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    font-family: inherit;
    width: 100%;
    margin-top: 8px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--teal), var(--green-bright));
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(29,111,60,0.3);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--white);
    color: var(--teal);
    padding: 11px 22px;
    border: 2px solid var(--teal);
    border-radius: var(--radius-sm);
    font-size: 0.93rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    font-family: inherit;
}

.btn-secondary:hover {
    background: var(--teal);
    color: var(--white);
    transform: translateY(-1px);
}

.btn-small {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 11px;
    background: var(--teal);
    color: var(--white);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-small:hover { background: var(--primary); transform: translateY(-1px); }

.btn-link {
    display: inline-block;
    color: var(--teal);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
}
.btn-link:hover { color: var(--green-bright); }

/* ---------- FILTERS ---------- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.filter-btn {
    padding: 7px 16px;
    background: var(--white);
    color: var(--dark-text);
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.83rem;
    font-weight: 500;
    border: 1.5px solid var(--gray-light);
    transition: var(--transition);
    white-space: nowrap;
}

.filter-btn.active, .filter-btn:hover {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

/* ---------- ALERTS ---------- */
.alert {
    padding: 13px 16px;
    margin-bottom: 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert.success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.alert.success::before { content: '✅'; flex-shrink: 0; }
.alert.error   { background: #fce4ec; color: #c62828; border: 1px solid #ef9a9a; }
.alert.error::before   { content: '❌'; flex-shrink: 0; }
.alert.warning { background: #fffde7; color: #f57f17; border: 1px solid #ffe082; }
.alert.warning::before { content: '⚠️'; flex-shrink: 0; }

/* error de login */
.error {
    background: #fdf2f2;
    color: #c0392b;
    border: 1px solid #f5c6cb;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    text-align: center;
    margin: 10px 0;
    font-size: 0.9rem;
}

/* ---------- MODAL ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(14,30,20,0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-content {
    background: var(--white);
    padding: 28px;
    border-radius: var(--radius-md);
    max-width: 540px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.close {
    position: absolute;
    top: 14px;
    right: 18px;
    font-size: 1.4rem;
    cursor: pointer;
    color: #888;
    transition: var(--transition);
    background: none;
    border: none;
    line-height: 1;
}
.close:hover { color: var(--dark-text); }

/* ---------- PAGE CONTAINER ---------- */
.page-container {
    width: 100%;
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.page-header h1 {
    color: var(--dark-bg);
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    border: none;
    padding: 0;
}

/* ---------- STAT CARDS ---------- */
.stat-card {
    background: var(--white);
    border-radius: var(--radius-md);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--teal);
}

.stat-card.green { border-left-color: var(--green-bright); }
.stat-card.teal  { border-left-color: var(--teal); }
.stat-card.olive { border-left-color: var(--green-lime); }

/* ---------- MISC ---------- */
.password { color: var(--primary); font-weight: 700; font-size: 1.05em; letter-spacing: 1px; }

.timeline { position: relative; padding-left: 28px; }
.timeline::before {
    content: ''; position: absolute; left: 8px; top: 0; bottom: 0;
    width: 2px; background: linear-gradient(180deg, var(--teal), var(--green-bright));
}
.timeline-item { position: relative; margin-bottom: 22px; }
.timeline-item::before {
    content: ''; position: absolute; left: -24px; top: 6px;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--teal); border: 2px solid var(--white);
    box-shadow: 0 0 0 2px var(--teal);
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1024px) {
    .form-container { padding: 26px 22px; }
    .welcome-section { padding: 22px 24px; }
}

@media (max-width: 768px) {
    .cards-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .actions-section { grid-template-columns: 1fr; }
    .form-container { padding: 20px 16px; border-radius: var(--radius-sm); }
    .welcome-section { padding: 20px 18px; }
    .Recordatorio { width: 100%; }
    .section h2, .page-container > h1 { font-size: 1.1rem; }
}

@media (max-width: 540px) {
    .cards-grid { grid-template-columns: 1fr; }
    .filter-btn { padding: 6px 12px; font-size: 0.8rem; }
    .btn-action { font-size: 0.88rem; padding: 13px 14px; }

    /* En móvil: las tablas mantienen sus columnas pero con scroll horizontal */
    .data-table th, .data-table td { padding: 10px 10px; font-size: 0.8rem; }
}

/* ---------- UTILITIES ---------- */
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.mt-1 { margin-top: 8px; }   .mt-2 { margin-top: 16px; }  .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.fw-bold    { font-weight: 700; }
.text-muted { color: #888; font-style: italic; }
.text-success { color: var(--green-bright); }
.text-danger  { color: #c62828; }
.text-teal    { color: var(--teal); }
