/*
 * PASTA HUB — charte graphique.
 *
 * Cette feuille se pose par-dessus le CSS de Filament et n'en remplace rien :
 * elle redefinit ses variables de couleur et de rayon, puis habille les
 * quelques composants propres au tableau de bord. Aucune etape de build n'est
 * necessaire, ce qui evite d'imposer npm sur le serveur de production.
 */

:root {
    --ph-primary: #E85D2A;
    --ph-primary-hover: #D94816;
    --ph-primary-light: #FFF1EB;
    --ph-primary-border: #FFD7C7;

    --ph-success: #16A364;
    --ph-success-light: #EAF8F1;
    --ph-warning: #F59E0B;
    --ph-warning-light: #FFF7E6;
    --ph-danger: #E5484D;
    --ph-danger-light: #FFF0F0;
    --ph-info: #3478F6;
    --ph-info-light: #EDF4FF;

    --ph-text-primary: #111827;
    --ph-text-secondary: #667085;
    --ph-text-muted: #98A2B3;
    --ph-border: #E5E7EB;
    --ph-background: #F8F9FB;
    --ph-surface: #FFFFFF;

    --ph-radius: 12px;
    --ph-radius-lg: 14px;
    --ph-shadow: 0 1px 2px rgb(16 24 40 / 0.04), 0 1px 3px rgb(16 24 40 / 0.06);
    --ph-transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Filament calcule ses rayons a partir de cette echelle. */
    --radius-xl: var(--ph-radius);
    --radius-lg: var(--ph-radius);
}

/* ------------------------------------------------------------------ */
/* Fond general et cartes                                              */
/* ------------------------------------------------------------------ */

.fi-body {
    background-color: var(--ph-background);
    color: var(--ph-text-primary);
}

.fi-section,
.fi-wi-stats-overview-stat,
.fi-ta-ctn {
    border-radius: var(--ph-radius-lg);
    border-color: var(--ph-border);
    box-shadow: var(--ph-shadow);
}

/* ------------------------------------------------------------------ */
/* Barre laterale                                                      */
/* ------------------------------------------------------------------ */

.fi-sidebar {
    border-right: 1px solid var(--ph-border);
    background-color: var(--ph-surface);
}

.fi-sidebar-header {
    background-color: var(--ph-surface);
    border-bottom: 1px solid var(--ph-border);
    box-shadow: none;
}

.ph-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
}

.ph-brand__mark {
    width: 2rem;
    height: 2rem;
    flex: none;
    object-fit: contain;
}

.ph-brand__name {
    font-size: 1.125rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    white-space: nowrap;
    color: #101828;
}

/* Barre laterale repliee : l'icone reste, le nom disparait. */
.fi-sidebar-nav-groups:not(.fi-sidebar-open) ~ * .ph-brand__name,
.fi-sidebar-collapsed .ph-brand__name {
    display: none;
}

/* Titres de groupe : discrets, ils separent sans decouper. */
.fi-sidebar-group-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ph-text-muted);
}

.fi-sidebar-group + .fi-sidebar-group {
    border-top: 1px solid var(--ph-border);
    padding-top: 0.75rem;
    margin-top: 0.5rem;
}

.fi-sidebar-item-button {
    border-radius: 10px;
    transition: background-color var(--ph-transition), color var(--ph-transition);
}

.fi-sidebar-item:not(.fi-active) .fi-sidebar-item-button:hover {
    background-color: #F4F5F7;
}

.fi-sidebar-item.fi-active .fi-sidebar-item-button {
    background-color: var(--ph-primary-light);
}

.fi-sidebar-item.fi-active .fi-sidebar-item-label,
.fi-sidebar-item.fi-active .fi-sidebar-item-icon {
    color: var(--ph-primary);
    font-weight: 600;
}

/* La barre de defilement interne reste fine pour ne pas alourdir la colonne. */
.fi-sidebar-nav {
    scrollbar-width: thin;
    scrollbar-color: var(--ph-border) transparent;
}

.fi-sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.fi-sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--ph-border);
    border-radius: 999px;
}

/* ------------------------------------------------------------------ */
/* Barre superieure                                                    */
/* ------------------------------------------------------------------ */

.fi-topbar > nav {
    background-color: var(--ph-surface);
    border-bottom: 1px solid var(--ph-border);
    box-shadow: none;
}

