/* ============================================================
   main.css
   Sistema de Gestión de Refugios
   Layout, navbar, sidebar, responsive, utilidades.
   ============================================================ */

/* ──────────────────────────────────────────────────────
   LAYOUT
   ────────────────────────────────────────────────────── */
html,
body {
    overflow-x: hidden;
}

:root {
    --app-navbar-height: 64px;
    --app-sidebar-width: 248px;
    --app-sidebar-collapsed-width: 76px;
}

body.sidebar-collapsed {
    --app-sidebar-width: var(--app-sidebar-collapsed-width);
}

.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg);
}

.app-body {
    display: flex;
    flex: 1;
}

.main-content {
    flex: 1;
    padding: 1.5rem;
    margin-left: var(--app-sidebar-width);
    margin-top: var(--app-navbar-height);
    min-width: 0;
    min-height: calc(100vh - var(--app-navbar-height));
    overflow-y: auto;
    transition: margin-left var(--transition);
}

/* ──────────────────────────────────────────────────────
   NAVBAR
   ────────────────────────────────────────────────────── */
.navbar {
    position: fixed;
    top: 0;
    left: var(--app-sidebar-width);
    right: 0;
    height: var(--app-navbar-height);
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.5rem;
    z-index: 100;
    box-shadow: 0 10px 24px rgba(15, 36, 64, 0.16);
    transition: left var(--transition);
}

.navbar-brand {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 0.75rem;
}

.navbar-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.navbar-sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.34);
}

.navbar-sidebar-toggle-icon {
    transition: transform var(--transition);
}

.navbar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    min-width: 0;
    max-width: min(52vw, 420px);
}

.navbar-logo:hover {
    color: #fff;
    opacity: 0.9;
}

.navbar-logo-img {
    display: block;
    width: 156px;
    height: 48px;
    max-width: 34vw;
    max-height: 48px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 4px 6px;
    box-shadow: 0 2px 10px rgba(15, 36, 64, 0.18);
}

.navbar-logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    min-width: 0;
}

.navbar-logo-title {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.navbar-logo-subtitle {
    font-size: 0.6875rem;
    font-weight: 500;
    opacity: 0.8;
    white-space: nowrap;
}

.navbar-menu-toggle {
    display: none;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
}

.navbar-menu-toggle-line {
    width: 20px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    display: block;
}

.navbar-sidebar-toggle:focus-visible,
.navbar-menu-toggle:focus-visible,
.sidebar-close:focus-visible,
.sidebar-overlay:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.navbar-user {
    text-align: right;
}

.navbar-user-name {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.2;
}

.navbar-user-role {
    display: block;
    font-size: 0.75rem;
    opacity: 0.75;
    text-transform: capitalize;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    padding: 0.375rem 0.75rem;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 0.8125rem;
    transition: background var(--transition);
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ──────────────────────────────────────────────────────
   SIDEBAR
   ────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--app-sidebar-width);
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 50;
    box-shadow: 8px 0 24px rgba(15, 36, 64, 0.03);
    transition: width var(--transition);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
}

.sidebar-header {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 1rem 1.125rem;
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.18), transparent 9rem),
        linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 28px rgba(15, 36, 64, 0.14);
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    min-width: 0;
    color: #fff;
    text-align: center;
    text-decoration: none;
    transition: gap var(--transition);
}

.sidebar-brand:hover {
    color: #fff;
}

.sidebar-logo-card {
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(100%, 178px);
    padding: 5px 7px;
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 22px rgba(15, 36, 64, 0.18);
    transition: width var(--transition), padding var(--transition), border-radius var(--transition);
}

.sidebar-logo-img {
    display: block;
    width: 100%;
    height: 54px;
    object-fit: contain;
    transition: height var(--transition);
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    max-width: 200px;
    line-height: 1.15;
    overflow: hidden;
    transition: opacity var(--transition), max-height var(--transition), transform var(--transition);
}

.sidebar-brand-title {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.sidebar-brand-subtitle {
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.25;
    opacity: 0.84;
    text-align: center;
    max-width: 100%;
}

.sidebar-close {
    display: none;
}

.sidebar-overlay {
    display: none;
}

/* ──────────────────────────────────────────────────────
   NAV MENU
   ────────────────────────────────────────────────────── */
.nav-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-menu-item {
    margin: 0;
}

.nav-menu-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.nav-menu-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: opacity var(--transition), width var(--transition);
}

