/* ================================================================
   APPLE MODERN DESIGN SYSTEM (v3.0)
   ================================================================ */

:root {
    /* --- COLOR PALETTE (Apple System Colors) --- */
    --color-primary: #0071e3;       /* Apple System Blue */
    --color-primary-rgb: 0, 113, 227;
    --color-primary-hover: #0077ED; /* Slightly lighter on hover */
    --color-primary-soft: #eef5ff;

    /* Accents */
    --color-accent: #0071e3;
    
    /* Neutrals */
    --color-bg-body: #F5F5F7;       /* Apple Light Gray Background */
    --color-bg-surface: #ffffff;
    --color-border: #d2d2d7;        /* Subtle Border */
    --color-border-soft: #e5e5e5;
    
    --color-text-main: #1d1d1f;     /* Near Black */
    --color-text-body: #86868b;     /* Muted Gray text */
    --color-text-muted: #86868b;
    
    /* Functional */
    --color-success: #34c759;
    --color-success-bg: #e4fdef;
    --color-warning: #ff9f0a;
    --color-warning-bg: #fff5e5;
    --color-danger: #ff3b30;
    --color-danger-bg: #fff2f1;
    --color-info: #5ac8fa;
    --color-info-bg: #eaf8ff;

    /* Design Tokens - Rounded & Soft */
    --radius-sm: 10px;
    --radius-md: 18px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    
    /* Soft, diffused shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.12);
    
    --transition-fast: 0.2s cubic-bezier(0.25, 1, 0.5, 1); /* Apple-like snap */
    --transition-smooth: 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--color-bg-body);
    color: var(--color-text-main);
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--color-text-main);
    letter-spacing: -0.02em;
    font-weight: 600;
}

/* --- COMPONENTS: BUTTONS --- */
.btn {
    border-radius: var(--radius-full); /* Pills everywhere */
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.6rem 1.4rem;
    transition: all 0.2s ease;
    border: none;
    box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px; /* Consistent spacing for icon+text */
}

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

/* Primary: System Blue */
.btn-primary {
    background-color: var(--color-primary) !important;
    color: white;
}
.btn-primary:hover {
    background-color: #0077ED !important;
    box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3);
}

/* Secondary / Light: Soft Gray background */
.btn-light, .btn-white {
    background-color: white !important;
    color: var(--color-text-main) !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.btn-light:hover, .btn-white:hover {
    background-color: #f5f5f7 !important;
    color: var(--color-primary) !important;
}

/* UNIFIED MAIN COLOR (No Green/Red) */
/* Remap all functional buttons to the Main Brand Color for a monochrome/clean look */
.btn-success, .btn-danger, .btn-info, .btn-warning {
    background-color: var(--color-primary) !important;
    color: white !important;
    box-shadow: 0 4px 6px rgba(0, 113, 227, 0.2);
}
.btn-success:hover, .btn-danger:hover, .btn-info:hover, .btn-warning:hover {
    background-color: var(--color-primary-hover) !important;
    transform: translateY(-1px);
    box-shadow: 0 8px 12px rgba(0, 113, 227, 0.3);
}

/* Icons in buttons - Removed margin in favor of gap */
.btn i { margin-right: 0; }

/* --- COMPONENTS: INPUTS (Apple Style) --- */
.form-control, .form-select, .input-group-text {
    border-radius: 12px !important;
    border: 1px solid transparent; /* No border usually */
    background-color: #e8e8ed; /* Light gray input background */
    padding: 0.7rem 1rem;
    font-size: 0.95rem;
    box-shadow: none;
    color: var(--color-text-main);
    transition: all 0.2s;
}

/* Focus state - Blue Ring */
.form-control:focus, .form-select:focus {
    background-color: white;
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15);
    border-color: var(--color-primary);
}

/* Transparent Inputs (used in custom UI) */
.bg-transparent { background-color: transparent !important; }
.bg-white { background-color: white !important; }

/* Rounded Input Groups */
.input-group.rounded-pill .form-control { border-radius: 50px 0 0 50px !important; }
.input-group.rounded-pill .input-group-text { border-radius: 50px 0 0 50px !important; }

