/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #f8fdfb;
    overflow-x: hidden;
}

body.tc-pwa-shell {
    min-height: 100dvh;
    background:
        radial-gradient(circle at top left, rgba(109, 212, 168, 0.12), transparent 28%),
        linear-gradient(180deg, #f8fdfb 0%, #ffffff 34%);
}

/* Design tokens */
:root {
    --bg: #ffffff;
    --bg-soft: #f8fdfb;
    --border: #d4f1e8;
    --text: #1a1a1a;
    --muted: #718096;
    --muted-2: #718096;
    --primary: #4db896;
    --primary-soft: #d4f1e8;
}

/* App Container */
.app-container {
    display: block;
    min-height: 100vh;
}

/* Sidebar Styles */
.sidebar {
    width: 256px;
    background: var(--bg);
    color: var(--text);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
    z-index: 1000;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand-logo {
    width: 176px;
    max-width: 100%;
    height: auto;
    display: block;
}

.topbar-brand-logo {
    width: 168px;
    max-width: 100%;
    height: auto;
    display: block;
}

/* Collapse toggle (desktop) */
.collapse-toggle {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    height: 32px;
    width: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.collapse-toggle:hover {
    background: var(--bg-soft);
    border-color: #b8e6d5;
    color: #4a5568;
}
.sidebar.collapsed .collapse-toggle i {
    transform: rotate(180deg);
    transition: transform 0.2s ease;
}

.sidebar-toggle {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(77, 184, 150, 0.22);
    color: #3f6e88;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 15px;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 10px 30px rgba(77, 184, 150, 0.08);
}

.sidebar-toggle:hover {
    background: linear-gradient(135deg, #f5fffb 0%, #ebfaf4 100%);
    border-color: rgba(77, 184, 150, 0.38);
    color: #244d66;
    transform: translateY(-1px);
}

.sidebar-toggle i {
    font-size: 1.35rem;
    line-height: 1;
}

.sidebar-toggle--mobile {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(243, 252, 248, 0.96) 100%);
}

.sidebar-toggle--close {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    box-shadow: none;
}

/* Sidebar Menu */
.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin-bottom: 2px;
}

.nav-link {
    display: flex;
    flex-direction: row; /* fuerza ícono junto al texto */
    align-items: center;
    flex-wrap: nowrap; /* evita salto de línea entre ícono y texto */
    padding: 10px 14px;
    color: var(--muted);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
    margin: 2px 10px;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.92rem;
}

.nav-link:hover {
    background: var(--bg-soft);
    color: var(--text);
}

.nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    width: 3px;
    height: calc(100% - 16px);
    background: var(--primary);
    border-radius: 2px;
}

.nav-icon {
    font-size: 1.05rem;
    margin-right: 12px;
    min-width: 22px;
    display: inline-flex; /* evita que se expanda verticalmente */
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    line-height: 1; /* asegura altura compacta del ícono */
    color: var(--muted-2);
    transition: color 0.2s ease;
}

.nav-link:hover .nav-icon,
.nav-link.active .nav-icon {
    color: inherit;
}

.nav-text {
    flex: 1;
    font-weight: 500;
    font-size: 0.9rem;
}

.nav-arrow {
    font-size: 0.9rem;
    transition: transform 0.2s ease;
    color: var(--muted-2);
    margin-left: 8px;
}

.nav-link[aria-expanded="true"] .nav-arrow {
    transform: rotate(180deg);
}

/* Submenu Styles */
.nav-submenu {
    list-style: none;
    padding: 4px 0;
    margin: 2px 12px 8px 12px;
    background: var(--bg-soft);
    border-radius: 10px;
}

.nav-sublink {
    display: block;
    padding: 8px 14px 8px 44px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.15s ease, color 0.15s ease;
    border-radius: 8px;
    margin: 2px 6px;
    font-weight: 400;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.nav-sublink:hover {
    background: var(--bg);
    color: var(--text);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.sidebar-mobile-user,
.sidebar-mobile-actions {
    display: none;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 10px;
    background: var(--bg);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.user-avatar {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, #4db896 0%, #6dd4a8 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: white;
}

.user-details {
    flex: 1;
}

.user-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: #1a1a1a;
}

.user-role {
    font-size: 0.75rem;
    color: #718096;
    margin-top: 1px;
}

/* Main Content Area */
.main-content {
    margin-left: 256px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: all 0.3s ease;
}

/* No Sidebar Layout */
.no-sidebar .main-content {
    margin-left: 0;
}

/* Top Bar */
.top-bar {
    background: #ffffff;
    padding: 16px 32px;
    border-bottom: 1px solid #e8f9f3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(18px);
}

/* Navbar minimalist layout helpers */
.navbar-left, .navbar-center, .navbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-left {
    min-width: 0;
    flex: 1 1 auto;
}

.navbar-right {
    min-width: 0;
    margin-left: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    min-width: 0;
}

.brand-link .brand-text {
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-bar-search {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    background: var(--bg);
}
.top-bar-search .search-input {
    border: none;
    outline: none;
    min-width: 200px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: #4a5568;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.btn-icon:hover {
    background: var(--bg-soft);
    border-color: #b8e6d5;
    color: #1a1a1a;
}

.topbar-logout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 42px;
    line-height: 1;
    border-radius: 14px;
    border-width: 1.5px;
    padding: 0.55rem 0.9rem;
}

.tenant-switcher {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.tenant-switcher--topbar {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: linear-gradient(135deg, #ffffff 0%, #f8fdfb 100%);
    min-width: 0;
    box-shadow: 0 8px 22px rgba(77, 184, 150, 0.08);
}

.tenant-switcher__topbar-summary,
.tenant-switcher__topbar-controls {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.tenant-switcher__badge {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.05;
}

.tenant-switcher__badge-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #718096;
}

.tenant-switcher__badge-value {
    font-size: 0.86rem;
    font-weight: 700;
    color: #1a1a1a;
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tenant-switcher__topbar-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid #d4f1e8;
    background: #ffffff;
    color: #4db896;
    font-size: 0.85rem;
    font-weight: 800;
    line-height: 1;
}

.tenant-switcher__select--topbar {
    min-width: 240px;
    max-width: 300px;
    border-radius: 12px;
    border-color: #d4f1e8;
    min-height: 40px;
    font-size: 0.9rem;
    background-color: #ffffff;
}

.tenant-switcher__submit--topbar {
    white-space: nowrap;
    min-height: 40px;
    border-radius: 12px;
    font-weight: 700;
    padding-inline: 14px;
}

/* User chip on topbar */
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
}
.user-chip-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4db896 0%, #6dd4a8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
}
.user-chip-info {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}
.user-chip-name { font-weight: 600; font-size: 0.85rem; color: #1a1a1a; }
.user-chip-role { font-size: 0.75rem; color: #718096; }

.top-bar-title h1 {
    font-size: 1.4rem;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
    letter-spacing: -0.025em;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-notification {
    background: #f8fdfb;
    border: 1px solid #d4f1e8;
    position: relative;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    transition: all 0.2s ease;
    color: #718096;
}

.btn-notification:hover {
    background: #e8f9f3;
    border-color: #b8e6d5;
    color: #4a5568;
}

.notification-icon {
    font-size: 1.2rem;
}

.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    border: 2px solid white;
}

/* Page Content */
.page-content {
    flex: 1;
    padding: 32px;
    background: #ffffff; /* match app white content background */
    width: 100%;
    overflow-x: hidden;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(9, 19, 27, 0.38);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

body.sidebar-open {
    overflow: hidden;
}

/* Mobile Styles */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: min(88vw, 380px);
        max-width: calc(100vw - 1.25rem);
        height: 100dvh;
        border-radius: 0 28px 28px 0;
        box-shadow: 0 28px 56px rgba(15, 23, 42, 0.24);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-header {
        padding: calc(env(safe-area-inset-top, 0px) + 1rem) 1rem 1rem;
    }

    .sidebar-brand-logo {
        width: 188px;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .top-bar {
        padding: calc(env(safe-area-inset-top, 0px) + 0.9rem) 1rem 0.9rem;
        gap: 8px;
        min-height: calc(76px + env(safe-area-inset-top, 0px));
        background: rgba(255, 255, 255, 0.94);
    }
    
    .page-content {
        padding: 1rem;
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    }

    .navbar-left {
        gap: 0.9rem;
    }

    .navbar-right {
        gap: 0.75rem;
    }

    .tenant-switcher--topbar {
        display: none;
    }

    .topbar-brand-logo {
        width: min(48vw, 206px);
    }

    .nav-link {
        margin: 2px 12px;
        padding: 12px 14px;
        font-size: 0.98rem;
        border-radius: 16px;
    }

    .nav-icon {
        font-size: 1.25rem;
        min-width: 28px;
        width: 28px;
        height: 28px;
        margin-right: 14px;
    }

    .nav-text {
        font-size: 1rem;
    }

    .nav-submenu {
        margin: 4px 14px 10px;
        padding: 8px 0;
        border-radius: 16px;
    }

    .nav-sublink {
        padding: 10px 14px 10px 48px;
        font-size: 0.92rem;
    }

    .sidebar-footer {
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        background: linear-gradient(180deg, rgba(255,255,255,0.96) 0%, rgba(248,253,251,0.98) 100%);
    }

    .sidebar-mobile-user {
        display: flex;
        align-items: center;
        gap: 0.9rem;
        padding: 0.95rem 1rem;
        margin-bottom: 0.85rem;
        border-radius: 20px;
        border: 1px solid rgba(77, 184, 150, 0.16);
        background: linear-gradient(135deg, rgba(77, 184, 150, 0.14) 0%, rgba(212, 241, 232, 0.52) 100%);
    }

    .sidebar-mobile-user__avatar {
        width: 44px;
        height: 44px;
        border-radius: 16px;
        background: linear-gradient(135deg, #4db896 0%, #6dd4a8 100%);
        color: #ffffff;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 1rem;
        box-shadow: 0 10px 24px rgba(77, 184, 150, 0.22);
    }

    .sidebar-mobile-user__content {
        min-width: 0;
        display: grid;
        gap: 0.15rem;
    }

    .sidebar-mobile-user__name {
        color: #17324d;
        font-size: 0.94rem;
        font-weight: 700;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sidebar-mobile-user__role {
        color: #5d7492;
        font-size: 0.78rem;
        font-weight: 600;
    }

    .sidebar-mobile-actions {
        display: grid;
        gap: 0.75rem;
    }

    .sidebar-mobile-action {
        width: 100%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.7rem;
        min-height: 48px;
        padding: 0.9rem 1rem;
        border-radius: 16px;
        border: 1px solid rgba(77, 184, 150, 0.18);
        background: #ffffff;
        color: #2d5d78;
        text-decoration: none;
        font-weight: 700;
        box-shadow: 0 10px 22px rgba(15, 23, 42, 0.05);
        transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    }

    .sidebar-mobile-action:hover {
        transform: translateY(-1px);
        border-color: rgba(77, 184, 150, 0.34);
        color: #204a64;
    }

    .sidebar-mobile-action--danger {
        color: #b42332;
        border-color: rgba(220, 38, 38, 0.18);
        background: linear-gradient(135deg, #ffffff 0%, #fff6f6 100%);
    }

    .sidebar-mobile-logout-form {
        margin: 0;
    }

    .topbar-logout-btn {
        min-width: 46px;
        min-height: 46px;
        padding: 0.65rem;
        border-radius: 16px;
        box-shadow: 0 10px 26px rgba(220, 38, 38, 0.08);
    }
}

@media (max-width: 767.98px) {
    .top-bar {
        padding: calc(env(safe-area-inset-top, 0px) + 0.8rem) 0.9rem 0.85rem;
    }

    .page-content {
        padding: 0.9rem;
        padding-bottom: calc(1.35rem + env(safe-area-inset-bottom, 0px));
    }

    .topbar-brand-logo {
        width: min(52vw, 188px);
    }
}

@media (max-width: 575.98px) {
    .brand-link {
        gap: 8px;
    }

    .topbar-brand-logo {
        width: min(50vw, 176px);
    }

    .navbar-right {
        gap: 0.55rem;
    }

    .tenant-switcher__badge {
        display: none;
    }

    .tenant-switcher__topbar-count {
        display: none;
    }

    .tenant-switcher__select--topbar {
        min-width: 180px;
        max-width: 180px;
    }

    .topbar-logout-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 0.55rem;
    }

    .sidebar {
        width: calc(100vw - 1rem);
        max-width: calc(100vw - 1rem);
        border-radius: 0 24px 24px 0;
    }
}

/* Animations */
@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

/* Flyout submenu (hover when sidebar is collapsed) */
.submenu-flyout {
    position: fixed;
    top: 0; /* se establece por JS */
    left: 88px; /* se establece por JS; 80px sidebar + 8px gap */
    z-index: 1100;
    min-width: 240px;
    max-width: 280px;
    max-height: calc(100vh - 16px);
    overflow: auto;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(2, 8, 23, 0.1);
    padding: 8px;
}
.submenu-flyout .nav-submenu {
    display: block !important;
}
.submenu-flyout .nav-sublink {
    display: block;
    padding: 8px 10px;
    border-radius: 8px;
    color: #4a5568;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}
.submenu-flyout .nav-sublink:hover {
    background: var(--bg-soft);
    color: #1a1a1a;
}
.submenu-flyout .flyout-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #718096;
    padding: 4px 8px 8px;
}

/* Tooltip for single links */
.sidebar-tooltip {
    position: fixed;
    top: 0; /* por JS */
    left: 88px; /* por JS */
    z-index: 1100;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 10px;
    color: #1a1a1a;
    box-shadow: 0 6px 16px rgba(2, 8, 23, 0.08);
    white-space: nowrap;
    font-size: 0.85rem;
}

@media (max-width: 991.98px) {
    .submenu-flyout, .sidebar-tooltip { display: none !important; }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Custom Scrollbar for Sidebar */
.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Login Partial Styles in Sidebar */
.sidebar-footer .navbar-nav {
    flex-direction: column;
    gap: 4px;
}

.sidebar-footer .nav-link {
    color: #718096;
    padding: 6px 12px;
    font-size: 0.8rem;
    background: #ffffff;
    border: 1px solid #d4f1e8;
    border-radius: 6px;
    margin: 0;
    text-align: center;
    font-weight: 500;
    transition: all 0.2s ease;
}

.sidebar-footer .nav-link:hover {
    color: #4a5568;
    background: #f8fdfb;
    border-color: #b8e6d5;
    transform: none;
}

/* Collapsed state */
.sidebar.collapsed {
    width: 80px;
}
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-arrow,
.sidebar.collapsed .user-details {
    display: none;
}
.sidebar.collapsed .sidebar-brand-logo {
    width: 42px;
}
.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 10px;
}
.sidebar.collapsed .nav-icon {
    margin-right: 0;
}
.sidebar.collapsed .nav-submenu {
    display: none !important;
}
.sidebar.collapsed + .main-content {
    margin-left: 80px;
}
