/*
 * R6 Pricing Dashboard widget styles.
 *
 * Strategy:
 *   - Reuse the portal theme's KPI widget chrome via the
 *     .widget.basic-kpi class — the red `.top-section` styling
 *     comes free from portal-child/css/styles.css.
 *   - Override the theme's 36px .kpi-value (designed for big single
 *     numbers) so location names fit at a readable size.
 *   - Provide a fallback red header for contexts without the portal
 *     theme (preview server, other themes).
 *   - Body styling scoped under .r6-pricing-kpi so nothing leaks
 *     into actual KPI widgets sharing .basic-kpi.
 *
 * Price colour palette matches the admin dashboard:
 *   - red   #b91c1c — competitor undercutting customer
 *   - green #15803d — competitor priced higher than customer
 *   - blue  #2563eb — promo / discount lines
 */

/* ---------- Collapsible details / summary ----------------------- */
/*
 * The card body lives inside a <details> element so the whole tile
 * can collapse / expand by clicking the red header. Native HTML
 * mechanism — no JS required, works back to Safari 6 / Chrome 12 /
 * Firefox 49.
 */
.r6-pricing-kpi__details > summary {
    cursor: pointer;
    list-style: none;          /* hide the default disclosure marker */
    position: relative;
}
.r6-pricing-kpi__details > summary::-webkit-details-marker {
    display: none;             /* the -webkit variant of the same */
}

/* Print button — sits in the header right side, to the LEFT of
 * the refresh button. Visible to all visitors (the underlying
 * print route is signed-URL-gated, not session-gated). Same visual
 * style as the refresh button so they read as a paired toolbar.
 *
 * It's an <a> element (the refresh button is a <button>), which
 * means the host theme's `#main-content a { color: … }` and
 * `text-transform` rules win unless our selector matches at the
 * same depth. The paired declarations under
 * `#main-content .widget.basic-kpi.r6-pricing-kpi` add enough
 * specificity to beat any theme-level link rules.
 */
.r6-pricing-kpi__print,
.r6-pricing-kpi__print:link,
.r6-pricing-kpi__print:visited,
.r6-pricing-kpi__print:hover,
.r6-pricing-kpi__print:focus,
.r6-pricing-kpi__print:active {
    color: #ffffff;
    text-decoration: none;
    text-transform: none;
    letter-spacing: 0;
}
.r6-pricing-kpi__print {
    position: absolute;
    top: 50%;
    right: 156px;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 4px;
    padding: 4px 10px 4px 8px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    transition: background-color 0.15s ease-out;
}
.r6-pricing-kpi__print:hover,
.r6-pricing-kpi__print:focus {
    background: rgba(255, 255, 255, 0.28);
}

/* Portal-context specificity bumps — beat
 * `#main-content a { color: ... }` and any theme uppercase rules. */
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__print,
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__print:link,
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__print:visited,
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__print:hover,
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__print:focus,
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__print:active {
    color: #ffffff;
    text-decoration: none;
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
}
.r6-pricing-kpi__print-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
}
.r6-pricing-kpi__print-icon > svg {
    display: block;
    width: 16px;
    height: 16px;
}

/* Refresh button — sits in the header right side, to the LEFT of
 * the chevron. Only rendered to logged-in WP users. Lives outside
 * the <summary> so clicking it doesn't toggle the collapse state.
 *
 * Pinned absolutely so it stays in place regardless of header text
 * length. The whole header has `position: relative` via the
 * fallback `.top-section` rule below.
 */
.r6-pricing-kpi__refresh {
    position: absolute;
    top: 50%;
    right: 64px;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #ffffff;
    border-radius: 4px;
    padding: 4px 10px 4px 8px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    transition: background-color 0.15s ease-out, opacity 0.15s ease-out;
}
.r6-pricing-kpi__refresh:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.28);
}
.r6-pricing-kpi__refresh:disabled {
    cursor: wait;
    opacity: 0.7;
}
/*
 * Success / error states use a solid white background with coloured
 * text instead of a translucent colour wash. Translucent green over
 * the red header muddies into a khaki brown that doesn't read as
 * "success" — solid white with strong green text is unmistakable.
 */
.r6-pricing-kpi__refresh.is-success {
    background: #ffffff;
    color: #166534;
    border-color: #ffffff;
}
.r6-pricing-kpi__refresh.is-error {
    background: #ffffff;
    color: #991b1b;
    border-color: #ffffff;
}

.r6-pricing-kpi__refresh-icon {
    /*
     * Fixed-size inline-flex centre so the rotation box matches
     * whatever glyph or SVG lives inside. The default state is an
     * inline <svg> with a geometric path centred in its viewBox —
     * rotates wobble-free. Success/error states drop in checkmark
     * and cross text glyphs; flex centring keeps them visually
     * aligned with the SVG's footprint.
     */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    line-height: 1;
    font-size: 16px;
    transform-origin: 50% 50%;
}
.r6-pricing-kpi__refresh-icon > svg {
    display: block;
    width: 16px;
    height: 16px;
}
/* `⟳` spinner — rotate while the request is in flight. */
.r6-pricing-kpi__refresh-icon.is-spinning {
    animation: r6-pricing-kpi-spin 0.9s linear infinite;
}
@keyframes r6-pricing-kpi-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Custom chevron pinned to the right edge of the header. Renders
 * sideways (▸) when the card is collapsed; rotates 90° to point
 * down (▾) when expanded. Matches the common file-explorer /
 * "tree node" idiom for collapsible regions.
 *
 * Vertically centred via top:50% + transform-translate trick so it
 * sits in line with the kpi-value text regardless of header
 * padding. */
