/* === Global dark override for inline-styled inputs/selects === */
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
select,
textarea {
    background-color: #1f2937 !important;
    color: #f1f5f9 !important;
    border-color: #374151 !important;
}
input::placeholder, textarea::placeholder {
    color: #6b7280 !important;
    opacity: 1 !important;
}
select option { background: #1f2937; color: #f1f5f9; }

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

html { overflow-x: hidden; }

body {
    font-family: 'Calibri', 'Candara', 'Segoe UI', Roboto, sans-serif;
    background: #030712;
    color: #f1f5f9;
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
    min-height: 100vh;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #111827; }
::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #6b7280; }

/* === App Layout === */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
    width: 220px;
    min-width: 220px;
    background: #111827;
    border-right: 1px solid #1f2937;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    transition: transform 0.25s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1.1rem 1rem;
    border-bottom: 1px solid #1f2937;
    flex-shrink: 0;
}

.sidebar-logo-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #7c3aed;
    color: #fff;
    font-weight: 800;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.sidebar-brand-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: #f1f5f9;
    flex: 1;
}

.sidebar-close {
    background: none;
    border: none;
    color: #6b7280;
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.15rem 0.3rem;
    display: none;
    border-radius: 4px;
}
.sidebar-close:hover { color: #f1f5f9; background: #1f2937; }

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

/* === Nav Links (sidebar) === */
.nav-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #9ca3af;
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    font-size: 0.84rem;
    font-weight: 500;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
}

.nav-link:hover {
    color: #f1f5f9;
    background: #1f2937;
}

.nav-link.active {
    color: #fff;
    font-weight: 600;
    background: #7c3aed;
}

