/* ===================================================
   * THEME MODERN & PREMIUM (Qase Inspired)
   * Overrides for RAD Tchem Platform
   * =================================================== */

/* Variables Overrides */
[data-theme='dark'] {
    --primary: #6366F1;
    /* Indigo 500 */
    --primary-light: #A5B4FC;
    /* Brighter for contrast */
    --accent: #818CF8;
    --accent-hover: #C7D2FE;
    --accent-rgb: 99, 102, 241;
    --accent-gradient: linear-gradient(135deg, #6366F1 0%, #818CF8 100%);

    /* Backgrounds: VRAIMENT SOMBRE (OLED Style) */
    --bg: #131231;
    /* Fond bleu très sombre */
    --surface: #131231;
    /* Surface très sombre */
    --surface-solid: #131231;
    --surface-hover: #131231;
    --sidebar-bg: #131231;
    /* Sidebar bleu très sombre */
    --topbar-bg: #131231;

    /* Textes */
    --text-main: #F0F6FC;
    --text-muted: #8B949E;
    --text-sidebar: #F0F6FC;
    --text-sidebar-muted: #7D8590;

    /* Bordures */
    --border: #1071b8;
    --border-sidebar: #131231;
    --sidebar-active-bg: rgba(99, 102, 241, 0.20);
    /* Plus visible sur noir */

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.8);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.8);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.9);
}

:root {
    --bg: #FFFFFF !important;
    /* Retour au blanc pur */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Polish */
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif !important;
    -webkit-font-smoothing: antialiased;
    background-color: var(--bg) !important;
}

.content-wrapper,
.main-content {
    background-color: var(--bg) !important;
    color: var(--text-main);
}

.view-section {
    background-color: var(--bg) !important;
}

.page-header {
    background: var(--bg) !important;
    border-bottom: 1px solid var(--border);
    padding-bottom: 20px;
    margin-bottom: 30px !important;
}

.page-header h1 {
    color: var(--text-main) !important;
    background: transparent !important;
    margin: 0;
}

/* Sidebar Polish */
.sidebar {
    border-right: 1px solid var(--border-sidebar);
}

.sidebar-menu li a {
    border-radius: 8px;
    margin: 4px 12px;
    padding: 10px 16px !important;
    font-weight: 500;
    font-size: 14px;
}

/* Sidebar Active Logic */
.sidebar-menu li a.active {
    background-color: var(--primary) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(var(--accent-rgb), 0.2) !important;
}

[data-theme='dark'] .sidebar-menu li a.active {
    background-color: var(--sidebar-active-bg) !important;
    color: var(--primary-light) !important;
    box-shadow: none !important;
}

/* Table Polish */
table th {
    background: var(--bg) !important;
    font-weight: 600 !important;
    font-size: 11px !important;
    letter-spacing: 0.05em;
    padding: 12px 16px !important;
}

table td {
    padding: 14px 16px !important;
    font-size: 14px;
}

/* Card Polish */
.card,
.kpi-card {
    border: 1px solid var(--border) !important;
    background: var(--surface) !important;
}

/* ===================================================
   * RESPONSIVENESS (Mobile & Tablet)
   * =================================================== */

@media (max-width: 900px) {
    .topbar {
        padding: 0 16px !important;
    }

    .content-wrapper {
        padding: 80px 16px 16px !important;
    }

    /* Better burger menu area */
    .sidebar-toggle {
        width: 38px;
        height: 38px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        background: var(--surface);
        border: 1px solid var(--border);
        transition: var(--transition);
        margin-right: 12px;
    }

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

/* Tablet Refinement (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar:not(.collapsed) {
        width: 80px !important;
    }

    .sidebar:not(.collapsed) span,
    .sidebar:not(.collapsed) .logo-text,
    .sidebar:not(.collapsed) .brand-sub {
        display: none !important;
    }

    .content-wrapper:not(.sidebar-collapsed) {
        margin-left: 80px !important;
    }
}

/* Mobile Specific (Tablets and phones) */
@media (max-width: 900px) {

    /* Backdrop for sidebar on mobile */
    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 1050;
        transition: opacity 0.3s ease;
    }

    .sidebar {
        z-index: 1100;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2) !important;
    }
}