.ph-topbar-control {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0 0.625rem;
    height: 2.25rem;
    background-color: var(--ph-surface);
    border: 1px solid var(--ph-border);
    border-radius: 10px;
    transition: border-color var(--ph-transition), box-shadow var(--ph-transition);
}

.ph-topbar-control:focus-within {
    border-color: var(--ph-primary);
    box-shadow: 0 0 0 3px var(--ph-primary-light);
}

.ph-topbar-control__icon {
    display: flex;
    color: var(--ph-text-muted);
    flex: none;
}

.ph-topbar-control__select {
    border: 0;
    background: transparent;
    padding: 0 1.25rem 0 0;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ph-text-primary);
    max-width: 12rem;
    text-overflow: ellipsis;
    cursor: pointer;
}

.ph-topbar-control__select:focus {
    outline: none;
    box-shadow: none;
}

.ph-topbar-control__select--active {
    color: var(--ph-primary);
    font-weight: 600;
}

.ph-period-custom {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    z-index: 30;
    width: 15rem;
    padding: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    background-color: var(--ph-surface);
    border: 1px solid var(--ph-border);
    border-radius: var(--ph-radius);
    box-shadow: 0 12px 24px rgb(16 24 40 / 0.10);
}

.ph-period-custom__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--ph-text-secondary);
}

.ph-period-custom__input {
    border: 1px solid var(--ph-border);
    border-radius: 8px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    color: var(--ph-text-primary);
}

.ph-period-custom__error {
    font-size: 0.75rem;
    color: var(--ph-danger);
}

/* ------------------------------------------------------------------ */
/* En-tete du tableau de bord                                          */
/* ------------------------------------------------------------------ */

.ph-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.ph-page-header__title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ph-text-primary);
    margin: 0;
}

.ph-page-header__subtitle {
    margin-top: 0.25rem;
    font-size: 0.9375rem;
    color: var(--ph-text-secondary);
}

.ph-page-header__actions {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

/* ------------------------------------------------------------------ */
/* Cartes d'indicateur                                                 */
/* ------------------------------------------------------------------ */

.ph-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.ph-kpi {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    padding: 1.125rem;
    background-color: var(--ph-surface);
    border: 1px solid var(--ph-border);
    border-radius: var(--ph-radius-lg);
    box-shadow: var(--ph-shadow);
    transition: box-shadow var(--ph-transition), border-color var(--ph-transition);
}

.ph-kpi--clickable {
    cursor: pointer;
}

.ph-kpi--clickable:hover,
.ph-kpi--clickable:focus-visible {
    border-color: var(--ph-primary-border);
    box-shadow: 0 4px 12px rgb(16 24 40 / 0.08);
}

.ph-kpi__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 10px;
    flex: none;
}

.ph-kpi__icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.ph-kpi__icon--success { background-color: var(--ph-success-light); color: var(--ph-success); }
.ph-kpi__icon--info    { background-color: var(--ph-info-light);    color: var(--ph-info); }
.ph-kpi__icon--primary { background-color: var(--ph-primary-light); color: var(--ph-primary); }
.ph-kpi__icon--warning { background-color: var(--ph-warning-light); color: var(--ph-warning); }

.ph-kpi__body {
    min-width: 0;
    flex: 1;
}

.ph-kpi__label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ph-text-secondary);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.ph-kpi__value {
    margin-top: 0.125rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ph-text-primary);
    line-height: 1.2;
}

.ph-kpi__change {
    margin-top: 0.375rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8125rem;
    font-weight: 500;
}

.ph-kpi__change svg { width: 0.875rem; height: 0.875rem; }
.ph-kpi__change--up      { color: var(--ph-success); }
.ph-kpi__change--down    { color: var(--ph-danger); }
.ph-kpi__change--neutral { color: var(--ph-text-muted); }
.ph-kpi__change--warning { color: var(--ph-warning); }

.ph-kpi__comparison {
    color: var(--ph-text-muted);
    font-weight: 400;
}

.ph-kpi__spark {
    flex: none;
    width: 4.5rem;
    height: 2.25rem;
    align-self: center;
}

/* ------------------------------------------------------------------ */
/* Cartes de contenu                                                   */
/* ------------------------------------------------------------------ */

.ph-card {
    background-color: var(--ph-surface);
    border: 1px solid var(--ph-border);
    border-radius: var(--ph-radius-lg);
    box-shadow: var(--ph-shadow);
    overflow: hidden;
}

.ph-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.125rem;
    border-bottom: 1px solid var(--ph-border);
}