/* --- COMPONENTS: CARDS (Surfaces) --- */
.card {
    border: none;
    border-radius: var(--radius-lg); /* 24px for big cards */
    box-shadow: var(--shadow-sm);
    background: white;
    transition: var(--transition-smooth);
}
.card-header {
    background: white;
    border-bottom: 1px solid var(--color-border-soft);
    padding: 1.5rem 1.75rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
}
.card-body { padding: 1.75rem; }

/* Stat Cards */
.admin-stat-card {
    padding: 24px;
    border-radius: var(--radius-lg);
    background: white;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-fast);
}
.admin-stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
}

/* --- NAVBAR TABS (Pill Style) --- */
.navbar-tabs-group {
    height: 50px;
    align-items: center;
}

.navbar-tab-btn {
    border: none !important;
    background: transparent !important;
    color: #86868b !important;
    font-weight: 500 !important;
    padding: 16px 20px !important;
    border-radius: 50px !important; /* Pills */
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1) !important;
    font-size: 0.95rem !important;
    margin-right: 4px !important;
    display: inline-flex; /* Removed !important to allow inline display:none to work */
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important; /* Fix alignment issues */
}
.navbar-tab-btn:hover {
    color: #1d1d1f !important;
    background: rgba(0,0,0,0.04) !important;
}
.navbar-tab-active {
    color: white !important;
    background: var(--color-primary) !important; /* Blue Pill Active */
    box-shadow: 0 4px 12px rgba(0, 113, 227, 0.25);
}
.navbar-tab-active i { color: white !important; }

/* Divider */
.navbar-tabs-group {
    border-left: 1px solid #d2d2d7;
    margin-left: 1.5rem;
    padding-left: 1.5rem;
    height: 28px;
}

/* --- GLASS & HEADER --- */
.navbar-modern {
    background: rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
.glass-effect, .glass-card {
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-lg);
}