@media (max-width: 768px) {

    /* Transform Tables to Cards */
    .responsive-table-container table,
    .responsive-table-container thead,
    .responsive-table-container tbody,
    .responsive-table-container th,
    .responsive-table-container td,
    .responsive-table-container tr {
        display: block;
    }

    .responsive-table-container thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .responsive-table-container tr {
        border: 1px solid var(--border);
        border-radius: 12px;
        margin-bottom: 16px;
        background: var(--surface);
        padding: 8px;
        box-shadow: var(--shadow-sm);
    }

    .responsive-table-container td {
        border: none;
        border-bottom: 1px solid var(--border-sidebar);
        position: relative;
        padding-left: 45% !important;
        text-align: right !important;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }

    .responsive-table-container td:last-child {
        border-bottom: none;
    }

    .responsive-table-container td:before {
        position: absolute;
        left: 12px;
        width: 40%;
        white-space: nowrap;
        text-align: left;
        font-weight: 700;
        color: var(--text-muted);
        content: attr(data-label);
        font-size: 11px;
        text-transform: uppercase;
    }

    /* KPI Cards */
    .kpi-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    /* Drawers */
    .side-panel {
        width: 100% !important;
        right: -100% !important;
    }

    .side-panel.open {
        right: 0 !important;
    }
}

/* Fix for Side Panel overlapping on touch */
.panel-overlay {
    backdrop-filter: blur(4px) !important;
}

/* ===================================================
   EYANO PREMIUM SYSTEM (APPLE-INSPIRED) - FINAL OVERRIDES
   Safe visual layer only (no business logic impact)
   =================================================== */

:root {
    --primary: #1569BF !important;
    --primary-rgb: 21, 105, 191 !important;
    --primary-light: #1f7ad8 !important;
    --accent: #1569BF !important;
    --accent-rgb: 21, 105, 191 !important;
    --accent-hover: #0f5aa7 !important;
    --accent-gradient: linear-gradient(180deg, #1569BF 0%, #0f5aa7 100%) !important;
    --accent-light: #E8F1FB !important;

    --bg: #F5F7FA !important;
    --surface: #FFFFFF !important;
    --surface-solid: #FFFFFF !important;
    --surface-hover: #F9FBFF !important;
    --sidebar-bg: #FFFFFF !important;
    --topbar-bg: rgba(255, 255, 255, 0.94) !important;

    --text-main: #111827 !important;
    --text-muted: #64748B !important;
    --text-sidebar: #1F2937 !important;
    --text-sidebar-muted: #94A3B8 !important;

    --border: #E4E9F2 !important;
    --border-sidebar: #E4E9F2 !important;
    --sidebar-active-bg: #E8F1FB !important;

    --success: #16A34A !important;
    --warning: #F59E0B !important;
    --error: #DC2626 !important;
    --danger: #DC2626 !important;
    --info: #0284C7 !important;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06) !important;
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08) !important;
    --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.1) !important;
    --shadow-glow: none !important;
    --shadow-sidebar: 1px 0 0 #E4E9F2 !important;

    --radius: 8px !important;
    --radius-lg: 8px !important;
}

[data-theme='dark'] {
    --primary: #5EA2E8 !important;
    --primary-rgb: 94, 162, 232 !important;
    --primary-light: #8fc2f2 !important;
    --accent: #5EA2E8 !important;
    --accent-rgb: 94, 162, 232 !important;
    --accent-hover: #7ab4ec !important;
    --accent-gradient: linear-gradient(180deg, #5EA2E8 0%, #4A91D8 100%) !important;
    --accent-light: rgba(94, 162, 232, 0.16) !important;

    --bg: #0F1724 !important;
    --surface: #131D2C !important;
    --surface-solid: #131D2C !important;
    --surface-hover: #1A2638 !important;
    --sidebar-bg: #101A29 !important;
    --topbar-bg: rgba(16, 26, 41, 0.92) !important;

    --text-main: #E5EDF8 !important;
    --text-muted: #96A7BF !important;
    --text-sidebar: #D8E3F1 !important;
    --text-sidebar-muted: #7F91AA !important;

    --border: #233247 !important;
    --border-sidebar: #233247 !important;
    --sidebar-active-bg: rgba(94, 162, 232, 0.15) !important;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35) !important;
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.4) !important;
    --shadow-lg: 0 20px 44px rgba(0, 0, 0, 0.48) !important;
    --shadow-sidebar: 1px 0 0 #233247 !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", sans-serif !important;
    background: var(--bg) !important;
}

body::before {
    content: "";
    position: fixed;
    right: -120px;
    bottom: -120px;
    width: min(54vw, 760px);
    height: min(54vw, 760px);
    background: url("/static/images/branding/logo-watermark-light.9f9fd95b4c3e.png") no-repeat center/contain;
    opacity: 0.07;
    pointer-events: none;
    z-index: 0;
}

#app-view,
#login-view,
#reset-view {
    position: relative;
    z-index: 1;
}

.app-logo {
    object-fit: contain !important;
}

