/* ============================================
   KonX — Rapports & Exports Page Styles
   ============================================ */

/* ---- Page Content ---- */
.page-content {
    padding: var(--space-8) var(--space-8);
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

/* ---- Title Row ---- */
.rp-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-6);
}

.rp-title-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rp-page-title {
    font-size: 1.75rem;
    font-weight: var(--weight-extrabold);
    color: var(--neutral-900);
    letter-spacing: -0.02em;
    line-height: var(--line-height-tight);
}

.rp-page-subtitle {
    font-size: var(--font-md);
    color: var(--neutral-500);
    line-height: var(--line-height-relaxed);
}

/* Period Picker */
.rp-period-picker {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px 18px;
    background: var(--white);
    border: 1px solid var(--neutral-200);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    font-size: var(--font-md);
    font-weight: var(--weight-semibold);
    color: var(--neutral-800);
}

.rp-period-picker:hover {
    border-color: var(--neutral-300);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.rp-period-picker i:first-child {
    color: var(--primary-600);
}

.rp-period-settings {
    color: var(--neutral-400);
    font-size: var(--font-sm);
    margin-left: var(--space-2);
}

/* ---- KPI Row ---- */
.rp-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-6);
}

.rp-kpi-card {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    animation: rpFadeInUp 0.35s ease-out both;
}

.rp-kpi-card:nth-child(1) { animation-delay: 0.05s; }
.rp-kpi-card:nth-child(2) { animation-delay: 0.1s; }
.rp-kpi-card:nth-child(3) { animation-delay: 0.15s; }
.rp-kpi-card:nth-child(4) { animation-delay: 0.2s; }

.rp-kpi-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.rp-kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-xl);
    flex-shrink: 0;
}

.rp-kpi-icon-blue   { background: #eff6ff; color: #3b82f6; }
.rp-kpi-icon-red    { background: #fef2f2; color: var(--primary-700); }
.rp-kpi-icon-green  { background: #ecfdf5; color: #059669; }
.rp-kpi-icon-purple { background: #f3e8ff; color: #7c3aed; }

.rp-kpi-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: var(--border-radius-full);
    font-size: var(--font-xs);
    font-weight: var(--weight-semibold);
}

.rp-badge-green {
    background: #ecfdf5;
    color: #059669;
}

.rp-badge-green i {
    font-size: 9px;
}

.rp-badge-orange {
    background: #fff7ed;
    color: #ea580c;
}

.rp-badge-neutral {
    background: var(--neutral-100);
    color: var(--neutral-500);
}

.rp-kpi-bottom {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rp-kpi-label {
    font-size: var(--font-sm);
    color: var(--neutral-500);
    font-weight: var(--weight-medium);
}

.rp-kpi-value-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.rp-kpi-number {
    font-size: 2rem;
    font-weight: var(--weight-extrabold);
    color: var(--neutral-900);
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.rp-number-red {
    color: var(--primary-700);
}

.rp-kpi-currency {
    font-size: var(--font-md);
    font-weight: var(--weight-bold);
    color: var(--neutral-400);
}

.rp-kpi-check {
    font-size: var(--font-lg);
    color: #059669;
}

/* ---- Middle Row: Chart + Export ---- */
.rp-middle-row {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: var(--space-6);
    animation: rpFadeInUp 0.35s ease-out 0.25s both;
}

/* ---- Chart Card (matches Dashboard .card pattern) ---- */
.rp-chart-card {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chart Header — mirrors .card-header */
.rp-chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--neutral-100);
    gap: var(--space-4);
}

.rp-chart-title-area {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.rp-chart-icon-badge {
    width: 36px;
    height: 36px;
    background: var(--primary-500);
    color: var(--white);
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-md);
    flex-shrink: 0;
}

.rp-chart-title {
    font-size: var(--font-lg);
    font-weight: var(--weight-bold);
    color: var(--neutral-900);
    letter-spacing: -0.01em;
    line-height: var(--line-height-tight);
}

.rp-chart-subtitle {
    font-size: var(--font-sm);
    color: var(--neutral-500);
    margin-top: 2px;
    font-weight: var(--weight-normal);
}

.rp-chart-actions {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-shrink: 0;
}

.rp-chart-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--font-xs);
    font-weight: var(--weight-medium);
    color: var(--neutral-500);
}

.rp-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-500);
}

.rp-chart-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--white);
    border: 1px solid var(--neutral-200);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-sm);
    font-weight: var(--weight-medium);
    color: var(--neutral-700);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-family);
}

.rp-chart-filter-btn:hover {
    border-color: var(--neutral-300);
    background: var(--neutral-50);
}

.rp-chart-filter-btn i:first-child {
    color: var(--neutral-400);
    font-size: 11px;
}

.rp-chevron {
    font-size: 9px !important;
    color: var(--neutral-400) !important;
    margin-left: 2px;
}

/* Chart KPI Strip */
.rp-chart-kpis {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    padding: var(--space-4) var(--space-6);
    background: var(--neutral-50);
    border-bottom: 1px solid var(--neutral-100);
}

