/* ============================================================
   EMAROX PROFIT — full-screen orders & profitability workspace
   Dark-only, built on the :root tokens from style.css.
   NEVER hardcode #06b6d4 here: body.tir-mode swaps --neon-cyan
   to amber, and PROFIT should follow the map's mode for free.
   ============================================================ */

#profit-view {
    /* Above all map chrome (.mission-bar 999, .header-controls 1001) but BELOW
       .modal-overlay (9999) so SETTINGS / AI scanner / CyberModal still open on
       top of PROFIT without any stacking rewrite. */
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: none;
    flex-direction: column;
    background: var(--bg-deep);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
}

#profit-view.active {
    display: flex;
    animation: pfViewIn 0.22s cubic-bezier(0.23, 1, 0.32, 1) both;
}

@keyframes pfViewIn {
    from { opacity: 0; transform: scale(0.985); }
    to   { opacity: 1; transform: scale(1); }
}

/* Ambient wash so the flat #0f172a doesn't read as dead space */
#profit-view::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(900px 420px at 18% -8%, rgba(6, 182, 212, 0.07), transparent 70%),
        radial-gradient(700px 380px at 88% 4%, rgba(0, 255, 148, 0.045), transparent 70%);
}

/* ─────────────────────────────────────────────
   HEADER — modes + section tabs + close
   ───────────────────────────────────────────── */

#profit-header {
    position: relative;
    z-index: 2;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 0 22px;
    height: 60px;
    background: #141e2b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* Mode switch — the "map is just a mode" model, surfaced where there is room */
.pf-modes {
    display: flex;
    gap: 3px;
    padding: 3px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 22px;
    flex-shrink: 0;
}

.pf-mode {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 15px;
    border: none;
    border-radius: 18px;
    background: transparent;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s ease, background 0.2s ease;
}

.pf-mode i { font-size: 12px; }
.pf-mode:hover { color: var(--text-main); background: rgba(255, 255, 255, 0.04); }
.pf-mode:active { transform: scale(0.96); }

.pf-mode.is-active {
    background: var(--neon-cyan);
    color: #04121a;
    box-shadow: 0 0 16px rgba(6, 182, 212, 0.32);
}

.pf-mode.is-active:hover { background: var(--neon-cyan); color: #04121a; }

/* Section tabs with a sliding ink bar */
#profit-tabs {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

#profit-tabs::-webkit-scrollbar { display: none; }

.pf-tab {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
    padding: 0 15px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.9px;
    text-transform: uppercase;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s ease;
}

.pf-tab i { font-size: 12px; opacity: 0.75; transition: opacity 0.2s ease; }
.pf-tab:hover { color: var(--text-main); }
.pf-tab:hover i { opacity: 1; }
.pf-tab.is-active { color: var(--neon-cyan); }
.pf-tab.is-active i { opacity: 1; }

.pf-tab-ink {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    width: 0;
    border-radius: 2px 2px 0 0;
    background: var(--neon-cyan);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.6);
    /* transform-driven so the slide stays on the compositor */
    transform: translateX(0);
    transition: transform 0.28s cubic-bezier(0.23, 1, 0.32, 1),
                width 0.28s cubic-bezier(0.23, 1, 0.32, 1);
    pointer-events: none;
}

.pf-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.pf-icon-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.pf-icon-btn:hover {
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.07);
}

.pf-icon-btn:active { transform: scale(0.94); }

/* ─────────────────────────────────────────────
   SUBBAR — month picker, fx chip, actions
   ───────────────────────────────────────────── */

#profit-subbar {
    position: relative;
    z-index: 2;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    /* Wraps because the scope picker made this row long enough to overflow on a
       laptop; the spacer keeps the right-hand chips pinned while it fits. */
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 12px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(10px);
}

.pf-month {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
}

.pf-month button {
    width: 28px;
    height: 26px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.pf-month button:hover:not(:disabled) { color: var(--neon-cyan); background: rgba(255, 255, 255, 0.06); }
.pf-month button:active:not(:disabled) { transform: scale(0.9); }
.pf-month button:disabled { opacity: 0.25; cursor: default; }

.pf-month-label {
    min-width: 132px;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.6px;
    color: var(--text-main);
    text-transform: uppercase;
}

.pf-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
}

.pf-chip b {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-main);
    font-weight: 700;
}

.pf-chip i { color: var(--neon-cyan); font-size: 11px; }
.pf-spacer { flex: 1; }

/* ── scope picker (date range / all orders) ──────────────────
   Sits next to the month stepper because it replaces it: these controls decide
   which documents are loaded, unlike the per-screen filter bar which only
   narrows what is already in memory. */

.pf-scope {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pf-scope .glass-input {
    margin-bottom: 0;
    height: 32px;
    padding: 0 10px;
    font-size: 11px;
}

.pf-scope-date { width: 138px; }

.pf-scope-chip {
    text-transform: none;
    letter-spacing: 0.4px;
}

@media (max-width: 900px) {
    .pf-scope { flex-wrap: wrap; gap: 8px; }
    .pf-scope-date { width: 122px; }
}

/* ─────────────────────────────────────────────
   SCREEN CANVAS
   ───────────────────────────────────────────── */

#profit-screen {
    position: relative;
    z-index: 1;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 22px;
    outline: none;
}

#profit-screen::-webkit-scrollbar { width: 8px; }
#profit-screen::-webkit-scrollbar-track { background: transparent; }
#profit-screen::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.09);
    border-radius: 10px;
}
#profit-screen::-webkit-scrollbar-thumb:hover { background: rgba(6, 182, 212, 0.45); }

.pf-section-title {
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 2.2px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    gap: 9px;
}

.pf-section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.09), transparent);
}

/* House entrance: fadeUp with a 70ms stagger, matching .tool-tile */
.pf-stagger > * {
    opacity: 0;
    transform: translateY(10px);
    animation: pfFadeUp 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    animation-delay: calc(var(--order, 0) * 55ms);
}

@keyframes pfFadeUp {
    to { opacity: 1; transform: translateY(0); }
}

