/* ============================================
   CRUD Screens (Accounts, Contacts, Locations)
   ============================================ */

.crud-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.crud-filters input,
.crud-filters select {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    min-width: 180px;
}

.crud-filters input {
    flex: 1;
    min-width: 220px;
    max-width: 400px;
}

.crud-filters input:focus,
.crud-filters select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.crud-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.crud-stat-badge {
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: var(--bg-hover);
    padding: 4px 12px;
    border-radius: 20px;
}

.crud-stat-badge strong {
    color: var(--text-primary);
}

.crud-table-container {
    overflow-x: auto;
}

.crud-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.crud-table th,
.crud-table td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.crud-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 1;
}

.crud-table tbody tr {
    transition: background 0.12s;
}

.crud-table tbody tr:hover {
    background: var(--bg-hover);
}

.crud-table code {
    font-size: 0.82rem;
    background: var(--bg-hover);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--primary);
}

/* Locations table column widths */
.crud-table-locations {
    table-layout: fixed;
}

.crud-table-locations th:nth-child(1),
.crud-table-locations td:nth-child(1) {
    width: 12%;
}

.crud-table-locations th:nth-child(2),
.crud-table-locations td:nth-child(2) {
    width: 25%;
}

.crud-table-locations th:nth-child(3),
.crud-table-locations td:nth-child(3) {
    width: 18%;
}

.crud-table-locations th:nth-child(4),
.crud-table-locations td:nth-child(4) {
    width: 45%;
    word-break: break-word;
}

/* Accounts table column widths */
.crud-table-accounts {
    table-layout: fixed;
}

/* 5 columnas: Nombre, Tipo, Web, Dir. Facturación, Etiquetas.
   Con table-layout:fixed los anchos deben sumar 100% o las columnas sin
   ancho colapsan y el texto envuelto dispara la altura de las filas. */
.crud-table-accounts th,
.crud-table-accounts td {
    padding: 7px 12px;
}

.crud-table-accounts th:nth-child(1),
.crud-table-accounts td:nth-child(1) {
    width: 25%;
    word-break: break-word;
}

.crud-table-accounts th:nth-child(2),
.crud-table-accounts td:nth-child(2) {
    width: 13%;
}

.crud-table-accounts th:nth-child(3),
.crud-table-accounts td:nth-child(3) {
    width: 16%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crud-table-accounts th:nth-child(4),
.crud-table-accounts td:nth-child(4) {
    width: 30%;
    word-break: break-word;
}

.crud-table-accounts th:nth-child(5),
.crud-table-accounts td:nth-child(5) {
    width: 16%;
}

.btn-edit-crud {
    background: var(--primary-light) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

.btn-edit-crud:hover {
    background: var(--primary) !important;
    color: white !important;
}

/* CRUD Pagination */
.crud-pagination {
    margin-top: 16px;
}

.crud-pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.btn-page {
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-page:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.btn-page:disabled,
.btn-page.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* CRUD responsive */
@media (max-width: 768px) {
    .crud-filters {
        flex-direction: column;
    }

    .crud-filters input,
    .crud-filters select {
        width: 100%;
        min-width: 0;
    }

    .crud-table {
        font-size: 0.78rem;
    }

    .crud-table th,
    .crud-table td {
        padding: 8px 8px;
    }

    .crud-table th:nth-child(n+4),
    .crud-table td:nth-child(n+4) {
        display: none;
    }

    .crud-table th:last-child,
    .crud-table td:last-child {
        display: table-cell;
    }

    /* Locations: hide categoría, show dirección on mobile */
    .crud-table-locations th:nth-child(3),
    .crud-table-locations td:nth-child(3) {
        display: none;
    }

    .crud-table-locations th:nth-child(4),
    .crud-table-locations td:nth-child(4) {
        display: table-cell;
    }

    /* Accounts (5 col: Nombre, Tipo, Web, Dir, Etiquetas):
       en móvil se ocultan Web y Etiquetas */
    .crud-table-accounts th:nth-child(3),
    .crud-table-accounts td:nth-child(3),
    .crud-table-accounts th:nth-child(5),
    .crud-table-accounts td:nth-child(5) {
        display: none;
    }

    .crud-table-accounts th:nth-child(4),
    .crud-table-accounts td:nth-child(4) {
        display: table-cell;
        width: 50%;
    }

    /* AccContacts: keep contacto, cuenta, cargo; hide the rest on mobile */
    .crud-table-acccontacts th:nth-child(n+4),
    .crud-table-acccontacts td:nth-child(n+4) {
        display: none;
    }

    .crud-table-acccontacts th:last-child,
    .crud-table-acccontacts td:last-child {
        display: table-cell;
    }

    .crud-pagination-controls {
        gap: 8px;
    }

    .btn-page {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}

/* ============================================
   CRUD Modals - Form Grid Override
   ============================================ */

.project-form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 600px) {
    .project-form-grid-2 {
        grid-template-columns: 1fr;
    }
}

/* CRUD Detail Modal */
.crud-detail-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
    margin-top: 8px;
}

.crud-detail-field {
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
}

.crud-detail-field:nth-last-child(-n+2) {
    border-bottom: none;
}

.crud-detail-field.full-width {
    grid-column: 1 / -1;
}

.crud-detail-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 1px;
    line-height: 1.2;
}

.crud-detail-value {
    font-size: 0.88rem;
    color: var(--text-primary);
    word-break: break-word;
    line-height: 1.3;
}

.crud-detail-value:empty::after,
.crud-detail-value .detail-empty {
    color: var(--text-muted);
    font-style: italic;
}

.crud-table tbody tr {
    cursor: pointer;
}

/* Detail view: section headers */
.crud-detail-section {
    grid-column: 1 / -1;
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--primary);
    padding: 8px 0 3px;
    border-bottom: 2px solid var(--primary);
    margin-top: 2px;
}