.rp-chart-kpi {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.rp-chart-kpi-label {
    font-size: var(--font-xs);
    font-weight: var(--weight-medium);
    color: var(--neutral-400);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.rp-chart-kpi-val {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.rp-chart-kpi-number {
    font-size: 1.25rem;
    font-weight: var(--weight-extrabold);
    color: var(--neutral-900);
    letter-spacing: -0.02em;
    line-height: 1;
}

.rp-num-sm {
    font-size: 1.05rem;
}

.rp-chart-kpi-unit {
    font-size: var(--font-xs);
    font-weight: var(--weight-semibold);
    color: var(--neutral-400);
}

.rp-chart-kpi-trend {
    font-size: var(--font-md);
    font-weight: var(--weight-bold);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1.2;
}

.rp-chart-kpi-trend i {
    font-size: 9px;
}

.rp-trend-up {
    color: #059669;
}

.rp-trend-down {
    color: #dc2626;
}

.rp-chart-kpi-sep {
    width: 1px;
    height: 32px;
    background: var(--neutral-200);
    flex-shrink: 0;
}

/* Chart Canvas Area */
.rp-chart-canvas-wrap {
    position: relative;
    height: 220px;
    padding: var(--space-5) var(--space-4) var(--space-4);
}

.rp-chart-canvas-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Legacy compat */
.rp-chart-period {
    display: none;
}

/* Export Card (Dark) */
.rp-export-card {
    background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    border-radius: 16px;
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    color: var(--white);
    position: relative;
    overflow: hidden;
}

.rp-export-card::before {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.04);
}

.rp-export-card::after {
    content: '';
    position: absolute;
    bottom: -60px;
    right: -20px;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.02);
}

.rp-export-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    position: relative;
    z-index: 1;
}

.rp-export-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(239, 68, 68, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-md);
    color: #f87171;
}

.rp-export-label {
    font-size: var(--font-xs);
    font-weight: var(--weight-bold);
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.rp-export-title {
    font-size: 1.5rem;
    font-weight: var(--weight-extrabold);
    line-height: 1.3;
    letter-spacing: -0.02em;
    position: relative;
    z-index: 1;
}

.rp-export-desc {
    font-size: var(--font-sm);
    color: rgba(255, 255, 255, 0.55);
    line-height: var(--line-height-relaxed);
    position: relative;
    z-index: 1;
}

.rp-export-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    position: relative;
    z-index: 1;
}

.rp-export-features li {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-sm);
    font-weight: var(--weight-medium);
    color: rgba(255, 255, 255, 0.85);
}

.rp-export-features li i {
    color: #4ade80;
    font-size: var(--font-sm);
}

.rp-export-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: 14px 24px;
    background: #1a603a;
    color: var(--white);
    border: none;
    border-radius: var(--border-radius-lg);
    font-size: var(--font-sm);
    font-weight: var(--weight-bold);
    font-family: var(--font-family);
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: auto;
    position: relative;
    z-index: 1;
}

.rp-export-btn:hover {
    background: #0e4529;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(14, 69, 41, 0.4);
}

.rp-export-btn i {
    font-size: var(--font-md);
}

/* ---- Journal d'audit Section ---- */
.rp-journal-section {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    animation: rpFadeInUp 0.35s ease-out 0.35s both;
    overflow: hidden;
}

.rp-journal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-6) var(--space-6) var(--space-5);
}

.rp-journal-title-area {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.rp-journal-icon {
    font-size: var(--font-xl);
    color: var(--neutral-400);
}

.rp-journal-title {
    font-size: var(--font-xl);
    font-weight: var(--weight-bold);
    color: var(--neutral-900);
}

.rp-journal-link {
    font-size: var(--font-sm);
    font-weight: var(--weight-semibold);
    color: var(--primary-600);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.rp-journal-link:hover {
    color: var(--primary-700);
    text-decoration: underline;
}

/* Journal Table */
.rp-journal-table {
    width: 100%;
    border-collapse: collapse;
}

.rp-journal-table thead th {
    padding: 14px 24px;
    text-align: left;
    font-size: var(--font-xs);
    font-weight: var(--weight-semibold);
    color: var(--neutral-500);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--neutral-50);
    border-top: 1px solid var(--neutral-200);
    border-bottom: 1px solid var(--neutral-200);
    white-space: nowrap;
}

.rp-journal-table tbody tr {
    transition: background var(--transition-fast);
}

.rp-journal-table tbody tr:hover {
    background: var(--neutral-50);
}

.rp-journal-table tbody td {
    padding: 16px 24px;
    vertical-align: middle;
    border-bottom: 1px solid var(--neutral-100);
}

/* Action Cell */
.rp-action-cell {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--font-md);
    font-weight: var(--weight-medium);
    color: var(--neutral-800);
}

.rp-action-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-sm);
    flex-shrink: 0;
}

