/* ============================================================
   MABIX ERP — Design System v2
   Kit Visual Padrão: Blue #2563EB | Inter | Radius 8-12px
   ============================================================ */

/* ============================================
   CSS VARIABLES & DESIGN TOKENS
   ============================================ */
:root {
    /* Primary Colors — Blue #2563EB */
    --primary-50:  #DBEAFE;
    --primary-100: #BFDBFE;
    --primary-500: #3B82F6;
    --primary-600: #2563EB;
    --primary-700: #1D4ED8;

    /* Semantic Colors */
    --success:       #10B981;
    --success-light: #D1FAE5;
    --danger:        #EF4444;
    --danger-light:  #FEE2E2;
    --warning:       #F59E0B;
    --warning-light: #FEF3C7;
    --info:          #2563EB;
    --info-light:    #DBEAFE;

    /* Neutral Colors */
    --gray-50:  #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;

    /* Backgrounds */
    --bg-primary:   #FFFFFF;
    --bg-secondary: #F9FAFB;
    --bg-tertiary:  #F3F4F6;

    /* Text */
    --text-primary:   #1F2937;
    --text-secondary: #6B7280;
    --text-tertiary:  #9CA3AF;

    /* Borders & Radius */
    --border-color:     #E5E7EB;
    --border-radius-sm: 6px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
    --border-radius-xl: 16px;

    /* Shadows — sutis */
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.06);
    --shadow-md: 0 2px 8px 0 rgb(0 0 0 / 0.08);
    --shadow-lg: 0 4px 16px -2px rgb(0 0 0 / 0.10);
    --shadow-xl: 0 8px 24px -4px rgb(0 0 0 / 0.12);

    /* Spacing */
    --spacing-xs:  0.25rem;
    --spacing-sm:  0.5rem;
    --spacing-md:  1rem;
    --spacing-lg:  1.5rem;
    --spacing-xl:  2rem;
    --spacing-2xl: 3rem;

    /* Sidebar */
    --sidebar-width:           260px;
    --sidebar-collapsed-width: 80px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Gradients */
    --gradient-primary:   linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
    --gradient-success:   linear-gradient(135deg, #10B981 0%, #059669 100%);
    --gradient-warning:   linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    --gradient-danger:    linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
}

/* Dark Mode Variables */
.dark,
[data-theme="dark"] {
    --primary-50:  #1E3A5F;
    --primary-100: #1E3A5F;
    --primary-500: #3B82F6;
    --primary-600: #60A5FA;
    --primary-700: #93C5FD;

    --gray-50:  #111827;
    --gray-100: #1F2937;
    --gray-200: #374151;
    --gray-300: #4B5563;
    --gray-400: #6B7280;
    --gray-500: #9CA3AF;
    --gray-600: #D1D5DB;
    --gray-700: #E5E7EB;
    --gray-800: #F3F4F6;
    --gray-900: #F9FAFB;

    --bg-primary:   #1F2937;
    --bg-secondary: #111827;
    --bg-tertiary:  #374151;

    --text-primary:   #F9FAFB;
    --text-secondary: #D1D5DB;
    --text-tertiary:  #9CA3AF;

    --border-color:     #374151;
    --border-color-alt: #4B5563;

    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 2px 8px 0 rgb(0 0 0 / 0.4);
    --shadow-lg: 0 4px 16px -2px rgb(0 0 0 / 0.5);
    --shadow-xl: 0 8px 24px -4px rgb(0 0 0 / 0.6);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 15px;
    letter-spacing: -0.2px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================
   LAYOUT
   ============================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: #ffffff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
    transition: width var(--transition-base);
}

.sidebar-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-600);
    text-decoration: none;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
}

.sidebar-section {
    margin-bottom: var(--spacing-lg);
}

.sidebar-section-title {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    padding: var(--spacing-sm) var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

.sidebar-menu {
    list-style: none;
}

.sidebar-menu-item {
    margin-bottom: 2px;
}

.sidebar-menu-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: 0.5rem var(--spacing-md);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--border-radius-md);
    transition: all var(--transition-fast);
    font-size: 0.875rem;
    font-weight: 500;
}

.sidebar-menu-link:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.sidebar-menu-link.active {
    background: var(--primary-50);
    color: var(--primary-600);
    font-weight: 600;
}

.sidebar-menu-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-md);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-50);
    color: var(--primary-600);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.sidebar-user-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-base);
}

.content-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: var(--spacing-md) var(--spacing-xl);
    position: sticky;
    top: 0;
    z-index: 100;
}