.ph-card__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--ph-text-primary);
}

.ph-card__title svg {
    width: 1.125rem;
    height: 1.125rem;
    color: var(--ph-primary);
}

.ph-card__link {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ph-primary);
    text-decoration: none;
    white-space: nowrap;
}

.ph-card__link:hover { color: var(--ph-primary-hover); text-decoration: underline; }

.ph-card__body { padding: 1.125rem; }

/* Segments Jour / Semaine / Mois. */
.ph-segmented {
    display: inline-flex;
    padding: 0.1875rem;
    background-color: #F4F5F7;
    border-radius: 9px;
    gap: 0.125rem;
}

.ph-segmented__item {
    padding: 0.3125rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ph-text-secondary);
    background: transparent;
    border: 0;
    border-radius: 7px;
    cursor: pointer;
    transition: background-color var(--ph-transition), color var(--ph-transition);
}

.ph-segmented__item:hover { color: var(--ph-text-primary); }

.ph-segmented__item[aria-pressed="true"] {
    background-color: var(--ph-primary-light);
    color: var(--ph-primary);
    font-weight: 600;
}

/* ------------------------------------------------------------------ */
/* Repartition des ventes                                              */
/* ------------------------------------------------------------------ */

.ph-distribution {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.ph-distribution__chart {
    position: relative;
    width: 9.5rem;
    height: 9.5rem;
    flex: none;
}

.ph-distribution__center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    text-align: center;
}

.ph-distribution__total {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--ph-text-primary);
    line-height: 1.15;
}

.ph-distribution__caption {
    font-size: 0.6875rem;
    color: var(--ph-text-muted);
}

.ph-distribution__legend {
    flex: 1;
    min-width: 9rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ph-legend-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.ph-legend-row__dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
    margin-top: 0.375rem;
    flex: none;
}

.ph-legend-row__body { flex: 1; min-width: 0; }

.ph-legend-row__label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ph-text-primary);
}

.ph-legend-row__share { font-weight: 700; }
.ph-legend-row__amount { font-size: 0.75rem; color: var(--ph-text-muted); }

/* ------------------------------------------------------------------ */
/* Tableau de performance                                              */
/* ------------------------------------------------------------------ */

.ph-table-wrapper { overflow-x: auto; }

.ph-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.ph-table thead th {
    padding: 0.625rem 1.125rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ph-text-secondary);
    background-color: #FAFBFC;
    border-bottom: 1px solid var(--ph-border);
    white-space: nowrap;
}

.ph-table th[aria-sort] { cursor: pointer; user-select: none; }
.ph-table th[aria-sort]:hover { color: var(--ph-text-primary); }
.ph-table th[aria-sort="descending"],
.ph-table th[aria-sort="ascending"] { color: var(--ph-primary); }

.ph-table tbody td {
    padding: 0.8125rem 1.125rem;
    border-bottom: 1px solid #F1F3F5;
    color: var(--ph-text-primary);
    white-space: nowrap;
}

.ph-table tbody tr:last-child td { border-bottom: 0; }
.ph-table tbody tr:hover { background-color: #FAFBFC; }
.ph-table .ph-num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ */
/* Badges de statut                                                    */
/* ------------------------------------------------------------------ */

.ph-status {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
}

.ph-status__dot { width: 0.5rem; height: 0.5rem; border-radius: 999px; flex: none; }
.ph-status--online  { color: var(--ph-success); }
.ph-status--online  .ph-status__dot { background-color: var(--ph-success); }
.ph-status--warning { color: var(--ph-warning); }
.ph-status--warning .ph-status__dot { background-color: var(--ph-warning); }
.ph-status--offline { color: var(--ph-danger); }
.ph-status--offline .ph-status__dot { background-color: var(--ph-danger); }

/* ------------------------------------------------------------------ */
/* Alertes                                                             */
/* ------------------------------------------------------------------ */

.ph-alerts { display: flex; flex-direction: column; gap: 0.625rem; }

.ph-alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.8125rem 0.875rem;
    border-radius: var(--ph-radius);
    border: 1px solid transparent;
}

.ph-alert__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 8px;
    flex: none;
    background-color: var(--ph-surface);
}

.ph-alert__icon svg { width: 1.0625rem; height: 1.0625rem; }
.ph-alert__body { flex: 1; min-width: 0; }

.ph-alert__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ph-text-primary);
}

