/* Custom styles for American Factory - SaaS Premium Theme */

:root {
    /* Brand Colors - Modern SaaS Palette */
    --af-primary: #4fd1c5;
    /* Vibrant Teal for High Contrast */
    --af-primary-hover: #38b2ac;
    /* Slightly Darker Teal */
    --af-success: #10b981;
    /* Emerald 500 */
    --af-info: #06b6d4;
    /* Cyan 500 */
    --af-warning: #f59e0b;
    /* Amber 500 */
    --af-danger: #ef4444;
    /* Red 500 */
    --af-sidebar-badge-light: rgba(245, 158, 11, 0.4);
    --af-sidebar-badge-dark: #cc8400;

    /* Backgrounds */
    --af-bg-body: #0f172a;
    /* Slate 900 */
    --af-bg-card: #1e293b;
    /* Slate 800 */
    --af-bg-hover: #334155;
    /* Slate 700 */

    /* Text */
    --af-text-main: #f8fafc;
    /* Slate 50 */
    --af-text-muted: #94a3b8;
    /* Slate 400 */
    --af-border: #334155;
    /* Slate 700 */
}

.cursor-pointer {
    cursor: pointer !important;
}

/* Base Typography */
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--af-bg-body) !important;
    color: var(--af-text-main);
    padding-top: 0 !important;
    /* Removed padding for top navbar */
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    width: 100%;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.025em;
}

/* ================= LAYOUT: SIDEBAR ================= */
.sidebar {
    width: 220px;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background-color: var(--af-bg-card);
    border-right: 1px solid var(--af-border);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    /* overflow-x: hidden removed to prevent clipping the edge toggle */
}

/* Sidebar Logic - Supports both .sidebar.collapsed AND html.sidebar-collapsed (Pre-render) */
.sidebar.collapsed,
html.sidebar-collapsed .sidebar {
    width: 80px;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 70px;
    position: relative;
    flex-shrink: 0;
}

.sidebar-logo {
    height: 24px;
    transition: opacity 0.2s;
}

.sidebar.collapsed .sidebar-logo,
html.sidebar-collapsed .sidebar-logo {
    display: none;
}

.sidebar-logo-collapsed {
    height: 28px;
    display: none;
}

.sidebar.collapsed .sidebar-logo-collapsed,
html.sidebar-collapsed .sidebar-logo-collapsed {
    display: block;
}

/* Lead Avatar Standardized */
.af-avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50% !important;
    /* Force Round */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

/* Subtle Unread Row Highlight */
.unread-row {
    background-color: rgba(245, 158, 11, 0.05) !important;
    border-left: 3px solid var(--af-warning);
}

.unread-row:hover {
    background-color: rgba(245, 158, 11, 0.08) !important;
}

/* Transferred Lead Highlight (Green) */
.transferred-row {
    background-color: rgba(16, 185, 129, 0.08) !important;
    border-left: 3px solid var(--af-success);
}

.transferred-row:hover {
    background-color: rgba(16, 185, 129, 0.12) !important;
}

/* Toggle flutuante conforme imagem */
.sidebar-toggle-edge {
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background-color: var(--af-bg-card);
    border: 1px solid var(--af-border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--af-text-muted);
    cursor: pointer;
    z-index: 2050;
    transition: all 0.2s;
    padding: 0;
}

.sidebar-toggle-edge:hover {
    background-color: var(--af-bg-hover);
    color: #fff;
    border-color: var(--af-primary);
}

.sidebar-toggle-edge i {
    width: 12px;
    height: 12px;
}

.sidebar-nav {
    flex-grow: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

/* Slim scrollbar for sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.1);
}

.nav-item-af {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--af-text-muted);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 0.25rem;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
    /* Important for absolute badges */
}

.nav-item-af:hover {
    background-color: var(--af-bg-hover);
    color: #fff;
}

.nav-item-af.active {
    background-color: var(--af-primary);
    color: #000 !important;
}

/* Sidebar Badge Logic - Standardized for SAC and CRM */
.nav-item-af .af-badge-circle {
    background-color: var(--af-sidebar-badge-light) !important;
    color: #fff !important;
    transition: all 0.2s;
    font-weight: 600;
    margin-left: auto;
    /* Push to right in expanded mode */
    font-size: 0.65rem;
    padding: 0.35em 0.65em;
    border-radius: 50% !important;
    min-width: 18px;
    text-align: center;
}