/* ─────────────────────────────────────────────
   KPI CARDS
   ───────────────────────────────────────────── */

.pf-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 26px;
}

/* No backdrop-filter on the cards and panels: they sit on the flat, opaque
   #profit-view, so the blur showed nothing, yet it was re-rendered every
   frame while the KPIs counted up and the charts drew in, which made the
   opening stutter. */
.pf-kpi {
    position: relative;
    overflow: hidden;
    padding: 18px 20px 16px;
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    /* the house signature: accent hairline on the top edge only */
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    /* L1 dashboard rule: hover highlights the border, it does NOT lift the card —
       lifting hurts scanability in a dense information grid */
    transition: border-color 0.25s ease, background 0.25s ease;
}

.pf-kpi:hover {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(15, 23, 42, 0.62);
}

.pf-kpi::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.05), transparent 72%);
}

.pf-kpi-label {
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.pf-kpi-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 26px;
    line-height: 1.05;
    letter-spacing: -0.4px;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}

.pf-kpi-sub {
    margin-top: 7px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.pf-kpi.accent-cyan  { border-top-color: rgba(6, 182, 212, 0.55); }
.pf-kpi.accent-green { border-top-color: rgba(0, 255, 148, 0.5); }
.pf-kpi.accent-red   { border-top-color: rgba(255, 69, 69, 0.5); }
.pf-kpi.accent-amber { border-top-color: rgba(255, 152, 0, 0.5); }

.pf-kpi.accent-cyan  .pf-kpi-label i { color: var(--neon-cyan); }
.pf-kpi.accent-green .pf-kpi-label i { color: var(--neon-green); }
.pf-kpi.accent-red   .pf-kpi-label i { color: var(--neon-red); }
.pf-kpi.accent-amber .pf-kpi-label i { color: var(--neon-amber); }

.pf-pos { color: var(--neon-green); }
.pf-neg { color: var(--neon-red); }

/* ─────────────────────────────────────────────
   PANELS & CHARTS
   ───────────────────────────────────────────── */

.pf-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
    margin-bottom: 26px;
}

.pf-panel {
    padding: 20px;
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: border-color 0.25s ease;
}

.pf-panel:hover { border-color: rgba(255, 255, 255, 0.1); }

.pf-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 2.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.pf-panel-head i { filter: drop-shadow(0 0 8px currentColor); }

.pf-chart-wrap {
    position: relative;
    width: 100%;
    height: 250px;
}

/* ─────────────────────────────────────────────
   TABLES
   ───────────────────────────────────────────── */

.pf-table-wrap {
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

/* This element is the scroll container, which is what makes `position:sticky`
   on <th> actually work: sticking to #profit-screen instead would fail, because
   an ancestor with overflow already captures the sticky context. */
.pf-table-scroll {
    overflow: auto;
    max-height: calc(100vh - 268px);
    overscroll-behavior: contain;
}

.pf-table-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.pf-table-scroll::-webkit-scrollbar-track { background: transparent; }
.pf-table-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.09);
    border-radius: 10px;
}
.pf-table-scroll::-webkit-scrollbar-thumb:hover { background: rgba(6, 182, 212, 0.45); }

.pf-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.pf-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    text-align: left;
    padding: 13px 16px;
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: 1.3px;
    text-transform: uppercase;
    color: var(--text-muted);
    background: #16202e;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    white-space: nowrap;
    user-select: none;
}

.pf-table th.sortable { cursor: pointer; transition: color 0.15s ease; }
.pf-table th.sortable:hover { color: var(--text-main); }
.pf-table th .pf-sort { margin-left: 5px; opacity: 0.35; font-size: 9px; }
.pf-table th.sorted .pf-sort { opacity: 1; color: var(--neon-cyan); }
.pf-table th.sorted { color: var(--text-main); }

.pf-table td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    vertical-align: middle;
}

.pf-table tbody tr {
    transition: background 0.15s ease;
    cursor: pointer;
}

.pf-table tbody tr:hover { background: rgba(255, 255, 255, 0.035); }
.pf-table tbody tr:last-child td { border-bottom: none; }

/* Every number is mono — the app's strongest visual signature */
.pf-num {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

th.pf-num { text-align: right; }

.pf-muted { color: var(--text-muted); }
.pf-strong { font-weight: 600; }

.pf-route-cell {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
}

.pf-route-cell i { font-size: 8px; color: var(--neon-cyan); opacity: 0.7; }

.pf-cc {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 11px;
    color: var(--text-main);
}

.pf-route-cities {
    margin-left: 4px;
    max-width: 210px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Status + margin pills */
.pf-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 5px;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    white-space: nowrap;
}

.pf-pill.ok   { background: rgba(0, 255, 148, 0.1);  border: 1px solid rgba(0, 255, 148, 0.35);  color: var(--neon-green); }
.pf-pill.warn { background: rgba(255, 152, 0, 0.1);  border: 1px solid rgba(255, 152, 0, 0.35);  color: var(--neon-amber); }
.pf-pill.bad  { background: rgba(255, 69, 69, 0.1);  border: 1px solid rgba(255, 69, 69, 0.35);  color: var(--neon-red); }
.pf-pill.neutral { background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.12); color: var(--text-muted); }

/* Inline margin bar — reads faster than a bare percentage.
   Fixed width, or it stretches the cell and overflows the table. */
.pf-margin-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    width: 76px;
    margin-left: auto;
}

.pf-bar {
    position: relative;
    width: 76px;
    height: 4px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.07);
    overflow: hidden;
}

.pf-bar span {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: 3px;
    transform-origin: left center;
    transform: scaleX(0);
    animation: pfBarIn 0.55s cubic-bezier(0.23, 1, 0.32, 1) forwards;
    animation-delay: 0.1s;
}

@keyframes pfBarIn { to { transform: scaleX(1); } }

.pf-bar span.ok   { background: var(--neon-green); }
.pf-bar span.warn { background: var(--neon-amber); }
.pf-bar span.bad  { background: var(--neon-red); }

