/* ==========================================================================
   ALFASIC - ERP STYLESHEET (CSS PURO)
   ========================================================================== */

@import url('variables.css');

/* --- 1. Reset Básico --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    font-size: 13px;
    line-height: 1.45;
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- 2. Full Topbar Header Oficial --- */
#main-header {
    height: 56px;
    background-color: #0f172a;
    color: #ffffff;
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.05em;
    color: #38bdf8;
    text-decoration: none;
}

.header-tag {
    font-size: 10px;
    background-color: #1e293b;
    color: #94a3b8;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    letter-spacing: 0.04em;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 20px;
}

.nav-dropdown {
    position: relative;
}

.nav-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #cbd5e1;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
}

.nav-btn:hover {
    background-color: #1e293b;
    color: #ffffff;
}

.nav-btn.active {
    background-color: #0284c7;
    color: #ffffff;
    border-color: #38bdf8;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    width: 240px;
    background-color: #ffffff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
    padding: 8px;
    z-index: 200;
    display: none;
    margin-top: 4px;
}

/* Ponte invisivel de hover para impedir que o menu feche ao mover o mouse */
.dropdown-menu::before {
    content: '';
    position: absolute;
    top: -12px;
    left: 0;
    right: 0;
    height: 12px;
    background: transparent;
}

.dropdown-menu.show,
.nav-dropdown:hover .dropdown-menu {
    display: block;
}

.user-logout-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.user-logout-btn:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #ef4444;
}

.dd-title {
    font-size: 10px;
    font-weight: 800;
    color: #94a3b8;
    text-transform: uppercase;
    padding: 6px 12px 2px 12px;
    letter-spacing: 0.05em;
}

.dd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 12px;
    color: #334155;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 500;
    transition: background 0.1s;
    cursor: pointer;
}

.dd-item:hover {
    background-color: #f1f5f9;
    color: #0f172a;
    font-weight: 600;
}

.dd-item.active {
    background-color: #e0f2fe;
    color: #0369a1;
    font-weight: 700;
}

.dd-badge {
    font-size: 10px;
    background-color: #f1f5f9;
    color: #475569;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-weight: 700;
}

.header-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: #1e293b;
    border: 1px solid #334155;
    padding: 7px 16px;
    border-radius: 50px;
    font-size: 12px;
    color: #94a3b8;
    cursor: pointer;
    width: 320px;
    transition: var(--transition);
}

.header-search:hover {
    background-color: #0f172a;
    border-color: #38bdf8;
    color: #f8fafc;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.header-search-badge {
    font-size: 10px;
    background-color: #0f172a;
    color: #38bdf8;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-weight: 700;
    margin-left: auto;
}

/* --- 3. Abas Multitarefas Fixas no Topo (Tabbed Workspace) --- */
.workspace-tabs-wrapper {
    background-color: #1e293b;
    border-bottom: none;
    display: flex;
    align-items: flex-end;
    position: relative;
    z-index: 10;
    width: 100%;
    min-height: 38px;
}

.workspace-tabs-scroll-container {
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    display: flex;
    align-items: flex-end;
}

.workspace-tabs-scroll-container::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

#workspace-tabs {
    background-color: transparent;
    padding: 6px 46px 0 46px;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    flex-wrap: nowrap;
    min-width: min-content;
}

.tabs-scroll-btn {
    position: absolute;
    top: 5px;
    width: 26px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background-color: #0f172a;
    border: 1px solid #334155;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    transition: opacity 0.2s ease, background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tabs-scroll-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

#tabs-scroll-left {
    left: 12px;
}

#tabs-scroll-right {
    right: 22px;
}

.tabs-scroll-btn svg {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
}

.tabs-scroll-btn:hover {
    background-color: #334155;
    color: #ffffff;
    border-color: #94a3b8;
}

.w-tab {
    background-color: #0f172a;
    color: #94a3b8;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px 6px 0 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: 1px solid #334155;
    border-bottom: none;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    user-select: none;
    transition: var(--transition);
}