.nav-item-af:hover .af-badge-circle,
.nav-item-af.active .af-badge-circle {
    background-color: var(--af-bg-card) !important;
    color: var(--af-warning) !important;
}

.nav-item-af.active i,
.nav-item-af.active svg {
    stroke: #000 !important;
}

.nav-icon {
    width: 20px;
    height: 20px;
    min-width: 20px;
}

.nav-text {
    margin-left: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: opacity 0.2s;
}

.sidebar.collapsed .nav-text,
html.sidebar-collapsed .nav-text {
    opacity: 0;
    width: 0;
    margin-left: 0;
    pointer-events: none;
}

.sidebar.collapsed .nav-item-af,
html.sidebar-collapsed .nav-item-af {
    justify-content: center;
    padding: 0.75rem 0;
}

.sidebar.collapsed .nav-item-af .af-badge-circle,
html.sidebar-collapsed .nav-item-af .af-badge-circle {
    position: absolute;
    top: 5px;
    right: 12px;
    margin: 0 !important;
    transform: translate(50%, -50%);
    box-shadow: 0 0 0 2px var(--af-bg-card);
    z-index: 100;
    font-size: 0.6rem;
    padding: 2px 5px;
    min-width: 16px;
}

.sidebar.collapsed .nav-item-af.active .af-badge-circle,
html.sidebar-collapsed .nav-item-af.active .af-badge-circle {
    box-shadow: 0 0 0 2px var(--af-primary);
    background-color: var(--af-bg-card) !important;
    color: var(--af-warning) !important;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--af-border);
}

/* ================= LAYOUT: MAIN CONTENT ================= */
.main-wrapper {
    margin-left: 220px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 100vh;
    overflow-x: hidden;
    /* Extra safety against horizontal scroll */
    position: relative;
    width: calc(100% - 220px);
}

.main-wrapper.expanded,
html.sidebar-collapsed .main-wrapper {
    margin-left: 80px;
    width: calc(100% - 80px);
}

/* No sidebar layout for Directors */
.main-wrapper.no-sidebar {
    margin-left: 0 !important;
    width: 100% !important;
}

.main-wrapper.no-sidebar .top-bar {
    left: 0 !important;
}

.top-bar {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 2rem;
    background-color: rgba(15, 23, 42, 0.5);
    border-bottom: 1px solid var(--af-border);
    backdrop-filter: blur(8px);

    /* Fixed Positioning Logic */
    position: fixed;
    top: 0;
    right: 0;
    left: 220px;
    z-index: 900;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-wrapper.expanded .top-bar,
html.sidebar-collapsed .top-bar {
    left: 80px;
}

.user-dropdown-btn {
    background: transparent;
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: opacity 0.2s;
}

.user-dropdown-btn:hover {
    opacity: 0.8;
}

.content-container {
    padding: 2rem;
    padding-top: 90px;
    /* 70px header + 20px buffer */
}

/* ================= TABLE ADJUSTMENTS ================= */
.card {
    background-color: var(--af-bg-card);
    border: 1px solid var(--af-border);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    margin-bottom: 1.5rem;
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--af-border);
    padding: 0.75rem 1.25rem;
}

.card-body {
    padding: 1.5rem;
}

/* ================= COMPONENT: TABLES ================= */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--af-text-muted);
    border-color: var(--af-border);
}

.table thead th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--af-text-muted);
    background-color: rgba(255, 255, 255, 0.02);
    border-bottom: 2px solid var(--af-border) !important;
    padding: 0.65rem 1rem;
    white-space: nowrap;
    vertical-align: middle;
}

.table tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    color: var(--af-text-main);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85rem;
}

/* Ensure table containers allow horizontal scroll if content overflows */
.table-responsive {
    overflow-x: auto !important;
    width: 100%;
    scrollbar-width: thin;
}


.table-hover tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Sorting Styles */
.table thead th.sortable {
    cursor: pointer;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    border-bottom: 2px solid var(--af-border) !important;
}

.table thead th.sortable:hover {
    background-color: rgba(255, 255, 255, 0.04) !important;
    color: #fff !important;
}

.table thead th.sortable .sort-icon {
    display: inline-flex;
    align-items: center;
    transition: all 0.2s ease;
    opacity: 0.25;
    margin-left: 4px;
    vertical-align: middle;
}