.r6-pricing-kpi__chevron {
    position: absolute;
    top: 50%;
    right: 24px;
    color: #ffffff;
    font-size: 28px;
    line-height: 1;
    transform: translateY(-50%);
    transition: transform 0.18s ease-out;
}
.r6-pricing-kpi__details[open] > summary .r6-pricing-kpi__chevron {
    transform: translateY(-50%) rotate(90deg);
}
.r6-pricing-kpi__details > summary:hover .r6-pricing-kpi__chevron {
    color: #ffffff;
}
.r6-pricing-kpi__details > summary:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: -2px;
}

/* ---------- Header colour --------------------------------------- */
/*
 * Use the darker move-ins / occupancy shade (#ba2434), not the
 * default .basic-kpi red (#e02811). Distinguishes pricing widgets
 * from the other KPI tiles at a glance.
 *
 * Two declarations:
 *   1. Fallback for contexts without #main-content (preview server,
 *      themes other than portal-child).
 *   2. Higher-specificity override below for the portal context,
 *      which needs to beat the theme's #main-content .widget.basic-kpi
 *      .top-section { background: #e02811 } rule.
 */
.r6-pricing-kpi .top-section {
    background: #ba2434;
    color: #ffffff;
    padding: 16px 20px 20px;
    border-radius: 6px 6px 0 0;
    position: relative;
}
.r6-pricing-kpi .top-section .kpi-value,
.r6-pricing-kpi .top-section .kpi-name {
    color: #ffffff;
}
.r6-pricing-kpi .top-section .kpi-name {
    margin: 0 0 6px;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 600;
    opacity: 0.95;
}
.r6-pricing-kpi .top-section .kpi-value {
    margin: 0 0 4px;
    font-size: 26px;
    line-height: 1.15;
    font-weight: 700;
}

/* Custom subtitle for the "As of <date>" — NOT .kpi-legend, which
 * the theme styles with word-spacing: 5ch (designed for split
 * "Actual / Projected" labels in KPI tiles). */
.r6-pricing-kpi__as-of {
    margin: 4px 0 0 !important;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    word-spacing: normal;
    letter-spacing: 0;
    text-transform: none;
    font-style: italic;
}

/* Portal-context override: beat the theme's
 * `#main-content .widget.basic-kpi .top-section { background: #e02811 }`
 * by adding `.r6-pricing-kpi` to bump specificity. */
#main-content .widget.basic-kpi.r6-pricing-kpi .intern-padding .top-section {
    background-color: #ba2434;
}

/* The theme sizes .kpi-value at 36px for big numbers. Location names
 * read better at 26px and don't wrap on "Coburg North". Override
 * with higher specificity than the theme rule. */
#main-content .widget.basic-kpi.r6-pricing-kpi .intern-padding .top-section p.kpi-value {
    font-size: 26px;
    line-height: 1.15;
}
/* Match override for our :as-of class in the portal context. */
#main-content .widget.basic-kpi.r6-pricing-kpi .intern-padding .top-section p.r6-pricing-kpi__as-of {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    word-spacing: normal;
    letter-spacing: 0;
}

/* ---------- Card chrome ------------------------------------------ */
/*
 * Minimal — the theme's `.box` class already gives us the white
 * background, 5px border-radius, and soft shadow that the existing
 * KPI tiles use. We just clip overflow so our header's 6px corner
 * radius doesn't poke past the `.box` outline, and add a bit of
 * margin between stacked widgets.
 *
 * The previous version of this rule layered its own border +
 * shadow on top of `.box` because the page used to have a white
 * #main-content wrapper that the widget melted into. Now that the
 * page uses the Pricing Dashboard template with a transparent body,
 * `.box`'s native chrome reads correctly on its own.
 */
.r6-pricing-kpi {
    overflow: hidden;
    margin-bottom: 1.5rem;
}

/* ---------- Body ------------------------------------------------ */
.r6-pricing-kpi__body {
    padding: 16px 20px 20px;
    color: #0f172a;
    line-height: 1.55;
    /*
     * Larger base font size. Use higher specificity than the theme's
     * default body rules so this actually wins on the portal —
     * `#main-content .widget` styles are surprisingly aggressive.
     */
    font-size: 16px;
}
#main-content .widget.basic-kpi.r6-pricing-kpi .intern-padding .r6-pricing-kpi__body {
    font-size: 16px;
    line-height: 1.55;
}

.r6-pricing-kpi__summary {
    margin: 0.5rem 0;
    color: #1e293b;
    font-size: 15px;
}
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__summary {
    font-size: 15px;
}
.r6-pricing-kpi__summary--positioning {
    font-weight: 600;
}