/* ─────────────────────────────────────────────
   BUTTONS
   ───────────────────────────────────────────── */

.pf-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.pf-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(255, 255, 255, 0.22); }
.pf-btn:active { transform: scale(0.97); }

.pf-btn.primary {
    background: var(--neon-cyan);
    border-color: var(--neon-cyan);
    color: #04121a;
    box-shadow: 0 4px 18px rgba(6, 182, 212, 0.28);
}

.pf-btn.primary:hover { filter: brightness(1.1); background: var(--neon-cyan); }
.pf-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pf-btn:disabled:active { transform: none; }

/* ─────────────────────────────────────────────
   SKELETONS / EMPTY / ERROR
   ───────────────────────────────────────────── */

.pf-skel {
    border-radius: 8px;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0.045) 25%,
        rgba(255, 255, 255, 0.09) 37%,
        rgba(255, 255, 255, 0.045) 63%);
    background-size: 400% 100%;
    animation: pfShimmer 1.3s ease-in-out infinite;
}

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

.pf-skel-line { height: 12px; margin: 9px 0; }
.pf-skel-kpi  { height: 104px; border-radius: 18px; }
.pf-skel-row  { height: 44px; margin: 0 0 1px; border-radius: 0; }

.pf-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 66px 24px;
    text-align: center;
    color: var(--text-muted);
}

.pf-empty i { font-size: 34px; opacity: 0.28; }
.pf-empty h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--text-main);
}
.pf-empty p { margin: 0; font-size: 12px; max-width: 400px; line-height: 1.6; }

.pf-error {
    border-color: rgba(255, 69, 69, 0.3);
}
.pf-error .pf-empty i { color: var(--neon-red); opacity: 0.5; }

/* ─────────────────────────────────────────────
   RESPONSIVE
   ───────────────────────────────────────────── */

@media (max-width: 1024px) {
    .pf-tab span { display: none; }
    .pf-tab { padding: 0 14px; }
    .pf-tab i { font-size: 14px; opacity: 0.9; }
}

@media (max-width: 768px) {
    #profit-header { height: 54px; padding: 0 12px; gap: 12px; }
    .pf-mode span { display: none; }
    .pf-mode { padding: 7px 12px; }
    #profit-subbar { padding: 10px 12px; gap: 10px; flex-wrap: wrap; }
    .pf-month-label { min-width: 104px; font-size: 11px; }
    #profit-screen { padding: 14px; }
    .pf-kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .pf-kpi { padding: 14px; border-radius: 14px; }
    .pf-kpi-value { font-size: 19px; }
    .pf-grid-2 { grid-template-columns: 1fr; }
    .pf-chart-wrap { height: 210px; }

    /* Tables become cards — a 9-column financial table is unusable at 375px */
    .pf-table thead { display: none; }
    .pf-table, .pf-table tbody, .pf-table tr, .pf-table td { display: block; width: 100%; }
    /* Each row becomes its own card, so the eye can tell where one order ends
       and the next begins without a header to align against. */
    .pf-table-wrap {
        background: transparent;
        backdrop-filter: none;
        border: none;
        overflow: visible;
    }

    .pf-table tr {
        padding: 12px 14px;
        margin-bottom: 10px;
        border-radius: 14px;
        background: rgba(15, 23, 42, 0.55);
        border: 1px solid rgba(255, 255, 255, 0.06);
        border-top: 1px solid rgba(255, 255, 255, 0.11);
    }

    .pf-table tbody tr:hover { background: rgba(15, 23, 42, 0.55); }
    .pf-table tbody tr:active { background: rgba(6, 182, 212, 0.07); }
    .pf-margin-cell { flex-direction: row; align-items: center; gap: 9px; width: auto; }
    .pf-bar { width: 60px; }
    .pf-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        padding: 4px 0;
        border: none;
        font-size: 12px;
    }
    .pf-table td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: 9px;
        font-weight: 800;
        letter-spacing: 1px;
        text-transform: uppercase;
        color: var(--text-muted);
    }
    .pf-table td.pf-hide-mobile { display: none; }
    .pf-num { text-align: right; }
    .pf-table-scroll { max-height: none; }
    .pf-route-cities { max-width: 150px; }
}

@media (max-width: 480px) {
    .pf-kpi-grid { grid-template-columns: 1fr; }
}

/* ─────────────────────────────────────────────
   MAP-SIDE CHROME
   Two small additions to the map screen. The map layout itself is
   deliberately untouched — no repositioned HUD, no new floating bar.
   ───────────────────────────────────────────── */

/* PROFIT reads as the second half of the product, not as one more modal
   sitting between HISTORY and SETTINGS. */
.header-controls .nav-btn-profit {
    position: relative;
    color: var(--neon-cyan);
    border-color: rgba(6, 182, 212, 0.4) !important;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.16), rgba(6, 182, 212, 0.04)) !important;
}

.header-controls .nav-btn-profit:hover {
    color: var(--text-main);
    border-color: var(--neon-cyan) !important;
    box-shadow: 0 0 18px rgba(6, 182, 212, 0.28);
}

.header-controls .nav-btn-profit:active { transform: scale(0.96); }

/* ZAPISZ ZLECENIE — the single bridge from a calculation into the register */
.save-order-btn {
    width: 100%;
    margin-top: 16px;
    padding: 13px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border-radius: 9px;
    border: 1px solid rgba(6, 182, 212, 0.45);
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.18), rgba(6, 182, 212, 0.05));
    color: var(--neon-cyan);
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.3px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.22s ease, border-color 0.22s ease,
                color 0.22s ease, box-shadow 0.22s ease;
}

.save-order-btn:hover:not(:disabled) {
    background: var(--neon-cyan);
    border-color: var(--neon-cyan);
    color: #04121a;
    box-shadow: 0 6px 22px rgba(6, 182, 212, 0.32);
}

.save-order-btn:active:not(:disabled) { transform: scale(0.98); }

.save-order-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
}