.table thead th.sortable.active-sort {
    color: var(--af-primary) !important;
    background-color: rgba(79, 209, 197, 0.05) !important;
}

.table thead th.sortable.active-sort .sort-icon {
    opacity: 1;
    color: var(--af-primary);
    transform: scale(1.1);
}

/* ================= COMPONENT: PAGE HEADER ================= */
.af-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background-color: transparent;
    border-bottom: 1px solid var(--af-border);
    margin-bottom: 2rem;
}

.af-page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    color: #fff;
}

.af-page-header h1 i,
.af-page-header h1 svg {
    margin-right: 12px;
    width: 24px;
    height: 24px;
    color: var(--af-primary);
}

.af-page-header .header-actions {
    display: flex;
    gap: 12px;
}

/* ================= COMPONENT: AF BUTTONS (PREMIUM) ================= */
/* Primary Action Button */
.af-btn-primary {
    background-color: var(--af-primary);
    color: #0f172a;
    font-weight: 600;
    border: 1px solid var(--af-primary);
    padding: 0 1.25rem;
    height: 38px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(79, 209, 197, 0.2);
}

.af-btn-primary:hover {
    background-color: var(--af-primary-hover);
    border-color: var(--af-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 8px -1px rgba(79, 209, 197, 0.3);
}

/* Secondary / Outline Buttons */
.af-btn-secondary {
    background-color: transparent;
    border: 1px solid var(--af-border);
    color: var(--af-text-muted);
    font-weight: 500;
    padding: 0 1rem;
    height: 38px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.af-btn-secondary:hover {
    border-color: var(--af-text-muted);
    color: #fff;
    background-color: rgba(255, 255, 255, 0.05);
}

/* Outline Variants */
.af-btn-outline-primary {
    background: transparent;
    border: 1px solid var(--af-primary);
    color: var(--af-primary);
    height: 38px;
    padding: 0 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s;
}

.af-btn-outline-primary:hover {
    background: rgba(79, 209, 197, 0.1);
    box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.1);
}

.af-btn-outline-success {
    background: transparent;
    border: 1px solid var(--af-success);
    color: var(--af-success);
    height: 38px;
    padding: 0 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s;
}

.af-btn-outline-success:hover {
    background: rgba(16, 185, 129, 0.1);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* Ghost Buttons (Icon-only or subtle text) */
.af-btn-ghost-primary {
    background: rgba(79, 209, 197, 0.1);
    color: var(--af-primary);
    border: none;
    height: 38px;
    padding: 0 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s;
}

.af-btn-ghost-primary:hover {
    background: rgba(79, 209, 197, 0.2);
}

.af-btn-ghost-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--af-success);
    border: none;
    height: 38px;
    padding: 0 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s;
}

.af-btn-ghost-success:hover {
    background: rgba(16, 185, 129, 0.2);
}

.af-btn-ghost-info {
    background: rgba(14, 165, 233, 0.1);
    color: #0ea5e9;
    border: none;
    height: 38px;
    padding: 0 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s;
}

.af-btn-ghost-info:hover {
    background: rgba(14, 165, 233, 0.2);
}

.af-btn-ghost-secondary {
    background: rgba(100, 116, 139, 0.1);
    color: #64748b;
    border: none;
    height: 38px;
    padding: 0 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s;
}

.af-btn-ghost-secondary:hover {
    background: rgba(100, 116, 139, 0.2);
}

.af-btn-ghost-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--af-danger);
    border: none;
    height: 38px;
    padding: 0 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s;
}

.af-btn-ghost-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Specific styling for table action buttons to make them more elegant */
.table .af-btn-icon {
    padding: 0 !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* ================= COMPONENT: BUTTONS (Generics) ================= */
.btn {
    font-weight: 500;
    height: 38px !important;
    /* Fixed height for consistency */
    padding: 0 1.25rem;
    border-radius: 8px;
    /* Slightly sharper but still soft */
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap !important;
}

.btn-sm {
    height: 28px;
    /* Narrower for sm */
    padding: 0 0.75rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

.btn-sm i,
.btn-sm svg,
.btn i,
.btn svg {
    width: 18px !important;
    height: 18px !important;
    stroke-width: 2.5px !important;
}

/* Delicate / Well-style buttons and selects */
.btn-delicate-trigger {
    height: 38px !important;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--af-border) !important;
    color: #fff !important;
    font-size: 0.9rem !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px !important;
    border-radius: 8px !important;
    text-align: left;
    transition: all 0.2s ease;
}

.btn-delicate-trigger:hover,
.btn-delicate-trigger:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--af-primary) !important;
}

