/* ------------------------------------------------------------------
 * MOE — Unified Stats Card Design
 * Overrides Filament's StatsOverviewWidget stat cards to match the
 * ServiceStatsDesignOverview visual language. Registered via
 * FilamentPanelProvider assets.
 *
 * Every widget using Filament's native Stat::make() will inherit
 * this design automatically.
 * ------------------------------------------------------------------ */

/* ======================== STAT CARD =============================== */

.fi-stat-card {
    position: relative !important;
    background: var(--stat-bg) !important;
    border-radius: 16px !important;
    padding: 14px 18px 14px !important;
    box-shadow: 0 1px 2px rgba(15,23,42,0.04), 0 8px 20px rgba(15,23,42,0.05) !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    border: none !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
    container-type: inline-size;
}
.fi-stat-card:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 8px rgba(15,23,42,0.06), 0 22px 40px rgba(15,23,42,0.12) !important;
}
.dark .fi-stat-card {
    background: var(--stat-bg-dark) !important;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 14px 28px rgba(0,0,0,0.35) !important;
}
.dark .fi-stat-card:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.4), 0 22px 40px rgba(0,0,0,0.5) !important;
}

/* Top accent bar */
.fi-stat-card__accent {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--stat-accent);
}

/* ======================== TOP ROW ================================= */

.fi-stat-card__top {
    display: flex;
    flex-direction: row-reverse;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding-top: 4px;
}

/* Icon */
.fi-stat-card__icon {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--stat-accent);
    box-shadow: 0 8px 18px rgba(15,23,42,0.10);
    color: #ffffff;
}
.fi-stat-card__icon svg,
.fi-stat-card__icon .fi-stat-card__icon-svg {
    width: 22px !important;
    height: 22px !important;
    color: #ffffff !important;
}

/* Head (label, value, subtitle) */
.fi-stat-card__head {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-width: 0;
    flex: 1 1 auto;
}

.fi-stat-card__label {
    font-size: 13px;
    font-weight: 600;
    color: #6B7280;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.5;
}
.dark .fi-stat-card__label { color: #9CA3AF; }

.fi-stat-card__value {
    font-size: 26px;
    font-weight: 800;
    color: #0F172A;
    line-height: 1.1;
    letter-spacing: -0.5px;
    white-space: normal;
    overflow-wrap: anywhere;
}
.dark .fi-stat-card__value { color: #F9FAFB; }

/* Narrow cards: step the value down so long amounts stay on one line. */
@container (max-width: 270px) {
    .fi-stat-card__value { font-size: 21px; }
}

.fi-stat-card__subtitle {
    font-size: 12px;
    color: #9CA3AF;
    font-weight: 500;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
}

/* ======================== CHART =================================== */

.fi-stat-card__chart {
    width: 45%;
    height: 56px;
    margin-left: auto;
}
.fi-stat-card__chart-inner {
    height: 56px !important;
}
.fi-stat-card__chart-inner canvas {
    height: 56px !important;
    max-height: 56px !important;
}

/* ======================== FOOTER ================================== */

.fi-stat-card__footer {
    display: flex;
    flex-direction: row-reverse;
    justify-content: space-between;
    align-items: center;
    padding-top: 2px;
}

.fi-stat-card__compare {
    font-size: 12px;
    color: #9CA3AF;
    font-weight: 500;
}

.fi-stat-card__change {
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.fi-stat-card__change--pill {
    padding: 4px 10px;
    border-radius: 9px;
}

.fi-stat-card__change--up {
    color: #10B981;
    background: rgba(16,185,129,0.10);
}

.fi-stat-card__change--down {
    color: #EF4444;
    background: rgba(239,68,68,0.10);
}

.fi-stat-card__change-icon {
    width: 14px;
    height: 14px;
}

/* ======================== STATS GRID SPACING ====================== */

/* Responsive card grid: never squeeze a card below 240px — reflow the
   column count instead, so labels and amounts are never clipped. */
.fi-wi-stats-overview .fi-section-content.fi-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)) !important;
    gap: 16px !important;
}

.fi-wi-stats-overview .fi-wi-stats-overview-stats-ctn {
    gap: 16px !important;
}

/* Direction override for the stats grid */
.fi-wi-stats-overview {
    direction: rtl;
}

/* ==================================================================
 * MOE — Chart Card Design System
 * Matches the MonthlyChartsOverview (mco__) visual language exactly.
 * Applied automatically to all Filament ChartWidget instances via the
 * published chart-widget.blade.php override.
 * ================================================================== */