.nav-menu-link:hover {
    background: #f9fafb;
    color: var(--text);
}

.nav-menu-item.is-active .nav-menu-link {
    color: var(--primary);
    background: #f0f4f8;
    border-left-color: var(--primary);
    font-weight: 600;
}

.nav-menu-link svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

body.sidebar-collapsed .sidebar-header {
    align-items: center;
    flex-direction: column;
    justify-content: center;
    gap: 0.625rem;
    padding: 0.75rem 0.5rem;
}

body.sidebar-collapsed .sidebar-brand {
    flex: none;
    width: 100%;
    gap: 0;
}

body.sidebar-collapsed .sidebar-logo-card {
    width: 48px;
    padding: 4px;
    border-radius: 14px;
}

body.sidebar-collapsed .sidebar-logo-img {
    height: 34px;
}

body.sidebar-collapsed .sidebar-brand-text {
    max-height: 0;
    opacity: 0;
    transform: translateY(-0.25rem);
}

body.sidebar-collapsed .navbar-sidebar-toggle-icon {
    transform: rotate(180deg);
}

body.sidebar-collapsed .sidebar-nav {
    padding-top: 0.625rem;
}

body.sidebar-collapsed .nav-menu-link {
    justify-content: center;
    gap: 0;
    min-height: 46px;
    padding: 0.75rem 0.5rem;
}

body.sidebar-collapsed .nav-menu-label {
    width: 0;
    opacity: 0;
}

/* ──────────────────────────────────────────────────────
   FOOTER
   ────────────────────────────────────────────────────── */
.footer {
    margin-left: var(--app-sidebar-width);
    margin-top: 0;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-white);
    transition: margin-left var(--transition);
}

.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8125rem;
    color: var(--text-light);
}

/* ──────────────────────────────────────────────────────
   BREADCRUMBS
   ────────────────────────────────────────────────────── */
.breadcrumbs {
    margin-bottom: 1rem;
}

.breadcrumbs-list {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.8125rem;
    color: var(--text-light);
}

.breadcrumbs-item {
    display: flex;
    align-items: center;
}

.breadcrumbs-item + .breadcrumbs-item::before {
    content: '/';
    margin: 0 0.5rem;
    color: var(--text-light);
}

.breadcrumbs-item a {
    color: var(--text-secondary);
}

.breadcrumbs-item.is-active span {
    color: var(--text);
    font-weight: 500;
}

/* ──────────────────────────────────────────────────────
   AUTH LAYOUT
   ────────────────────────────────────────────────────── */
.auth-layout {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(44, 82, 130, 0.16), transparent 34rem),
        radial-gradient(circle at bottom right, rgba(242, 195, 0, 0.14), transparent 28rem),
        linear-gradient(135deg, #eef3f8 0%, #f8fafc 58%, #eef2f6 100%);
    padding: 2rem 1.25rem;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    background: var(--bg-white);
    border: 1px solid rgba(229, 231, 235, 0.9);
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(15, 36, 64, 0.16);
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

.auth-container::before {
    content: '';
    position: absolute;
    inset: 0 0 auto;
    height: 5px;
    background: linear-gradient(90deg, var(--accent) 0 33%, var(--info) 33% 66%, var(--danger) 66% 100%);
}

.auth-brand {
    text-align: center;
    margin-bottom: 1.25rem;
}

.auth-logo {
    display: block;
    width: min(100%, 248px);
    max-width: 100%;
    height: auto;
    max-height: 104px;
    object-fit: contain;
    margin: 0 auto;
}

.auth-institution {
    margin: 0.25rem 0 0;
    color: var(--primary);
    font-weight: 700;
    line-height: 1.25;
    font-size: 0.9375rem;
}

.auth-system-name {
    margin: 0.25rem 0 0;
    color: var(--text);
    font-size: 0.9375rem;
    font-weight: 600;
}

.auth-subtitle,
.auth-description {
    margin: 0.375rem 0 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
}

.auth-title {
    font-size: clamp(1.55rem, 4vw, 1.85rem);
    margin-bottom: 0.375rem;
    text-align: left;
    color: var(--text);
    letter-spacing: -0.03em;
}

.auth-description {
    max-width: 26rem;
    margin: 0 0 1rem;
}

.auth-container .form-group {
    margin-bottom: 1rem;
}

.auth-container .form-label {
    font-weight: 700;
    color: var(--text);
}

.auth-container .form-input {
    min-height: 46px;
    border-radius: 10px;
    background: #fbfdff;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.auth-container .form-input:focus {
    background: #fff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.auth-container .form-check {
    align-items: center;
    gap: 0.625rem;
    color: var(--text);
}

.auth-container .form-check input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.auth-container .btn-primary {
    justify-content: center;
    min-height: 48px;
    border-radius: 10px;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 10px 18px rgba(26, 58, 92, 0.18);
}

.auth-container form button[type="submit"].btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
}