.form-select.crm-delicate-select {
    background-color: rgba(0, 0, 0, 0.2) !important;
    border: 1px solid var(--af-border) !important;
    height: 38px !important;
    line-height: 38px;
    padding: 0 0.85rem !important;
    color: #fff !important;
}

.btn-delicate-trigger {
    background: transparent !important;
    border: 1px solid rgba(255, 193, 7, 0.3) !important;
    color: #ffc107 !important;
    font-size: 0.85rem !important;
    height: 34px !important;
    padding: 0 12px !important;
    border-radius: 6px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    transition: all 0.2s ease !important;
}

.btn-delicate-trigger:hover {
    background: rgba(255, 193, 7, 0.1) !important;
    border-color: #ffc107 !important;
}

.btn-delicate-trigger::after {
    margin-left: 8px;
}

.dropdown-item-delicate {
    font-size: 0.9rem;
    padding: 10px 16px;
    color: rgba(255, 255, 255, 0.8) !important;
}

.dropdown-item-delicate:hover {
    background: var(--af-bg-hover);
    color: white !important;
}

/* Specific styling for table action buttons to make them more elegant */


/* ================= COMPONENT: TOP PROGRESS BAR ================= */
.top-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(to right, var(--af-primary), var(--af-info));
    z-index: 10000;
    transition: width 0.4s cubic-bezier(0.1, 0.05, 0, 1), opacity 0.3s ease;
    box-shadow: 0 0 10px rgba(79, 209, 197, 0.5), 0 0 5px rgba(6, 182, 212, 0.5);
    opacity: 0;
    pointer-events: none;
}

.top-progress-bar.loading {
    opacity: 1;
}

.top-progress-bar.manual-pending {
    background: linear-gradient(to right, var(--af-warning), var(--af-danger)) !important;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.5) !important;
}


.table .btn-sm:hover {
    background: var(--af-primary);
    border-color: var(--af-primary);
    color: #000;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.btn-primary {
    background-color: var(--af-primary) !important;
    border-color: var(--af-primary) !important;
    color: #000 !important;
}

.btn-primary:hover {
    background-color: var(--af-primary-hover) !important;
    border-color: var(--af-primary-hover) !important;
    color: #000 !important;
}

.btn-primary i,
.btn-primary svg {
    stroke: #000 !important;
}

.btn-outline-secondary {
    border-color: var(--af-border);
    color: var(--af-text-muted);
}

.btn-outline-secondary:hover {
    background-color: var(--af-bg-hover);
    border-color: var(--af-border);
    color: #fff;
}

/* ================= COMPONENT: FORMS ================= */
.form-control,
.form-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: rgba(0, 0, 0, 0.2) !important;
    border: 1px solid var(--af-border) !important;
    border-radius: 8px;
    color: white !important;
    font-size: 0.9rem !important;
    font-weight: 400 !important;
    padding: 0 0.85rem !important;
    height: 38px !important;
    /* Mantido fixo para inputs e selects */
    line-height: 38px;
    color-scheme: dark;
    transition: all 0.2s ease;
}

textarea.form-control {
    height: auto !important;
    min-height: 100px;
    line-height: 1.5;
    padding: 12px 15px !important;
    resize: vertical;
}

/* Custom Resize Handle for Dark Mode */
textarea::-webkit-resizer {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(255, 255, 255, 0.3)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='21' y1='21' x2='9' y2='21'%3E%3C/line%3E%3Cline x1='21' y1='21' x2='21' y2='9'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: bottom right;
}

/* Ensure options have dark background */
.form-select option {
    background-color: #1a1d21;
    color: white;
    font-weight: 300;
    font-size: 0.85rem;
    padding: 8px;
}

/* Custom Chevron for Selects */
.form-select {
    padding-right: 2.5rem !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='rgb(255, 255, 255, 0.5)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.75rem center !important;
    background-size: 16px !important;
    transition: all 0.2s ease;
}

.form-control:focus,
.form-select:focus {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: var(--af-primary) !important;
    box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.15) !important;
    outline: none;
    color: white !important;
}

/* Custom Placeholder Style */
::placeholder {
    color: var(--af-text-muted) !important;
    opacity: 0.4 !important;
    font-style: italic;
    font-size: 0.85em;
    font-weight: 300;
}