.login-brand-logo {
    width: min(230px, 78%) !important;
    height: auto !important;
    max-height: none !important;
    display: block;
}

.login-brand-logo.dark-logo {
    display: none !important;
}

[data-theme='dark'] .login-brand-logo.light-logo {
    display: none !important;
}

[data-theme='dark'] .login-brand-logo.dark-logo {
    display: block !important;
}

.liquid-bg,
.blob {
    display: none !important;
}

.card,
.kpi-card,
.modal-container,
.sp-section,
.episode-item,
.srp-info-card,
.sp-info-item {
    border-radius: 8px !important;
    border: 1px solid var(--border) !important;
    box-shadow: var(--shadow-sm) !important;
    background: var(--surface) !important;
}

.card:hover,
.kpi-card:hover,
.episode-item:hover {
    transform: translateY(-1px) !important;
    box-shadow: var(--shadow-md) !important;
    border-color: #cfd7e6 !important;
}

.btn,
.form-control,
select,
textarea,
.sidebar-menu li a,
.user-profile-menu,
#user-dropdown,
.glass-dropdown {
    border-radius: 8px !important;
}

.btn-primary {
    background: var(--primary) !important;
    color: #fff !important;
    border: 1px solid var(--primary) !important;
    box-shadow: none !important;
}

.btn-primary:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    transform: translateY(-1px) !important;
}

.btn:focus-visible,
.form-control:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 0 !important;
    box-shadow: 0 0 0 3px rgba(21, 105, 191, 0.2) !important;
    border-color: var(--primary) !important;
}

.form-control:focus {
    box-shadow: 0 0 0 3px rgba(21, 105, 191, 0.2) !important;
    border-color: var(--primary) !important;
}

.sidebar {
    background: var(--sidebar-bg) !important;
    border-right: 1px solid var(--border-sidebar) !important;
    box-shadow: none !important;
}

.sidebar-header {
    border-bottom: 1px solid var(--border-sidebar) !important;
}

.sidebar-header span,
.sidebar-title {
    background: none !important;
    -webkit-text-fill-color: initial !important;
    color: #1569BF !important;
    font-weight: 700 !important;
}

.sidebar-menu li a {
    color: var(--text-sidebar) !important;
    background: transparent !important;
}

.sidebar-menu li a i {
    color: var(--text-sidebar-muted) !important;
}

.sidebar-menu li a:hover {
    background: #F3F7FD !important;
    color: var(--primary) !important;
}

.sidebar-menu li a.active {
    background: var(--primary) !important;
    color: #fff !important;
    box-shadow: none !important;
}

.sidebar-menu li a.active i {
    color: #fff !important;
}

.topbar {
    background: var(--topbar-bg) !important;
    border-bottom: 1px solid var(--border) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
}

table th {
    font-size: 12px !important;
    font-weight: 600 !important;
    letter-spacing: 0.04em !important;
    color: #64748B !important;
    border-bottom: 1px solid var(--border) !important;
    background: #F9FBFF !important;
}

table td {
    font-size: 14px !important;
    color: var(--text-main) !important;
    border-bottom: 1px solid var(--border) !important;
}

tr:hover td {
    background: #F8FBFF !important;
}

[data-theme='dark'] tr:hover td {
    background: rgba(94, 162, 232, 0.08) !important;
}

.page-header {
    background: transparent !important;
    border-bottom: 1px solid var(--border) !important;
}

.page-header h1,
h1,
h2,
h3 {
    color: #111827 !important;
    letter-spacing: 0 !important;
}

[data-theme='dark'] .page-header h1,
[data-theme='dark'] h1,
[data-theme='dark'] h2,
[data-theme='dark'] h3 {
    color: #E5EDF8 !important;
}

.kpi-label {
    font-size: 12px !important;
    letter-spacing: 0.04em !important;
}

.kpi-value {
    font-size: 34px !important;
    font-weight: 700 !important;
}

[data-theme='dark'] .sidebar-header span,
[data-theme='dark'] .sidebar-title {
    color: #8fc2f2 !important;
}

[data-theme='dark'] .sidebar-menu li a {
    color: var(--text-sidebar) !important;
}

[data-theme='dark'] .sidebar-menu li a i {
    color: var(--text-sidebar-muted) !important;
}

[data-theme='dark'] .sidebar-menu li a:hover {
    background: rgba(94, 162, 232, 0.12) !important;
    color: #cfe6ff !important;
}

[data-theme='dark'] .sidebar-menu li a.active {
    background: rgba(94, 162, 232, 0.2) !important;
    color: #e7f2ff !important;
}

[data-theme='dark'] .sidebar-menu li a.active i {
    color: #e7f2ff !important;
}