.navbar-logo {
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* --- AG GRID (Clean) --- */
.ag-theme-alpine {
    --ag-border-radius: 16px;
    --ag-header-background-color: #fafafa;
    --ag-header-foreground-color: #86868b;
    --ag-row-hover-color: #f5f5f7;
    --ag-selected-row-background-color: #eef5ff;
    --ag-font-family: inherit;
    --ag-borders: none;
    --ag-font-size: 13px;
    --ag-row-height: 48px;
}
.ag-header-cell {
    font-weight: 600 !important;
    text-transform: none !important; /* Apple doesn't typically ALL-CAPS headers */
    font-size: 0.8rem;
    color: #1d1d1f !important;
}

/* Utils */
.line-height-1 { line-height: 1; }
.cursor-pointer { cursor: pointer; }
.hover-bg-light:hover { background-color: #f5f5f7; }

/* Colors Override */
.text-primary { color: var(--color-primary) !important; }
.bg-primary-subtle { background-color: #eef5ff !important; color: var(--color-primary) !important; }
.border-primary-subtle { border-color: rgba(0, 113, 227, 0.2) !important; }
.border-warning-subtle { border-color: rgba(245, 158, 11, 0.2) !important; }
.border-danger-subtle { border-color: rgba(239, 68, 68, 0.2) !important; }

/* Layout Utils */

/* --- MODERN SEARCH & REPLACE --- */
/* --- MODERN SEARCH & REPLACE --- */

/* Main Floating Search Pill */
.custom-search-bar {
    z-index: 20;
    position: relative;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    background: white;
    border: 1px solid rgba(0,0,0,0.08) !important;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    padding: 4px;
    /* Desktop: Pill Shape */
    border-radius: 28px !important; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
    width: 100%;
}

.custom-search-bar:focus-within {
    box-shadow: 0 8px 24px rgba(0, 113, 227, 0.12), 0 2px 6px rgba(0,0,0,0.04);
    border-color: rgba(0, 113, 227, 0.3) !important;
    transform: translateY(-1px);
}

/* Search Input Field */
.custom-search-bar .form-control {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding-left: 12px;
    font-size: 0.95rem;
    height: 42px;
    max-width: 200px;
}

/* Input Icon Wrapper */
.search-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    color: #86868b;
    border-right: 1px solid transparent; /* Separator placeholder */
}

/* Navigation & Action Buttons (Inside Search) */
.search-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 50% !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    background: transparent;
    border: none !important;
    transition: all 0.2s ease;
    margin: 0 2px;
}
.search-action-btn:hover:not(:disabled) {
    background-color: #f5f5f7;
    color: var(--color-primary);
    transform: scale(1.05);
}
.search-action-btn:disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* Replace Toggle Button (Special Style) */
.replace-toggle-btn {
    border-radius: 20px !important; /* Lozenge */
    padding: 0 16px !important;
    height: 36px;
    background-color: #f2f2f7;
    color: var(--color-text-main);
    font-weight: 500;
    font-size: 0.85rem;
    margin-left: 8px;
    white-space: nowrap;
}
.replace-toggle-btn:hover {
    background-color: #e5e5ea !important;
    color: var(--color-primary) !important;
}
.replace-toggle-btn.active {
    background-color: var(--color-primary) !important;
    color: white !important;
}

/* Vertical Separator */
.search-separator {
    width: 1px;
    height: 24px;
    background-color: #e5e5e5;
    margin: 0 8px;
}

/* Column Dropdown Wrapper */
.column-selector-wrapper {
    min-width: 220px;
    max-width: 350px;
    transition: all 0.3s ease;
}

/* Controls wrapper - always right aligned */
.search-controls-wrapper {
    margin-left: auto;
    flex-shrink: 0;
}

/* --- RESPONSIVE SEARCH BAR (Mobile) --- */
@media (max-width: 768px) {
    .custom-search-bar {
        flex-wrap: wrap; /* Allow wrapping */
        border-radius: 16px !important; /* Softer radius for blocky look */
        padding: 8px;
        gap: 8px;
    }

    /* Input row takes full width */
    .search-input-group {
        flex: 1 1 100%;
        display: flex;
        align-items: center;
        border-bottom: 1px solid #f0f0f0;
        padding-bottom: 8px;
        margin-bottom: 4px;
    }
    
    .custom-search-bar .form-control {
        height: 38px;
        padding-left: 8px;
    }

    /* Column Selector specific for mobile */
    .column-selector-wrapper {
        flex: 1 1 auto; /* Allow shrink */
        min-width: 100px;
        order: 2; /* Put it after controls if needed, or before */
    }

    /* Controls row */
    .search-controls-wrapper {
        flex: 1 0 auto;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        order: 3;
    }

    .search-separator { display: none; }
}


/* --- REPLACE TRAY --- */
.replace-tray {
    background: #fbfbfd;
    margin-top: -24px;   /* Pull up snugly behind search */
    padding: 28px 4px 4px 4px; /* Minimal padding */
    border-radius: 0 0 24px 24px;
    border: 1px solid rgba(0,0,0,0.06);
    border-top: none;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 10;
    width: 96%;          /* Slightly narrower than search bar to look nested */
    margin-left: 2%;
    transition: all 0.3s ease;
}

.replace-input-group {
    background: white;
    border: 1px solid #e5e5ea;
    border-radius: 50px; /* Full Pill Shape */
    padding: 2px;        /* Tight fit */
    display: flex;
    align-items: center;
    height: 40px;        /* Fixed height matching search */
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.replace-input-group:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.1);
}

/* Replace Input Field Override */
.replace-input-group .form-control {
    height: 36px !important;
    padding-left: 12px;
    font-size: 0.9rem;
    background: transparent !important;
}

/* Replace Button */
.btn-replace-action {
    border-radius: 50px !important; /* Match container */
    padding: 0 20px !important;     /* Horizontal padding only */
    height: 34px !important;        /* Fit inside container */
    margin: 0 1px 0 0 !important;   /* Align right */
    font-weight: 600;
    font-size: 0.85rem;
    box-shadow: none !important;    /* Flat inside */
    transition: all 0.2s;
    display: flex;
    align-items: center;
    white-space: nowrap;            /* FIX: Ensure text stays on one line */
}
.btn-replace-action:hover {
    background-color: var(--color-primary-hover) !important;
    transform: none !important; /* No movement needed inside tight container */
}

/* 1. Modern Pill Dropdown (Transparent / Minimal) */
.modern-pill-dropdown .Select-control {
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 8px !important; /* Slightly squarer inside pill */
    height: 36px !important;
    max-height: 36px !important;    /* FIX: Force fixed height */
    overflow: visible !important;    /* CHANGED: Allow scrolling */
    min-height: 36px;
    transition: all 0.2s;
    display: flex;                  /* Ensure alignment */
    align-items: center;
}
.modern-pill-dropdown .Select-value {
    line-height: 24px !important;    /* Smaller line height for inner pill */
    color: var(--color-primary) !important;
    background: rgba(0, 113, 227, 0.1) !important;
    border: 1px solid rgba(0, 113, 227, 0.2) !important;
    border-radius: 12px !important;  /* Fully rounded pills */
    margin: 0 2px !important;
    padding: 0 8px !important;       /* Compact padding */
    display: inline-flex !important;
    align-items: center;
    font-size: 0.75rem !important;   /* Smaller font */
    white-space: nowrap !important;  /* No wrapping text */
    height: 26px !important;         /* Fixed small height */
}