/* ================= COMPONENT: FORMS (FLOATING LABELS) ================= */

/* Container de floating label (estilo premium) */
.af-floating-group {
    position: relative;
    margin-top: 0.75rem !important;
    margin-bottom: 0.75rem !important;
}

.af-checkbox-align {
    padding-bottom: 6px;
}

/* Label em estado de repouso (dentro do campo) */
.af-floating-group .form-label {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 14px;
    background-color: transparent;
    padding: 0 4px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--af-text-muted);
    z-index: 5;
    margin-bottom: 0;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    opacity: 0.8;
    text-transform: none; /* Inicia normal */
}

/* Ajuste para labels em campos de busca para não sobrepor o ícone */
.af-floating-group:has(.af-search-container) .form-label {
    left: 40px;
}

.af-floating-group:has(.af-search-container):focus-within .form-label,
.af-floating-group:has(.af-search-container .form-control:not(:placeholder-shown)) .form-label {
    left: 10px;
}

/* Estado Flutuante: Foco ou campo preenchido */
.af-floating-group:focus-within .form-label,
.af-floating-group:has(.form-control:not(:placeholder-shown)) .form-label,
.af-floating-group:has(.form-select:not([value=""])) .form-label,
.af-floating-group:has(.form-select:focus) .form-label,
.af-floating-group:has(.dropdown-toggle:focus) .form-label, /* Foco no dropdown customizado */
.af-floating-group:has(input[type="hidden"][value]:not([value=""])) .form-label, /* Input hidden preenchido */
.af-floating-group:has(.input-group .form-control:not(:placeholder-shown)) .form-label,
.af-floating-group:has(.af-tag-input-wrapper:not(:empty)) .form-label {
    top: 0;
    transform: translateY(-50%);
    left: 10px;
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--af-primary);
    background: linear-gradient(to bottom, transparent 45%, var(--af-bg-card, #1a1a1a) 45%, var(--af-bg-card, #1a1a1a) 55%, transparent 55%), var(--af-bg-card, #1a1a1a);
    padding: 0 6px;
    border-radius: 4px;
    opacity: 1;
    z-index: 10;
}

/* Ajuste específico para quando o label está dentro de um "well" ou card com fundo ligeiramente diferente */
.card .af-floating-group:focus-within .form-label,
.card .af-floating-group:has(.form-control:not(:placeholder-shown)) .form-label {
    background-color: var(--af-bg-card);
}

/* Quando focado, a label fica branca (destaque) */
.af-floating-group:focus-within .form-label {
    color: #fff;
}

/* Evitar sobreposição de placeholder customizado com o label centralizado */
.af-floating-group .form-control::placeholder {
    opacity: 0 !important;
    transition: opacity 0.2s ease;
}

.af-floating-group .form-control:focus::placeholder {
    opacity: 0.4 !important;
}

/* Tratamento para Selects customizados: se o label não está flutuando, o texto do botão deve ser transparente */
.af-floating-group:not(:focus-within):not(:has(input[type="hidden"][value]:not([value=""]))) .btn-delicate-trigger span {
    color: transparent !important;
}

/* Ajuste para inputs desabilitados ou readonly */
.af-floating-group:has(.form-control:disabled, .form-control[readonly]) .form-label {
    opacity: 0.5;
    background-color: transparent;
}

/* ================= COMPONENT: TABS ================= */
.nav-tabs {
    border-bottom: 1px solid var(--af-border);
}

.nav-tabs .nav-link {
    border: none;
    color: var(--af-text-muted);
    font-weight: 500;
    font-size: 0.85rem;
    /* Reduced from default */
    padding: 0.75rem 1.25rem;
    /* More compact padding */
    background: transparent;
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.nav-tabs .nav-link i,
.nav-tabs .nav-link svg {
    width: 16px;
    /* Smaller icons */
    height: 16px;
    margin-right: 8px;
}

.nav-tabs .nav-link:hover {
    color: #fff;
}

.nav-tabs .nav-link.active {
    color: var(--af-primary);
    border-bottom: 2px solid var(--af-border);
    background: transparent;
}

/* ================= UTILITIES & EXTRAS ================= */
.text-muted {
    color: var(--af-text-muted) !important;
}

.badge {
    font-weight: 500;
    padding: 0.35em 0.65em;
    border-radius: 6px;
    letter-spacing: 0.02em;
}

.bg-success {
    background-color: rgba(16, 185, 129, 0.2) !important;
    color: #6ee7b7 !important;
}

.bg-warning {
    background-color: rgba(245, 158, 11, 0.2) !important;
    color: #fcd34d !important;
}

.bg-danger {
    background-color: rgba(239, 68, 68, 0.2) !important;
    color: #fca5a5 !important;
}

.bg-info {
    background-color: rgba(6, 182, 212, 0.2) !important;
    color: #67e8f9 !important;
}

.bg-primary {
    background-color: rgba(79, 209, 197, 0.15) !important;
    color: #4fd1c5 !important;
}

/* Dropdown SaaS Style */
.dropdown-menu {
    background-color: var(--af-bg-card);
    border: 1px solid var(--af-border);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    padding: 0.5rem;
    border-radius: 12px;
}

.dropdown-item {
    color: var(--af-text-muted);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.dropdown-item:hover {
    background-color: var(--af-bg-hover);
    color: #fff;
}

.dropdown-divider {
    border-top-color: var(--af-border);
}

/* Login Page specific */
.login-container {
    background: radial-gradient(circle at top right, #042f2e, #0f172a);
}

/* ================= COMPONENT: MODALS ================= */
.modal-content {
    background-color: var(--af-bg-card);
    border: 1px solid var(--af-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border-radius: 16px;
}

.modal-header {
    border-bottom: 1px solid var(--af-border);
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 16px 16px 0 0;
}

.modal-footer {
    border-top: 1px solid var(--af-border);
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 16px 16px;
}

.modal-title {
    color: #fff;
    font-weight: 600;
}

.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
    /* White close button */
}

/* Modal Overlay/Backdrop */
.modal-backdrop.show {
    opacity: 0.85 !important;
    background-color: #020617 !important;
    /* Very dark slate/black */
    backdrop-filter: blur(4px);
}

/* ================= COMPONENT: DROPZONE ================= */
.upload-dropzone {
    background-color: rgba(255, 255, 255, 0.03);
    border: 2px dashed var(--af-border);
    border-radius: 12px;
    padding: 3rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-dropzone:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--af-primary);
}

.upload-dropzone i {
    color: var(--af-primary);
}

/* ================= COMPONENT: TABLES IN MODALS ================= */
.modal-body .table {
    margin-bottom: 0;
}

.modal-body .table thead th {
    background-color: rgba(0, 0, 0, 0.3);
    color: #fff;
}

.modal-body .table td {
    color: var(--af-text-main);
    border-color: var(--af-border);
}

.modal-body .table-hover tbody tr:hover {
    color: var(--af-text-light);
    background-color: rgba(255, 255, 255, 0.05);
}

.modal-body .table-striped>tbody>tr:nth-of-type(odd) {
    --bs-table-accent-bg: rgba(255, 255, 255, 0.02);
    color: var(--af-text-main);
}

/* Fix for Select2 or native selects in dark modals */
select option {
    background-color: var(--af-bg-card);
    color: #fff;
}

/* Step 2 Alert Styling */
.alert-info {
    background-color: rgba(6, 182, 212, 0.15);
    border: 1px solid rgba(6, 182, 212, 0.3);
    color: #a5f3fc;
}

/* Dark Mode Table Variants */
.table-warning {
    --bs-table-bg: rgba(245, 158, 11, 0.1) !important;
    --bs-table-color: #fcd34d !important;
    --bs-table-border-color: rgba(245, 158, 11, 0.2) !important;
}

.table-success {
    --bs-table-bg: rgba(16, 185, 129, 0.1) !important;
    --bs-table-color: #6ee7b7 !important;
    --bs-table-border-color: rgba(16, 185, 129, 0.2) !important;
}

/* Scrollbar Style */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--af-bg-body);
}

::-webkit-scrollbar-thumb {
    background: var(--af-border);
    border-radius: 4px;
}

/* Remove Number Input Arrows/Spinners */
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Firefox */
input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* ================= COMPONENT: LIST HEADERS ================= */
.card-header.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    gap: 1rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    /* Increased gap */
}