.ph-alert__detail {
    font-size: 0.8125rem;
    color: var(--ph-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ph-alert__time { font-size: 0.75rem; color: var(--ph-text-muted); }

.ph-alert__action {
    flex: none;
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 600;
    border-radius: 8px;
    text-decoration: none;
    transition: background-color var(--ph-transition);
}

.ph-alert--danger  { background-color: var(--ph-danger-light);  border-color: #FBD5D5; }
.ph-alert--danger  .ph-alert__icon   { color: var(--ph-danger); }
.ph-alert--danger  .ph-alert__action { background-color: #FBD5D5; color: #B42318; }
.ph-alert--danger  .ph-alert__action:hover { background-color: #F7BFBF; }

.ph-alert--warning { background-color: var(--ph-warning-light); border-color: #FDE8BF; }
.ph-alert--warning .ph-alert__icon   { color: var(--ph-warning); }
.ph-alert--warning .ph-alert__action { background-color: #FDE8BF; color: #B54708; }
.ph-alert--warning .ph-alert__action:hover { background-color: #FBDCA1; }

.ph-alert--info    { background-color: var(--ph-info-light);    border-color: #D6E4FF; }
.ph-alert--info    .ph-alert__icon   { color: var(--ph-info); }
.ph-alert--info    .ph-alert__action { background-color: var(--ph-info); color: #FFFFFF; }
.ph-alert--info    .ph-alert__action:hover { background-color: #2563EB; }

/* ------------------------------------------------------------------ */
/* Etats vides, erreurs et chargement                                  */
/* ------------------------------------------------------------------ */

.ph-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2.5rem 1rem;
    text-align: center;
}

.ph-empty__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 999px;
    background-color: #F4F5F7;
    color: var(--ph-text-muted);
}

.ph-empty__icon svg { width: 1.25rem; height: 1.25rem; }
.ph-empty__title { font-size: 0.9375rem; font-weight: 600; color: var(--ph-text-primary); }
.ph-empty__text  { font-size: 0.8125rem; color: var(--ph-text-secondary); max-width: 22rem; }

.ph-empty--error .ph-empty__icon { background-color: var(--ph-danger-light); color: var(--ph-danger); }

.ph-skeleton {
    background: linear-gradient(90deg, #EEF0F3 25%, #F6F7F9 37%, #EEF0F3 63%);
    background-size: 400% 100%;
    animation: ph-skeleton 1.4s ease infinite;
    border-radius: 6px;
}

@keyframes ph-skeleton {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
    .ph-skeleton { animation: none; }
    * { transition-duration: 0.01ms !important; }
}

/* ------------------------------------------------------------------ */
/* Grille du tableau de bord                                           */
/* ------------------------------------------------------------------ */

/*
 * La disposition en colonnes du tableau de bord est celle de Filament :
 * chaque widget declare son columnSpan et la page sa grille. Une carte doit
 * donc remplir la cellule qui lui est allouee, sinon deux cartes voisines
 * n'ont pas la meme hauteur.
 */
.fi-wi-widget > .ph-card {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.fi-wi-widget > .ph-card > .ph-card__body {
    flex: 1 1 auto;
}

/* Tablette : deux indicateurs par ligne, graphiques empiles. */
@media (max-width: 1279px) {
    .ph-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Mobile : une carte par ligne, aucun debordement horizontal. */
@media (max-width: 767px) {
    .ph-kpi-grid { grid-template-columns: minmax(0, 1fr); }

    .ph-page-header { flex-direction: column; align-items: stretch; }
    .ph-page-header__actions { width: 100%; }
    .ph-page-header__actions > * { flex: 1; }
    .ph-page-header__title { font-size: 1.375rem; }

    .ph-kpi__spark { display: none; }

    .ph-distribution { flex-direction: column; align-items: stretch; }
    .ph-distribution__chart { align-self: center; }

    /* Les controles de la barre du haut restent atteignables au pouce. */
    .ph-topbar-control { height: 2.5rem; }
    .ph-topbar-control__select { max-width: 8rem; }
}

/* Focus visible partout, y compris sur les elements decores. */
.ph-kpi--clickable:focus-visible,
.ph-card__link:focus-visible,
.ph-alert__action:focus-visible,
.ph-segmented__item:focus-visible,
.ph-table th[aria-sort]:focus-visible {
    outline: 2px solid var(--ph-primary);
    outline-offset: 2px;
    border-radius: 6px;
}

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