/* Componentes reutilizables */

/* ---- Botones ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--touch-target);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: var(--text-md);
    text-decoration: none;
    border: 1px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--color-brand);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-brand-dark);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-ink);
    border-color: var(--color-line);
}

.btn-secondary:hover {
    background: var(--color-brand-softer);
    border-color: var(--color-brand);
    color: var(--color-brand-dark);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: #832C20;
}

.btn-ghost {
    background: transparent;
    color: inherit;
}

.btn-ghost:hover {
    background: rgba(0, 0, 0, 0.06);
}

.btn-block {
    width: 100%;
}

.btn-lg {
    min-height: 50px;
    font-size: var(--text-lg);
}

/* ---- Campos ---- */
.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
}

.field label {
    font-weight: 600;
    font-size: var(--text-sm);
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="email"],
input[type="number"],
select,
textarea {
    width: 100%;
    min-height: var(--touch-target);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    font-size: var(--text-md);
    color: var(--color-ink);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--color-brand);
    outline: 3px solid var(--color-brand-ring);
    outline-offset: 0;
}

.form-single {
    max-width: 420px;
}

/* ---- Tarjetas ---- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: 700;
    margin-bottom: var(--space-4);
}

/* ---- Badges y chips ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-2);
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.badge-role {
    background: var(--color-brand-soft);
    color: var(--color-brand-dark);
}

.badge-area {
    background: var(--color-info-soft);
    color: var(--color-info);
}

.badge-success {
    background: var(--color-success-soft);
    color: var(--color-success);
}

.badge-muted {
    background: var(--color-line-soft);
    color: var(--color-ink-soft);
}

.chip {
    display: inline-flex;
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 600;
}

.chip-default {
    background: var(--color-line-soft);
    color: var(--color-ink-soft);
}

.chip-danger {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

/* ---- Avatar ---- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-brand);
    color: #fff;
    font-weight: 700;
    font-size: var(--text-sm);
    flex-shrink: 0;
}

.avatar-sm {
    width: 30px;
    height: 30px;
    font-size: var(--text-xs);
}

.avatar-xl {
    width: 64px;
    height: 64px;
    font-size: var(--text-lg);
}

/* Foto de perfil (img con la misma forma que las iniciales) */
.avatar-img {
    object-fit: cover;
    display: block;
}

.profile-photo-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.profile-photo-confirm {
    display: none;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}
.profile-photo-confirm.is-visible { display: flex; }

/* ---- Alertas ---- */
.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 600;
    margin-bottom: var(--space-4);
    border: 1px solid transparent;
}

.alert-error {
    background: var(--color-danger-soft);
    color: var(--color-danger);
    border-color: rgba(179, 38, 30, 0.2);
}

.alert-success {
    background: var(--color-brand-soft);
    color: var(--color-brand-dark);
    border-color: rgba(31, 122, 68, 0.2);
}

.alert-info {
    background: var(--color-info-soft);
    color: var(--color-info);
    border-color: rgba(30, 90, 168, 0.2);
}

/* ---- Toasts ---- */
.toast-region {
    position: fixed;
    top: calc(var(--topbar-height) + var(--space-3));
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: min(92vw, 420px);
    pointer-events: none;
}

.toast {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    font-weight: 600;
    font-size: var(--text-sm);
    box-shadow: var(--shadow);
    background: var(--color-ink);
    color: #fff;
    animation: toast-in 0.2s ease;
}

.toast-success {
    background: var(--color-brand-dark);
}

.toast-error {
    background: var(--color-danger);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- Breadcrumb ---- */
.breadcrumb {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--color-ink-soft);
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.breadcrumb-item {
    background: none;
    border: 0;
    padding: var(--space-1) 0;
    font: inherit;
    color: var(--color-ink-soft);
    cursor: pointer;
    white-space: nowrap;
    border-radius: 4px;
}

.breadcrumb-item:hover {
    color: var(--color-brand-dark);
}

.breadcrumb-sep {
    color: var(--color-ink-faint);
}

.breadcrumb-item.is-current {
    color: var(--color-ink);
    font-weight: 700;
}

/* ---- Estado vacío ---- */
.empty-state {
    text-align: center;
    padding: var(--space-6) var(--space-5);
}

.empty-state-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--color-brand-soft);
    color: var(--color-brand);
    margin-bottom: var(--space-4);
}