/* ================= COMPONENT: INPUT GROUPS ================= */
.input-group {
    border-radius: 8px;
    overflow: hidden;
}

.input-group>.form-control,
.input-group>.btn {
    border-radius: 8px !important;
    /* Base radius */
}

.input-group> :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating) {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.input-group> :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    margin-left: -1px;
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

/* De-highlight outline buttons inside input groups by default to match input border */
.input-group>.btn-outline-primary {
    border-color: rgba(255, 255, 255, 0.1) !important;
}

.input-group>.btn-outline-primary:hover,
.input-group>.btn-outline-primary:focus {
    border-color: var(--af-primary) !important;
    z-index: 3;
}

.af-floating-group:has(.af-search-container) .form-label {
    left: 44px;
}

.af-floating-group:has(.af-search-container):focus-within .form-label,
.af-floating-group:has(.af-search-container .form-control:not(:placeholder-shown)) .form-label {
    left: 10px;
}

.af-search-container {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    transition: all 0.2s ease-in-out;
    display: flex;
    align-items: center;
    padding: 0 16px;
    height: 38px !important;
    width: 100%;
    /* Default to 100% for better layout usage */
    max-width: 100%;
}

.af-search-container:focus-within {
    border-color: var(--af-primary) !important;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.15);
}

.af-search-container i,
.af-search-container svg {
    color: var(--af-text-muted);
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.af-search-input {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #fff !important;
    font-size: 0.9rem;
    width: 100%;
    margin-left: 12px;
    outline: none !important;
    height: 100%;
    padding: 0;
    /* Let container handle padding */
}

/* Specific fix for nested form-controls inside search containers */
.af-search-container .form-control,
.af-search-container .form-control:focus {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    height: 100% !important;
    margin-left: 12px;
}

.af-search-input::placeholder {
    color: rgba(148, 163, 184, 0.6);
}

.af-input-well {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    padding: 10px 15px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Fix for Search Visibility (Autocomplete Clipping) */
.position-relative:has(.af-search-container) {
    z-index: 10;
}

.af-search-container+.list-group.position-absolute,
#formula_materia_results,
#cust_materia_results,
#std_results {
    z-index: 2000 !important;
    background-color: var(--af-bg-card) !important;
    border: 1px solid var(--af-border) !important;
}

/* Ensure cards with search don't clip results */
.card:has(.af-search-container) {
    overflow: visible !important;
}

/* ================= MOBILE RESPONSIVENESS ================= */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px !important;
        /* Sidebar always full width on mobile when open */
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .top-bar {
        left: 0 !important;
    }

    .content-container {
        padding: 1rem;
        padding-top: 80px;
    }

    /* Mobile Header Simplification */
    .card-header.list-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .header-actions {
        justify-content: space-between;
    }

    .search-container {
        width: 100%;
    }

    /* Adjust table fonts for list cards */
    .table td,
    .table th {
        white-space: normal;
    }
}

