/* ═══════════════════════════════════════════════════════════
   AeroContratos — Paleta Aerosanidad
   Primarios:   #2BB6C7  #666564  #9C9B99  #FFFFFF
   Secundarios: #F4EFE6  #1B6368  #7F7FF4
   Tipografía:  Bebas Neue (display) · Inter (cuerpo)
   ═══════════════════════════════════════════════════════════ */

:root {
    --font-display: 'Bebas Neue', 'Arial Narrow', sans-serif;
    --font-body:    'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    /* Marca */
    --brand-teal:       #2BB6C7;
    --brand-teal-dark:  #1B6368;
    --brand-teal-light: #d6f2f5;
    --brand-purple:     #7F7FF4;
    --brand-cream:      #F4EFE6;
    --brand-gray-dark:  #666564;
    --brand-gray-mid:   #9C9B99;

    /* Sidebar */
    --sidebar-bg:       #1B6368;
    --sidebar-hover:    rgba(43, 182, 199, 0.18);
    --sidebar-active:   #2BB6C7;
    --sidebar-border:   rgba(255, 255, 255, 0.09);
    --sidebar-width:    262px;

    /* Layout */
    --topbar-height:    64px;
    --body-bg:          #F4EFE6;
    --card-bg:          #FFFFFF;
    --card-shadow:      0 1px 4px rgba(27, 99, 104, 0.08), 0 1px 2px rgba(27, 99, 104, 0.05);
    --radius:           10px;

    /* Texto */
    --text-primary:     #3a3938;
    --text-secondary:   #666564;
    --text-muted:       #9C9B99;

    /* Bordes */
    --border:           #e5ddd3;

    /* Botón primario */
    --btn-primary:      #2BB6C7;
    --btn-primary-hov:  #1B6368;
}

/* ── Reset base ── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: var(--font-body);
    background: var(--body-bg);
    color: var(--text-primary);
    margin: 0;
    line-height: 1.55;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    letter-spacing: .5px;
    line-height: 1.15;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #ede6dc; }
::-webkit-scrollbar-thumb { background: #b5cdd0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--brand-teal); }

/* ══════════════════════════════════════════════
   AUTH PAGES
   ══════════════════════════════════════════════ */