.empty-state-icon svg {
    width: 30px;
    height: 30px;
}

.empty-state h2 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-2);
}

.empty-state p {
    color: var(--color-ink-soft);
    max-width: 380px;
    margin: 0 auto;
}

/* ---- Tablas ---- */
.table-card {
    padding: 0;
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
    min-width: 560px;
}

.table th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-ink-faint);
    background: var(--color-brand-softer);
    border-bottom: 1px solid var(--color-line);
    white-space: nowrap;
}

.table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-line-soft);
    vertical-align: middle;
}

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

.table tbody tr:hover {
    background: var(--color-brand-softer);
}

.table-empty {
    text-align: center;
    color: var(--color-ink-soft);
    padding: var(--space-6) var(--space-4) !important;
}

.table-note {
    padding: var(--space-2) var(--space-4);
    color: var(--color-ink-faint);
    font-size: var(--text-xs);
}

.cell-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-weight: 600;
}

/* ---- Página: encabezado ---- */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.page-actions {
    flex-wrap: wrap;
}

.page-title {
    font-size: var(--text-xl);
    font-weight: 800;
    letter-spacing: -0.01em;
}

.search-form {
    display: flex;
    gap: var(--space-2);
    width: 100%;
}

.search-form input,
.search-form select {
    flex: 1;
}

/* ---- Autenticación (login) ---- */
body.auth {
    display: grid;
    place-items: center;
    padding: var(--space-4);
    background: #5a7f71;
}

.auth-wrap {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    padding: 0;
    overflow: hidden;
    border: 0;
    box-shadow: var(--shadow);
}

.auth-brand {
    text-align: center;
    background: var(--color-brand-darker);
    padding: var(--space-5) var(--space-5) var(--space-4);
    background-image: radial-gradient(circle at top right, rgba(255, 255, 255, 0.12), transparent 55%);
}

.auth-logo {
    display: block;
    width: min(210px, 100%);
    height: auto;
    margin: 0 auto;
}

.auth-subtitle {
    color: rgba(240, 234, 227, 0.75);
    font-size: var(--text-sm);
    margin-top: var(--space-3);
}

.auth-body {
    padding: var(--space-5);
    background: #d6d1ca;
}

.auth-intro {
    color: var(--color-ink-soft);
    font-size: var(--text-sm);
    line-height: 1.5;
    margin-bottom: var(--space-5);
}

.auth-form .field {
    margin-bottom: var(--space-4);
}

.auth-form input:-webkit-autofill,
.auth-form input:-webkit-autofill:hover,
.auth-form input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--color-ink);
    -webkit-box-shadow: 0 0 0 1000px var(--color-surface) inset;
    transition: background-color 9999s ease-out 0s;
}

.auth-password-input {
    position: relative;
}

.auth-password-input input {
    padding-right: 48px;
}

.auth-toggle-password {
    position: absolute;
    top: 50%;
    right: var(--space-2);
    width: 36px;
    height: 36px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--color-ink-soft);
}

.auth-toggle-password:hover {
    background: var(--color-brand-softer);
    color: var(--color-brand-dark);
}

.auth-toggle-password svg {
    width: 19px;
    height: 19px;
}

.auth-footer {
    text-align: center;
    color: rgba(255, 255, 255, 0.82);
    font-size: var(--text-xs);
    margin-top: var(--space-5);
}

/* ---- Perfil ---- */
.profile-grid {
    display: grid;
    gap: var(--space-5);
}

.profile-settings {
    display: grid;
    gap: var(--space-5);
}

