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

:root {
    --safe-top: env(safe-area-inset-top, 0);
    --safe-right: env(safe-area-inset-right, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
    --safe-left: env(safe-area-inset-left, 0);
    --touch-min: 44px;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    font-size: clamp(0.9375rem, 2vw + 0.5rem, 1rem);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    padding-bottom: var(--safe-bottom);
    padding-top: var(--safe-top);
    overflow-x: hidden;
}

/* Dashboard - Estilo Formal Despacho de Abogados */
#dashboard-view {
    background: #f8f8f8;
}

#dashboard-view .view-header {
    background: #1a1a1a;
    color: #ffffff;
    padding: 2rem 2.5rem;
    border-bottom: 3px solid #2c3e50;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.dashboard-header-brand {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.dashboard-logo {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
}

.dashboard-header-titles {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.dashboard-office-name {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: #ffffff;
    margin: 0;
    letter-spacing: 0.5px;
    line-height: 1.3;
}

#dashboard-view .view-header h2 {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 1.75rem;
    font-weight: 600;
    color: #ffffff;
    margin: 0;
    letter-spacing: 0.5px;
}

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

.dashboard-firm-selector {
    margin-bottom: 1rem;
}
.dashboard-firm-selector label {
    margin-right: 0.5rem;
}
.dashboard-firm-selector select {
    padding: 0.35rem 0.5rem;
    min-width: 12rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.9rem; /* Reduced from 1.25rem */
    margin-bottom: 2rem;
}

.stat-card {
    background: #ffffff;
    padding: 1.2rem 1rem; /* Reduced ~35% from 2rem 1.5rem */
    border: 1px solid #e0e0e0;
    border-left: 4px solid #2c3e50;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    font-family: 'Georgia', 'Times New Roman', serif;
    min-height: 100px; /* Reduced from 140px */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.stat-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

.stat-card h3 {
    margin: 0 0 0.75rem 0; /* Reduced from 1.25rem */
    color: #555;
    font-size: 0.85rem; /* Reduced from 0.9rem */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border-bottom: 1px solid #e8e8e8;
    padding-bottom: 0.5rem; /* Reduced from 0.75rem */
}

.stat-card p {
    margin: 0;
    font-size: 1.4rem; /* Reduced from 3rem */
    font-weight: 700;
    color: #1a1a1a;
    font-family: 'Georgia', 'Times New Roman', serif;
    line-height: 1;
}

.priority-stats-section {
    background: #ffffff;
    padding: 2rem 1.5rem;
    border: 1px solid #e0e0e0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 2rem;
}

.priority-stats-section h3 {
    margin: 0 0 1.75rem 0;
    color: #1a1a1a;
    font-size: 1.4rem;
    font-weight: 600;
    font-family: 'Georgia', 'Times New Roman', serif;
    border-bottom: 2px solid #2c3e50;
    padding-bottom: 1rem;
    letter-spacing: 0.5px;
}

.priority-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
}

.priority-stat {
    padding: 1.5rem;
    background: #fafafa;
    border: 1px solid #e8e8e8;
    border-left: 3px solid #2c3e50;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.priority-stat:hover {
    background: #f5f5f5;
    border-left-color: #34495e;
}

.priority-stat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e0e0e0;
}

.priority-stat-icon {
    font-size: 1.25rem;
    opacity: 0.8;
}

.priority-stat-label {
    font-weight: 600;
    color: #333;
    font-size: 0.95rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.priority-stat-value {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: #1a1a1a;
    font-family: 'Georgia', 'Times New Roman', serif;
}

.priority-stat.urgent .priority-stat-value {
    color: #8b0000;
}

.priority-stat.medium .priority-stat-value {
    color: #b8860b;
}

.priority-stat.well .priority-stat-value {
    color: #2d5016;
}

.priority-stat.concluded-won .priority-stat-value {
    color: #1e7e34;
}

.priority-stat.concluded-lost .priority-stat-value {
    color: #8b0000;
}

.priority-stat.concluded-revoked .priority-stat-value {
    color: #6c757d;
}

.additional-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
}

.stat-card.stat-law {
    border-left-color: #6c757d;
}

.stat-card.stat-law p {
    color: #495057;
}

.stat-card.stat-reminder {
    border-left-color: #856404;
}

.stat-card.stat-reminder p {
    color: #856404;
}

.stat-card.stat-shared-sent {
    border-left-color: #4a148c;
}

.stat-card.stat-shared-sent p {
    color: #4a148c;
}

.stat-card.stat-shared-received {
    border-left-color: #880e4f;
}

.stat-card.stat-shared-received p {
    color: #880e4f;
}