.content-header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-title {
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.content-body {
    padding: var(--spacing-xl);
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.card-header {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: var(--spacing-lg);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: var(--bg-primary);
    padding: var(--spacing-lg);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: var(--spacing-md);
}

.stat-card-icon.primary  { background: var(--primary-50);    color: var(--primary-600); }
.stat-card-icon.success  { background: var(--success-light); color: var(--success); }
.stat-card-icon.warning  { background: var(--warning-light); color: var(--warning); }
.stat-card-icon.danger   { background: var(--danger-light);  color: var(--danger); }

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: var(--spacing-xs);
}

/* ============================================
   BUTTONS — Kit Visual Padrão Mabix v2
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    border: 1px solid transparent;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition:
        background var(--transition-fast),
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}

.btn:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

.btn:active {
    filter: brightness(0.95);
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Variants */
.btn-primary {
    background: var(--primary-600);
    color: #fff;
    border-color: var(--primary-600);
}
.btn-primary:hover {
    background: var(--primary-700);
    border-color: var(--primary-700);
    box-shadow: 0 2px 8px rgb(37 99 235 / 0.25);
    color: #fff;
}

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover {
    filter: brightness(0.92);
    box-shadow: 0 2px 8px rgb(16 185 129 / 0.25);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover {
    filter: brightness(0.92);
    box-shadow: 0 2px 8px rgb(239 68 68 / 0.25);
    color: #fff;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
    border-color: var(--warning);
}
.btn-warning:hover {
    filter: brightness(0.92);
    color: #fff;
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--text-primary);
    border-color: var(--gray-200);
}
.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover {
    background: var(--bg-secondary);
    border-color: var(--gray-300);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Sizes */
.btn-sm {
    padding: 0.3125rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.6875rem 1.5rem;
    font-size: 0.9375rem;
}

.btn-icon {
    padding: 0.5rem;
    border-radius: var(--border-radius-md);
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: var(--spacing-md);
}

.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.form-control {
    width: 100%;
    padding: 0.5625rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-600);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.12);
    background: var(--bg-primary);
}

.form-control::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

/* ============================================
   TABLES
   ============================================ */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.table thead {
    background: var(--bg-secondary);
}

.table th {
    padding: 0.625rem 0.875rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.table td {
    padding: 0.75rem 0.875rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-primary);
}

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

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

/* ============================================
   MODALS
   ============================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: var(--spacing-lg);
}

.modal-footer {
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
}

/* ============================================
   ALERTS
   ============================================ */
.alert {
    padding: 0.75rem var(--spacing-md);
    border-radius: var(--border-radius-md);
    margin-bottom: var(--spacing-md);
    border-left: 4px solid;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.875rem;
}

.alert-success {
    background: var(--success-light);
    border-color: var(--success);
    color: #065f46;
}

.alert-error {
    background: var(--danger-light);
    border-color: var(--danger);
    color: #991b1b;
}

.alert-warning {
    background: var(--warning-light);
    border-color: var(--warning);
    color: #92400e;
}

.alert-info {
    background: var(--info-light);
    border-color: var(--info);
    color: #1e40af;
}

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 999px;
    white-space: nowrap;
}

.badge-primary { background: var(--primary-50);    color: var(--primary-700); }
.badge-success { background: var(--success-light); color: #065f46; }
.badge-danger  { background: var(--danger-light);  color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-gray    { background: var(--gray-100);      color: var(--gray-600); }

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 300px;
    max-width: 420px;
    background: #fff;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    border-radius: var(--border-radius-lg);
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

@keyframes toast-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.08);
    width: 100%;
}

.toast-progress-bar {
    height: 100%;
    width: 100%;
    transform-origin: left;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-success .toast-progress-bar { background: var(--success); }

.toast-error { border-left: 4px solid var(--danger); }
.toast-error .toast-progress-bar { background: var(--danger); }

.toast-warning { border-left: 4px solid var(--warning); }
.toast-warning .toast-progress-bar { background: var(--warning); }

@keyframes shrink {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

.animate-shrink {
    animation: shrink 6s linear forwards;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.custom-scrollbar::-webkit-scrollbar       { width: 5px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 999px; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

.scrollbar-none { scrollbar-width: none; }
.scrollbar-none::-webkit-scrollbar { display: none; }

/* Animations */
@keyframes fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fade-in 0.4s ease forwards;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
}

@media (max-width: 640px) {
    .content-header {
        padding: var(--spacing-md);
    }
    .content-body {
        padding: var(--spacing-md);
    }
    .card-header,
    .card-body {
        padding: var(--spacing-md);
    }
    .page-title {
        font-size: 1.125rem;
    }
    .stat-value {
        font-size: 1.5rem;
    }
    .btn {
        min-height: 44px;
    }
    .btn-sm {
        min-height: 40px;
    }
    input, select, textarea, .form-control {
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.8125rem;
    }
    .toast-container {
        top: 1rem;
        right: 1rem;
        left: 1rem;
    }
    .toast {
        min-width: auto;
        max-width: 100%;
    }
    .modal {
        padding: 0;
        align-items: flex-end;
    }
    .modal-content {
        max-width: 100%;
        max-height: 95vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
    .modal-footer {
        flex-direction: column-reverse;
    }
    .modal-footer .btn {
        width: 100%;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .content-body {
        padding: var(--spacing-lg);
    }
}

/* Print */
@media print {
    .sidebar,
    .toast-container {
        display: none !important;
    }
    .main-content {
        margin-left: 0;
    }
    body {
        background: #fff;
        font-size: 12px;
    }
}