.r6-pricing-kpi__empty {
    padding: 0.75rem 1rem;
    background: #fef3c7;
    color: #78350f;
    border-radius: 0.5rem;
}

/* ---------- Pricing table ----------------------------------------- */
.r6-pricing-kpi__table-wrap {
    overflow-x: auto;
    margin-top: 1rem;
}

.r6-pricing-kpi__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__table { font-size: 15px; }

.r6-pricing-kpi__table th,
.r6-pricing-kpi__table td {
    padding: 0.8rem 1rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: top;
    font-size: 15px;
}
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__table th,
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__table td {
    font-size: 15px;
}

.r6-pricing-kpi__table thead th {
    font-weight: 700;
    color: #b91c1c;          /* matches the red header band for visual cohesion */
    border-bottom: 2px solid #cbd5e1;
    background: transparent;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}
.r6-pricing-kpi__table thead th a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}

.r6-pricing-kpi__table tbody th {
    font-weight: 600;
    color: #0f172a;
    background: transparent;
}

/* Alternate row striping subtly — matches the .previous-month rows
 * on the existing KPI widgets, which have a soft bottom border. */
.r6-pricing-kpi__table tbody tr {
    background: transparent;
}
.r6-pricing-kpi__table tbody tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.025);
}

/* ---------- Cell content ------------------------------------------ */
.r6-pricing-kpi__cell-row {
    line-height: 1.4;
}

.r6-pricing-kpi__cell + .r6-pricing-kpi__cell {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed #e2e8f0;
}

/* Price colour palette — mirrors the Laravel dashboard exactly. */
.r6-pricing-kpi__price {
    font-weight: 700;
    font-size: 17px;
}
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__price {
    font-size: 17px;
}
.r6-pricing-kpi__price small {
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.7;
    margin-left: 1px;
}
.r6-pricing-kpi__price--neutral { color: #0f172a; }
.r6-pricing-kpi__price--up      { color: #15803d; }  /* competitor priced higher than customer */
.r6-pricing-kpi__price--down    { color: #b91c1c; }  /* competitor undercutting */

.r6-pricing-kpi__arrow {
    font-size: 0.75rem;
    margin-left: 0.15rem;
}
.r6-pricing-kpi__arrow--up   { color: #16a34a; }
.r6-pricing-kpi__arrow--down { color: #dc2626; }

.r6-pricing-kpi__size {
    color: #64748b;
    font-size: 13px;
    margin-left: 0.25rem;
}
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__size {
    font-size: 13px;
}

/* Floor badge — inline colours come from the API (per-floor
 * bg/text), so no per-floor rules here. */
.r6-pricing-kpi__floor {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.4;
    vertical-align: 0.1em;
}
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__floor {
    font-size: 11px;
    padding: 2px 6px;
}

/* Promo + discount lines — blue, matching the dashboard. */
.r6-pricing-kpi__promo {
    color: #2563eb;
    font-size: 13px;
    font-weight: 600;
    margin-top: 0.2rem;
}
.r6-pricing-kpi__discounted {
    color: #2563eb;
    font-size: 13px;
    margin-top: 0.05rem;
}
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__promo,
#main-content .widget.basic-kpi.r6-pricing-kpi .r6-pricing-kpi__discounted {
    font-size: 13px;
}

.r6-pricing-kpi__quote {
    color: #92400e;
    font-style: italic;
}
.r6-pricing-kpi__empty-cell {
    color: #cbd5e1;
}

/* Compact "j/n" freshness label below each cell. Same shape as the
 * Laravel dashboard's per-cell scraped-at indicator — small, muted
 * grey so it reads as metadata rather than competing with the
 * price + promo lines above. */
.r6-pricing-kpi__scraped-at {
    display: block;
    color: #94a3b8;
    font-size: 11px;
    margin-top: 0.15rem;
    font-variant-numeric: tabular-nums;   /* so 5/5 and 19/5 align */
}

/* ---------- "+N more" expander ----------------------------------- */
.r6-pricing-kpi__more {
    margin-top: 0.5rem;
}
.r6-pricing-kpi__more > summary {
    cursor: pointer;
    color: #b73c10;
    font-size: 0.85rem;
    font-weight: 600;
    user-select: none;
    list-style: none;
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
}
.r6-pricing-kpi__more > summary::-webkit-details-marker { display: none; }
.r6-pricing-kpi__more > summary:hover { background: rgba(183, 60, 16, 0.08); }
.r6-pricing-kpi__more[open] > summary::after { content: ' (close)'; opacity: 0.6; font-weight: 400; }

/* ---------- Floor legend ----------------------------------------- */
.r6-pricing-kpi__legend {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem 1.25rem;
    font-size: 0.85rem;
    color: #475569;
}
.r6-pricing-kpi__legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

/* ---------- Error notices (shared back-compat class) ------------- */
.r6-pricing-dashboard--error {
    padding: 1rem;
    background: #fef3c7;
    color: #78350f;
    border-radius: 0.5rem;
    margin: 0.5rem 0;
}
