@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --bg-dark: #0f172a;
    --bg-sidebar: rgba(15, 23, 42, 0.95);
    --bg-card: rgba(30, 41, 59, 0.6);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    /* overflow-x gerenciado pelo sidebar-open e wrappers responsivos */
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    transition: all 0.3s;
    cursor: pointer;
}

.nav-item:hover, .nav-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.nav-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.nav-group-toggle {
    justify-content: flex-start;
    position: relative;
}

.nav-chevron {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    margin-left: auto;
    transition: transform 0.3s;
    flex-shrink: 0;
}

.nav-group.open .nav-chevron {
    transform: rotate(180deg);
}

.nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.nav-group.open > .nav-submenu {
    max-height: 500px;
}

.nav-subitem {
    padding-left: 2.5rem;
    font-size: 0.9rem;
}

.nav-subitem-deep {
    padding-left: 3.75rem;
    font-size: 0.85rem;
}

.nav-chevron-sm {
    width: 12px;
    height: 12px;
}

/* Main Content */
.main-wrapper {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Top Header */
.top-header {
    height: 70px;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-search {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    width: 300px;
    border: 1px solid var(--border);
}

.header-search input {
    background: transparent;
    border: none;
    color: var(--text-main);
    outline: none;
    margin-left: 0.5rem;
    width: 100%;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.warehouse-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(59, 130, 246, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(59, 130, 246, 0.2);
    cursor: pointer;
}

.warehouse-selector select {
    background: transparent;
    border: none;
    color: var(--primary);
    font-weight: 600;
    outline: none;
    cursor: pointer;
    appearance: none;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
}

/* Dashboard Content */
.content-area {
    padding: 2rem;
    flex: 1;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s, box-shadow 0.3s;
    backdrop-filter: blur(10px);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.stat-icon.blue { background: rgba(59, 130, 246, 0.1); color: var(--primary); }
.stat-icon.green { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.stat-icon.orange { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.stat-icon.red { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.stat-info h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-info p {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

/* Panels Grid */
.panels-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.panel-title {
    font-size: 1.125rem;
    font-weight: 600;
}

/* Table */
.data-table,
.table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.table th {
    text-align: left;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.data-table td,
.table td {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.9rem;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.success { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.badge.warning { background: rgba(245, 158, 11, 0.2); color: var(--warning); }

/* ── Sections (SPA) ─────────────────────────────────────────────── */
.section-page {
    display: none;
}
.section-page.active {
    display: block;
}

/* ── Page Header (título + ação) ────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-header .page-title {
    margin-bottom: 0;
}

/* ── Botões ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.625rem 1.25rem;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}
/* SVG/ícone dentro de .btn — reseta o estilo de botão standalone */
.btn svg,
.btn .btn-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: block;
    padding: 0;
    border: none;
    background: none;
    color: inherit;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}
.btn-ghost {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

/* ── Estados da tabela ──────────────────────────────────────────── */
.table-loading,
.table-empty,
.table-error {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.table-error { color: var(--danger); }

/* ── Badges de recurso / ação ───────────────────────────────────── */
.badge-resource {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    background: rgba(59, 130, 246, 0.12);
    color: #60a5fa;
}
.badge-action {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    background: rgba(167, 139, 250, 0.12);
    color: #a78bfa;
}
.badge-finalizado {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
}

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open {
    display: flex;
}
.modal {
    background: #1e293b;
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    margin: 1rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    animation: modalIn 0.2s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(-16px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.modal-title {
    font-size: 1rem;
    font-weight: 600;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 6px;
    transition: color 0.2s;
    display: flex;
    align-items: center;
}
.modal-close:hover { color: var(--text-main); }
.modal-body {
    padding: 1.5rem;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

/* ── Formulário ─────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.25rem;
    flex: 1;
}
.form-row {
    display: flex;
    gap: 1rem;
}
.form-label {
    display: block;
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.required { color: var(--danger); }
.form-control {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.625rem 0.875rem;
    color: var(--text-main);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.form-control option {
    background: #1e293b;
}
.form-feedback {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}
.form-feedback.error   { background: rgba(239, 68, 68, 0.12);  color: var(--danger);  border: 1px solid rgba(239,68,68,.25); }
.form-feedback.success { background: rgba(16, 185, 129, 0.12); color: var(--success); border: 1px solid rgba(16,185,129,.25); }

/* ── Botão ícone (ex: editar na tabela) ─────────────────────────── */
.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}
.btn-icon:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--primary);
}

/* ── Modal largo (edição de perfil) ─────────────────────────────── */
.modal-lg {
    max-width: 680px;
}

/* ── Lista de permissões com checkboxes ─────────────────────────── */
.permissions-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 320px;
    overflow-y: auto;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.perm-loading {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 1.5rem 0;
}
.perm-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}
.perm-checkbox:hover {
    background: rgba(59, 130, 246, 0.06);
    border-color: rgba(59, 130, 246, 0.15);
}
.perm-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    accent-color: var(--primary);
    flex-shrink: 0;
    cursor: pointer;
}
.perm-checkbox:has(input:checked) {
    background: rgba(59, 130, 246, 0.08);
    border-color: rgba(59, 130, 246, 0.2);
}
.perm-checkbox-body {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.perm-checkbox-nome {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}
.perm-checkbox-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ── Célula de armazéns na tabela de usuários ───────────────────── */
.cell-armazens {
    font-size: 0.82rem;
    color: var(--text-muted);
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Label hint ─────────────────────────────────────────────────── */
.form-label-hint {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

/* ── Lista dinâmica de linhas armazém+perfil ────────────────────── */
.armazens-perfis-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.ap-loading {
    font-size: 0.875rem;
    color: var(--text-muted);
    padding: 0.75rem 0;
}
.ap-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.65rem;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: border-color 0.2s;
}
.ap-row:hover {
    border-color: rgba(59, 130, 246, 0.2);
}
.btn-remove-row {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}
.btn-remove-row:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

/* ── Botão "Incluir novo armazém" ───────────────────────────────── */
.btn-add-row {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: 1px dashed rgba(59, 130, 246, 0.35);
    color: var(--primary);
    font-size: 0.825rem;
    font-weight: 600;
    padding: 0.45rem 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    justify-content: center;
}
.btn-add-row:hover {
    background: rgba(59, 130, 246, 0.07);
    border-color: var(--primary);
}

/* ── Card (container de tabelas nas seções) ─────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    overflow-x: auto;
}

/* ── Botão hamburger (visível apenas em tablet/mobile) ──────────── */
.btn-hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
}
.btn-hamburger:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
}

/* ── Overlay escuro por trás da sidebar aberta ──────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 99;
    backdrop-filter: blur(2px);
    cursor: pointer;
}
body.sidebar-open .sidebar-overlay { display: block; }
/* Impede scroll do body enquanto sidebar está aberta no mobile */
body.sidebar-open { overflow: hidden; }

/* Impede scroll do body enquanto qualquer modal está aberto */
body:has(.modal-overlay.open) { overflow: hidden; }

/* ── Tabela responsiva: scroll horizontal (tablet) + card (mobile) ─ */

/* Garante min-width para acionar o scroll horizontal no tablet */
.responsive-table {
    min-width: 640px;
}

/* ── Responsive: Tablet (≤ 1024px) ─────────────────────────────── */
@media (max-width: 1024px) {

    /* Sidebar desliza para fora por padrão */
    .sidebar {
        transform: translateX(-260px);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    /* Conteúdo ocupa a largura toda */
    .main-wrapper {
        margin-left: 0;
        width: 100%;
    }

    /* Mostra hamburger */
    .btn-hamburger {
        display: flex;
    }

    /* Painel duplo → coluna única */
    .panels-grid {
        grid-template-columns: 1fr;
    }

    /* Search bar menor */
    .header-search {
        flex: 1;
        width: auto;
        max-width: 260px;
    }

    /* Tabelas: scroll horizontal dentro dos containers */
    .card,
    .panel {
        overflow-x: auto;
    }
}

/* ── Responsive: Mobile (≤ 640px) ──────────────────────────────── */
@media (max-width: 640px) {

    /* Header */
    .top-header {
        padding: 0 1rem;
        gap: 0.5rem;
    }
    .header-search {
        display: none;
    }
    .header-actions {
        gap: 0.75rem;
    }
    /* Esconde o texto nome/sair do usuário, mantém só o avatar */
    .user-profile > div:last-child {
        display: none;
    }

    /* Conteúdo */
    .content-area {
        padding: 1rem;
    }
    .page-title {
        font-size: 1.15rem;
    }

    /* Stats em 2 colunas no mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    /* Formulários empilham */
    .form-row {
        flex-direction: column;
    }

    /* Linha armazém+perfil: 1 coluna */
    .ap-row {
        grid-template-columns: 1fr 1fr auto;
    }

    /* ── Tabela responsiva → layout de card no mobile ─────────────── */
    .responsive-table {
        min-width: unset;   /* cancela o min-width do tablet */
    }
    .responsive-table thead {
        display: none;      /* esconde o cabeçalho */
    }
    .responsive-table tbody tr {
        display: block;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid var(--border);
        border-radius: 10px;
        margin-bottom: 0.75rem;
        padding: 0.25rem 0.75rem;
    }
    .responsive-table tbody tr:last-child {
        margin-bottom: 0;
    }
    /* Primeira coluna (ID #) fica oculta no mobile */
    .responsive-table tbody td:first-child {
        display: none;
    }
    .responsive-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        padding: 0.55rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        font-size: 0.875rem;
        border-radius: 0;
    }
    .responsive-table tbody td:last-child {
        border-bottom: none;
        padding-bottom: 0.65rem;
        justify-content: flex-end;
    }
    /* Label gerado pelo data-label */
    .responsive-table tbody td[data-label]::before {
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* Modal vira bottom-sheet */
    .modal-overlay {
        align-items: flex-end;
    }
    .modal,
    .modal-lg {
        max-width: 100%;
        max-height: 92vh;
        border-radius: 16px 16px 0 0;
        margin: 0;
        overflow-y: auto;
    }
    @keyframes modalIn {
        from { opacity: 0; transform: translateY(32px); }
        to   { opacity: 1; transform: translateY(0);    }
    }
}

/* ── Responsive: Extra-small (≤ 400px) ─────────────────────────── */
@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .stat-card {
        padding: 1rem;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}