.auth-body {
    min-height: 100vh;
    background: linear-gradient(150deg, #1B6368 0%, #1e7a82 45%, #2BB6C7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.auth-container { width: 100%; max-width: 440px; }

.auth-card {
    background: #fff;
    border-radius: 18px;
    padding: 2.5rem;
    box-shadow: 0 24px 64px rgba(27, 99, 104, 0.30);
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}
.auth-logo i {
    font-size: 2.8rem;
    color: var(--brand-teal);
    margin-bottom: .5rem;
    display: block;
}
.auth-logo h1 {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 400;
    color: var(--brand-teal-dark);
    margin: 0;
    letter-spacing: 1.5px;
}
.auth-logo p { color: var(--text-muted); margin: .3rem 0 0; font-size: .88rem; }

.auth-footer { text-align: center; margin-top: 1.5rem; color: var(--text-muted); font-size: .88rem; }
.auth-footer a { color: var(--brand-teal); font-weight: 600; text-decoration: none; }
.auth-footer a:hover { color: var(--brand-teal-dark); text-decoration: underline; }

/* Bootstrap overrides for auth inputs */
.auth-card .form-control:focus,
.auth-card .input-group-text { border-color: var(--brand-teal); }
.auth-card .form-control:focus { box-shadow: 0 0 0 .2rem rgba(43, 182, 199, .2); }

/* ══════════════════════════════════════════════
   LAYOUT WRAPPER
   ══════════════════════════════════════════════ */
.wrapper { display: flex; min-height: 100vh; }

/* ══════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: #d8eff0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    z-index: 1000;
    transition: transform .3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    padding: 1.5rem 1.25rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.logo-container { display: flex; align-items: center; gap: .75rem; }

.logo-icon { font-size: 1.8rem; color: var(--brand-teal); }

/* Logo cargado dinámicamente */
.sidebar-logo-img {
    max-width: 200px;
    max-height: 64px;
    width: 100%;
    object-fit: contain;
    object-position: left center;
    display: block;
}

.sidebar-logo-mini {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 8px;
    flex-shrink: 0;
}

/* Cuando hay logo, el header del sidebar tiene más padding vertical */
.sidebar-header:has(.sidebar-logo-img) {
    padding: 1.1rem 1.25rem;
}
.sidebar-header:has(.sidebar-logo-img) .logo-container {
    justify-content: flex-start;
}

.app-name {
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 400;
    color: #ffffff;
    line-height: 1.1;
    letter-spacing: 1.5px;
}

.app-subtitle {
    font-size: .65rem;
    color: rgba(43, 182, 199, 0.75);
    text-transform: uppercase;
    letter-spacing: .7px;
    margin-top: 1px;
}

/* Menu */
.sidebar-menu { list-style: none; padding: .75rem 0; margin: 0; flex: 1; }

.menu-label {
    font-family: var(--font-display);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: rgba(43, 182, 199, 0.6);
    padding: 1.1rem 1.25rem .35rem;
    font-weight: 400;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .62rem 1.25rem;
    color: #aed8dc;
    text-decoration: none;
    border-radius: 8px;
    margin: 2px .6rem;
    transition: all .18s;
    font-family: var(--font-body);
    font-size: .875rem;
    font-weight: 500;
}

.sidebar-menu li a:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-menu li.active a {
    background: var(--brand-teal);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 3px 10px rgba(43, 182, 199, .4);
}

.sidebar-menu li a i { width: 18px; text-align: center; flex-shrink: 0; }

/* User info bottom */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--sidebar-border);
    margin-top: auto;
    background: rgba(0,0,0,.12);
}

.user-avatar {
    width: 38px; height: 38px;
    background: var(--brand-teal);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: .82rem; color: #fff;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,.2);
}

.user-avatar-sm {
    width: 30px; height: 30px;
    background: var(--brand-teal);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .75rem; color: #fff;
}

.user-name {
    font-size: .84rem; font-weight: 600; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 155px;
}
.user-role { font-size: .7rem; color: rgba(43, 182, 199, 0.7); }

/* ══════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════ */
.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left .3s ease, width .3s ease;
}

/* ── Top Navbar ── */
.top-navbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 2px solid var(--brand-cream);
    padding: 0 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0; z-index: 999;
    box-shadow: 0 1px 6px rgba(27, 99, 104, .07);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    width: 38px; height: 38px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: all .18s;
    padding: 0;
    cursor: pointer;
}
.btn-icon:hover { background: var(--brand-teal-light); color: var(--brand-teal-dark); }
.btn-user-toggle { width: auto !important; padding: 0 .5rem !important; }

/* Breadcrumb */
.breadcrumb-item a { color: var(--brand-teal); text-decoration: none; font-size: .85rem; }
.breadcrumb-item.active { color: var(--text-secondary); font-size: .85rem; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--brand-gray-mid); }

/* ── Page content ── */
.page-content { padding: 1.75rem; flex: 1; }

.page-header {
    display: flex; align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    gap: 1rem; flex-wrap: wrap;
}

.page-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 400;
    color: var(--brand-teal-dark);
    margin: 0;
    letter-spacing: 1px;
}

.page-subtitle { color: var(--text-muted); margin: .3rem 0 0; font-size: .875rem; }

/* ══════════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════════ */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    background: var(--card-bg);
}

.card-header {
    background: none;
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
}

.card-title {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 400;
    color: var(--brand-teal-dark);
    letter-spacing: .8px;
}

/* ══════════════════════════════════════════════
   STAT CARDS
   ══════════════════════════════════════════════ */