.modern-pill-dropdown .Select-value-icon {
    padding: 0 4px 0 0 !important;
    border-right: none !important; /* Remove separator */
    color: var(--color-primary) !important;
}
.modern-pill-dropdown .Select-value-icon:hover {
    color: #0056b3 !important;
    background: transparent !important;
}

/* Scrollable Wrapper */
.modern-pill-dropdown .Select-multi-value-wrapper,
.modern-pill-dropdown .Select-value-container {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: scroll !important;
    overflow-y: hidden !important;
    align-items: center;
    height: 36px !important;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
    flex: 1 !important;
    min-width: 0 !important;
    max-width: 100% !important; /* Ensure it respects parent width */
}
/* Chrome/Safari: Thin scrollbar */
.modern-pill-dropdown .Select-multi-value-wrapper::-webkit-scrollbar {
    height: 4px;
}
.modern-pill-dropdown .Select-multi-value-wrapper::-webkit-scrollbar-track {
    background: transparent;
}
.modern-pill-dropdown .Select-multi-value-wrapper::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.modern-pill-dropdown .Select-control:hover {
    background-color: rgba(0,0,0,0.04) !important;
}
.modern-pill-dropdown .Select-placeholder, 
.modern-pill-dropdown .Select-value-label {
    line-height: normal !important; /* FIX: Let flexbox handle align */
    padding-left: 8px !important;
    padding-right: 24px !important;
    color: #444 !important;
    font-weight: 500;
    font-size: 0.85rem;
    position: relative !important;
    top: auto !important;
    bottom: auto !important;
}

/* Fix Arrow Centering */
.modern-pill-dropdown .Select-arrow-zone {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 36px !important;
    padding-right: 8px !important;
}
.modern-pill-dropdown .Select-arrow {
    top: auto !important; /* Reset default absolute positioning */
}

.modern-pill-dropdown .Select-input {
    height: 36px !important;
    margin-left: 0 !important;
    display: flex;
    align-items: center;
}
.modern-pill-dropdown .Select-menu-outer {
    border: none !important;
    box-shadow: 0 10px 40px -10px rgba(0,0,0,0.2) !important;
    border-radius: 12px !important;
    background: white !important;
    padding: 8px;
    width: 240px !important;
    margin-top: 12px !important;
    position: absolute !important; /* Force absolute */
    z-index: 9999 !important;
    right: 0 !important; /* Align right to container */
    left: auto !important;
}
.modern-pill-dropdown .Select-option {
    border-radius: 6px;
    padding: 8px 12px !important;
    transition: background 0.1s;
    font-size: 0.9rem;
    color: #333;
}
.modern-pill-dropdown .Select-option.is-focused {
    background-color: #f5f5f7 !important;
    color: var(--color-primary);
}

/* 2. Text Toggles (Checklist as Buttons) */
.modern-toggles {
    display: flex;
    gap: 8px;
}
.modern-toggles .btn-check + .btn {
    border: 1px solid var(--color-border);
    background: white;
    color: var(--color-text-body);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.4rem 1rem;
    border-radius: 50px; /* Pill */
    box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
    transition: all 0.2s;
}
.modern-toggles .btn-check:checked + .btn {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
    box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.3);
}
.modern-toggles .btn:hover {
    background-color: #f1f5f9;
    transform: translateY(-1px);
}
.modern-toggles .btn-check:checked + .btn:hover {
    background-color: var(--color-primary-hover);
}

/* Replace Input Pill */
.replace-input-group {
    border-radius: 50px;
    background: white;
    border: 1px solid var(--color-border);
    box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
    overflow: hidden;
    transition: all 0.2s;
}
/* --- GLOBAL APPLE CONTROLS OVERRIDE --- */

