/* ============================================================
   SMARTCLINIC - LAYOUT
   App shell: sidebar + toolbar + main
   Sidebar colapsavel via logo
   ============================================================ */

/* ============================================================
   APP SHELL
   ============================================================ */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--toolbar-height) 1fr;
    grid-template-areas:
        "sidebar toolbar"
        "sidebar main";
    min-height: 100vh;
    transition: grid-template-columns 0.22s ease;
}

.app-shell.is-collapsed {
    grid-template-columns: var(--sidebar-width-collapsed) 1fr;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.app-sidebar {
    grid-area: sidebar;
    background: var(--brand);
    color: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 20;
}

/* ------------------------------------------------------------
   BRAND (logo clicavel para colapsar)
   ------------------------------------------------------------ */

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 18px;
    height: var(--toolbar-height);
    min-height: var(--toolbar-height);
    border: 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    background: transparent;
    color: #fff;
    font-family: inherit;
    font-size: var(--font-size-lg);
    font-weight: 700;
    text-align: left;
    width: 100%;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    overflow: hidden;
    transition: background 0.15s ease, padding 0.22s ease;
}

.sidebar-brand:hover {
    background: rgba(255,255,255,0.06);
}

.sidebar-brand:focus-visible {
    outline: 2px solid rgba(255,255,255,0.5);
    outline-offset: -2px;
}

.sidebar-brand-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(255,255,255,0.15);
    display: grid;
    place-items: center;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-brand-text {
    color: #fff;
    overflow: hidden;
    transition: opacity 0.18s ease;
}

.app-shell.is-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
}

.app-shell.is-collapsed .sidebar-brand-text {
    opacity: 0;
    width: 0;
}

/* ------------------------------------------------------------
   NAV (menu)
   ------------------------------------------------------------ */

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 0 16px;
    background: transparent;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.sidebar-section {
    padding: 16px 18px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    background: transparent;
    transition: opacity 0.18s ease, height 0.18s ease, padding 0.18s ease;
}

.app-shell.is-collapsed .sidebar-section {
    opacity: 0;
    height: 6px;
    padding: 3px 0;
    pointer-events: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    color: rgba(255,255,255,0.82);
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
    background: transparent;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar-link.is-active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-left-color: #fff;
    font-weight: 600;
}

.sidebar-link-icon {
    width: 22px;
    text-align: center;
    flex-shrink: 0;
    font-size: 16px;
    line-height: 1;
}

.sidebar-link-text {
    overflow: hidden;
    transition: opacity 0.18s ease;
}

.app-shell.is-collapsed .sidebar-link {
    justify-content: center;
    padding: 10px 0;
    gap: 0;
}

.app-shell.is-collapsed .sidebar-link-text {
    opacity: 0;
    width: 0;
}

/* Tooltip quando colapsado */
.app-shell.is-collapsed .sidebar-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--brand-darker);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.app-shell.is-collapsed .sidebar-link:hover::after {
    opacity: 1;
}

/* ------------------------------------------------------------
   FOOTER
   ------------------------------------------------------------ */

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: transparent;
    color: rgba(255,255,255,0.5);
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 0;
    transition: opacity 0.18s ease;
}

.app-shell.is-collapsed .sidebar-footer {
    opacity: 0;
    height: 0;
    padding: 0;
}

/* ============================================================
   TOOLBAR
   ============================================================ */

.app-toolbar {
    grid-area: toolbar;
    background: var(--card);
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 15;
    min-height: var(--toolbar-height);
}

.toolbar-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text);
    margin: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

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

.toolbar-btn.is-primary:hover {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: #fff;
}

.toolbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 12px;
    margin-left: 4px;
    border-left: 1px solid var(--border-soft);
    font-size: 14px;
    color: var(--text-soft);
    white-space: nowrap;
}

.toolbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.toolbar-user-name {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   MAIN
   ============================================================ */

.app-main {
    grid-area: main;
    padding: 30px;
    overflow-x: hidden;
}

.app-content {
    max-width: var(--content-max);
    margin: 0 auto;
    width: 100%;
}

/* ============================================================
   RESPONSIVIDADE
   ============================================================ */

/* Tablet: sidebar colapsada automaticamente */
@media (max-width: 1024px) {
    .app-shell {
        grid-template-columns: var(--sidebar-width-collapsed) 1fr;
    }
    .app-shell .sidebar-brand-text,
    .app-shell .sidebar-link-text,
    .app-shell .sidebar-section,
    .app-shell .sidebar-footer {
        opacity: 0;
        width: 0;
    }
    .app-shell .sidebar-link {
        justify-content: center;
        padding: 10px 0;
        gap: 0;
    }
    .app-shell.is-expanded {
        grid-template-columns: var(--sidebar-width) 1fr;
    }
    .app-shell.is-expanded .sidebar-brand-text,
    .app-shell.is-expanded .sidebar-link-text,
    .app-shell.is-expanded .sidebar-footer {
        opacity: 1;
        width: auto;
    }
    .app-shell.is-expanded .sidebar-link {
        justify-content: flex-start;
        padding: 10px 18px;
        gap: 12px;
    }
}

/* Mobile: sidebar vira drawer */
@media (max-width: 768px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-areas:
            "toolbar"
            "main";
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 0 0 40px rgba(0,0,0,0.25);
        overflow-y: auto;
    }

    .app-shell.is-drawer-open .app-sidebar {
        transform: translateX(0);
    }

    .app-shell.is-drawer-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 19;
    }

    .app-shell .sidebar-brand-text,
    .app-shell .sidebar-link-text,
    .app-shell .sidebar-section,
    .app-shell .sidebar-footer {
        opacity: 1;
        width: auto;
    }
    .app-shell .sidebar-link {
        justify-content: flex-start;
        padding: 10px 18px;
        gap: 12px;
    }
    .app-shell .sidebar-link::after { display: none; }

    .app-main { padding: 0; }
    .app-toolbar { padding: 0 12px; gap: 8px; }
    .toolbar-user-name { display: none; }
}

@media (max-width: 480px) {
    .app-main { padding: 12px; }
    .toolbar-btn { padding: 8px 10px; font-size: 12px; }
    .toolbar-btn-label { display: none; }
}

/* ============================================================
   SUBMENU (acordeao)
   ============================================================ */

.sidebar-group {
    display: block;
}

/* Botao pai (igual ao link, mas com seta) */
.sidebar-link-toggle {
    width: 100%;
    border: 0;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.sidebar-link-arrow {
    margin-left: auto;
    font-size: 12px;
    color: rgba(255,255,255,0.5);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    width: 14px;
    text-align: center;
}

.sidebar-group.is-open .sidebar-link-arrow {
    transform: rotate(180deg);
}

/* Sublinks */
.sidebar-submenu {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.25s ease;
    background: rgba(0,0,0,0.12);
}

.sidebar-group.is-open .sidebar-submenu {
    max-height: 500px;
}

.sidebar-sublink {
    display: block;
    padding: 9px 18px 9px 52px;
    color: rgba(255,255,255,0.72);
    text-decoration: none;
    font-size: 13.5px;
    border-left: 3px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.sidebar-sublink::before {
    content: "";
    position: absolute;
    left: 32px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    transition: background 0.15s ease;
}

.sidebar-sublink:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.sidebar-sublink:hover::before {
    background: rgba(255,255,255,0.7);
}

.sidebar-sublink.is-active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-left-color: #fff;
    font-weight: 600;
}

.sidebar-sublink.is-active::before {
    background: #fff;
}

/* Se o grupo esta ativo, o pai fica destacado */
.sidebar-group.is-open > .sidebar-link-toggle {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

/* Quando colapsado, submenu nao aparece */
.app-shell.is-collapsed .sidebar-group .sidebar-submenu {
    display: none;
}

.app-shell.is-collapsed .sidebar-group {
    display: none;
}

/* Tooltip quando colapsado nos toggles */
.app-shell.is-collapsed .sidebar-link-toggle::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--brand-darker);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.app-shell.is-collapsed .sidebar-link-toggle:hover::after {
    opacity: 1;
}

/* ============================================================
   SIDEBAR - BLOCO DE USUARIO + BOTAO SAIR
   ============================================================ */

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.08);
    flex-shrink: 0;
    overflow: hidden;
    transition: padding 0.22s ease;
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.sidebar-user-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    transition: opacity 0.18s ease;
}

.sidebar-user-name {
    color: #fff;
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    color: rgba(255,255,255,0.55);
    font-size: 11px;
    text-transform: capitalize;
    white-space: nowrap;
}

.sidebar-logout {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: rgba(255,255,255,0.75);
    background: transparent;
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
}

.sidebar-logout:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
}

/* Tooltip do logout quando colapsado */
.app-shell.is-collapsed .sidebar-logout::after {
    content: "Sair";
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--brand-darker);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.app-shell.is-collapsed .sidebar-logout:hover::after {
    opacity: 1;
}

/* Sidebar colapsado: esconde texto, centraliza */
.app-shell.is-collapsed .sidebar-user {
    padding: 12px 6px;
    justify-content: center;
}

.app-shell.is-collapsed .sidebar-user-text {
    display: none;
}

.app-shell.is-collapsed .sidebar-user-info {
    justify-content: center;
    flex: 0;
}

.app-shell.is-collapsed .sidebar-logout {
    display: none;
}

/* Mobile drawer: sempre expandido */
@media (max-width: 768px) {
    .app-shell .sidebar-user {
        padding: 12px 14px;
        justify-content: flex-start;
    }
    .app-shell .sidebar-user-text {
        display: flex;
    }
    .app-shell .sidebar-logout {
        display: grid;
    }
}