.rp-action-edit   { background: #dbeafe; color: #3b82f6; }
.rp-action-export { background: #ecfdf5; color: #059669; }
.rp-action-delete { background: #fee2e2; color: #dc2626; }
.rp-action-create { background: #f3e8ff; color: #7c3aed; }
.rp-action-send   { background: #fff7ed; color: #ea580c; }

/* Element Cell */
.rp-element-cell {
    font-size: var(--font-sm);
    color: var(--neutral-700);
    font-family: 'SF Mono', 'Fira Code', monospace;
    letter-spacing: 0.02em;
    font-weight: var(--weight-medium);
}

/* Author Cell */
.rp-author-cell {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.rp-author-cell img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
}

.rp-author-cell span {
    font-size: var(--font-sm);
    font-weight: var(--weight-medium);
    color: var(--neutral-700);
}

/* Date Cell */
.rp-date-cell {
    font-size: var(--font-sm);
    color: var(--neutral-500);
    white-space: nowrap;
}

/* Status Badges */
.rp-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: var(--border-radius-full);
    font-size: var(--font-xs);
    font-weight: var(--weight-semibold);
    white-space: nowrap;
}

.rp-status-badge i {
    font-size: 7px;
}

.rp-status-success { background: #ecfdf5; color: #059669; }
.rp-status-warning { background: #fef3c7; color: #d97706; }
.rp-status-info    { background: #dbeafe; color: #3b82f6; }
.rp-status-error   { background: #fee2e2; color: #dc2626; }

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes rpFadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1200px) {
    .rp-kpi-row {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-4);
    }

    .rp-middle-row {
        grid-template-columns: 1fr;
    }

    .rp-chart-header {
        flex-wrap: wrap;
    }
}

@media (max-width: 768px) {
    .page-content {
        padding: var(--space-6) var(--space-4);
    }

    .rp-title-row {
        flex-direction: column;
    }

    .rp-page-title {
        font-size: var(--font-2xl);
    }

    .rp-kpi-row {
        grid-template-columns: 1fr;
    }

    .rp-middle-row {
        grid-template-columns: 1fr;
    }

    .rp-chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .rp-chart-actions {
        width: 100%;
        justify-content: space-between;
    }

    .rp-chart-kpis {
        flex-wrap: wrap;
        gap: var(--space-4);
    }

    .rp-chart-kpi-sep {
        display: none;
    }

    .rp-chart-canvas-wrap {
        height: 180px;
    }

    .rp-journal-header {
        flex-direction: column;
        gap: var(--space-3);
        align-items: flex-start;
    }

    .rp-journal-table {
        display: block;
        overflow-x: auto;
    }
}

/* ── KPI Card Hover ── */
.rp-kpi-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}
.rp-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* ── Journal Row Enhanced Hover ── */
.rp-journal-row {
    transition: background 0.15s ease, transform 0.15s ease;
}
.rp-journal-row:hover {
    background: #fef2f2 !important;
    transform: scale(1.002);
}

/* ── Sidebar Backdrop ── */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ── Search Focus ── */
.search-focused {
    border-color: #b91c1c !important;
    box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12) !important;
}

/* ---- RTL ---- */
html[dir="rtl"] .rp-journal-table thead th,
html[dir="rtl"] .rp-journal-table tbody td {
    text-align: right !important;
}

html[dir="rtl"] .rp-action-cell,
html[dir="rtl"] .rp-chart-title-area,
html[dir="rtl"] .rp-chart-actions,
html[dir="rtl"] .rp-chart-legend-item,
html[dir="rtl"] .rp-chart-kpis,
html[dir="rtl"] .rp-export-header,
html[dir="rtl"] .rp-export-features li,
html[dir="rtl"] .rp-export-btn,
html[dir="rtl"] .rp-kpi-top,
html[dir="rtl"] .rp-kpi-badge,
html[dir="rtl"] .rp-journal-title-area,
html[dir="rtl"] .rp-title-row,
html[dir="rtl"] .rp-period-picker,
html[dir="rtl"] .rp-status-badge {
    flex-direction: row-reverse;
}

/* RTL table icon+label order fix: icon right, text left */
html[dir="rtl"] .rp-action-cell,
html[dir="rtl"] .rp-author-cell,
html[dir="rtl"] .rp-status-badge {
    flex-direction: row;
    direction: rtl;
}

/* Keep Latin initials punctuation stable in RTL (e.g. Sarah B.) */
html[dir="rtl"] .rp-author-cell span {
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-block;
}

html[dir="rtl"] .rp-chart-kpi-val {
    flex-direction: row;
}

html[dir="rtl"] .rp-period-settings,
html[dir="rtl"] .rp-chevron {
    margin-left: 0;
    margin-right: var(--space-2);
}

/* RTL KPI value display - ensure number before DH */
html[dir="rtl"] .rp-kpi-value-row {
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-flex;
    flex-direction: row;
    align-items: baseline;
}

html[dir="rtl"] .rp-kpi-number {
    order: 1;
}

html[dir="rtl"] .rp-kpi-currency {
    order: 2;
    margin-left: 6px;
}