/* Responsive para dashboard - PWA */
@media (max-width: 1200px) {
    .stats-grid,
    .additional-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .priority-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .statistics-container {
        padding: 1rem;
    }
    
    .stats-grid,
    .additional-stats-grid {
        grid-template-columns: repeat(2, 1fr); /* 2 columns on mobile */
        gap: 0.75rem; /* Tighter gap */
    }
    
    .stat-card {
        padding: 1rem 0.85rem; /* More compact on mobile */
        min-height: 90px; /* Reduced from 120px */
    }
    
    .stat-card h3 {
        font-size: 0.8rem; /* Smaller on mobile */
        margin-bottom: 0.6rem;
    }
    
    .stat-card p {
        font-size: 1.3rem; /* Reduced from 2.5rem */
    }
    
    .priority-stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .priority-stats-section {
        padding: 1.5rem 1rem;
    }
    
    .priority-stats-section h3 {
        font-size: 1.2rem;
        margin-bottom: 1.5rem;
    }
    
    .priority-stat {
        padding: 1.25rem;
    }
    
    .priority-stat-value {
        font-size: 1.5rem;
    }
    
    #dashboard-view .view-header {
        padding: 1.25rem 1rem;
    }
    
    #dashboard-view .view-header h2 {
        font-size: 1.4rem;
    }
    
    .dashboard-office-name {
        font-size: 1rem;
    }
    
    .dashboard-logo {
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 480px) {
    .statistics-container {
        padding: 0.75rem;
    }
    
    .stat-card {
        padding: 0.9rem 0.75rem; /* More compact */
        min-height: 85px; /* Reduced from 110px */
    }
    
    .stat-card p {
        font-size: 1.2rem; /* Reduced from 2.25rem */
    }
    
    .priority-stats-section {
        padding: 1.25rem 0.75rem;
    }
    
    .priority-stat {
        padding: 1rem;
    }
}

/* Firm Memo Chat */
.firm-memo-card {
    background: #ffffff;
    padding: 1.5rem;
    border: 1px solid #e0e0e0;
    border-left: 4px solid #4a90e2;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-top: 2rem;
}

.firm-memo-title {
    margin: 0 0 1rem 0;
    color: #1a1a1a;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: 'Georgia', 'Times New Roman', serif;
    border-bottom: 2px solid #4a90e2;
    padding-bottom: 0.5rem;
}

.firm-memo-list {
    max-height: 280px;
    overflow-y: auto;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e8e8e8;
}

.firm-memo-item {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: #f9f9f9;
    border-left: 3px solid #4a90e2;
    border-radius: 4px;
}

.firm-memo-item:last-child {
    margin-bottom: 0;
}

.firm-memo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.firm-memo-author {
    font-weight: 600;
    color: #2c3e50;
}

.firm-memo-time {
    color: #888;
    font-size: 0.8rem;
}

.firm-memo-text {
    color: #333;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.firm-memo-composer {
    margin-top: 1rem;
}

.firm-memo-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 0.75rem;
    box-sizing: border-box;
}

.firm-memo-input:focus {
    outline: none;
    border-color: #4a90e2;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

.firm-memo-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.firm-memo-actions .btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

@media (max-width: 768px) {
    .firm-memo-card {
        padding: 1.25rem 1rem;
    }
    
    .firm-memo-list {
        max-height: 220px;
    }
    
    .firm-memo-title {
        font-size: 1rem;
    }
}

/* Pantallas */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: block;
}