.save-order-btn.is-saved {
    border-color: rgba(0, 255, 148, 0.5);
    background: linear-gradient(135deg, rgba(0, 255, 148, 0.16), rgba(0, 255, 148, 0.04));
    color: var(--neon-green);
}

.save-order-btn.is-saved:hover:not(:disabled) {
    background: var(--neon-green);
    border-color: var(--neon-green);
    color: #04140c;
    box-shadow: 0 6px 22px rgba(0, 255, 148, 0.3);
}

/* After an AI scan: "review the route, then save here". */
.save-order-btn.attention:not(:disabled) {
    animation: pf-save-attention 1.1s ease-in-out infinite;
}

@keyframes pf-save-attention {
    0%, 100% { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.55); }
    50% { box-shadow: 0 0 0 7px rgba(6, 182, 212, 0); }
}

@keyframes pf-save-attention-tir {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.55); }
    50% { box-shadow: 0 0 0 7px rgba(255, 152, 0, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .save-order-btn.attention:not(:disabled) { animation: none; }
}

/* ─────────────────────────────────────────────
   TIR MODE
   --neon-cyan already turns amber in TIR; these are the places that had the
   cyan hardcoded as rgba(6,182,212,…). Disabled / ZAPISANE keep their looks.
   ───────────────────────────────────────────── */

body.tir-mode .save-order-btn:not(:disabled):not(.is-saved) {
    border-color: rgba(255, 152, 0, 0.45);
    background: linear-gradient(135deg, rgba(255, 152, 0, 0.18), rgba(255, 152, 0, 0.05));
}

body.tir-mode .save-order-btn:not(.is-saved):hover:not(:disabled) {
    background: var(--neon-cyan);
    box-shadow: 0 6px 22px rgba(255, 152, 0, 0.32);
}

body.tir-mode .save-order-btn.attention:not(:disabled) {
    animation-name: pf-save-attention-tir;
}

body.tir-mode #pf-modal .modal-content {
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.9), 0 0 20px rgba(255, 152, 0, 0.1);
}

body.tir-mode .pf-btn.primary {
    box-shadow: 0 4px 18px rgba(255, 152, 0, 0.28);
}

body.tir-mode .pf-dup-note {
    border-color: rgba(255, 152, 0, 0.28);
    border-left-color: var(--neon-cyan);
    background: rgba(255, 152, 0, 0.06);
}

body.tir-mode .pf-preview-card {
    border-top-color: rgba(255, 152, 0, 0.4);
}

/* Amber is the TIR accent, so "missing" switches to red to stay distinct. */
body.tir-mode .pf-missing,
body.tir-mode .pf-combo.pf-missing > .glass-input {
    border-color: #ff5a5a !important;
    box-shadow: 0 0 0 1px rgba(255, 90, 90, 0.18) inset;
}

body.tir-mode .pf-combo.pf-missing {
    box-shadow: none;
}

body.tir-mode .pf-missing-note {
    border-color: rgba(255, 90, 90, 0.3);
    border-left-color: #ff5a5a;
    background: rgba(255, 90, 90, 0.07);
    color: #ff7a7a;
}

body.tir-mode .pf-combo-list {
    border-color: rgba(255, 152, 0, 0.35);
}

body.tir-mode .pf-combo-opt:hover,
body.tir-mode .pf-combo-opt.is-active {
    background: rgba(255, 152, 0, 0.14);
}

/* Result preview at the top of the save modal */
.pf-preview-card {
    padding: 14px 16px;
    margin-bottom: 18px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-top: 1px solid rgba(6, 182, 212, 0.4);
}

/* ── type-ahead picker (vehicle / driver) ── */

.pf-combo {
    position: relative;
}

.pf-combo > .glass-input {
    width: 100%;
    padding-right: 34px;
}

.pf-combo-toggle {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--neon-cyan);
    font-size: 11px;
    cursor: pointer;
}

.pf-combo-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* The flag class sits on the wrapper; draw it on the input. */
.pf-combo.pf-missing {
    box-shadow: none;
}

.pf-combo.pf-missing > .glass-input {
    border-color: var(--neon-amber, #FF9800) !important;
    box-shadow: 0 0 0 1px rgba(255, 152, 0, 0.18) inset;
}

.pf-combo-list {
    position: fixed;
    z-index: 10060;
    max-height: 240px;
    overflow-y: auto;
    padding: 4px;
    border-radius: 10px;
    background: rgba(10, 16, 30, 0.98);
    border: 1px solid rgba(6, 182, 212, 0.35);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.6);
}

.pf-combo-opt {
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 12.5px;
    color: var(--text-main);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pf-combo-opt:hover,
.pf-combo-opt.is-active {
    background: rgba(6, 182, 212, 0.14);
}

.pf-combo-opt.is-current {
    color: var(--neon-cyan);
    font-weight: 700;
}

.pf-combo-empty {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-muted);
}