.w-tab span.w-tab-title {
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
}

.w-tab:hover {
    color: #ffffff;
    background-color: #1e293b;
}

.w-tab.dragging {
    opacity: 0.45;
    background-color: #1e293b;
    border-color: #38bdf8;
    cursor: grabbing;
}

.w-tab.drag-over {
    border-left: 2px solid #38bdf8;
    background-color: #334155;
}

.w-tab.active {
    background-color: var(--bg-body);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 8px;
    position: relative;
    z-index: 20;
}

.w-tab-close {
    color: #64748b;
    margin-left: 4px;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    cursor: pointer;
    transition: var(--transition);
}

.w-tab-close:hover {
    color: #ef4444;
    background-color: #fee2e2;
}

.w-add-tab {
    background: transparent;
    border: 1px dashed #475569;
    color: #cbd5e1;
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    margin-bottom: 3px;
    transition: var(--transition);
}

.w-add-tab:hover {
    background-color: #334155;
    color: #ffffff;
    border-color: #94a3b8;
}

/* --- 4. Estrutura Principal --- */
.app-layout {
    display: flex;
    flex-direction: column;
    width: 100vw;
    min-height: 100vh;
}

/* Main Area */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Topbar */
.topbar {
    height: 52px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.breadcrumb-link {
    color: #64748b;
    text-decoration: none;
    font-size: 13px;
    font-weight: 400;
    transition: color 0.15s ease;
}

.breadcrumb-link:hover {
    color: var(--text-main);
}

.breadcrumb-separator {
    color: #cbd5e1;
    font-size: 12px;
    user-select: none;
}

.breadcrumb-current {
    color: var(--text-main);
    font-weight: 600;
    font-size: 13px;
}

.breadcrumb-active {
    color: var(--text-main);
    font-weight: 600;
}

/* Page Content */
.page-content {
    flex: 1;
    padding: 28px 36px;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

.page-header {
    margin-bottom: 16px;
}

.page-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-main);
}

.page-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* --- 3. Painéis & Tabelas ERP --- */
.panel {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 12px;
}

.data-table th {
    background-color: var(--bg-subtle);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background-color: var(--bg-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* --- 4. Formulários & Busca --- */
.search-wrapper {
    position: relative;
    width: 100%;
    max-width: 380px;
}

.search-input {
    width: 100%;
    padding: 6px 12px 6px 32px;
    font-size: 12px;
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--brand-primary);
    background-color: var(--bg-surface);
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    pointer-events: none;
    width: 14px;
    height: 14px;
}

/* --- 5. Botões & Badges --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    border: 1px solid transparent;
    transition: var(--transition);
}

.btn-primary {
    background-color: var(--brand-primary);
    color: var(--brand-text-on-primary);
}

.btn-primary:hover {
    background-color: var(--brand-primary-hover);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--bg-subtle);
    border-color: var(--border-strong);
}

.btn-sm {
    padding: 3px 7px;
    font-size: 11px;
}

/* Botão Ícone de Ação na Tabela */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
}

.btn-icon:hover {
    background-color: var(--bg-subtle);
    border-color: var(--border-strong);
    color: var(--brand-primary);
}

.btn-icon svg {
    width: 14px;
    height: 14px;
    stroke-width: 1.8;
}

/* Dropdown de Ações da Linha da Tabela (Menu 3 Pontinhos) */
.row-actions-dropdown {
    position: relative;
    display: inline-block;
}

.btn-row-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.btn-row-action:hover, .btn-row-action.active {
    background-color: var(--bg-subtle);
    border-color: var(--border-strong);
    color: var(--text-main);
}

.row-action-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    min-width: 190px;
    padding: 4px;
    display: none;
    flex-direction: column;
    z-index: 999999;
}

.row-action-menu.show {
    display: flex;
}

/* Combobox de Produtos com Busca em Tempo Real */
.combobox-wrapper {
    position: relative;
    width: 100%;
}

.combobox-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2);
    max-height: 260px;
    overflow-y: auto;
    z-index: 10000;
    display: none;
}