/* Login/Registro */
.login-container {
    max-width: 400px;
    width: calc(100% - 2rem);
    margin: max(2rem, env(safe-area-inset-top)) auto 2rem;
    padding: 2rem;
    padding-left: calc(2rem + var(--safe-left));
    padding-right: calc(2rem + var(--safe-right));
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.login-container h1 {
    text-align: center;
    margin-bottom: 2rem;
    color: #2c2c2c;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

/* Contenedor para input de contraseña con botón de mostrar/ocultar */
.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrapper input {
    padding-right: 2.5rem;
    width: 100%;
}

.password-toggle {
    position: absolute;
    right: 0.75rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 1.1rem;
    transition: color 0.2s ease;
    z-index: 1;
    touch-action: manipulation;
}

.password-toggle:hover {
    color: #333;
}

.password-toggle:focus {
    outline: 2px solid #4285f4;
    outline-offset: 2px;
    border-radius: 4px;
}

.eye-icon {
    display: inline-block;
    user-select: none;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.switch-form {
    text-align: center;
    margin-top: 1rem;
}

.switch-form a {
    color: #2c2c2c;
    text-decoration: none;
}

/* Drawer de navegación */
.nav-drawer {
    position: fixed;
    top: 0;
    left: -280px;
    width: min(280px, calc(100vw - 2rem));
    max-width: 280px;
    height: 100vh;
    height: 100dvh;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    background: #2c2c2c;
    color: white;
    z-index: 1001;
    transition: left 0.3s ease;
    box-shadow: 2px 0 8px rgba(0,0,0,0.2);
}

.nav-drawer.open {
    left: 0;
}

.drawer-header {
    padding: 1.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.drawer-header h2 {
    font-size: 1.25rem;
    margin: 0;
}

.drawer-nav {
    padding: 1rem 0;
}

.drawer-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    min-height: var(--touch-min);
    color: white;
    text-decoration: none;
    transition: background 0.2s;
    gap: 1rem;
}

.drawer-item:hover {
    background: rgba(255,255,255,0.1);
}

.drawer-item.active {
    background: rgba(255,255,255,0.15);
}

.drawer-icon {
    font-size: 1.5rem;
    width: 2rem;
    text-align: center;
}

.drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
}

.drawer-overlay.active {
    display: block;
}

/* Header */
.app-header {
    background: #2c2c2c;
    color: white;
    padding: calc(1rem + var(--safe-top)) 1rem 1rem;
    padding-left: calc(1rem + var(--safe-left));
    padding-right: calc(1rem + var(--safe-right));
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 0.5rem;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
    touch-action: manipulation;
}

.icon-btn:hover,
.icon-btn:focus {
    background: rgba(255,255,255,0.3);
}

/* Breadcrumb */
.breadcrumb {
    background: white;
    padding: 0.75rem 1rem;
    padding-left: calc(1rem + var(--safe-left));
    padding-right: calc(1rem + var(--safe-right));
    border-bottom: 1px solid #ddd;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.breadcrumb-item {
    color: #666;
}

.breadcrumb-item::after {
    content: ' / ';
    margin: 0 0.5rem;
}

.breadcrumb-item:last-child::after {
    content: '';
}

/* Contenido principal */
.main-content {
    padding: 1rem;
    padding-left: calc(1rem + var(--safe-left));
    padding-right: calc(1rem + var(--safe-right));
    padding-bottom: calc(1rem + var(--safe-bottom));
    max-width: 1200px;
    margin: 0 auto;
    overflow-x: hidden;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.view-header h2 {
    color: #333;
}

#shared-files-view .view-header > div:last-child {
    position: relative;
    z-index: 2;
}

/* Listas */
.list-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.list-item {
    background: white;
    padding: 1rem;
    min-height: var(--touch-min);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    gap: 1rem;
}

.list-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.item-content h3 {
    margin-bottom: 0.25rem;
    color: #333;
}

.item-meta {
    font-size: 0.875rem;
    color: #666;
}

.btn-icon {
    background: #2c2c2c;
    color: white;
    border: none;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    touch-action: manipulation;
    padding: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    min-width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: #1a1a1a;
}

.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: auto;
}

.btn-icon.btn-danger {
    background: #d32f2f;
}

.btn-icon.btn-danger:hover {
    background: #c62828;
}

.btn-icon.btn-protect {
    background: #f57c00;
}

.btn-icon.btn-protect:hover {
    background: #ef6c00;
}

.item-actions {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.notes-pagination {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

.notes-page-info {
    padding: 0 1rem;
    color: #666;
}

/* Botones */
.btn {
    padding: 0.75rem 1.5rem;
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    touch-action: manipulation;
}

.btn-primary {
    background: #2c2c2c;
    color: white;
}

.btn-primary:hover {
    background: #1a1a1a;
}

.btn-secondary {
    background: #666;
    color: white;
}

.btn-secondary:hover {
    background: #555;
}

.btn-danger {
    background: #d32f2f;
    color: white;
}

.btn-danger:hover {
    background: #c62828;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Detalle de registro */
.detail-container {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.record-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.record-notes,
.record-pdfs {
    margin-bottom: 2rem;
}

.record-notes h3,
.record-pdfs h3 {
    margin-bottom: 1rem;
    color: #333;
}

.notes-content {
    padding: 1rem;
    background: #f9f9f9;
    border-radius: 4px;
    min-height: 100px;
}

.protected-record {
    text-align: center;
    padding: 2rem;
}

.pdfs-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pdf-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: #f9f9f9;
    border-radius: 4px;
    gap: 1rem;
}

.pdf-item span {
    flex: 1;
}

.not-available {
    color: #999;
    font-style: italic;
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 2rem;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: white;
    padding: 2rem;
    padding-top: calc(2rem + var(--safe-top));
    padding-bottom: calc(2rem + var(--safe-bottom));
    padding-left: calc(2rem + var(--safe-left));
    padding-right: calc(2rem + var(--safe-right));
    border-radius: 8px;
    max-width: 500px;
    width: calc(100% - 1rem);
    max-height: min(90vh, 90dvh);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
    transition: all 0.3s ease;
    pointer-events: auto;
    z-index: 1;
}

.modal.maximized {
    max-width: 95vw;
    width: 95vw;
    max-height: 95vh;
    height: 95vh;
    border-radius: 0;
    padding: 1rem;
}

.modal-close {
    position: absolute;
    top: calc(1rem + var(--safe-top));
    right: calc(1rem + var(--safe-right));
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #666;
    line-height: 1;
    z-index: 10;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    touch-action: manipulation;
}

.modal-close:hover,
.modal-close:focus {
    color: #333;
}

.modal-maximize {
    position: absolute;
    top: calc(1rem + var(--safe-top));
    right: calc(3rem + var(--safe-right));
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    line-height: 1;
    z-index: 10;
    padding: 0.25rem 0.5rem;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.modal-maximize:hover,
.modal-maximize:focus {
    color: #333;
    background: rgba(0,0,0,0.05);
    border-radius: 4px;
}

.modal h2 {
    margin-bottom: 1.5rem;
    color: #333;
}

#modal-content {
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 100%;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
}

#modal-content input:not([type="checkbox"]):not([type="radio"]),
#modal-content textarea,
#modal-content select {
    pointer-events: auto;
}

#modal-content object[type="application/pdf"],
#modal-content iframe#pdf-viewer,
.pdf-viewer-embed {
    width: 100%;
    height: min(70vh, 70dvh);
    max-height: min(70vh, 70dvh);
    min-height: min(300px, 50dvh);
    border: 1px solid #ddd;
    border-radius: 4px;
    display: block;
}

/* Image preview list: on touch devices show overlay so edit/remove are tappable */
#images-preview-list .image-preview-overlay button {
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    touch-action: manipulation;
}

@media (hover: none) {
    #images-preview-list .image-preview-overlay {
        opacity: 1 !important;
    }
}

/* Vista de detalle de carpeta/expediente */
.item-detail-header {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
}

.item-identifier {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.folder-icon {
    font-size: 2.5rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
    flex-shrink: 0;
}

.item-number {
    font-size: 2rem;
    font-weight: bold;
    color: #2c2c2c;
    white-space: nowrap;
}

.item-name {
    font-size: 2rem;
    font-weight: bold;
    color: #2c2c2c;
    margin: 0;
    display: inline;
}

/* Botones de acción en la vista de detalle */
.item-detail-view .item-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #e9ecef;
}

#item-detail-content .item-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0;
}

