/* ===================================================
   LAYOUT — estrutura de páginas internas (3 colunas)
   =================================================== */

/* App container: 3 colunas fixas, altura total, header embutido na col-3 */
.app{
    height: 100dvh;
    display: grid;
    grid-template-columns: 312px 1fr; /* drawer | conteúdo */
    grid-template-rows: 1fr;
    background: var(--bg-app);
}

/* Drawer desktop */
.drawer{
    display: grid;
    grid-template-columns: 72px 240px;
    min-width: 0;
    min-height: 0;
}

/* No desktop, botão escondido */
.drawer-toggle{
    display: none;
}

/* Backdrop escondido no desktop */
.drawer-backdrop{
    display: none;
}

/* Ajuste: colunas continuam iguais dentro do drawer */
.drawer .col-areas{
    width: 72px;
}

.drawer .col-menu{
    width: 240px;
}

/* ==========================================
    Coluna 1 — Áreas (apenas ícones)
   ========================================== */
.col-areas{
    background: var(--bg-elev-1);
    border-right: var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--sp-3) 0;
    gap: var(--sp-2);
}
.col-areas .area-btn{
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display:flex;
    align-items:center;
    justify-content:center;
    color:#334155;
    border: 1px solid transparent;
    cursor:pointer;
}
.col-areas .area-btn:hover{ background:#f1f5f9; }
.col-areas .area-btn.is-active{
    background: color-mix(in srgb, var(--brand) 12%, #fff);
    border-color: color-mix(in srgb, var(--brand) 35%, #e5e7eb);
    color: var(--brand);
}

.col-areas .area-btn i{ font-size:24px; }

/* ==============================================
     Coluna 2 — Menu da área (lista de seções)
   ============================================== */
.col-menu{
    background: var(--bg-elev-1);
    border-right: var(--border);
    display: flex;
    flex-direction: column;
    padding: var(--sp-2) var(--sp-3) var(--sp-4) var(--sp-3);
    gap: var(--sp-2);
    overflow-y: auto;
}
.col-menu .menu-section-title{
    font-size: var(--fs-12); font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em;
    margin: var(--sp-2) 0 var(--sp-1);
}
.col-menu .menu-item{
    display:flex;
    align-items:center;
    gap: var(--sp-2);
    padding: 10px 12px;
    border-radius: 10px; color:#0f172a;
}
.col-menu .menu-item:hover{ background:#f8fafc; }
.col-menu .menu-item.is-active{
    background: color-mix(in srgb, var(--brand) 12%, #fff);
    color: var(--brand);
    font-weight: 600;
}

/* ========== USER DROPDOWN .ud (top menu - Perfil, Ajuda, Notificações e Sair) ========== */
.ud{
    position: relative;
    display: block;
    margin-bottom: var(--sp-4);
}
.ud[open] .ud-summary{ border-color:#cbd5e1; background:#f8fafc; }
.ud[open] .ud-caret{ transform: rotate(180deg); }

.ud-summary{
    list-style: none;
    display: grid;
    grid-template-columns: 40px 1fr 18px; /* avatar | info | caret */
    align-items: center;
    gap: var(--sp-2);
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
    user-select: none;
    background: #fff;
}
.ud-summary::-webkit-details-marker{ display:none; }

.ud-avatar{
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display:flex;
    align-items:center;
    justify-content:center;
    background:#eef2f7; color:#667892;
}
.ud-info{ min-width: 0; }
.ud-name{ display:block;
    font-weight:700;
    color:#0f172a;
    line-height:1.1;
}
.ud-role{ display:block;
    color: var(--muted);
    font-size: var(--fs-12);
}
.ud-caret{ color:#667892; transition: transform .15s ease; }

/* Menu popup */
.ud-menu{
    position: absolute; inset-inline-start: 0; top: calc(100% + 8px);
    min-width: 220px;
    background:#fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-1);
    padding: 6px;
    z-index: 20;
}
.ud-item{
    width:100%;
    display:flex;
    align-items:center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color:#0f172a;
    text-align:left;
    background: transparent;
    border:0;
    cursor:pointer;
}
.ud-item i{ color:#556581; }
.ud-item:hover{ background:#f8fafc; }
.ud-sep{ height:1px; background: var(--line); margin: 6px 4px; }
.ud-danger{ color:#991b1b; }
.ud-danger i{ color:#991b1b; }

/* Ajuste em telas estreitas (se necessário) */
@media (max-height: 640px){
    .ud-menu{ max-height: 60vh; overflow:auto; }
}

/* ========== SIDE MENU (multi-nível) .sm ========== */
.sm { display: flex; flex-direction: column; gap: 6px; }

/* item simples (link) */
.sm-item{
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 5px 12px 3px 12px;
  border-radius: 10px;
  color:#0f172a;
  text-decoration:none;
}
.sm-item i{ color:#556581; font-size:18px; }
.sm-item:hover{ background:#f8fafc; }
.sm-item.is-active{
  background:#ecfdf5;
  color:#16a34a;
  font-weight:600;
}

/* grupo (abre/fecha) */
.sm-group{ display:block; }
.sm-summary{
  list-style:none;
  cursor:pointer;
  user-select:none;
  display:grid;
  grid-template-columns: 20px 1fr 16px;
  align-items:center;
  gap:10px;
  padding: 5px 12px 3px 12px;
  border-radius:10px;
}
.sm-summary::-webkit-details-marker{ display:none; }
.sm-summary i{ color:#556581; font-size:18px; }
.sm-summary:hover{ background:#f8fafc; }

/* caret */
.sm-caret{ color:#8895a7; font-size:16px; transition: transform .15s ease; }
.sm-group[open] > .sm-summary .sm-caret{ transform: rotate(180deg); }

/* filhos (indent + linha guia sutil) */
.sm-children{
  margin-top: 6px;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px dashed var(--line);
  display:flex; flex-direction:column; gap:6px;
}

/* segundo nível dentro de filhos (terceiro nível total) */
.sm-children .sm-children{
  margin-left: 10px; padding-left: 10px; border-left-style: dotted;
}

/* “ativo” também em resumo de grupo */
.sm-summary.is-active{
  background:#ecfdf5;
  color:#16a34a;
  font-weight:600;
}
.sm-summary.is-active i{ color:#16a34a; }

/* ======================================================
    Coluna 3 — Conteúdo (topbar + conteúdo com scroll)
   ====================================================== */
.col-content{
    display: grid;
    grid-template-rows: auto 1fr; /* topbar (auto) + main (1fr) */
    min-width: 0;                 /* para permitir overflow interno */
    min-height: 0;
}

/* ========== Top bar (dinâmica por área) ==========  */
.topbar{
    background: var(--bg-elev-1);
    border-bottom: var(--border);
    padding: var(--sp-3) var(--sp-4);
    display: grid;
    grid-template-columns: 1fr auto auto; /* esquerda | centro (auto) | direita (auto) */
    align-items: center;
    gap: var(--sp-3);
}
.topbar .tb-left{
    display:flex; align-items:center; gap: var(--sp-3); min-width:0;
}

.tb-right{ display:flex; align-items:center; gap: var(--sp-3); }

.topbar .title{
    font-size: var(--fs-20); font-weight: 700; color: var(--text);
}
.topbar .breadcrumb{ color: var(--muted); font-size: var(--fs-13); }

.tb-actions{
    display:inline-flex; align-items:center; gap: var(--sp-1);
    background: var(--bg-app);
    padding: 2px;
    border-radius: 12px;
    border: none;
    box-shadow: 0 1px 0 rgba(15,23,42,.03);
}

/* Botões icônicos da topbar */
.tp-icon-btn{
    --btn-border: #e5e7eb;
    background: #fff;
    border: 1px solid var(--btn-border);
    border-radius: 10px;
    width: 36px; height: 36px;
    display:inline-flex; align-items:center; justify-content:center;
    color: #334155; cursor:pointer;
    transition: box-shadow .15s, border-color .15s, transform .03s;
}
.tp-icon-btn-green {
    background: #d1fae5;
    border: 1px solid #a7f3d0;
}

.tp-icon-btn i{ font-size:22px; }

.tp-icon-btn:hover{
    border-color: #cbd5e1;
    box-shadow: 0 2px 8px rgba(15,23,42,.06);
}
.tp-icon-btn:active{ transform: translateY(1px); }

/* Estado ativo (usa o verde da brand) */
.tp-icon-btn.is-active{
    border-color: #bbf7d0;
    box-shadow: 0 2px 10px rgba(34,197,94,.12);
}
.tp-icon-btn.is-active i{ color: var(--brand); }

.tp-icon-btn.muted{
  transform: translateY(1px);
  background-color: #aaa;
}


/* Seletor compacto à direita da topbar (campo visual, ex: produtos) */
.tp-select-lite{
    display:inline-flex; align-items:center; gap: 10px;
    background:#fff; border: 1px solid #cdd6e4;
    border-radius: 12px; padding: 10px 12px;
    color:#0f172a; min-height: 38px;
    box-shadow: 0 2px 8px rgba(15,23,42,.04);
}
.tp-select-lite i{ color:#667892; }
.tp-select-lite:hover{ border-color:#b6c2d6; }

/* area de importação de arquivos */
#importOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
#importOverlay[hidden] {
    display: none !important;
}

/* ========== Conteúdo padrão "card page" ========== */
.page-card{
    background: var(--bg-elev-1);
    border: var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-1);
    margin: 10px;
    display: flex;
    min-width: 0;
    flex-direction: column;
    min-height: 0;
}

/* Header fixo */
.page-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--white);
    margin: 10px 5px 0 10px;
    padding: 5px 30px 0 15px;
    border-radius: var(--radius) var(--radius) 0 0;
}

/* Área de dados com scroll */
.page-data {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0; /* evita estourar o container */
    overflow: visible;
    overflow-y: scroll;
    outline: none;
    margin: 0 10px 0 10px;
    padding:0 15px 10px 15px;
    background: var(--white);
    border-radius: 0 0 var(--radius) var(--radius);
}

/* Págionas de erro (404, 500, etc) */
.page-error{
    margin: auto;
}
.error-icon{
    font-size: 100px; color: var(--muted);
    line-height: 1;
}
.error-ri-icon{
    color: rgb(153, 43, 61);
}
.error-code{
    font-weight: 900;
    margin-left: 10px;
}
.error-heading{
    text-align: center;
    font-size: 20px; color: var(--muted);
    font-weight: 600;
}
.error-message{
    margin-top: 30px;
}
.error-actions{
    text-align: center;
    margin-top: 30px;
}

/* ===================================================
   TABLET / MOBILE
   =================================================== */

@media (max-width: 900px){

    .app{
        grid-template-columns: 1fr;
    }

    .drawer{
        position: fixed;
        inset: 0 auto 0 0;
        width: 312px;
        max-width: calc(100vw - 40px);
        height: 100dvh;
        z-index: 1001;

        display: grid;
        grid-template-columns: 72px minmax(0, 240px);

        background: var(--bg-elev-1);

        transform: translateX(-100%);
        transition: transform .22s ease;
    }

    body.drawer-open .drawer{
        transform: translateX(0);
    }

    .drawer-backdrop{
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1000;
        background: rgba(15, 23, 42, .35);
        opacity: 0;
        pointer-events: none;
        transition: opacity .22s ease;
    }

    body.drawer-open .drawer-backdrop{
        opacity: 1;
        pointer-events: auto;
    }

    .drawer-toggle{
        display: inline-flex;
        align-items: center;
    }

    .topbar{
        grid-template-columns: auto 1fr ;
    }

    .col-content{
        min-width: 0;
        width: 100%;
    }

    .page-card{
        margin: 8px;
    }
}

/* ===================================================
   MOBILE MAIS ESTREITO
   =================================================== */

@media (max-width: 520px){

    .drawer{
        width: 292px;
        grid-template-columns: 64px minmax(0, 228px);
    }

    .drawer .col-areas{
        width: 64px;
    }

    .drawer .col-menu{
        width: auto;
        padding-left: var(--sp-2);
        padding-right: var(--sp-2);
    }

    .topbar{
        padding: var(--sp-2) var(--sp-3);
        gap: var(--sp-2);
    }

    .topbar .title{
        font-size: var(--fs-18);
    }

    .topbar .breadcrumb{
        font-size: var(--fs-12);
    }

    .tb-actions{
        gap: 2px;
    }

    .tp-icon-btn{
        width: 34px;
        height: 34px;
    }

    .page-card{
        margin: 6px;
        border-radius: var(--radius);
    }

    .page-header{
        margin: 8px 5px 0 8px;
        padding: 5px 16px 0 12px;
    }

    .page-data{
        margin: 0 8px 0 8px;
        padding: 0 12px 10px 12px;
    }
}

/* ===================================================
   TOPBAR ACTIONS RESPONSIVO
   =================================================== */

.tb-actions-dropdown{
    position: relative;
}

.tb-actions-dropdown > summary{
    list-style: none;
}

.tb-actions-dropdown > summary::-webkit-details-marker{
    display: none;
}


/* Mobile: ações viram menu */
@media (max-width: 900px){
    .topbar{
        grid-template-columns: auto 1fr auto;
    }

    .tb-left{
        min-width: 0;
    }

    .tb-left .title,
    .tb-left .breadcrumb{
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .tb-actions-dropdown .tb-actions{
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        z-index: 900;

        display: flex;
        align-items: center;
        gap: 4px;

        width: max-content;
        max-width: calc(100vw - 24px);

        background: #fff;
        border: var(--border);
        border-radius: 14px;
        box-shadow: var(--shadow-1);
        padding: 6px;
    }

    .tb-actions-dropdown:not([open]) .tb-actions{
        display: none;
    }
}

/* Desktop: ações sempre visíveis */
@media (min-width: 901px){

    .tb-actions-dropdown > summary{
        display: none;
    }

    .tb-actions-dropdown .tb-actions{
        display: inline-flex;
        position: static;
    }
}