.combobox-dropdown.show {
    display: block;
}

.combobox-item {
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-main);
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.1s ease;
}

.combobox-item:last-child {
    border-bottom: none;
}

.combobox-item:hover, .combobox-item.active {
    background-color: #f1f5f9;
}

.combobox-item-name {
    font-weight: 600;
}

.combobox-item-price {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}

.action-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    color: #334155;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    border-radius: 3px;
    transition: var(--transition);
    text-align: left;
    background: transparent;
    border: none;
    width: 100%;
    cursor: pointer;
}

.action-menu-item:hover {
    background-color: #f1f5f9;
    color: #0f172a;
}

.action-menu-item svg {
    color: #64748b;
    flex-shrink: 0;
}

.action-menu-item:hover svg {
    color: var(--brand-primary);
}

.action-menu-item.danger {
    color: #dc2626;
}

.action-menu-item.danger:hover {
    background-color: #fef2f2;
    color: #b91c1c;
}

.action-menu-item.danger svg {
    color: #dc2626;
}

.action-menu-divider {
    height: 1px;
    background-color: #e2e8f0;
    margin: 4px 0;
}

/* Badges 100% Neutras e Discretas */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid var(--badge-border);
    background-color: var(--badge-bg);
    color: var(--badge-text);
}

/* --- 6. Grid de Métricas --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}

.metric-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.metric-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 4px;
    letter-spacing: -0.02em;
}

.metric-desc {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* --- 7. Detalhes de Cliente --- */
.client-info-header {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.info-item-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.info-item-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-top: 1px;
}

/* --- 8. Slide-Over Drawer (Modal Lateral à Direita) --- */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 99999;
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.drawer-overlay.show {
    display: block;
    opacity: 1;
}

.drawer-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 580px;
    max-width: 95vw;
    height: 100vh;
    background-color: #ffffff;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2);
    z-index: 100000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.drawer-panel.show {
    transform: translateX(0);
}

.drawer-header {
    padding: 16px 20px;
    background-color: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.drawer-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
}

.drawer-close {
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.drawer-close:hover {
    color: #ef4444;
    background-color: #fee2e2;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.drawer-footer {
    padding: 14px 20px;
    background-color: #f8fafc;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.panel-view-all-link:hover {
    background-color: #e2e8f0 !important;
    color: #0f172a !important;
}

/* ==========================================================================
   RESPONSIVIDADE PARA TELAS MENORES, TABLETS E CELULARES (Mobile-First Polish)
   ========================================================================== */

@media (max-width: 1024px) {
    .page-content {
        padding: 16px 20px;
    }
}

@media (max-width: 768px) {
    #main-header {
        height: 48px;
        padding: 0 12px;
    }

    .header-brand img {
        height: 22px !important;
    }

    .header-brand span {
        font-size: 15px !important;
    }

    .header-search {
        padding: 5px 8px;
        font-size: 11px;
    }

    .header-search-badge {
        display: none;
    }

    .header-nav {
        margin-left: 8px;
    }

    .nav-btn {
        padding: 5px 8px;
        font-size: 12px;
    }

    .page-content {
        padding: 14px 12px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 16px;
    }

    .page-title {
        font-size: 18px !important;
    }

    .data-table th,
    .data-table td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .drawer-panel {
        width: 100vw;
        max-width: 100vw;
    }

    .drawer-body {
        padding: 14px;
    }

    .drawer-footer {
        padding: 12px 14px;
    }

    /* Grids empilhados no mobile */
    .mobile-stack,
    div[style*="grid-template-columns: 1fr 340px"],
    div[style*="grid-template-columns: repeat(auto-fit, minmax(360px, 1fr))"] {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .header-search {
        display: none;
    }

    .w-tab {
        padding: 6px 8px;
        font-size: 11px;
        max-width: 140px;
    }

    .btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    div[style*="grid-template-columns: repeat(auto-fit, minmax(220px, 1fr))"] {
        grid-template-columns: 1fr !important;
    }
}