/* ---- Card ---- */
.moe-chart-card {
    background: #FFFFFF;
    border-radius: 22px;
    padding: 22px 24px 18px;
    box-shadow: 0 1px 2px rgba(15,23,42,0.04), 0 14px 28px rgba(15,23,42,0.06);
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}
.dark .moe-chart-card {
    background: #1F2937;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 14px 28px rgba(0,0,0,0.35);
}

/* ---- Header ---- */
.moe-chart-card__header {
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.moe-chart-card__heading {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
}

.moe-chart-card__title {
    font-size: 18px;
    font-weight: 800;
    color: #0F172A;
    margin: 0;
    line-height: 1.2;
}
.dark .moe-chart-card__title { color: #F9FAFB; }

.moe-chart-card__subtitle {
    font-size: 13px;
    color: #9CA3AF;
    margin: 0;
    font-weight: 500;
}

/* ---- Filter (pill button + dropdown — matches mco__filter exactly) ---- */
.moe-chart-card__filter-wrap {
    position: relative;
    z-index: 50;
    flex: 0 0 auto;
}

.moe-chart-card__filter {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 130px;
    padding: 10px 18px;
    background: #FFFFFF;
    border: 1.5px solid #E5E7EB;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    color: #0F172A;
    cursor: pointer;
    transition: border-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
    font-family: 'Tajawal','Cairo','IBM Plex Sans Arabic',sans-serif;
}
.moe-chart-card__filter:hover {
    border-color: #C7CCD5;
}
.moe-chart-card__filter--open {
    border-color: #6366F1;
    color: #4F46E5;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}
.dark .moe-chart-card__filter {
    background: #111827;
    border-color: #374151;
    color: #E5E7EB;
}
.dark .moe-chart-card__filter--open {
    border-color: #818CF8;
    color: #C7D2FE;
}

.moe-chart-card__filter-caret {
    width: 14px;
    height: 14px;
    opacity: .6;
    transition: transform 200ms ease;
}
.moe-chart-card__filter-caret--up {
    transform: rotate(180deg);
    opacity: 1;
}

/* Dropdown menu */
.moe-chart-card__menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 200px;
    background: #FFFFFF;
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12), 0 2px 4px rgba(15, 23, 42, 0.06);
    padding: 8px;
    z-index: 60;
}
.dark .moe-chart-card__menu {
    background: #1F2937;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.moe-chart-card__menu-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: 0;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    text-align: right;
    font-family: 'Tajawal','Cairo','IBM Plex Sans Arabic',sans-serif;
    transition: background-color 120ms ease, color 120ms ease;
}
.moe-chart-card__menu-item:hover {
    background: #F1F5F9;
    color: #0F172A;
}
.moe-chart-card__menu-item--active {
    background: #EEF2FF;
    color: #4F46E5;
    font-weight: 700;
}
.dark .moe-chart-card__menu-item { color: #CBD5E1; }
.dark .moe-chart-card__menu-item:hover { background: #374151; color: #F3F4F6; }
.dark .moe-chart-card__menu-item--active { background: #312E81; color: #C7D2FE; }

.moe-chart-card__dropdown-content {
    padding: 8px;
}

/* ---- Divider ---- */
.moe-chart-card__divider {
    height: 1px;
    background: #F1F5F9;
    margin: 0 -24px;
}
.dark .moe-chart-card__divider { background: #374151; }

/* ---- Chart area ---- */
.moe-chart-card__chart {
    position: relative;
    width: 100%;
    min-height: 260px;
    margin-top: 4px;
}
.moe-chart-card__chart canvas {
    max-height: 320px;
}

/* ---- Suppress Filament's default section chrome ---- */
.fi-wi-chart .fi-section,
.fi-wi-chart .fi-section-content-ctn,
.fi-wi-chart .fi-section-content {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

/* ---- Legend (matches mco__legend exactly) ---- */
.moe-chart-card__legend {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 28px;
    padding-top: 8px;
}
.moe-chart-card__legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.moe-chart-card__legend-dot {
    width: 22px;
    height: 4px;
    border-radius: 999px;
    display: inline-block;
}
.moe-chart-card__legend-label {
    font-size: 13px;
    color: #4B5563;
    font-weight: 600;
}
.dark .moe-chart-card__legend-label { color: #D1D5DB; }

/* x-cloak support */
[x-cloak] { display: none !important; }