.profile-name-form {
    margin-top: var(--space-4);
}

.profile-head {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}

.profile-name {
    font-size: var(--text-lg);
    font-weight: 800;
}

.profile-username {
    color: var(--color-ink-soft);
    font-size: var(--text-sm);
}

.profile-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.profile-meta {
    display: grid;
    gap: var(--space-3);
}

.profile-meta > div {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    border-bottom: 1px solid var(--color-line-soft);
    padding-bottom: var(--space-2);
}

.profile-meta dt {
    color: var(--color-ink-soft);
    font-size: var(--text-sm);
}

.profile-meta dd {
    font-weight: 600;
    font-size: var(--text-sm);
    text-align: right;
}

/* ---- Modales ---- */
body.modal-open {
    overflow: hidden;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(14, 30, 21, 0.55);
    padding: 0;
}

.modal {
    background: var(--color-surface);
    width: 100%;
    max-width: 560px;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow);
    animation: modal-up 0.22s ease;
}

.modal-sm {
    max-width: 420px;
}

@media (min-width: 600px) {
    .modal-overlay {
        align-items: center;
        padding: var(--space-4);
    }

    .modal {
        border-radius: var(--radius-lg);
    }
}

@keyframes modal-up {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-line-soft);
}

.modal-header h2 {
    font-size: var(--text-lg);
    font-weight: 700;
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-target);
    height: var(--touch-target);
    border-radius: 50%;
    color: var(--color-ink-soft);
}

.modal-close:hover {
    background: var(--color-line-soft);
    color: var(--color-ink);
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    padding: var(--space-5);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-line-soft);
}

.confirm-overlay .modal-body {
    padding-bottom: var(--space-4);
}

.confirm-message {
    font-weight: 600;
}

.btn-danger-confirm {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger-confirm:hover {
    background: #832C20;
}

/* ---- Menú contextual ---- */
.menu {
    position: fixed;
    z-index: 95;
    min-width: 190px;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--space-1);
}

.menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-md);
    font-weight: 500;
    text-align: left;
}

.menu-item:hover {
    background: var(--color-brand-softer);
    color: var(--color-brand-dark);
}

.menu-item-danger {
    color: var(--color-danger);
}

.menu-item-danger:hover {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

.btn-sm {
    min-height: 38px;
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-sm);
}

/* Papelera */
.trash-row {
    opacity: 0.95;
}

.trash-actions {
    display: flex;
    gap: var(--space-2);
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .trash-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .trash-row {
        flex-wrap: wrap;
    }

    .trash-actions {
        width: 100%;
        padding-left: 56px;
    }
}

/* ---- Barra de progreso ---- */
.progress {
    height: 10px;
    background: var(--color-line-soft);
    border-radius: 999px;
    overflow: hidden;
    margin: var(--space-3) 0;
}

.progress-bar {
    height: 100%;
    background: var(--color-brand);
    border-radius: 999px;
    transition: width 0.2s ease;
}

/* ---- Pills de filtro ---- */
.pill-group {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
}

.pill {
    padding: var(--space-2) var(--space-3);
    border-radius: 999px;
    border: 1px solid var(--color-line);
    background: var(--color-surface);
    color: var(--color-ink-soft);
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
    min-height: 38px;
}

.pill.is-active {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: #fff;
}

/* ---- Caja de búsqueda ---- */
.search-box {
    position: relative;
    flex: 1;
    min-width: 160px;
}

.search-box svg {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--color-ink-faint);
    pointer-events: none;
}

.search-box input {
    padding-left: 40px;
}

.sort-select {
    min-width: 150px;
    appearance: none;
    -webkit-appearance: none;
    padding-right: 44px;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236C6058' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
}

/* ---- Subida ---- */
.upload-drop {
    border: 2px dashed var(--color-line);
    border-radius: var(--radius);
    padding: var(--space-6) var(--space-4);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
}

.upload-drop svg {
    width: 34px;
    height: 34px;
    color: var(--color-brand);
}