.stat-card {
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex; align-items: center; gap: 1rem;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: var(--card-shadow);
    transition: transform .2s, box-shadow .2s;
    text-decoration: none;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(27, 99, 104, .13); }

.stat-card.ring-active {
    outline: 2px solid var(--brand-teal);
    outline-offset: 2px;
}

.stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; flex-shrink: 0;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 2.1rem;
    font-weight: 400;
    color: var(--brand-teal-dark);
    line-height: 1;
    letter-spacing: .5px;
}
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

/* Variantes de stat cards con paleta Aerosanidad */
.stat-card-blue    .stat-icon { background: #d6f2f5; color: var(--brand-teal); }
.stat-card-green   .stat-icon { background: #d1ecee; color: var(--brand-teal-dark); }
.stat-card-yellow  .stat-icon { background: #fef9c3; color: #b45309; }
.stat-card-orange  .stat-icon { background: #ffedd5; color: #c2410c; }
.stat-card-purple  .stat-icon { background: #ede9fe; color: var(--brand-purple); }
.stat-card-primary .stat-icon { background: #d6f2f5; color: var(--brand-teal); }
.stat-card-secondary .stat-icon { background: #f1f5f9; color: var(--text-secondary); }
.stat-card-success .stat-icon { background: #dcfce7; color: #15803d; }
.stat-card-warning .stat-icon { background: #fef9c3; color: #b45309; }
.stat-card-danger  .stat-icon { background: #fee2e2; color: #b91c1c; }
.stat-card-info    .stat-icon { background: #d6f2f5; color: var(--brand-teal); }
.stat-card-dark    .stat-icon { background: #f1f5f9; color: var(--text-secondary); }

/* ══════════════════════════════════════════════
   BUTTONS (Bootstrap overrides)
   ══════════════════════════════════════════════ */
.btn-primary {
    background-color: var(--brand-teal) !important;
    border-color: var(--brand-teal) !important;
    color: #fff !important;
    font-weight: 600;
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--brand-teal-dark) !important;
    border-color: var(--brand-teal-dark) !important;
    box-shadow: 0 4px 12px rgba(43, 182, 199, .35) !important;
}

.btn-outline-primary {
    color: var(--brand-teal) !important;
    border-color: var(--brand-teal) !important;
}
.btn-outline-primary:hover {
    background-color: var(--brand-teal) !important;
    color: #fff !important;
}

.btn-success {
    background-color: var(--brand-teal-dark) !important;
    border-color: var(--brand-teal-dark) !important;
    color: #fff !important;
    font-weight: 600;
}
.btn-success:hover {
    background-color: #155257 !important;
    border-color: #155257 !important;
}

/* ══════════════════════════════════════════════
   FORM CONTROLS
   ══════════════════════════════════════════════ */
.form-control, .form-select, .input-group-text, label, .form-label, .form-check-label {
    font-family: var(--font-body);
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand-teal);
    box-shadow: 0 0 0 .2rem rgba(43, 182, 199, .2);
}

.input-group-text {
    background: var(--brand-cream);
    border-color: #dee2e6;
    color: var(--brand-teal-dark);
}

/* ══════════════════════════════════════════════
   TABLES
   ══════════════════════════════════════════════ */
.table > :not(caption) > * > * { padding: .72rem 1rem; }

.table thead th {
    font-family: var(--font-display);
    font-size: .88rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--brand-teal-dark);
    font-weight: 400;
    background: #f0fafa;
    border-bottom: 2px solid #c5e8eb;
}

.table tbody tr { border-bottom: 1px solid #f4ede5; }
.table-hover tbody tr:hover { background: #f0fafa; }

/* ══════════════════════════════════════════════
   BADGES — paleta Aerosanidad
   ══════════════════════════════════════════════ */
.badge { font-family: var(--font-body); font-weight: 600; letter-spacing: .3px; padding: .35em .65em; }

/* Override Bootstrap badge colors */
.badge.bg-primary  { background-color: var(--brand-teal)      !important; }
.badge.bg-success  { background-color: var(--brand-teal-dark)  !important; }
.badge.bg-info     { background-color: var(--brand-teal)       !important; color: #fff !important; }
.badge.bg-warning  { background-color: #f59e0b !important; color: #fff !important; }
.badge.bg-danger   { background-color: #dc2626 !important; }
.badge.bg-secondary{ background-color: var(--brand-gray-mid) !important; }
.badge.bg-dark     { background-color: var(--brand-gray-dark) !important; }

/* Custom health-category badges */
.badge-teal    { background: var(--brand-teal);     color: #fff; }
.badge-teal-dk { background: var(--brand-teal-dark); color: #fff; }
.badge-purple  { background: var(--brand-purple);   color: #fff; }
.badge-cream   { background: var(--brand-cream);    color: var(--brand-teal-dark); border: 1px solid #d4c9b8; }

/* ══════════════════════════════════════════════
   CATEGORY QUICK FILTER BUTTONS
   ══════════════════════════════════════════════ */
.cat-badge {
    border-radius: 20px;
    font-size: .8rem;
    font-weight: 600;
    transition: all .18s;
    border-width: 1.5px;
}

.cat-badge[data-cat=""].active,
.cat-badge.active {
    background: var(--brand-teal) !important;
    color: #fff !important;
    border-color: var(--brand-teal) !important;
    box-shadow: 0 3px 8px rgba(43, 182, 199, .35);
}

/* ── Quick Filters Card ── */
.quick-filters-card { border-color: var(--border); }
.filter-group-label {
    font-family: var(--font-display);
    font-size: .8rem;
    letter-spacing: 1px;
    color: var(--text-muted);
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Time filter badges ── */
.time-badge {
    border-radius: 20px;
    font-size: .8rem;
    font-weight: 600;
    transition: all .18s;
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
}
.time-badge:hover {
    border-color: var(--brand-teal-dark);
    color: var(--brand-teal-dark);
    background: var(--brand-teal-light);
}
.time-badge.active {
    background: var(--brand-teal-dark) !important;
    color: #fff !important;
    border-color: var(--brand-teal-dark) !important;
    box-shadow: 0 3px 8px rgba(27, 99, 104, .3);
}
.time-badge-24h:not(.active) {
    border-color: #2BB6C7;
    color: #1B6368;
}
.time-badge-7d:not(.active) {
    border-color: var(--brand-purple);
    color: var(--brand-purple);
}
.time-badge-24h:not(.active):hover { background: var(--brand-teal-light); }
.time-badge-7d:not(.active):hover  { background: #ede9fe; }
.time-badge-24h.active, .time-badge-7d.active {
    background: var(--brand-teal-dark) !important;
    border-color: var(--brand-teal-dark) !important;
}
.time-count {
    background: rgba(255,255,255,.25) !important;
    font-size: .68rem;
    padding: .2em .45em;
}

.btn-outline-info    { color: var(--brand-teal) !important; border-color: var(--brand-teal) !important; }
.btn-outline-info:hover { background: var(--brand-teal) !important; color: #fff !important; }
.btn-outline-warning { color: #b45309 !important; border-color: #f59e0b !important; }
.btn-outline-warning:hover { background: #f59e0b !important; color: #fff !important; }
.btn-outline-danger  { color: #b91c1c !important; border-color: #ef4444 !important; }
.btn-outline-danger:hover  { background: #ef4444 !important; color: #fff !important; }
.btn-outline-success { color: var(--brand-teal-dark) !important; border-color: var(--brand-teal-dark) !important; }
.btn-outline-success:hover { background: var(--brand-teal-dark) !important; color: #fff !important; }
.btn-outline-secondary { color: var(--text-secondary) !important; border-color: var(--brand-gray-mid) !important; }
.btn-outline-secondary:hover { background: var(--brand-gray-mid) !important; color: #fff !important; }

/* ══════════════════════════════════════════════
   FILTER PANEL
   ══════════════════════════════════════════════ */
.cursor-pointer { cursor: pointer; }

[data-bs-toggle="collapse"] .fa-chevron-down { transition: transform .28s; }
[data-bs-toggle="collapse"].collapsed .fa-chevron-down { transform: rotate(-90deg); }

#filterPanel .card-header { background: #f0fafa; border-bottom-color: #c5e8eb; }

/* ══════════════════════════════════════════════
   CONTRACT DETAIL MODAL
   ══════════════════════════════════════════════ */
.modal-content { border: none; border-radius: 14px; overflow: hidden; }
.modal-header {
    background: linear-gradient(135deg, var(--brand-teal-dark) 0%, var(--brand-teal) 100%);
    color: #fff;
    border: none;
    padding: 1.25rem 1.5rem;
}
.modal-header .modal-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 1.35rem;
    letter-spacing: 1px;
    color: #fff;
}
.modal-header .btn-close { filter: invert(1); }

.modal-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.detail-label {
    font-family: var(--font-display);
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--brand-teal-dark);
    font-weight: 400;
    margin-bottom: .25rem;
}
.detail-value { font-size: .95rem; color: var(--text-primary); word-break: break-word; }

.price-highlight {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 400;
    color: var(--brand-teal-dark);
    letter-spacing: .5px;
}

.modal-footer {
    background: var(--brand-cream);
    border-top: 1px solid var(--border);
}

/* ══════════════════════════════════════════════
   ALERTS & LIST GROUPS
   ══════════════════════════════════════════════ */
.alert-info {
    background: var(--brand-teal-light);
    border-color: #93d8df;
    color: var(--brand-teal-dark);
}

.list-group-item { border-color: var(--border); }
.list-group-item:hover { background: #f9f5ef; }

/* Unread alert highlight */
.list-group-item.list-group-item-warning {
    background: rgba(127, 127, 244, .07) !important;
    border-left: 3px solid var(--brand-purple) !important;
}

/* ══════════════════════════════════════════════
   LOADING SPINNER
   ══════════════════════════════════════════════ */
#loadingState { padding: 4rem; }

.spinner-border.text-primary { color: var(--brand-teal) !important; }

/* ══════════════════════════════════════════════
   DATATABLES OVERRIDES
   ══════════════════════════════════════════════ */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_info {
    font-family: var(--font-body);
}

.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .4rem .75rem;
    color: var(--text-primary);
}
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--brand-teal);
    box-shadow: 0 0 0 .15rem rgba(43, 182, 199, .2);
    outline: none;
}
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .3rem .5rem;
}
.page-link { color: var(--brand-teal); }
.page-link:hover { color: var(--brand-teal-dark); }
.page-item.active .page-link {
    background-color: var(--brand-teal);
    border-color: var(--brand-teal);
}

/* ══════════════════════════════════════════════
   SELECT2 OVERRIDES
   ══════════════════════════════════════════════ */
.select2-container--bootstrap-5 .select2-selection {
    border-color: #dee2e6 !important;
}
.select2-container--bootstrap-5.select2-container--focus .select2-selection {
    border-color: var(--brand-teal) !important;
    box-shadow: 0 0 0 .2rem rgba(43, 182, 199, .2) !important;
}
.select2-container--bootstrap-5 .select2-dropdown .select2-results__option--highlighted {
    background-color: var(--brand-teal) !important;
}

/* ══════════════════════════════════════════════
   SWEETALERT2 OVERRIDES
   ══════════════════════════════════════════════ */
.swal2-confirm { background-color: var(--brand-teal) !important; }
.swal2-confirm:hover { background-color: var(--brand-teal-dark) !important; }
.swal2-popup { font-family: var(--font-body) !important; }
.swal2-title { font-family: var(--font-display) !important; font-weight: 400 !important; letter-spacing: .8px !important; }

/* ══════════════════════════════════════════════
   DESCRIPTION CELL (offers table)
   ══════════════════════════════════════════════ */
.desc-cell {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .85rem;
    color: var(--text-secondary);
}

/* ══════════════════════════════════════════════
   SIDEBAR OVERLAY (backdrop for mobile/tablet)
   ══════════════════════════════════════════════ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(27, 99, 104, 0.52);
    z-index: 999;
    animation: overlayIn .22s ease;
}
.sidebar-overlay.visible { display: block; }
@keyframes overlayIn { from { opacity: 0 } to { opacity: 1 } }

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */

/* ── Tablets + Mobile (≤ 1024px): collapse sidebar ── */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); z-index: 1000; }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; width: 100%; }
}

/* ── Tablet (768px – 1024px) ── */
@media (min-width: 768px) and (max-width: 1024px) {
    .page-content  { padding: 1.35rem 1.5rem; }
    .page-title    { font-size: 1.75rem; }
    .stat-value    { font-size: 1.85rem; }
    .sidebar       { width: 248px; }
}

/* ── Mobile (< 768px) ── */
@media (max-width: 767px) {
    /* Layout */
    .page-content { padding: 1rem .9rem; }
    .top-navbar   { padding: 0 .9rem; }

    /* Typography */
    .page-title      { font-size: 1.5rem; }
    .stat-value      { font-size: 1.65rem; }
    .price-highlight { font-size: 1.5rem; }
    .card-title      { font-size: 1.05rem; }

    /* Page header: sync/action button goes full width */
    .page-header { gap: .6rem; }
    .page-header > a.btn,
    .page-header > button.btn { width: 100%; justify-content: center; }

    /* Modal: single-column grid + full-width dialog */
    .modal-detail-grid          { grid-template-columns: 1fr; }
    .modal-xl                   { --bs-modal-width: 96vw; }
    .modal-dialog               { margin: .5rem auto; max-width: calc(100vw - 1rem); }

    /* Nav tabs: horizontal scroll, no wrapping */
    .nav-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 1px;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-link { white-space: nowrap; font-size: .82rem; padding: .5rem .75rem; }

    /* Filter group label: block to sit on its own line */
    .filter-group-label {
        display: block;
        width: 100%;
        margin-bottom: .2rem;
        white-space: normal;
    }

    /* Quick filter time row: last sync text de-floats */
    .quick-filters-card .card-body > div:last-child > .ms-auto {
        margin-left: 0 !important;
        width: 100%;
        padding-top: .15rem;
    }

    /* Offers table: hide secondary columns */
    #offersTable thead th:nth-child(1),
    #offersTable tbody td:nth-child(1),
    #offersTable thead th:nth-child(4),
    #offersTable tbody td:nth-child(4),
    #offersTable thead th:nth-child(6),
    #offersTable tbody td:nth-child(6),
    #offersTable thead th:nth-child(7),
    #offersTable tbody td:nth-child(7) { display: none; }

    /* Description cell narrower on mobile */
    .desc-cell { max-width: 170px; }

    /* Status bar: stacked */
    #statusBar { flex-direction: column; align-items: flex-start !important; gap: .4rem; }

    /* Pagination footer: stacked */
    .card-footer.d-flex { flex-direction: column; gap: .5rem; align-items: flex-start !important; }

    /* Stat card: tighter */
    .stat-card { padding: 1rem .85rem; gap: .7rem; }
    .stat-icon { width: 44px; height: 44px; font-size: 1.2rem; }

    /* Auth */
    .auth-card { padding: 1.75rem 1.25rem; }

    /* Doc flow: vertical on mobile */
    .doc-flow   { flex-direction: column; align-items: flex-start; }
    .flow-arrow { transform: rotate(90deg); align-self: center; }

    /* DataTables layout fix */
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length { width: 100%; text-align: left !important; margin-bottom: .5rem; }
    .dataTables_wrapper .dataTables_filter input { width: 100%; margin-left: 0 !important; margin-top: .25rem; display: block; }
}

/* ── Extra-small (< 480px): phones portrait ── */
@media (max-width: 479px) {
    .page-content { padding: .75rem .65rem; }
    .page-title   { font-size: 1.3rem; }
    .stat-value   { font-size: 1.45rem; }
    .stat-label   { font-size: .72rem; }
    .stat-icon    { width: 38px; height: 38px; font-size: 1rem; border-radius: 9px; }
    .stat-card    { padding: .8rem .65rem; gap: .5rem; }

    /* Also hide Estado column (col 8) on very small phones */
    #offersTable thead th:nth-child(8),
    #offersTable tbody td:nth-child(8) { display: none; }

    /* Auth */
    .auth-card   { padding: 1.5rem 1rem; }
    .auth-logo h1 { font-size: 1.8rem; }

    /* Sidebar slightly narrower on 320px phones */
    .sidebar { width: 240px; }

    /* Nav tabs even more compact */
    .nav-tabs .nav-link { font-size: .76rem; padding: .4rem .6rem; }

    /* Page header button */
    .page-header .btn { font-size: .82rem; padding: .45rem .75rem; }

    /* desc-cell even narrower */
    .desc-cell { max-width: 130px; }
}

/* ══════════════════════════════════════════════
   FILTER PANEL ACTION BUTTONS (responsive)
   ══════════════════════════════════════════════ */
.filter-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.filter-actions .btn { flex: 1 1 120px; }

/* ══════════════════════════════════════════════
   PAGE-SPECIFIC RESPONSIVE FIXES
   ══════════════════════════════════════════════ */

/* ── Mobile (< 768px) ── */
@media (max-width: 767px) {

    /* Tab-content inline padding override (docs.php, notifications.php) */
    .tab-content { padding: 1rem !important; }

    /* Card headers with space-between: allow wrap */
    .card-header.d-flex.justify-content-between { flex-wrap: wrap; gap: .5rem; }

    /* List-group item row: wrap action buttons below content */
    .list-group-item > .d-flex.justify-content-between { flex-wrap: wrap; gap: .5rem; }
    .list-group-item .text-nowrap.ms-3 { margin-left: 0 !important; width: 100%; color: var(--text-muted); }

    /* Tab pane section headers (notifications.php) */
    .tab-pane > .d-flex.justify-content-between { flex-wrap: wrap; gap: .5rem; }
    .tab-pane > .d-flex.justify-content-between .btn { white-space: nowrap; }

    /* Notifications.php: email test input full-width */
    #emailTest { max-width: none !important; flex: 1 1 200px; min-width: 0; }
    .d-flex:has(#emailTest) { flex-wrap: wrap; }

    /* my_applications.php: hide secondary columns */
    #myAppsTable thead th:nth-child(1),
    #myAppsTable tbody td:nth-child(1),
    #myAppsTable thead th:nth-child(4),
    #myAppsTable tbody td:nth-child(4),
    #myAppsTable thead th:nth-child(6),
    #myAppsTable tbody td:nth-child(6),
    #myAppsTable thead th:nth-child(8),
    #myAppsTable tbody td:nth-child(8) { display: none; }

    /* my_applications.php stat cards: compact without icon */
    #myAppsTable + .d-flex { flex-wrap: wrap; }
    .stat-card:not(:has(.stat-icon)) { padding: .75rem .85rem; }
}

/* ── Extra-small (< 480px) ── */
@media (max-width: 479px) {
    /* my_applications: also hide Notas column on tiny screens */
    #myAppsTable thead th:nth-child(8),
    #myAppsTable tbody td:nth-child(8) { display: none; }

    /* Stack card headers vertically */
    .card-header.d-flex.justify-content-between { flex-direction: column; align-items: flex-start !important; }
    .card-header.d-flex.justify-content-between .btn,
    .card-header.d-flex.justify-content-between a.btn { align-self: flex-start; }
}