.crud-detail-section:first-child {
    padding-top: 0;
    margin-top: 0;
}

/* ---- Inline detail view (replaces modal) ---- */
.crud-detail-inline {
    animation: fadeIn 0.2s ease;
}

.crud-detail-inline-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.crud-detail-inline-title {
    flex: 1;
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crud-detail-inline-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-back-list {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    padding: 4px 12px;
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .crud-detail-inline-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .crud-detail-inline-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ---- Location Photo Gallery ---- */
.loc-photos-gallery {
    padding: 8px 0;
}

.loc-photos-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 12px;
}

.loc-photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.loc-photo-card {
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary, #f3f4f6);
    border: 1px solid var(--border-color, #e5e7eb);
    transition: transform 0.15s, box-shadow 0.15s;
}

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

.loc-photo-thumb {
    width: 100%;
    padding-bottom: 75%;
    background-size: cover;
    background-position: center;
    background-color: var(--bg-tertiary, #e5e7eb);
}

.loc-photo-name {
    padding: 6px 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 600px) {
    .loc-photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }
}

/* ---- Photo Multi-Select ---- */

.photo-select-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.photo-select-toolbar .loc-photos-count {
    margin: 0 auto 0 0;
}

.loc-photos-en-carrito {
    color: var(--success);
    font-size: 0.85rem;
    font-weight: 600;
}

.photo-select-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-elevated, #f0f4ff);
    border: 1px solid var(--accent, #4f46e5);
    border-radius: 8px;
    margin-bottom: 12px;
    gap: 12px;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.photo-card.photo-selectable,
.loc-photo-card.photo-selectable {
    position: relative;
}

.photo-card.photo-selectable::after,
.loc-photo-card.photo-selectable::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.85);
    background: rgba(0,0,0,0.3);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    z-index: 2;
    pointer-events: none;
}

.photo-card.selected::after,
.loc-photo-card.selected::after {
    content: '\2713';
    background: var(--accent, #4f46e5);
    border-color: var(--accent, #4f46e5);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
}

.photo-card.selected,
.loc-photo-card.selected {
    outline: 3px solid var(--accent, #4f46e5);
    outline-offset: -3px;
}

/* ---- Inline Edit Form ---- */
.crud-inline-edit-body {
    padding: 8px 0 0;
}

.crud-inline-edit-body .project-form-grid {
    margin-bottom: 4px;
}

.crud-inline-edit-body .form-group {
    margin-bottom: 8px;
}

/* Ensure subcategory tag selector's dropdown floats above subsequent form sections */
.crud-inline-edit-body .form-group:has(.subcat-tag-selector),
#crudLocationModal .form-group:has(.subcat-tag-selector) {
    position: relative;
    z-index: 10;
}

/* Ensure the grid row containing subcategory selector sits above following sections in the modal */
#crudLocationModal .project-form-grid:has(.subcat-tag-selector) {
    position: relative;
    z-index: 10;
}

.crud-inline-edit-body .project-form-section-title {
    margin-top: 16px;
    margin-bottom: 8px;
}

.crud-inline-edit-body .project-form-section-title:empty {
    border-bottom: none;
    margin-top: 4px;
    margin-bottom: 0;
    padding-bottom: 0;
}

.crud-inline-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

@media (max-width: 600px) {
    .crud-inline-edit-actions {
        flex-direction: column;
    }
    .crud-inline-edit-actions button {
        width: 100%;
        min-height: 44px;
    }
}

/* Detail view: tags (subcategorias) */
.crud-tag {
    display: inline-block;
    font-size: 0.78rem;
    background: var(--bg-hover);
    color: var(--text-primary);
    padding: 2px 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin: 2px 4px 2px 0;
}

/* Detail view: boolean badges */
.crud-badge {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 12px;
}

.crud-badge.badge-yes {
    background: #dcfce7;
    color: #166534;
}

.crud-badge.badge-no {
    background: #fef2f2;
    color: #991b1b;
}

.crud-badge.crud-badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.crud-badge.crud-badge-danger {
    background: #fef2f2;
    color: #991b1b;
}
.crud-badge.crud-badge-success {
    background: #f0fdf4;
    color: #166534;
}
.crud-badge.crud-badge-principal {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    font-weight: 600;
}

/* Boolean checkbox display */
.bool-check {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.92em;
    font-weight: 500;
}
.bool-check.bool-yes {
    color: #166534;
}
.bool-check.bool-no {
    color: #991b1b;
}
.bool-check.bool-null {
    color: #9ca3af;
    font-style: italic;
    font-weight: 400;
}

