/* CSS Principal para o PCP Multi-tenant */

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

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Cores Premium Tailored (Azul Moderno/Notion/Linear) */
    --background: #f8fafc;
    --foreground: #0f172a;
    
    --card: #ffffff;
    --card-foreground: #0f172a;
    
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-foreground: #ffffff;
    
    --muted: #64748b;
    --muted-foreground: #94a3b8;
    
    --border: #e2e8f0;
    --input: #ffffff;
    
    --success: #10b981;
    --success-foreground: #ffffff;
    --warning: #f59e0b;
    --warning-foreground: #ffffff;
    --danger: #ef4444;
    --danger-foreground: #ffffff;
    --info: #06b6d4;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    --radius: 12px;
    --sidebar-width: 230px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--foreground);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   TELA DE LOGIN
   ========================================================================== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at top left, #eff6ff 0%, #f8fafc 100%);
}

.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    padding: 40px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.login-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 25px 30px -5px rgb(0 0 0 / 0.08), 0 12px 14px -6px rgb(0 0 0 / 0.08);
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background-color: #eff6ff;
    color: var(--primary);
    border-radius: 12px;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 16px;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--foreground);
    letter-spacing: -0.5px;
    margin-bottom: 8px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--muted);
}

/* Formulários */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 550;
    color: #334155;
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    height: 40px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: 8px;
    background-color: var(--input);
    color: var(--foreground);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    line-height: 1.5;
}

select.form-control {
    padding-top: 6px;
    padding-bottom: 6px;
}

textarea.form-control {
    height: auto;
    min-height: 80px;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}


.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    text-decoration: none;
    gap: 8px;
    white-space: nowrap;
}

.btn-sm {
    height: 30px;
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 6px;
    gap: 4px;
}

.btn-sm svg {
    width: 12px !important;
    height: 12px !important;
}

.btn:active {
    transform: scale(0.98);
}

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

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

.btn-block {
    width: 100%;
}

.btn-secondary {
    background-color: #f1f5f9;
    color: #334155;
    border-color: var(--border);
}

.btn-secondary:hover {
    background-color: #e2e8f0;
}

.btn-danger {
    background-color: var(--danger);
    color: var(--danger-foreground);
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-success {
    background-color: var(--success);
    color: var(--success-foreground);
}

.btn-success:hover {
    background-color: #059669;
}

/* Feedbacks */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 20px;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-danger {
    background-color: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.alert-success {
    background-color: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

.alert-warning {
    background-color: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

/* ==========================================================================
   LAYOUT DO PAINEL PRINCIPAL (SIDEBAR + MAIN CONTENT)
   ========================================================================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Impersonation Banner */
.impersonation-banner {
    background: linear-gradient(90deg, #f59e0b, #d97706);
    color: white;
    padding: 10px 20px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    z-index: 1000;
    position: relative;
    box-shadow: var(--shadow);
}

.impersonation-banner a {
    color: white;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px 12px;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s ease;
}

.impersonation-banner a:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Sidebar Fixa à Esquerda */
.sidebar {
    width: var(--sidebar-width);
    background-color: #0f172a;
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    border-right: 1px solid #1e293b;
    overflow-y: auto;
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #1e293b;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background-color: var(--primary);
    color: white;
    border-radius: 8px;
    font-weight: 700;
    font-size: 16px;
}

.sidebar-brand-name {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.5px;
}

.sidebar-menu {
    flex: 1;
    padding: 20px 8px;
}

.sidebar-category {
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    letter-spacing: 1px;
    padding: 12px 12px 6px 12px;
    text-transform: uppercase;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    margin-bottom: 4px;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.sidebar-item:hover {
    color: #f8fafc;
    background-color: #1e293b;
}

.sidebar-item.active {
    background-color: var(--primary);
    color: white;
}

.sidebar-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid #1e293b;
    background-color: #0b0f19;
}

.user-profile-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.user-profile-name {
    font-size: 13px;
    font-weight: 600;
    color: #f8fafc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-profile-role {
    font-size: 11px;
    color: #64748b;
}

/* Área de Conteúdo Principal */
.main-content {
    flex: 1;
    min-width: 0;
    width: calc(100vw - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    margin-left: var(--sidebar-width);
    padding: 24px 30px;
    background-color: var(--background);
    min-height: 100vh;
    box-sizing: border-box;
    overflow-x: hidden;
}


/* Cabeçalho da Página */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 20px;
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--foreground);
    letter-spacing: -0.5px;
}

.page-subtitle {
    font-size: 14px;
    color: var(--muted);
    margin-top: 4px;
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 13px;
    color: var(--muted);
}

.tenant-badge {
    background-color: #eff6ff;
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 9999px;
    font-weight: 600;
    border: 1px solid #dbeafe;
}

/* ==========================================================================
   CARDS E INDICADORES (DASHBOARD)
   ========================================================================= */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 1280px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-width: 0;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: transparent;
}

.stat-card.stat-primary::before { background-color: var(--primary); }
.stat-card.stat-success::before { background-color: var(--success); }
.stat-card.stat-warning::before { background-color: var(--warning); }
.stat-card.stat-danger::before { background-color: var(--danger); }
.stat-card.stat-info::before { background-color: var(--info); }

.stat-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--foreground);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-subtext {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Barras de Progresso */
.progress-bar-container {
    width: 100%;
    height: 6px;
    background-color: #e2e8f0;
    border-radius: 9999px;
    margin-top: 8px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary);
    border-radius: 9999px;
    transition: width 0.3s ease;
}

.progress-bar.success { background-color: var(--success); }
.progress-bar.warning { background-color: var(--warning); }
.progress-bar.danger { background-color: var(--danger); }

/* Grid de duas colunas */
.layout-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.layout-split > * {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

@media (max-width: 1100px) {
    .layout-split {
        grid-template-columns: 1fr;
    }
}


/* ==========================================================================
   TABELAS E COMPONENTES DE LISTAS
   ========================================================================== */
.card-box {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 30px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}


.card-title-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.card-title-box h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--foreground);
}

.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

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

.table-custom th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 600;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table-custom td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    color: #334155;
    vertical-align: middle;
    height: 52px;
    white-space: nowrap;
}