/* Botones de acción en la lista (deben estar en fila) */
.list-item .item-actions,
.record-item .item-actions {
    display: flex !important;
    flex-direction: row !important;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
    margin-bottom: 0;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: 1px solid #2c3e50;
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: 'Georgia', 'Times New Roman', serif;
    color: #2c3e50;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    text-transform: none;
    letter-spacing: 0.3px;
}

.action-btn:hover {
    background: #f8f9fa;
    border-color: #1a252f;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transform: none;
}

.action-btn:active {
    background: #e9ecef;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.action-btn-red {
    background: #ffffff;
    border-color: #8b2635;
    color: #8b2635;
}

.action-btn-red:hover {
    background: #f8f4f4;
    border-color: #6b1d28;
    color: #6b1d28;
}

.action-btn-green {
    background: #ffffff;
    border-color: #2d5016;
    color: #2d5016;
}

.action-btn-green:hover {
    background: #f4f8f4;
    border-color: #1f350f;
    color: #1f350f;
}

.action-btn-orange {
    background: #ffffff;
    border-color: #8b6914;
    color: #8b6914;
}

.action-btn-orange:hover {
    background: #faf8f4;
    border-color: #6b5010;
    color: #6b5010;
}

.action-icon {
    font-size: 1.1rem;
    font-weight: normal;
    opacity: 0.8;
}

/* En PC/tablet, ocultar los iconos y mostrar solo el texto */
@media (min-width: 769px) {
    .item-actions .action-btn:not(#item-priority-select) .action-icon {
        display: none;
    }
    
    /* En desktop, el select de prioridad puede tener un ancho mínimo razonable */
    #item-priority-select {
        min-width: 180px !important;
        width: auto !important;
    }
}