/* Figure + small second line (empty km, rate per km) in table cells */
.pf-cell-stack {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.pf-cell-sub {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── vehicle window tiles ── */

.pf-vtile {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.pf-vtile-label {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.pf-vtile-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
}

.pf-vtile-value.pf-pos { color: var(--neon-green); }
.pf-vtile-value.pf-neg { color: var(--neon-red); }

.pf-vtile-sub {
    font-size: 10px;
    color: var(--text-muted);
}

/* ── vehicle window ── */

.pf-vtiles {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

@media (max-width: 600px) {
    .pf-vtiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.pf-vsection {
    margin: 4px 0 10px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.pf-vsummary .pf-cbars { margin-bottom: 20px; }

/* Order cards: collapsed = scan line, open = route + costs + actions */
.pf-order-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pf-ocard {
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(255, 255, 255, 0.025);
    overflow: hidden;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.pf-ocard:hover { border-color: rgba(255, 255, 255, 0.14); }

.pf-ocard.is-open {
    border-color: rgba(6, 182, 212, 0.45);
    background: rgba(6, 182, 212, 0.04);
}

.pf-ocard.is-cancelled { opacity: 0.55; }

.pf-ocard-head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.pf-ocard-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.pf-ocard-date {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.pf-ocard-client {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pf-ocard-route {
    font-size: 11px;
    color: var(--text-muted);
}

.pf-ocard-figs {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    flex-shrink: 0;
}

.pf-ocard-rev {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
}

.pf-ocard-margin {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
}

.pf-ocard-chev {
    color: var(--text-muted);
    font-size: 11px;
    transition: transform 0.2s ease;
}

.pf-ocard.is-open .pf-ocard-chev {
    transform: rotate(180deg);
    color: var(--neon-cyan);
}

.pf-ocard-body {
    display: none;
    padding: 12px 14px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.pf-ocard.is-open .pf-ocard-body { display: block; }

.pf-ocard-actions,
.pf-doc-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pf-ocard-actions {
    justify-content: flex-end;
    margin-top: 14px;
}

.pf-doc-row { margin-bottom: 14px; }
.pf-ocard-actions .pf-doc-row { margin-bottom: 0; }

.pf-vempty {
    padding: 14px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* Attachment toggle in the save modal */
.pf-attach {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px dashed rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
}

.pf-attach input {
    margin-top: 2px;
    accent-color: var(--neon-cyan);
}

.pf-attach-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.pf-attach-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
}

.pf-attach-files {
    font-size: 11px;
    color: var(--text-muted);
    word-break: break-all;
}

body.tir-mode .pf-ocard.is-open {
    border-color: rgba(255, 152, 0, 0.45);
    background: rgba(255, 152, 0, 0.04);
}

/* ─────────────────────────────────────────────
   REDUCED MOTION
   The rest of the app has no such block. A financial dashboard is the
   wrong place to keep that gap: numbers must be legible immediately.
   ───────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    #profit-view.active,
    .pf-stagger > *,
    .pf-bar span,
    .pf-skel {
        animation: none !important;
    }
    .pf-stagger > * { opacity: 1 !important; transform: none !important; }
    .pf-bar span { transform: scaleX(1) !important; }
    .pf-skel { background: rgba(255, 255, 255, 0.06); }
    .pf-tab-ink { transition: none !important; }
    #profit-view *, #profit-view *::before, #profit-view *::after {
        transition-duration: 0.01ms !important;
    }
}

/* ── filter bar ──────────────────────────────────────────────
   Shared by Zlecenia / Flota / Klienci. Filtering is client-side on the
   month already loaded, so these controls never wait on the network. */

.pf-filterbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.pf-filterbar .glass-input {
    margin-bottom: 0;
    height: 34px;
    padding: 0 12px;
    font-size: 12px;
}

.pf-filter-search {
    flex: 1 1 240px;
    min-width: 180px;
    max-width: 420px;
}

.pf-filter-select { flex: 0 0 auto; }

.pf-filter-dates {
    display: flex;
    align-items: center;
    gap: 7px;
}

.pf-filter-date {
    width: 145px;
    font-family: 'JetBrains Mono', monospace;
}

/* Pushed to the far end: it reports on the row above rather than being
   another control to operate. */
.pf-filter-count {
    margin-left: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Cyan only while a filter is actually narrowing the list, so "you are looking
   at a subset" reads at a glance. */
.pf-filter-count.active {
    color: var(--neon-cyan);
    font-weight: 700;
}

@media (max-width: 768px) {
    .pf-filter-search { max-width: none; flex-basis: 100%; }
    .pf-filter-dates { flex: 1 1 100%; }
    .pf-filter-date { flex: 1 1 0; width: auto; }
    .pf-filter-count { margin-left: 0; flex-basis: 100%; }
}

/* ── missing / duplicate notices in the save modal ────────────
   The scanner fills this form from OCR, so "what did it fail to
   find?" has to be visible at a glance rather than discovered
   after saving. */

.pf-missing {
    border-color: var(--neon-amber, #FF9800) !important;
    box-shadow: 0 0 0 1px rgba(255, 152, 0, 0.18) inset;
}

/* Blocking: the save button is disabled until these are filled. */
.pf-missing-note {
    margin-top: 2px;
    padding: 9px 12px;
    border-radius: 9px;
    border: 1px solid rgba(255, 152, 0, 0.3);
    border-left: 3px solid var(--neon-amber, #FF9800);
    background: rgba(255, 152, 0, 0.07);
    color: var(--neon-amber, #FF9800);
    font-size: 11.5px;
    line-height: 1.5;
}

/* Non-blocking: order numbers legitimately repeat between clients, so this
   informs rather than prevents. */
.pf-dup-note {
    margin-top: 2px;
    padding: 9px 12px;
    border-radius: 9px;
    border: 1px solid rgba(6, 182, 212, 0.28);
    border-left: 3px solid var(--neon-cyan, #06b6d4);
    background: rgba(6, 182, 212, 0.06);
    color: var(--text-muted);
    font-size: 11.5px;
    line-height: 1.5;
}

/* ─────────────────────────────────────────────
   PRZEGLĄD v2 — cost bars, KPI deltas, period presets,
   "EMAROX widzi", drill-down windows
   ───────────────────────────────────────────── */

/* Cost bars. Deliberately NOT .pf-bar: that name is the 76 px margin bar in
   the tables, and sharing it clipped these rows to 4 px. */
.pf-cbars {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.pf-cbars-lead {
    margin: 0 0 4px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}

.pf-cbars-lead b { color: var(--text-main); font-weight: 700; }

.pf-cbar {
    display: grid;
    grid-template-columns: minmax(90px, 130px) minmax(40px, 1fr) auto 52px;
    align-items: center;
    gap: 12px;
    font-size: 12px;
}

.pf-cbar-label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--text-main);
}

.pf-cbar-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.pf-cbar-track {
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
}

.pf-cbar-fill {
    height: 100%;
    border-radius: 4px;
}

.pf-cbar-amt,
.pf-cbar-pct {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.pf-cbar-amt { color: var(--text-main); font-weight: 700; }
.pf-cbar-pct { color: var(--text-muted); font-size: 11px; }

.pf-cbar-total {
    margin-top: 2px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.pf-cbar-total .pf-cbar-label {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.pf-cbar-total .pf-cbar-track { background: none; height: 0; }

@media (max-width: 600px) {
    .pf-cbar {
        grid-template-columns: 1fr auto 46px;
        grid-template-areas: "label amt pct" "track track track";
        row-gap: 6px;
    }
    .pf-cbar-label { grid-area: label; }
    .pf-cbar-track { grid-area: track; }
    .pf-cbar-amt { grid-area: amt; }
    .pf-cbar-pct { grid-area: pct; }
}

/* KPI: change vs the previous period, and the clickable variant */
.pf-kpi-delta {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pf-kpi-delta .pf-kpi-vs {
    font-family: Inter, sans-serif;
    font-weight: 600;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
}

.pf-kpi-delta.good { color: var(--neon-green); }
.pf-kpi-delta.bad  { color: var(--neon-red); }

.pf-kpi.is-link { cursor: pointer; }

.pf-kpi.is-link:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 2px;
}

.pf-kpi .pf-kpi-label i.pf-kpi-go {
    margin-left: auto;
    font-size: 9px;
    color: var(--text-muted);
    opacity: 0.45;
    filter: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.pf-kpi.is-link:hover .pf-kpi-label i.pf-kpi-go {
    opacity: 1;
    transform: translateX(2px);
}

.pf-kpi-row2 { margin-top: -12px; }
.pf-kpi-row2 .pf-kpi-value { font-size: 21px; }

/* Conclusion above the trend chart: the sentence first, the chart as proof. */
.pf-trend-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 8px;
    margin: -4px 0 12px;
    font-size: 13px;
    font-weight: 800;
    color: var(--text-main);
}

.pf-trend-head i { font-size: 12px; }
.pf-trend-num { font-family: 'JetBrains Mono', monospace; }
.pf-trend-head.good i, .pf-trend-head.good .pf-trend-num { color: var(--neon-green); }
.pf-trend-head.bad i, .pf-trend-head.bad .pf-trend-num { color: var(--neon-red); }
.pf-trend-sub { font-size: 11px; font-weight: 600; color: var(--text-muted); }

/* Quick periods. Scrolls sideways on a phone instead of wrapping into rows. */
.pf-presets {
    display: flex;
    gap: 2px;
    max-width: 100%;
    padding: 3px;
    overflow-x: auto;
    scrollbar-width: none;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
}

.pf-presets::-webkit-scrollbar { display: none; }

.pf-presets button {
    flex-shrink: 0;
    height: 26px;
    padding: 0 10px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font-family: Inter, sans-serif;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.4px;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.2s ease, background 0.2s ease;
}

.pf-presets button:hover { color: var(--text-main); background: rgba(255, 255, 255, 0.06); }
.pf-presets button.is-active { color: #020617; background: var(--neon-cyan); }

/* ── the ANALIZA button ──────────────────────────────────────
   One thing to press. The working animation is cosmetic — the analysis itself
   takes milliseconds — so JS skips it entirely under reduced motion. */

.pf-analyze-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 6px 0 30px;
    padding: 26px 20px;
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.pf-analyze {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 260px;
    padding: 18px 40px;
    border: 1px solid rgba(6, 182, 212, 0.5);
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.22), rgba(6, 182, 212, 0.06));
    color: var(--text-main);
    font-family: Inter, sans-serif;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 2px;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(6, 182, 212, 0.15);
    transition: transform 0.2s ease, box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.pf-analyze:hover {
    transform: translateY(-1px);
    border-color: var(--neon-cyan);
    box-shadow: 0 16px 40px rgba(6, 182, 212, 0.3);
}

.pf-analyze:active { transform: translateY(0) scale(0.99); }
.pf-analyze:focus-visible { outline: 2px solid var(--neon-cyan); outline-offset: 3px; }

.pf-analyze-face { display: inline-flex; align-items: center; gap: 12px; }
.pf-analyze-face i { color: var(--neon-cyan); font-size: 16px; }

.pf-analyze-bar {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 3px;
    transform: scaleX(0);
    transform-origin: left center;
    background: var(--neon-cyan);
}

.pf-analyze.is-working { cursor: progress; border-color: var(--neon-cyan); }
.pf-analyze.is-working .pf-analyze-face { opacity: 0.75; }
.pf-analyze.is-working .pf-analyze-bar { animation: pfScan 1.1s cubic-bezier(0.4, 0, 0.2, 1) forwards; }

.pf-analyze.is-working::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 20%, rgba(6, 182, 212, 0.2) 50%, transparent 80%);
    animation: pfSweep 1.1s linear infinite;
}

@keyframes pfScan { to { transform: scaleX(1); } }
@keyframes pfSweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.pf-analyze-hint { font-size: 12px; color: var(--text-muted); }

.pf-analyze-status {
    min-height: 14px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.6px;
    color: var(--neon-cyan);
}

body.tir-mode .pf-analyze {
    border-color: rgba(255, 152, 0, 0.5);
    background: linear-gradient(135deg, rgba(255, 152, 0, 0.22), rgba(255, 152, 0, 0.06));
    box-shadow: 0 10px 30px rgba(255, 152, 0, 0.15);
}

body.tir-mode .pf-analyze:hover {
    border-color: var(--neon-amber, #FF9800);
    box-shadow: 0 16px 40px rgba(255, 152, 0, 0.3);
}

body.tir-mode .pf-analyze-face i,
body.tir-mode .pf-analyze-status { color: var(--neon-amber, #FF9800); }
body.tir-mode .pf-analyze-bar { background: var(--neon-amber, #FF9800); }
body.tir-mode .pf-analyze.is-working::after {
    background: linear-gradient(100deg, transparent 20%, rgba(255, 152, 0, 0.2) 50%, transparent 80%);
}

@media (max-width: 600px) {
    .pf-analyze-wrap { padding: 20px 14px; }
    .pf-analyze { min-width: 0; width: 100%; padding: 16px 18px; font-size: 14px; }
}

/* ── the analysis report ─────────────────────────────────────
   Semantic levels, one colour per meaning: green fine, yellow watch,
   amber worth fixing, red act now. */

.lvl-ok      { --lvl: var(--neon-green); }
.lvl-watch   { --lvl: #FACC15; }
.lvl-improve { --lvl: var(--neon-amber, #FF9800); }
.lvl-problem { --lvl: var(--neon-red); }

.pf-rep-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 14px;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.pf-rep-head > i { color: var(--lvl); font-size: 18px; }
.pf-rep-title { font-size: 15px; font-weight: 800; color: var(--text-main); }
.pf-rep-sub { font-size: 12px; line-height: 1.5; color: var(--text-muted); }
.pf-rep-sub b { color: var(--text-main); }

.pf-rep-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 22px;
}

.pf-rep-kpi {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.pf-rep-kpi-label {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.pf-rep-kpi-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
}

.pf-rep-kpi .pf-kpi-delta { margin-top: 2px; font-size: 10px; }

.pf-fcards { display: flex; flex-direction: column; gap: 10px; }

.pf-fcard {
    padding: 13px 15px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-left: 3px solid var(--lvl);
}

.pf-fcard-head {
    display: grid;
    grid-template-columns: 12px 1fr;
    gap: 10px;
    align-items: start;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-main);
}

.pf-fcard-head .pf-ins-dot { margin-top: 5px; }

.pf-fcard-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed rgba(255, 255, 255, 0.08);
}

.pf-fcard-do {
    display: flex;
    align-items: baseline;
    gap: 9px;
    flex: 1;
    min-width: 220px;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-muted);
}

.pf-fcard-do-label {
    flex-shrink: 0;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: var(--lvl);
}

.pf-fcard-do b { color: var(--text-main); font-weight: 700; }
.pf-fcard-note { margin-top: 7px; font-size: 10px; color: var(--text-muted); }

.pf-ins-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--lvl);
    box-shadow: 0 0 10px var(--lvl);
}

.pf-goods { display: flex; flex-direction: column; gap: 9px; margin-bottom: 18px; }

.pf-good {
    display: grid;
    grid-template-columns: 14px 1fr;
    gap: 10px;
    align-items: start;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-muted);
}

.pf-good > i { margin-top: 3px; font-size: 11px; color: var(--neon-green); }
.pf-good b { color: var(--text-main); font-weight: 700; }
.pf-dq > i { color: var(--neon-cyan); }

.pf-rep-foot { margin-top: 20px; }

.pf-copy-area {
    width: 100%;
    margin-top: 14px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}

.pf-btn.pf-btn-sm { padding: 6px 11px; font-size: 10px; }
.pf-ins-more { margin-top: 12px; }

.pf-ins-note {
    padding: 10px 0 2px;
    font-size: 12px;
    color: var(--text-muted);
}

/* On a phone the fix and the button stack; side by side, the sentence was
   squeezed into a column two words wide. */
@media (max-width: 600px) {
    .pf-fcard-foot { flex-direction: column; align-items: stretch; gap: 10px; }
    .pf-fcard-do { min-width: 0; flex-direction: column; gap: 4px; }
    .pf-fcard-foot .pf-btn { align-self: flex-start; }
}

/* The sheet the PDF is rendered on. Off-screen, A4 wide, and light: a dark
   dashboard palette on paper is unreadable, so the tokens are redefined here
   instead of fighting every component. */
.pf-pdf-surface {
    position: absolute;
    left: -10000px;
    top: 0;
    width: 794px;             /* A4 at 96 dpi */
    padding: 28px 32px;
    background: #ffffff;
    color: #111827;
    font-family: Inter, sans-serif;
    --text-main: #111827;
    --text-muted: #4b5563;
}

.pf-pdf-title {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid #111827;
}

.pf-pdf-title strong { font-size: 15px; font-weight: 800; letter-spacing: 1.4px; }
.pf-pdf-title span { font-size: 12px; color: #4b5563; }

.pf-pdf-surface .pf-fcard,
.pf-pdf-surface .pf-rep-kpi { background: #fff; border-color: #d1d5db; }

.pf-pdf-surface .pf-rep-head { border-bottom-color: #e5e7eb; }
.pf-pdf-surface .pf-fcard-foot { border-top-color: #d1d5db; }
.pf-pdf-surface .pf-why-track,
.pf-pdf-surface .pf-cbar-track { background: #e5e7eb; }
.pf-pdf-surface .pf-ins-dot { box-shadow: none; }
.pf-pdf-surface .pf-btn { display: none; }

/* Neon on white is unreadable; darker equivalents keep the same meaning. */
.pf-pdf-surface .lvl-ok      { --lvl: #047857; }
.pf-pdf-surface .lvl-watch   { --lvl: #b45309; }
.pf-pdf-surface .lvl-improve { --lvl: #c2410c; }
.pf-pdf-surface .lvl-problem { --lvl: #b91c1c; }

.pf-pdf-surface .pf-pos,
.pf-pdf-surface .pf-kpi-delta.good,
.pf-pdf-surface .pf-good > i { color: #047857; }

.pf-pdf-surface .pf-neg,
.pf-pdf-surface .pf-kpi-delta.bad { color: #b91c1c; }

.pf-pdf-surface .pf-dq > i { color: #1d4ed8; }
.pf-pdf-surface .pf-why-fill.good { background: #047857; }
.pf-pdf-surface .pf-why-fill.bad { background: #b91c1c; }
@media (prefers-reduced-motion: reduce) {
    .pf-analyze.is-working .pf-analyze-bar,
    .pf-analyze.is-working::after { animation: none !important; }
}

/* Drill-down windows: ranked rows and the margin-change breakdown */
.pf-rank {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
}

.pf-rank-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    font-family: inherit;
    font-size: 12px;
    text-align: left;
}

button.pf-rank-row { cursor: pointer; transition: border-color 0.2s ease, background 0.2s ease; }
button.pf-rank-row:hover { border-color: rgba(6, 182, 212, 0.4); background: rgba(6, 182, 212, 0.05); }

.pf-rank-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pf-rank-title { font-weight: 700; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pf-rank-sub { font-size: 10.5px; color: var(--text-muted); }

.pf-rank-fig {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    white-space: nowrap;
}

.pf-rank-fig small { font-size: 10.5px; font-weight: 600; color: var(--text-muted); }
.pf-rank-row.is-flag .pf-rank-sub { color: var(--neon-amber, #FF9800); }

/* Fleet table: the vehicle clearly above the fleet's empty share */
.pf-cell-sub.pf-flag { color: var(--neon-amber, #FF9800); font-weight: 700; }

.pf-why-lead {
    margin: 0 0 14px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-muted);
}

.pf-why-lead b { color: var(--text-main); }

.pf-why {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-bottom: 20px;
}

.pf-why-row {
    display: grid;
    grid-template-columns: minmax(96px, 150px) minmax(60px, 1fr) 72px;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-main);
}

.pf-why-track {
    position: relative;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.pf-why-track::before {
    content: '';
    position: absolute;
    left: 50%;
    top: -3px;
    bottom: -3px;
    width: 1px;
    background: rgba(255, 255, 255, 0.25);
}

.pf-why-fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.pf-why-fill.good { left: 50%; background: var(--neon-green); }
.pf-why-fill.bad  { right: 50%; background: var(--neon-red); }

.pf-why-val {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
}

.pf-note-small {
    margin: -8px 0 16px;
    font-size: 10.5px;
    line-height: 1.5;
    color: var(--text-muted);
}

body.tir-mode .pf-presets button.is-active { background: var(--neon-amber, #FF9800); }
body.tir-mode .pf-kpi.is-link:focus-visible { outline-color: var(--neon-amber, #FF9800); }
body.tir-mode button.pf-rank-row:hover { border-color: rgba(255, 152, 0, 0.45); background: rgba(255, 152, 0, 0.05); }

/* ── Driver periods: alerts, idle band, day calendar ─────────
   Every day a driver is on the road costs the day rate; these show the
   days that carried no load (profit-periods.js). */

.pf-dr-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 14px;
}

.pf-palerts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.pf-palert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(255, 152, 0, 0.07);
    border: 1px solid rgba(255, 152, 0, 0.35);
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-main);
}

.pf-palert > i { color: var(--neon-amber, #FF9800); flex-shrink: 0; }
.pf-palert-text { flex: 1; min-width: 0; }
.pf-palert .pf-btn { flex-shrink: 0; }

.pf-idle-band {
    margin: 0 0 18px;
    padding: 16px 20px;
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(232, 121, 249, 0.22);
    border-left: 3px solid #E879F9;
    transition: border-color 0.25s ease;
}

.pf-idle-band.is-link { cursor: pointer; }
.pf-idle-band.is-link:hover { border-color: rgba(232, 121, 249, 0.45); }
.pf-idle-band.is-link:focus-visible { outline: 2px solid #E879F9; outline-offset: 2px; }

.pf-idle-lead {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-main);
    margin-bottom: 12px;
}

.pf-idle-lead > i:first-child { color: #E879F9; }
.pf-idle-lead > span { flex: 1; }

.pf-idle-figs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
}

.pf-idle-fig { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.pf-idle-fig-label {
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.pf-idle-fig-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
}

.pf-active-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.pf-active-period {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(255, 255, 255, 0.025);
}

.pf-active-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.pf-active-main .pf-muted { font-size: 11.5px; }

.pf-active-amt {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    white-space: nowrap;
}

.pf-active-btns { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.pf-period-block {
    padding: 14px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.pf-period-block:first-child { padding-top: 0; }

.pf-period-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
}

.pf-period-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.pf-days {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
    gap: 6px;
}

.pf-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 7px 4px;
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.pf-day i { font-size: 10px; }
.pf-day-d { font-family: 'JetBrains Mono', monospace; font-weight: 700; }

.pf-day.is-loaded { border-color: rgba(0, 255, 148, 0.3); background: rgba(0, 255, 148, 0.06); }
.pf-day.is-loaded i { color: var(--neon-green); }

.pf-day.is-idle {
    border-color: color-mix(in srgb, var(--reason, #64748B) 55%, transparent);
    background: color-mix(in srgb, var(--reason, #64748B) 12%, transparent);
}

.pf-day.is-idle i { color: var(--reason, #64748B); }
.pf-day.is-unspec { border-style: dashed; }
.pf-day.is-marked::after { content: '•'; line-height: 0.6; color: var(--text-muted); }
.pf-day:hover { border-color: rgba(255, 255, 255, 0.35); }
.pf-day.is-sel { outline: 2px solid var(--neon-cyan); outline-offset: 1px; }

.pf-day-editor-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    font-size: 12.5px;
}

.pf-crew { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }

.pf-crew-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
}

.pf-crew-row > i { color: var(--text-muted); width: 16px; text-align: center; }
.pf-crew-row .pf-crew-swap { color: var(--neon-amber, #FF9800); }
.pf-crew-amt { margin-left: auto; font-family: 'JetBrains Mono', monospace; font-weight: 700; }

.pf-idle-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 12px;
    border: 1px dashed color-mix(in srgb, var(--reason, #64748B) 60%, transparent);
    background: color-mix(in srgb, var(--reason, #64748B) 8%, transparent);
}

.pf-idle-card > i { color: var(--reason, #64748B); }
.pf-idle-card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; }
.pf-idle-card-main .pf-muted { font-size: 11px; }
.pf-idle-card-amt { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12.5px; }
.pf-idle-card-amt .pf-neg { font-family: 'JetBrains Mono', monospace; font-weight: 700; }
.pf-idle-card-amt .pf-muted { font-size: 10.5px; white-space: nowrap; }

@media (max-width: 900px) {
    .pf-idle-figs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
    .pf-active-period { flex-wrap: wrap; }
    .pf-active-btns { width: 100%; justify-content: flex-start; }
    .pf-palert { flex-wrap: wrap; }
    .pf-idle-card { flex-wrap: wrap; }
    .pf-idle-card-amt { align-items: flex-start; }
}