.upload-drop-text {
    font-weight: 600;
}

.upload-filelist {
    margin: var(--space-3) 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.upload-file-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-line-soft);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.upload-file-item.is-invalid {
    border-color: rgba(179, 38, 30, 0.4);
    background: var(--color-danger-soft);
}

.upload-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.upload-file-size {
    color: var(--color-ink-soft);
    white-space: nowrap;
}

.upload-file-remove {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--color-ink-soft);
    flex-shrink: 0;
}

.upload-file-remove:hover {
    background: var(--color-line-soft);
    color: var(--color-danger);
}

.upload-status {
    font-size: var(--text-sm);
    font-weight: 600;
}

.upload-status.is-ok {
    color: var(--color-brand-dark);
}

.upload-status.is-error {
    color: var(--color-danger);
}

.upload-failed-list {
    margin-top: var(--space-2);
    color: var(--color-danger);
    font-weight: 500;
    list-style: none;
    padding: 0;
}

.upload-failed-list li {
    padding: var(--space-1) 0;
    border-bottom: 1px dashed rgba(179, 38, 30, 0.25);
}

/* ---- Detalles ---- */
.details-list > div {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-line-soft);
    font-size: var(--text-sm);
}

.details-list dt {
    color: var(--color-ink-soft);
    flex-shrink: 0;
}

.details-list dd {
    text-align: right;
    word-break: break-word;
    font-weight: 500;
}

.hint-file-name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-ink-soft);
    margin-bottom: var(--space-3);
}

.file-preview {
    margin-bottom: var(--space-4);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--color-line-soft);
    background: var(--color-brand-softer);
}

.file-preview img,
.file-preview iframe {
    width: 100%;
    height: 320px;
    object-fit: contain;
    display: block;
    border: 0;
}

/* ---- Lista de archivos ---- */
.file-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.row-icon-file {
    background: var(--color-brand-soft);
    color: var(--color-brand-dark);
}

/* Enlaces externos (Drive, etc.) */
.row-icon-link {
    background: var(--color-brand-soft);
    color: var(--color-brand-dark);
}

.provider-chip {
    display: inline-flex;
    align-items: center;
    padding: 1px var(--space-2);
    background: var(--color-brand-softer);
    color: var(--color-brand);
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: 700;
    max-width: 180px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.note-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px var(--space-2);
    background: var(--color-warning-soft);
    color: var(--color-warning);
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: 700;
    max-width: 160px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.note-chip svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.row-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-target);
    height: var(--touch-target);
    border-radius: 50%;
    color: var(--color-ink-soft);
    flex-shrink: 0;
}

.row-menu-btn:hover {
    background: var(--color-line-soft);
    color: var(--color-ink);
}

.row-menu-btn svg {
    width: 20px;
    height: 20px;
}

.load-more-wrap {
    display: flex;
    justify-content: center;
    padding: var(--space-5) 0;
}

.list-loading {
    display: flex;
    justify-content: center;
    padding: var(--space-5) 0;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--color-line);
    border-top-color: var(--color-brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Compartir ---- */
.share-users {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    max-height: 320px;
    overflow-y: auto;
}

.share-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid transparent;
}

.share-user:hover {
    background: var(--color-brand-softer);
}

.share-user input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--color-brand);
    flex-shrink: 0;
}

.share-user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.share-user-name {
    font-weight: 600;
    font-size: var(--text-sm);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.share-user-meta {
    font-size: var(--text-xs);
    color: var(--color-ink-soft);
}

.share-chip {
    background: var(--color-info-soft);
    color: var(--color-info);
}

.muted {
    color: var(--color-ink-soft);
    font-weight: 400;
}

.table-actions {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: var(--space-1);
    justify-content: flex-end;
}

.table-actions .btn-icon {
    width: 38px;
    padding: 0;
}

.table-actions .btn-icon svg {
    width: 18px;
    height: 18px;
}