/* ================= UTILITY CLASSES ================= */
.cursor-pointer {
    cursor: pointer;
}

.hover-text-primary:hover {
    color: var(--af-primary) !important;
}

.opacity-75 {
    opacity: 0.75;
}

.opacity-50 {
    opacity: 0.5;
}

.fw-medium {
    font-weight: 500;
}

/* ================= ANIMATIONS ================= */
.animate__fadeInLeft {
    animation-duration: 0.5s;
}

/* ================= NEW SECTION HEADER STYLES (GLOBAL) ================= */
.section-title {
    color: #5bb4a8;
    font-weight: 300;
    border-bottom: 1px solid var(--af-border);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    width: 100%;
}

.section-title i,
.section-title svg {
    font-weight: normal;
    margin-right: 12px;
    width: 12px;
    height: 12px;
    font-size: inherit;
    stroke-width: 1.5px;
}

.subsection-title {
    color: var(--af-text-muted);
    font-weight: 700;
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
    letter-spacing: 0.05em;
    display: block;
}

/* ================= FILE CARDS ================= */
.af-file-card {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
    text-decoration: none;
    color: var(--af-text-muted);
    height: 100%;
    margin-bottom: 0;
}

.af-file-card:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    color: white;
}

.af-file-card .file-icon {
    width: 24px;
    height: 24px;
    margin-right: 10px;
    color: var(--af-primary);
    opacity: 0.8;
}

.af-file-card .file-info {
    flex-grow: 1;
    overflow: hidden;
}