/* 1. Global Dropdowns (dcc.Dropdown / React-Select) - iOS Picker Style */
.Select-control {
    border: 1px solid transparent !important;
    background-color: rgba(118, 118, 128, 0.12) !important; /* Apple secondary fill */
    border-radius: 12px !important;
    height: 40px !important;
    box-shadow: none !important;
    transition: all 0.2s;
}
.Select-control:hover {
    background-color: rgba(118, 118, 128, 0.2) !important;
}
.is-focused .Select-control {
    background-color: white !important;
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15) !important;
}
.Select-placeholder, .Select-value-label {
    line-height: 40px !important;
    padding-left: 12px !important;
    color: var(--color-text-main) !important;
    font-size: 0.95rem;
}
.Select-arrow-zone { opacity: 0.5; }
.Select-menu-outer {
    border: none !important;
    border-radius: 14px !important;
    box-shadow: var(--shadow-lg) !important;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(20px);
    margin-top: 8px !important;
    padding: 6px !important;
    position: relative; /* Ensure it respects stacking */
    z-index: 9999 !important; /* Force it to top */
}
.Select-option {
    border-radius: 8px !important;
    font-size: 0.9rem !important;
    color: var(--color-text-main) !important;
    padding: 10px 12px !important;
}
.Select-option.is-focused {
    background-color: var(--color-primary) !important;
    color: white !important;
}

/* 2. Global TABS (dcc.Tabs) - iOS Segmented Control Style */
.tab-container, .tab-content { border: none !important; }
.tab-container {
    width: 100% !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    background-color: rgba(118, 118, 128, 0.12) !important; /* Inner Gray Track */
    border-radius: 99px !important;
    padding: 2px !important;
}
.tab-content {
    width: 100% !important;
}
._dash-undo-redo { display: none !important; }

/* The Track */
.tab-parent {
    background-color: white !important; /* Outer White Background */
    padding: 6px;
    border-radius: 99px; /* Pill track */
    display: inline-flex !important;
    min-width: fit-content !important;
    margin-bottom: 24px;
    border: none !important; /* Border removed */
}
/* The Individual Tabs */
.tab {
    border: none !important;
    background-color: transparent !important;
    padding: 8px 24px !important;
    font-weight: 500 !important;
    color: var(--color-text-body) !important;
    font-size: 0.9rem !important;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    border-radius: 99px !important;
    cursor: pointer;
    flex: 1 0 auto !important;
    width: auto !important;
    min-width: 120px !important;
    text-align: center;
    white-space: nowrap !important;
}
/* Selected State (Floating White Pill) */
.tab--selected {
    background-color: white !important;
    color: var(--color-text-main) !important;
    box-shadow: 0 3px 8px rgba(0,0,0,0.12) !important;
    font-weight: 600 !important;
}

/* 3. Checkboxes & Radios (Apple Style) */
.form-check-input {
    width: 1.3em;
    height: 1.3em;
    margin-top: 0.1em;
    border: 1px solid #d1d1d6;
    background-color: #f2f2f7;
    cursor: pointer;
}
/* --- GRAPH CONTAINER FIX --- */
/* Ensure the graph container has a defined height so overflow works */
.graph-container {
    height: calc(100vh - 250px);
    overflow-y: auto;
    padding-right: 10px; /* Space for scrollbar */
}
.form-check-input[type="radio"] { border-radius: 50%; }
.form-check-input[type="checkbox"] { border-radius: 6px; }

/* 4. Scrollbars (Hidden/Modern) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: #d1d1d6;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: #aeaeb2; }

.line-height-1 { line-height: 1; }

/* --- DYNAMIC CONTENT LAYOUT --- */
.data-tab-layout {
    display: flex;
    flex-direction: column;
    /* Calculated height to fit viewport: 100vh - Navbar (~72px) - Padding/Margins (~48px) */
    height: calc(100vh - 120px);
    overflow: hidden;
}

/* Controls shouldn't shrink, but handle their own size */
.table-controls-fixed {
    flex-shrink: 0;
    margin-bottom: 1rem !important; /* Override mb-4 for tighter fit */
    transition: all 0.3s ease;
    /* Stacking context fix for dropdowns */
    z-index: 50; 
}
/* --- MONOCHROME ICONS --- */
/* Force all functional icons to use the main text color or primary color, avoiding rainbow colors */
.fas, .far, .fab {
    color: inherit;
}