.nav-link.active .nav-icon { color: #c4b5fd; }

/* === Sidebar Footer === */
.sidebar-footer {
    border-top: 1px solid #1f2937;
    padding: 0.75rem 1rem;
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.sidebar-user-name {
    font-size: 0.8rem;
    color: #9ca3af;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.25rem;
}

.sidebar-user-actions {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-user-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    background: none;
    border: none;
    color: #9ca3af;
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    border-radius: 5px;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.sidebar-user-btn:hover {
    background: #1f2937;
    color: #f1f5f9;
}

.sidebar-user-btn--danger:hover {
    background: rgba(239,68,68,0.12);
    color: #f87171;
}

/* === Sidebar Overlay (mobile) === */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 199;
}
.sidebar-overlay.open { display: block; }

/* === Main Wrapper === */
.main-wrapper {
    flex: 1;
    margin-left: 220px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* === Topbar === */
.topbar {
    background: #111827;
    border-bottom: 1px solid #1f2937;
    padding: 0.7rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-toggle {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 0.3rem;
    border-radius: 5px;
    transition: color 0.15s, background 0.15s;
}
.topbar-toggle:hover { color: #f1f5f9; background: #1f2937; }

.topbar-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #9ca3af;
    margin: 0;
}

/* === Main Container === */
.app-container {
    flex: 1;
    padding: 1.5rem;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
}

/* === Section === */
.section {
    background: #111827;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    border: 1px solid #1f2937;
    width: 100%;
    margin-bottom: 1.25rem;
}

/* Wrapper que permite scroll horizontal solo en la tabla */
.table-scroll {
    overflow-x: auto;
    width: 100%;
    margin-top: 1rem;
    border-radius: 8px;
}

.section-title {
    font-size: 1.1rem;
    color: #f1f5f9;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #1f2937;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* === Forms === */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
    color: #9ca3af;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #374151;
    border-radius: 6px;
    font-size: 0.9rem;
    background: #1f2937;
    color: #f1f5f9;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: #6b7280;
}

.form-group select option {
    background: #1f2937;
    color: #f1f5f9;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 2px rgba(124,58,237,0.2);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

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

/* Un campo solo en su fila ocupa TODO el ancho. Sin esto, un único .form-group
   quedaba en la primera columna de la grilla 1fr 1fr y dejaba un hueco a la derecha. */
.form-row > .form-group:only-child {
    grid-column: 1 / -1;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1.1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: #7c3aed;
    color: #fff;
}
.btn-primary:hover { background: #6d28d9; }

.btn-secondary {
    background: #374151;
    color: #f1f5f9;
}
.btn-secondary:hover { background: #4b5563; }

.btn-danger {
    background: rgba(239,68,68,0.15);
    color: #f87171;
    border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover {
    background: rgba(239,68,68,0.25);
    color: #fca5a5;
}

/* === Error Messages === */
.error-message {
    color: #f87171;
    font-size: 0.82rem;
    margin-top: 0.25rem;
}

.form-group.has-error input,
.form-group.has-error select,
.form-group.has-error textarea {
    border-color: #ef4444;
}

/* === Alerts === */
.alert {
    padding: 0.7rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-error, .alert-danger {
    background: rgba(239,68,68,0.12);
    color: #fca5a5;
    border: 1px solid rgba(239,68,68,0.25);
}

.alert-success {
    background: rgba(34,197,94,0.12);
    color: #86efac;
    border: 1px solid rgba(34,197,94,0.25);
}

.alert-info {
    background: rgba(59,130,246,0.12);
    color: #93c5fd;
    border: 1px solid rgba(59,130,246,0.25);
}

.alert-warning {
    background: rgba(245,158,11,0.12);
    color: #fcd34d;
    border: 1px solid rgba(245,158,11,0.25);
}

/* === Tables === */
/* Contenedor con scroll horizontal para tablas anchas (clave en celular: sin esto
   las columnas de la derecha se cortaban porque body/html tienen overflow-x:hidden). */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0;
}

.data-table th,
.data-table td {
    padding: 0.6rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid #1f2937;
    font-size: 0.855rem;
    vertical-align: middle;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #e2e8f0;
}

.data-table th {
    background: #0f172a;
    color: #9ca3af;
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-bottom: 1px solid #374151;
}

.data-table tbody tr { background: transparent; }

.data-table tbody tr:hover {
    background: rgba(124,58,237,0.06);
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table .actions {
    white-space: nowrap;
    text-align: right;
}

.data-table .actions-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    justify-content: flex-end;
}

/* Botones de acción en tabla */
.data-table .btn-icon {
    background: transparent;
    width: 28px;
    height: 28px;
    border-radius: 5px;
    color: #6b7280;
    transform: none;
}
.data-table .btn-icon:hover { transform: none; }
.data-table .btn-icon.primary { color: #60a5fa; }
.data-table .btn-icon.primary:hover { background: rgba(96,165,250,0.12); }
.data-table .btn-icon.purple { color: #a78bfa; }
.data-table .btn-icon.purple:hover { background: rgba(167,139,250,0.12); }
.data-table .btn-icon.danger { color: #f87171; }
.data-table .btn-icon.danger:hover { background: rgba(248,113,113,0.12); }
.data-table .btn-icon.success { color: #4ade80; }
.data-table .btn-icon.success:hover { background: rgba(74,222,128,0.12); }

/* Input inline fuera de form-group (búsquedas en sección header) */
.search-input-inline {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid #374151;
    border-radius: 6px;
    font-size: 0.9rem;
    background: #1f2937;
    color: #f1f5f9;
    font-family: inherit;
    transition: border-color 0.2s;
}
.search-input-inline::placeholder { color: #6b7280; }
.search-input-inline:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 2px rgba(124,58,237,0.2);
}

/* === Search === */
.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.search-bar input,
.search-bar select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #374151;
    border-radius: 6px;
    font-size: 0.875rem;
    background: #1f2937;
    color: #f1f5f9;
    font-family: inherit;
}

.search-bar input { flex: 1; }

.search-bar input::placeholder { color: #6b7280; }

.search-bar input:focus,
.search-bar select:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 2px rgba(124,58,237,0.2);
}

.search-bar select option { background: #1f2937; }

/* === Checkbox Labels === */
.checkbox-label {
    display: block;
    padding: 0.35rem 0;
    font-size: 0.9rem;
    cursor: pointer;
    color: #e2e8f0;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 0.5rem;
    accent-color: #7c3aed;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: #6b7280;
    font-size: 0.92rem;
}

/* === Utility === */
.hidden { display: none !important; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* === Icon Buttons === */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
    background: #374151;
    color: #d1d5db;
}
.btn-icon:hover { background: #4b5563; transform: scale(1.1); }
.btn-icon.primary { background: rgba(96,165,250,0.15); color: #60a5fa; }
.btn-icon.primary:hover { background: rgba(96,165,250,0.25); }
.btn-icon.danger { background: rgba(248,113,113,0.15); color: #f87171; }
.btn-icon.danger:hover { background: rgba(248,113,113,0.25); }
.btn-icon.success { background: rgba(74,222,128,0.15); color: #4ade80; }
.btn-icon.success:hover { background: rgba(74,222,128,0.25); }
.btn-icon.purple { background: rgba(167,139,250,0.15); color: #a78bfa; }
.btn-icon.purple:hover { background: rgba(167,139,250,0.25); }

/* === Modal === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1200; /* por encima del modal de formulario (1100) para verse al abrir desde Editar */
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 10px;
    padding: 1.5rem;
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #9ca3af;
    line-height: 1;
}
.modal-close:hover { color: #f87171; }
.modal-content img {
    max-width: 100%;
    max-height: 80vh;
    /* Fondo claro en damero para ver imágenes PNG transparentes (huella/firma) */
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
        linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
    background-size: 18px 18px;
    background-position: 0 0, 0 9px, 9px -9px, -9px 0;
    border-radius: 6px;
}
.modal-content iframe { width: 80vw; height: 80vh; border: none; }

/* === Autocomplete === */
.autocomplete-wrapper { position: relative; }
.autocomplete-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1f2937;
    border: 1px solid #374151;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 220px;
    overflow-y: auto;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.autocomplete-results.open { display: block; }
.autocomplete-item {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid #374151;
    color: #e2e8f0;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: #374151; color: #f1f5f9; }
.autocomplete-item.no-result {
    color: #6b7280;
    cursor: default;
    font-style: italic;
}
.autocomplete-item.no-result:hover { background: transparent; }

/* === Audit Info Popup === */
.audit-link {
    color: #a78bfa;
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.85rem;
}
.audit-link:hover { color: #c4b5fd; }

.audit-popup-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.audit-popup {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    min-width: 280px;
    max-width: 90vw;
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
    position: relative;
}
.audit-popup h3 {
    font-size: 1rem;
    color: #f1f5f9;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #374151;
}
.audit-popup .audit-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.35rem 0;
    font-size: 0.85rem;
    border-bottom: 1px solid #111827;
}
.audit-popup .audit-row:last-child { border-bottom: none; }
.audit-popup .audit-label {
    font-weight: 600;
    color: #9ca3af;
    min-width: 120px;
    flex-shrink: 0;
}
.audit-popup .audit-value { color: #e2e8f0; word-break: break-word; }
.audit-popup .audit-close {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: #9ca3af;
}
.audit-popup .audit-close:hover { color: #f87171; }

/* === Dashboard === */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.dash-card {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 10px;
    padding: 1.2rem 1rem;
    text-align: center;
    border-left: 4px solid transparent;
}

.dash-card-blue   { border-left-color: #3b82f6; }
.dash-card-orange { border-left-color: #f97316; }
.dash-card-green  { border-left-color: #22c55e; }
.dash-card-red    { border-left-color: #ef4444; }
.dash-card-purple { border-left-color: #a855f7; }

.dash-card-icon   { font-size: 1.8rem; margin-bottom: 0.3rem; }
.dash-card-value  { font-size: 1.5rem; font-weight: 700; color: #f1f5f9; }
.dash-card-label  { font-size: 0.82rem; color: #9ca3af; margin-top: 0.2rem; }

.dashboard-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.dash-chart-box {
    min-height: 300px;
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 10px;
    padding: 1rem;
}

.dash-chart-box canvas { max-height: 260px; }

@media (max-width: 768px) {
    .dashboard-charts { grid-template-columns: 1fr; }
    .dashboard-cards { grid-template-columns: repeat(2, 1fr); }
    .dash-card-value { font-size: 1.2rem; }
}

/* === Form Modal === */
.form-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.65);
    z-index: 1100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 3vh;
    overflow-y: auto;
}

.form-modal {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 10px;
    width: 95%;
    max-width: 640px;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: modalSlideIn 0.2s ease-out;
}

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

.form-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #374151;
    background: #111827;
    border-radius: 10px 10px 0 0;
    position: sticky;
    top: 0;
    z-index: 1;
}

.form-modal-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #f1f5f9;
}

.form-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #9ca3af;
    line-height: 1;
    padding: 0 0.25rem;
}
.form-modal-close:hover { color: #f87171; }

.form-modal-body { padding: 1.25rem; }

.form-modal-footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem 1.25rem;
}

#form-modal-alert { padding: 0 1.25rem; }

@media (max-width: 768px) {
    .form-modal { width: 94%; max-height: 92vh; }
    .form-modal-body { padding: 1rem; }
}

/* === Ficha del Cliente === */
.profile-heading {
    font-size: 1.05rem;
    color: #a78bfa;
    border-bottom: 2px solid #374151;
    padding-bottom: 0.3rem;
    margin-bottom: 0.75rem;
}
.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 1.5rem;
}
.profile-field {
    padding: 0.25rem 0;
    font-size: 0.92rem;
    color: #e2e8f0;
}
.profile-label {
    font-weight: 600;
    color: #9ca3af;
}
.profile-section { margin-bottom: 1.25rem; }
.profile-claim-card {
    border: 1px solid #374151;
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: #0f172a;
}
.profile-claim-header {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: #e2e8f0;
}
.profile-actions { padding: 0.5rem 0; }

@media (max-width: 600px) {
    .profile-grid { grid-template-columns: 1fr; }
    .profile-claim-header { flex-direction: column; gap: 0.25rem; }
}

@media print {
    .no-print { display: none !important; }
}

/* === DNI Upload Area === */
.dni-upload-area {
    border: 2px dashed #374151;
    border-radius: 8px;
    overflow: hidden;
    background: #111827;
    transition: border-color 0.15s, background 0.15s;
}
.dni-upload-area.dragover {
    border-color: #7c3aed;
    background: rgba(124,58,237,0.08);
}
.dni-upload-preview {
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.dni-upload-preview div { width: 100%; height: 100%; }
.dni-upload-preview img {
    width: 100% !important;
    height: 150px !important;
    object-fit: cover !important;
    display: block;
}
.dni-upload-preview:empty::before {
    content: 'Arrastra una imagen aquí';
    color: #6b7280;
    font-size: 0.85rem;
}
.dni-upload-btns {
    display: flex;
    border-top: 1px solid #374151;
}
.dni-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 0.5rem;
    background: #1f2937;
    border: none;
    font-size: 0.85rem;
    font-weight: 500;
    color: #9ca3af;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}
.dni-btn:first-child { border-right: 1px solid #374151; }
.dni-btn:hover { background: #374151; color: #f1f5f9; }
.dni-remove-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.15s;
}
.dni-remove-btn:hover { background: rgba(239,68,68,0.8); }

/* === Client Cards (mobile) === */
.client-cards-view { display: none; }

@media (max-width: 768px) {
    .client-table-view { display: none; }
    .client-cards-view { display: block; margin-top: 0.75rem; }

    .client-card {
        background: #1f2937;
        border-radius: 10px;
        border: 1px solid #374151;
        margin-bottom: 0.65rem;
        display: flex;
        align-items: stretch;
        overflow: hidden;
    }
    .client-card-left {
        flex: 1;
        min-width: 0;
        padding: 0.6rem 0.85rem;
        display: flex;
        flex-direction: column;
        gap: 0;
    }
    .client-card-name { font-weight: 700; font-size: 0.95rem; color: #f1f5f9; }
    .client-card-meta { font-size: 0.8rem; color: #9ca3af; }
    .client-card-row {
        font-size: 0.82rem;
        color: #d1d5db;
        display: flex;
        align-items: center;
        gap: 0.35rem;
        flex-wrap: wrap;
    }
    .client-card-icon { display: inline-flex; align-items: center; color: #6b7280; flex-shrink: 0; }
    .client-card-actions {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 0.35rem;
        padding: 0.6rem 0.55rem;
        border-left: 1px solid #374151;
        background: #111827;
    }
    .client-card-actions .btn-icon { width: 40px; height: 40px; background: transparent; color: #6b7280; transform: none; border-radius: 8px; }
    .client-card-actions .btn-icon:hover { transform: none; }
    .client-card-actions .btn-icon.primary { color: #60a5fa; }
    .client-card-actions .btn-icon.primary:hover { background: rgba(96,165,250,0.12); }
    .client-card-actions .btn-icon.purple { color: #a78bfa; }
    .client-card-actions .btn-icon.purple:hover { background: rgba(167,139,250,0.12); }
    .client-card-actions .btn-icon.danger { color: #f87171; }
    .client-card-actions .btn-icon.danger:hover { background: rgba(248,113,113,0.12); }
}

/* === Responsive sidebar === */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        width: 240px;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-close { display: block; }
    .main-wrapper { margin-left: 0; }
    .app-container { padding: 1rem; }
    .form-row { grid-template-columns: 1fr; gap: 0; }
    .search-bar { flex-direction: column; }
    .search-bar input { min-width: unset !important; }
    .btn { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
}

@media (max-width: 600px) {
    .data-table th,
    .data-table td { padding: 0.4rem 0.5rem; font-size: 0.8rem; }
    .dashboard-cards { grid-template-columns: repeat(2, 1fr); }
    .app-container { padding: 0.75rem; }
}

/* === iPhone / PWA instalada: respetar la zona segura (notch, reloj, barra home) === */
@supports (padding: env(safe-area-inset-top)) {
    .topbar {
        padding-top: calc(0.7rem + env(safe-area-inset-top));
    }
    .sidebar {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .app-container {
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }
    /* Modales: que no queden bajo el reloj ni la barra home del iPhone */
    .form-modal-overlay {
        padding-top: calc(3vh + env(safe-area-inset-top));
        padding-bottom: calc(2vh + env(safe-area-inset-bottom));
    }
}

/* Móvil: secciones con padding más cómodo (menos desperdicio lateral) */
@media (max-width: 600px) {
    .section { padding: 1rem 0.9rem; border-radius: 8px; }
    .topbar { padding-left: 0.9rem; padding-right: 0.9rem; }
}

/* Previsualización de huella/firma con damero para ver la transparencia del PNG */
.huella-firma-preview {
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
        linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    border-radius: 6px;
}
.huella-firma-preview img { background: transparent; }

/* === Barra de "cliente activo" en el topbar === */
.active-client-bar {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.acb-chip {
    background: rgba(124,58,237,0.18);
    color: #c4b5fd;
    border: 1px solid #7c3aed;
    border-radius: 999px;
    padding: 0.25rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.acb-chip .acb-dni { color: #9ca3af; font-weight: 400; }
.acb-btn {
    background: #1f2937;
    color: #e5e7eb;
    border: 1px solid #374151;
    border-radius: 6px;
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}
.acb-btn:hover { background: #374151; }
.acb-btn.acb-select { background: #7c3aed; color: #fff; border-color: #7c3aed; font-weight: 600; }
.acb-btn.acb-clear { color: #f87171; font-weight: 700; padding: 0.25rem 0.5rem; }
@media (max-width: 640px) {
    .acb-chip { max-width: 150px; font-size: 0.75rem; }
    .topbar-title { display: none; }
}

/* === Columna de alertas "Atender hoy" === */
.alerts-rail {
    width: 340px;
    min-width: 340px;
    background: #0d1420;
    border-left: 1px solid #1f2937;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 35;
}
#app-layout.rail-on .main-wrapper { margin-right: 340px; }
.alerts-rail-head {
    display: flex; justify-content: space-between; align-items: center;
    gap: 0.5rem; padding: 0.7rem 0.85rem;
    border-bottom: 1px solid #1f2937; background: #111827; color: #f1f5f9;
}
.alerts-rail-head-actions { display: flex; align-items: center; gap: 0.4rem; }
.alerts-rail-count {
    background: #7c3aed; color: #fff; border-radius: 10px;
    padding: 0 7px; font-size: 0.72rem; font-weight: 700; vertical-align: middle;
}
.alerts-rail-link {
    background: none; border: none; color: #a78bfa; cursor: pointer;
    font-size: 0.8rem; text-decoration: underline; padding: 2px 4px;
}
.alerts-rail-refresh { background: none; border: none; color: #9ca3af; font-size: 0.95rem; cursor: pointer; line-height: 1; padding: 2px 4px; }
.alerts-rail-refresh:hover { color: #f1f5f9; }
.alerts-rail-refresh.spin { animation: rail-spin 0.6s linear; }
@keyframes rail-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.alerts-rail-close { display: none; background: none; border: none; color: #9ca3af; font-size: 1.3rem; cursor: pointer; line-height: 1; }
.alerts-rail-body { flex: 1; overflow-y: auto; padding: 0.5rem; }
.alerts-rail-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 34; }
.alerts-rail-backdrop.open { display: block; }

/* Botón flotante (solo móvil) */
.alerts-fab {
    position: fixed; bottom: 18px; right: 16px; z-index: 40;
    width: 54px; height: 54px; border-radius: 50%;
    background: #7c3aed; color: #fff; border: none; cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
    font-size: 1.4rem; display: none; align-items: center; justify-content: center;
}
.alerts-fab-badge {
    position: absolute; top: -3px; right: -3px;
    background: #ef4444; color: #fff; border-radius: 10px;
    min-width: 20px; height: 20px; padding: 0 5px;
    font-size: 0.72rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

@media (max-width: 900px) {
    #app-layout.rail-on .main-wrapper { margin-right: 0; }
    .alerts-rail {
        width: min(90vw, 360px); min-width: 0;
        transform: translateX(100%); transition: transform 0.22s ease;
    }
    .alerts-rail.open { transform: translateX(0); }
    .alerts-rail-close { display: block; }
    #app-layout.rail-on .alerts-fab { display: flex; }
}

/* === Guía en móvil: los botones del paso bajan debajo del texto (no lo aplastan) === */
@media (max-width: 600px) {
    .guia-step-row { flex-wrap: wrap; }
    .guia-step-actions {
        flex-basis: 100%;
        text-align: left !important;
        margin-top: 6px;
        padding-left: 26px; /* alinear bajo el texto (nº de paso + gap) */
    }
    .guia-step-btns { flex-direction: row !important; flex-wrap: wrap; }
    .guia-step-btns .btn { flex: 1 1 auto; }
}