.af-file-card .file-name {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.af-file-card .file-meta {
    font-size: 0.7rem;
    color: var(--af-text-muted);
    margin-top: -2px;
    opacity: 0.7;
}

.af-file-card .file-action {
    opacity: 0;
    transition: opacity 0.2s ease;
    margin-left: 8px;
    color: var(--af-text-muted);
}

.af-file-card:hover .file-action {
    opacity: 1;
}

/* ================= STYLED SELECTS (DELICATE) ================= */
.crm-delicate-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: rgba(0, 0, 0, 0.2) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 6px !important;
    color: white !important;
    padding: 0.5rem 2.5rem 0.5rem 1rem !important;
    font-size: 0.9rem !important;
    font-weight: 400 !important;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='rgb(255, 255, 255, 0.5)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.75rem center !important;
    background-size: 16px !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.crm-delicate-select:hover {
    border-color: rgba(255, 255, 255, 0.3) !important;
}

.crm-delicate-select:focus {
    border-color: var(--af-primary) !important;
    box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.15) !important;
    outline: none;
}

.crm-delicate-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.crm-delicate-select option {
    background-color: #1a1d21;
    color: white;
}

/* Placeholder look for empty values */
.crm-delicate-select:invalid,
.crm-delicate-select:placeholder-shown,
.crm-delicate-select[value=""] {
    color: rgba(255, 255, 255, 0.5) !important;
}

/* ================= DELICATE BUTTON TRIGGERS ================= */
.btn-delicate-trigger {
    background-color: rgba(0, 0, 0, 0.2) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 8px !important;
    color: white !important;
    height: 38px !important;
    font-size: 0.85rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 1rem !important;
    transition: all 0.2s ease;
}

.btn-delicate-trigger:hover {
    background-color: rgba(0, 0, 0, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
}

.btn-delicate-trigger:focus {
    border-color: var(--af-primary) !important;
    box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.15) !important;
}

/* Global dark dropdown menu styling */
.dropdown-menu-dark {
    background-color: #1a1d21 !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    padding: 0.5rem 0 !important;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2) !important;
}

.dropdown-item-delicate {
    border-radius: 6px !important;
    margin: 0 4px;
    width: calc(100% - 8px);
}

/* ==========================================
   3. Table Premium Components
   ========================================== */

.af-table-card {
    background: var(--af-bg-card);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    overflow: visible;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    margin-bottom: 2rem;
}

.af-table-card .card-body {
    overflow: visible;
    border-radius: 0 0 12px 12px;
}

.af-table-card .card-header.list-header {
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 1.25rem 1.5rem;
    overflow: visible;
    border-radius: 12px 12px 0 0;
}

.af-table-header {
    padding: 1rem 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.af-table-card thead th.sortable {
    cursor: pointer;
    transition: background 0.2s ease;
}

.af-table-card thead th.sortable:hover {
    background: rgba(255, 255, 255, 0.05);
}

.af-table-card thead th.active-sort {
    color: var(--af-primary) !important;
}

.af-table-card thead th svg {
    transition: all 0.2s ease;
}

.af-table-card thead th {
    background: rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: var(--af-text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 1rem 0.75rem;
}

.af-table-card tbody td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

/* ==========================================
   TABLE-LEVEL LOADER
   ========================================== */

.af-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.08);
    border-top-color: var(--af-primary, #4fd1c5);
    animation: af-spin 0.8s linear infinite;
}

.af-loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.af-loading-text {
    color: #94a3b8;
    font-size: 0.875rem;
    margin-top: 1rem;
}

/* Container: spinner on top, text below, centered */
.table-loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 3rem 1rem;
}

@keyframes af-spin {
    to {
        transform: rotate(360deg);
    }
}

.af-badge-circle {
    width: 20px;
    height: 20px;
    min-width: 20px;
    padding: 0 !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem !important;
    font-weight: 700;
    line-height: 1;
    vertical-align: middle;
    box-sizing: border-box;
    margin-left: 8px;
}

/* Ensure d-none always wins over inline-flex !important */
.af-badge-circle.d-none {
    display: none !important;
}

.af-badge-circle:empty {
    display: none !important;
}

/* ==========================================
   HTMX SPA LOADING INDICATOR
   ========================================== */

#htmx-progress-bar.htmx-request {
    opacity: 1;
    width: 100%;
    animation: htmx-progress-animate 2s infinite linear;
}

@keyframes htmx-progress-animate {
    0% {
        width: 0%;
    }

    50% {
        width: 70%;
    }

    100% {
        width: 100%;
    }
}