.auth-submit-text {
    display: block;
    width: 100%;
    text-align: center;
    margin: 0 auto;
}

.auth-container .alert {
    border-radius: 10px;
    margin-bottom: 1rem;
}

/* ── Divisor y enlace de registro público ── */
.auth-divider {
    display: flex;
    align-items: center;
    margin: 1.25rem 0;
    gap: 0.75rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border, #d1d5db);
}

.auth-divider-text {
    font-size: 0.8125rem;
    color: var(--text-secondary, #6b7280);
    font-weight: 500;
}

.auth-register-section {
    text-align: center;
    margin-top: 0.5rem;
}

.auth-register-text {
    font-size: 0.875rem;
    color: var(--text-secondary, #6b7280);
    margin: 0 0 0.375rem;
}

.auth-register-link {
    display: inline-block;
    color: var(--primary, #2563eb);
    font-weight: 600;
    font-size: 0.9375rem;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border: 2px solid var(--primary, #2563eb);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.auth-register-link:hover {
    background: var(--primary, #2563eb);
    color: #fff;
    text-decoration: none;
}

/* ──────────────────────────────────────────────────────
   DASHBOARD
   ────────────────────────────────────────────────────── */
.dashboard-welcome {
    text-align: center;
    padding: 3rem 1rem;
}

.dashboard-title {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.dashboard-role {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.dashboard-message {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    line-height: 1.75;
}

/* ──────────────────────────────────────────────────────
   PAGE CONTENT
   ────────────────────────────────────────────────────── */
.page-content {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

/* ──────────────────────────────────────────────────────
   UTILIDADES
   ────────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-left   { text-align: left; }

.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info    { color: var(--info); }
.text-muted   { color: var(--text-light); }

.fw-normal   { font-weight: 400; }
.fw-medium   { font-weight: 500; }
.fw-semibold { font-weight: 600; }
.fw-bold     { font-weight: 700; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mt-5 { margin-top: 2rem; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mb-5 { margin-bottom: 2rem; }

.p-0 { padding: 0; }
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 1rem; }
.p-4 { padding: 1.5rem; }
.p-5 { padding: 2rem; }

.d-flex    { display: flex; }
.d-inline-flex { display: inline-flex; }
.align-items-center { align-items: center; }
.justify-content-center { justify-content: center; }
.justify-content-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }

.w-100 { width: 100%; }

/* ──────────────────────────────────────────────────────
   RESPONSIVE
   ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root {
        --app-navbar-height: 64px;
    }

    .navbar {
        left: 0;
        padding: 0 0.875rem;
        gap: 0.75rem;
    }

    .navbar-menu-toggle {
        display: inline-flex;
    }

    .navbar-sidebar-toggle {
        display: none;
    }

    .navbar-brand {
        gap: 0.625rem;
        flex: 1;
        min-width: 0;
    }

    .navbar-logo {
        flex: 1;
        max-width: none;
        min-width: 0;
    }

    .navbar-logo-img {
        width: min(36vw, 136px);
        height: 42px;
        max-width: 136px;
        max-height: 42px;
        padding: 3px 5px;
    }

    .navbar-logo-subtitle {
        display: none;
    }

    .navbar-logo-title {
        max-width: 32vw;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .navbar-right {
        gap: 0.5rem;
    }

    .sidebar {
        top: 0;
        bottom: auto;
        width: min(84vw, 320px);
        height: 100vh;
        height: 100dvh;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform var(--transition);
        box-shadow: var(--shadow-lg);
        will-change: transform;
    }

    .main-content {
        margin-left: 0;
        margin-top: var(--app-navbar-height);
        padding: 1.125rem;
        min-height: calc(100vh - var(--app-navbar-height));
    }

    .footer {
        margin-left: 0;
    }

    .navbar-user-name,
    .navbar-user-role,
    .btn-logout-text {
        display: none;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar-header {
        min-height: var(--app-navbar-height);
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 0.75rem;
        padding: 0.75rem 3.75rem;
        border-bottom: 1px solid var(--border);
        background: linear-gradient(135deg, var(--primary-dark), var(--primary));
        color: #fff;
        box-shadow: none;
    }

    .sidebar-brand {
        display: flex;
        flex: initial;
        width: auto;
        align-items: center;
        justify-content: center;
        gap: 0.625rem;
        font-weight: 700;
        min-width: 0;
    }

    .sidebar-logo-card {
        width: 150px;
        padding: 3px 5px;
        border-radius: var(--radius-sm);
        box-shadow: 0 2px 10px rgba(15, 36, 64, 0.18);
    }

    .sidebar-logo-img {
        display: block;
        width: 138px;
        height: 48px;
        max-width: 54vw;
        object-fit: contain;
        flex-shrink: 0;
    }

    .sidebar-brand-text {
        display: none;
    }

    body.sidebar-collapsed .sidebar-header {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 0.75rem;
        padding: 0.75rem 3.75rem;
    }

    body.sidebar-collapsed .sidebar-brand {
        flex: initial;
        width: auto;
        gap: 0.625rem;
    }

    body.sidebar-collapsed .sidebar-logo-card {
        width: 150px;
        padding: 3px 5px;
        border-radius: var(--radius-sm);
    }

    body.sidebar-collapsed .sidebar-logo-img {
        width: 138px;
        height: 48px;
        max-width: 54vw;
    }

    body.sidebar-collapsed .sidebar-brand-text {
        display: none;
    }

    body.sidebar-collapsed .nav-menu-link {
        justify-content: flex-start;
        gap: 0.75rem;
        min-height: 44px;
        padding: 0.625rem 1.25rem;
    }

    body.sidebar-collapsed .nav-menu-label {
        width: auto;
        opacity: 1;
    }

    .sidebar-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 50%;
        right: 1rem;
        transform: translateY(-50%);
        width: 40px;
        height: 40px;
        border: 1px solid rgba(255, 255, 255, 0.25);
        border-radius: var(--radius-md);
        background: rgba(255, 255, 255, 0.12);
        color: #fff;
        font-size: 1.75rem;
        line-height: 1;
        cursor: pointer;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 150;
        background: rgba(15, 23, 42, 0.52);
        border: 0;
        padding: 0;
        cursor: pointer;
    }

    .sidebar-overlay[hidden] {
        display: none;
    }

    body.menu-open {
        overflow: hidden;
    }

    .nav-menu-link {
        min-height: 44px;
    }

    .footer-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.875rem;
    }

    .page-content {
        padding: 0.875rem;
        border-radius: var(--radius-md);
    }

    .navbar {
        padding: 0 0.75rem;
    }

    .navbar-logo-img {
        width: min(38vw, 120px);
        height: 40px;
    }

    .navbar-logo-title {
        display: none;
    }

    .btn-logout {
        min-width: 40px;
        min-height: 40px;
        justify-content: center;
        padding: 0.375rem;
    }

    .auth-layout {
        padding: 1rem 0.875rem;
        align-items: flex-start;
    }

    .auth-container {
        padding: 1.5rem 1.125rem;
        border-radius: 16px;
    }

    .auth-logo {
        width: min(100%, 228px);
        max-height: 96px;
    }

    .auth-title {
        font-size: 1.5rem;
    }
}

@media (max-width: 360px) {
    .navbar {
        padding: 0 0.625rem;
    }

    .navbar-logo-img {
        width: 104px;
    }

    .main-content {
        padding: 0.75rem;
    }

    .page-content {
        padding: 0.75rem;
    }

    .auth-container {
        padding: 1.375rem 1rem;
    }
}