.item-detail-content {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.records-list h3 {
    margin-bottom: 1rem;
    color: #333;
}

.record-item {
    padding: 1rem;
    min-height: var(--touch-min);
    background: #f9f9f9;
    border-radius: 4px;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.record-item:hover {
    background: #f0f0f0;
}

.record-content {
    flex: 1;
}

.record-item h4 {
    margin: 0 0 0.5rem 0;
    color: #333;
}

.record-meta {
    margin: 0;
    font-size: 0.875rem;
    color: #666;
}

/* Responsive */
@media (max-width: 768px) {
    .login-container {
        margin: max(1rem, env(safe-area-inset-top)) 1rem 1rem;
    }

    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .record-actions {
        flex-direction: row !important;
    }
    
    .record-item .item-actions {
        flex-direction: row !important;
    }

    .pdf-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .item-number,
    .item-name {
        font-size: 1.5rem;
    }

    .folder-icon {
        font-size: 2rem;
    }
    
    /* Botones de acción en móvil */
    .item-detail-view .item-actions {
        flex-direction: column;
        gap: 0.75rem;
        padding: 1rem;
    }
    
    .item-actions-row {
        flex-direction: row;
        gap: 0.5rem;
        width: 100%;
    }
    
    .action-btn {
        width: auto;
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
        justify-content: flex-start;
        min-height: 48px; /* Tamaño mínimo táctil recomendado */
    }
    
    /* En móvil, ocultar el texto de los botones de acción pero mantener los iconos */
    /* Solo aplicar a los botones, NO al select de prioridad */
    .item-actions .action-btn:not(#item-priority-select) span:not(.action-icon) {
        display: none;
    }
    
    /* Ajustar el padding de los botones en móvil para que solo muestren el icono */
    .item-actions .action-btn:not(#item-priority-select) {
        padding: 0.875rem;
        min-width: 48px;
        justify-content: center;
        width: auto; /* Permitir que el ancho se ajuste al contenido (solo icono) */
    }
    
    /* El select de prioridad mantiene su texto visible */
    #item-priority-select {
        width: 100% !important;
        min-width: 0 !important; /* Override inline min-width */
        max-width: 100% !important;
        padding: 0.875rem 1rem !important;
        font-size: 0.9rem !important;
        min-height: 48px;
        box-sizing: border-box !important;
    }
}

/* ========== Pricing / Plans view (legal SaaS, Hostinger-like) ========== */
.pricing-view {
    padding: 1.5rem 1rem 3rem;
    max-width: 1280px;
    margin: 0 auto;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

.pricing-header {
    text-align: center;
    margin-bottom: 2rem;
}

.pricing-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.pricing-tagline {
    color: #64748b;
    font-size: 1rem;
    margin-bottom: 1rem;
}

.pricing-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.pricing-badge {
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    background: #e2e8f0;
    color: #475569;
}

.pricing-badge-usd { background: #dbeafe; color: #1d4ed8; }
.pricing-badge-mxn { background: #dcfce7; color: #15803d; }

.billing-status-banner {
    max-width: 600px;
    margin: 0 auto 1.5rem;
    padding: 0.75rem 1rem;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.billing-status-banner .btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }

.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem;
    list-style: none;
}

.plan-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
    border: 1px solid #e2e8f0;
    padding: 1.5rem;
    position: relative;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s, transform 0.2s;
}

.plan-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.08);
}

.plan-card.popular {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

.plan-card.current {
    border-color: #2563eb;
    background: #f8fafc;
}

.plan-card-header {
    margin-bottom: 1rem;
}

.plan-card-badge {
    position: absolute;
    top: -1px;
    right: 1rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #6366f1;
    color: #fff;
    border-radius: 0 0 6px 6px;
}

.plan-card-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e293b;
}

.plan-card-price {
    font-size: 1.5rem;
    font-weight: 800;
    color: #1e293b;
    margin-top: 0.25rem;
}

.plan-card-price span { font-size: 0.9rem; font-weight: 500; color: #64748b; }

.plan-card-benefits {
    list-style: none;
    margin: 1rem 0;
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.7;
    color: #475569;
}

.plan-card-benefits li {
    padding: 0.25rem 0;
    padding-left: 1.25rem;
    position: relative;
}

.plan-card-benefits li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: #22c55e;
    font-weight: bold;
}

.plan-card-actions {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.plan-card-actions .btn { width: 100%; justify-content: center; }
.plan-card-actions .btn:disabled { opacity: 0.7; cursor: not-allowed; }

@media (min-width: 900px) {
    .plans-grid { grid-template-columns: repeat(4, 1fr); }
}