/* Specific overrides for where we want them to be Primary Blue */
.text-primary .fas, .text-primary .far, 
.btn-primary .fas, .btn-primary .far,
.navbar-tab-active .fas {
    color: white !important; /* White on blue backgrounds */
}

/* On light buttons or plain text, they should look slate/dark or primary */
.text-muted .fas { color: #86868b !important; }

/* Override bootstrap text utils for icons if they are used inline */
.text-success i, .text-danger i, .text-warning i, .text-info i {
    color: inherit !important; /* Reset to parent color */
}

/* Table container fills remaining space */
#data-table-container {
    flex-grow: 1;
    overflow: hidden;
    min-height: 0;
    position: relative;
    border-radius: var(--radius-md);
    background: white;
    box-shadow: var(--shadow-sm);
}

/* Force grid to take full height of the container */
#data-table-container > div,
#data-table-container .ag-theme-alpine {
    height: 100% !important;
    width: 100% !important;
}

/* AG Grid Filter Popup Fixes - CRITICAL FIX FOR WHITE SCREEN */
.ag-theme-alpine .ag-popup {
    position: absolute !important;
    z-index: 9999 !important;
}

.ag-theme-alpine .ag-popup-backdrop {
    pointer-events: none !important;
    background-color: transparent !important;
    backdrop-filter: none !important;
}

.ag-theme-alpine .ag-filter {
    background: white !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2) !important;
    border: 1px solid #e0e0e0 !important;
    overflow: hidden !important;
    min-height: 200px !important;
}

/* Ensure grid body stays visible */
/* Ensure grid body stays visible */
.ag-theme-alpine .ag-root-wrapper,
.ag-theme-alpine .ag-root-wrapper-body,
.ag-theme-alpine .ag-root {
    height: 100% !important;
    min-height: 0 !important;
}

/* Ensure data rows are visible */
.ag-theme-alpine .ag-row {
    background-color: white !important;
    opacity: 1 !important;
}

/* Alternate row shading */
.ag-theme-alpine .ag-row-odd {
    background-color: #fafbfc !important;
}

/* Header Styling */
.ag-theme-alpine .ag-header {
    background-color: #f8f9fa !important;
    border-bottom: 1px solid #e0e0e0 !important;
}

/* Make body non-scrollable if possible to force app-like feel, 
   but only if content fits. */
/* Body scroll restored for long pages (Graphs, Audit) */
body {
    overflow-y: auto; 
}

/* ================================================================
   MODERN TOAST NOTIFICATIONS
   ================================================================ */

/* Position specific status alerts as floating toasts - NOT alerts inside modals */
#data-status-alert,
#translations-status-alert,
#admin-status-alert,
#login-alert {
    position: fixed !important;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    min-width: 320px;
    max-width: 480px;
    padding: 14px 24px;
    border: none !important;
    border-radius: 14px !important;
    box-shadow: 0 12px 40px -8px rgba(0, 0, 0, 0.2) !important;
    backdrop-filter: blur(10px);
    font-weight: 500;
    font-size: 0.95rem;
    animation: toast-slide-in 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Toast Color Overrides - Only for toast alerts */
#data-status-alert.alert-success,
#translations-status-alert.alert-success,
#admin-status-alert.alert-success,
#login-alert.alert-success {
    background: rgba(52, 199, 89, 0.95) !important;
    color: white !important;
}

#data-status-alert.alert-danger,
#translations-status-alert.alert-danger,
#admin-status-alert.alert-danger,
#login-alert.alert-danger {
    background: rgba(255, 59, 48, 0.95) !important;
    color: white !important;
}

#data-status-alert.alert-warning,
#translations-status-alert.alert-warning,
#admin-status-alert.alert-warning,
#login-alert.alert-warning {
    background: rgba(255, 159, 10, 0.95) !important;
    color: white !important;
}

#data-status-alert.alert-info,
#translations-status-alert.alert-info,
#admin-status-alert.alert-info,
#login-alert.alert-info {
    background: rgba(90, 200, 250, 0.95) !important;
    color: white !important;
}

#data-status-alert.alert-primary,
#translations-status-alert.alert-primary,
#admin-status-alert.alert-primary,
#login-alert.alert-primary {
    background: rgba(0, 113, 227, 0.95) !important;
    color: white !important;
}