.table-custom td.allow-wrap {
    white-space: normal;
}

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

.table-custom tr:hover {
    background-color: #f8fafc;
}

/* Alinhamento de colunas */
.text-left { text-align: left !important; }
.text-right { text-align: right !important; }
.text-center { text-align: center !important; }

.actions-cell {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    align-items: center;
    white-space: nowrap;
}

/* Classes utilitárias de largura para tabelas */
.w-50 { min-width: 50px; }
.w-80 { min-width: 80px; }
.w-100 { min-width: 100px; }
.w-120 { min-width: 120px; }
.w-150 { min-width: 150px; }
.w-180 { min-width: 180px; }
.w-200 { min-width: 200px; }
.w-250 { min-width: 250px; }

.ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* Badges de Status Operacionais */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: capitalize;
}

.badge-success { background-color: #d1fae5; color: #065f46; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-danger { background-color: #fee2e2; color: #991b1b; }
.badge-info { background-color: #e0f2fe; color: #0369a1; }
.badge-secondary { background-color: #f1f5f9; color: #475569; }

/* Ações */
.actions-cell {
    display: flex;
    gap: 8px;
}

.action-link {
    font-size: 13px;
    font-weight: 550;
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s ease;
}

.action-link:hover {
    color: var(--primary-hover);
}

.action-link.danger {
    color: var(--danger);
}

.action-link.danger:hover {
    color: #b91c1c;
}

/* Estado Vazio */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
    font-size: 14px;
}

.empty-state svg {
    margin-bottom: 12px;
    color: var(--muted-foreground);
}

/* ==========================================================================
   FORMULÁRIOS DE CRIAÇÃO E EDIÇÃO
   ========================================================================== */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    align-items: end;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 30px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

/* Ficha Técnica Itens Grid */
.item-row {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    margin-bottom: 15px;
}

.item-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.btn-remove-row {
    padding: 10px;
    background-color: #fee2e2;
    color: var(--danger);
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1px;
}

.btn-remove-row:hover {
    background-color: #fecaca;
}

/* ==========================================================================
   ESTADO COLAPSADO DA SIDEBAR
   ========================================================================== */
.sidebar {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content {
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}

body.sidebar-collapsed .main-content {
    margin-left: 0;
}

/* Botão Flutuante de Colapso da Sidebar (Notion/Linear style) */
.sidebar-collapse-button {
    position: fixed;
    left: calc(var(--sidebar-width) - 12px);
    top: 24px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    color: #64748b;
    z-index: 1001;
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s;
}

.sidebar-collapse-button:hover {
    background-color: #f1f5f9;
    color: #2563eb;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
}

body.sidebar-collapsed .sidebar-collapse-button {
    left: 12px;
}

/* ==========================================================================
   PAGINAÇÃO
   ========================================================================== */
.pagination-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 16px;
    margin-top: 8px;
    border-top: 1px solid var(--border);
}

.pagination-info {
    font-size: 13px;
    color: var(--muted);
}

.pagination-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid var(--border);
    background-color: #ffffff;
    color: #334155;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    cursor: pointer;
    user-select: none;
}

.page-btn:hover:not(.active):not(.disabled) {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
}

.page-btn.active {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
    font-weight: 600;
    cursor: default;
}

.page-btn.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 32px;
    font-size: 13px;
    color: var(--muted);
    user-select: none;
}

/* ==========================================================================
   SUPORTE A ROLAGEM HORIZONTAL EM TABELAS E CARDS
   ========================================================================== */
.layout-split > * {
    min-width: 0;
}

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