/* Toast close button */
#data-status-alert .btn-close,
#translations-status-alert .btn-close,
#admin-status-alert .btn-close,
#login-alert .btn-close {
    filter: brightness(0) invert(1);
    opacity: 0.8;
}

/* ================================================================
   MODAL STYLING (Modern & Clean)
   ================================================================ */

/* Modal content - clean modern look */
.modal-content {
    border: none !important;
    border-radius: 16px !important;
    box-shadow: 0 25px 80px -12px rgba(0,0,0,0.3) !important;
    overflow: hidden;
}

.modal-header {
    border-bottom: 1px solid #f0f0f2 !important;
    padding: 20px 24px !important;
    background: white !important;
}

.modal-title {
    font-weight: 600 !important;
    font-size: 1.1rem !important;
}

.modal-body {
    padding: 24px !important;
    background: #fafafa !important;
}

.modal-footer {
    border-top: 1px solid #f0f0f2 !important;
    padding: 16px 24px !important;
    background: white !important;
}

/* Reset alerts inside modals to normal inline styling */
.modal-body .alert {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    min-width: auto !important;
    max-width: none !important;
    animation: none !important;
    border-radius: 10px !important;
    margin-bottom: 16px;
}

/* ================================================================
   SEARCH TOGGLE BUTTONS (Match Case / Exact Match)
   ================================================================ */

.search-toggle-btn {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px !important;
    font-size: 0.75rem !important;
    font-weight: 500;
    line-height: 1.2 !important;
    color: #6c757d;
    background-color: #f5f5f7;
    border: 1px solid #e0e0e0 !important;
    border-radius: 6px !important;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.search-toggle-btn:hover {
    background-color: #eaeaec;
    border-color: #d0d0d0 !important;
}

/* Active/Selected State */
.search-toggle-btn--active {
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: white !important;
}

.search-toggle-btn--active:hover {
    background-color: var(--color-primary-hover) !important;
}

/* ================================================================
   ROW FOCUS HIGHLIGHTING (For horizontal scroll orientation)
   ================================================================ */

/* Highlight the entire row when a cell is focused/clicked */
.ag-theme-alpine .ag-row.row-focus-highlight {
    background-color: rgba(0, 113, 227, 0.08) !important; /* Light blue highlight */
    transition: background-color 0.15s ease;
}

/* Also highlight odd rows when focused */
.ag-theme-alpine .ag-row-odd.row-focus-highlight {
    background-color: rgba(0, 113, 227, 0.12) !important;
}

/* Subtle left border indicator for the focused row */
.ag-theme-alpine .ag-row.row-focus-highlight::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: var(--color-primary);
    z-index: 1;
}

/* Make sure the highlight doesn't interfere with selected rows */
.ag-theme-alpine .ag-row-selected.row-focus-highlight {
    background-color: rgba(0, 113, 227, 0.15) !important;
}

/* Pinned columns should also show the highlight */
.ag-theme-alpine .ag-row.row-focus-highlight .ag-cell-first-left-pinned {
    background-color: rgba(0, 113, 227, 0.08) !important;
}

.ag-theme-alpine .ag-row-odd.row-focus-highlight .ag-cell-first-left-pinned {
    background-color: rgba(0, 113, 227, 0.12) !important;
}

/* ================================================================
   COPY NOTIFICATION STYLING
   ================================================================ */

.copy-notification {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* --- SCROLLING FIXES --- */
/* Overriding previous rules to support flexbox scrolling */
.data-tab-layout {
    /* Safe calculation: 100vh - Navbar (~80px) - Margins (~40px) - Footer/Safe (~40px) */
    height: calc(100vh - 160px) !important;
    min-height: 500px;
    display: flex !important; 
    flex-direction: column !important;
    position: relative !important;
    /* Ensure container itself doesn't scroll, forcing children (grid) to handle it */
    overflow: hidden !important; 
}

#data-table-container {
    flex: 1 1 auto !important;
    height: 100% !important; /* Force height to fill flex parent */
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    overflow: hidden !important; /* Pass scroll responsibility to Grid */
}

#ag-grid-table {
    flex: 1 !important;
    height: 100% !important;
    width: 100% !important;
    display: block !important;
}

/* Fallback for smaller screens */
@media (max-height: 600px) {
    .data-tab-layout {
        height: auto !important;
        overflow: visible !important;
    }
    #data-table-container {
        height: 600px !important;
    }
}
