/*
 * px-popover — the one dropdown primitive for the top bar.
 * ---------------------------------------------------------------------------
 * Before this file the five panels hanging off the header were four different
 * mechanisms: <details> (quick actions, account), a Bootstrap popover
 * (calculator), a Bootstrap dropdown (notifications) and a modal (today's
 * profit). They looked different, they closed differently, and three of them
 * did not close on an outside click at all.
 *
 * Everything here is one shape: a white card on a 1px border, small radii,
 * rings rather than heavy chrome — the same shadcn vocabulary the design
 * tokens in layouts/partials/css.blade.php already speak. Colours are read
 * from those tokens, never restated, so a tenant accent change moves the
 * panels with everything else.
 *
 * The one device that is ours rather than shadcn's: every panel opens with an
 * eyebrow row that names it and, where there is something live to say, says it
 * on the right — unread count, today's date, the calculator's history button.
 * The eyebrow is the constant; the meta slot is optional.
 *
 * Loaded after vendor.css, so the `!important` overrides in the calculator
 * block below win on equal specificity by source order.
 */

/* ---- Root + panel ------------------------------------------------------ */

.px-pop {
    position: relative;
    display: inline-flex;
}

.px-pop__panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    z-index: 1100;
    min-width: 13rem;
    max-width: calc(100vw - 1rem);
    padding: 0.25rem;
    background-color: var(--card, #fff);
    border: 1px solid var(--border, #e4e4e7);
    border-radius: var(--radius-lg, 10px);
    /* Two shadows: a tight one that seats the card on the page, and a wide,
       very soft one that lifts it off the accent band it drops from. */
    box-shadow:
        0 4px 6px -2px rgb(16 24 40 / 0.06),
        0 18px 36px -14px rgb(16 24 40 / 0.3);
    color: var(--foreground, #0a0a0a);
    text-align: start;
    font-size: 0.8125rem;
}

.px-pop__panel[hidden] {
    display: none;
}

/* Alignment. Logical properties do the RTL work; `start`/`end` are the two
   options and nothing in the bar needs a third. */
.px-pop__panel[data-align='end'] {
    inset-inline-end: 0;
    transform-origin: top right;
}

.px-pop__panel[data-align='start'] {
    inset-inline-start: 0;
    transform-origin: top left;
}

[dir='rtl'] .px-pop__panel[data-align='end'] {
    transform-origin: top left;
}

[dir='rtl'] .px-pop__panel[data-align='start'] {
    transform-origin: top right;
}

@keyframes px-pop-in {
    from {
        opacity: 0;
        transform: translateY(-0.25rem) scale(0.975);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.px-pop__panel[data-state='open'] {
    animation: px-pop-in 0.14s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
    .px-pop__panel[data-state='open'] {
        animation: none;
    }
}

/* The trigger reads as pressed while its panel is open. On the accent band
   .px-topbar already owns the hover fill, so this matches it rather than
   inventing a second one. */
.px-topbar .px-pop[data-px-pop-open] > .px-iconbtn,
.px-topbar .px-pop[data-px-pop-open] > .px-userchip {
    background-color: rgb(255 255 255 / 0.16);
    color: #fff;
}

.px-pop[data-px-pop-open] > .px-iconbtn,
.px-pop[data-px-pop-open] > .px-userchip {
    background-color: #eef2f6;
}

/* ---- Eyebrow head ------------------------------------------------------ */

.px-pop__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 2rem;
    margin: -0.25rem -0.25rem 0.25rem;
    padding: 0.4375rem 0.625rem;
    border-bottom: 1px solid var(--border, #e4e4e7);
}

.px-pop__eyebrow {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    line-height: 1;
    color: #8a8a93;
    white-space: nowrap;
}

.px-pop__meta {
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1;
    color: #a1a1aa;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.px-pop__meta:empty {
    display: none;
}

/* A button living in the meta slot (the calculator's history toggle). */
.px-pop__metabtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.1875rem 0.375rem;
    border: 0;
    border-radius: var(--radius-sm, 4px);
    background-color: transparent;
    color: #a1a1aa;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.px-pop__metabtn:hover,
.px-pop__metabtn:focus-visible {
    background-color: var(--muted, #f4f4f5);
    color: var(--foreground, #0a0a0a);
}

/* ---- Items ------------------------------------------------------------- */

.px-pop__item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.4375rem 0.625rem;
    border: 0;
    border-radius: var(--radius, 6px);
    background-color: transparent;
    color: var(--muted-foreground, #52525b);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.25rem;
    text-align: start;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.px-pop__item:hover,
.px-pop__item:focus,
.px-pop__item:focus-visible {
    background-color: var(--muted, #f4f4f5);
    color: var(--foreground, #0a0a0a);
    text-decoration: none;
}

.px-pop__item:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--ring, #6366f1) 45%, transparent);
    outline-offset: -2px;
}

/* The icon is the one place the accent shows up in a menu: it warms on hover
   and stays neutral otherwise, so a resting menu is entirely greyscale. */
.px-pop__item > svg {
    flex: 0 0 auto;
    width: 1.0625rem;
    height: 1.0625rem;
    color: #a1a1aa;
    transition: color 0.12s ease;
}

.px-pop__item:hover > svg,
.px-pop__item:focus-visible > svg {
    color: var(--accent-600, #4f46e5);
}

.px-pop__sep {
    height: 1px;
    margin: 0.25rem -0.25rem;
    background-color: var(--border, #e4e4e7);
}

/* ---- Identity block (account panel) ------------------------------------ */

.px-pop__identity {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.625rem 0.625rem;
}

.px-pop__identity-avatar {
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    object-fit: cover;
    background-color: var(--muted, #f4f4f5);
    color: #a1a1aa;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.px-pop__identity-name {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 700;
    line-height: 1.125rem;
    color: var(--foreground, #0a0a0a);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.px-pop__identity-sub {
    margin: 0;
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1rem;
    color: #a1a1aa;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Scroller + foot --------------------------------------------------- */

.px-pop__scroll {
    max-height: min(24rem, calc(100vh - 9rem));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #d4d4d8 transparent;
}

.px-pop__scroll::-webkit-scrollbar {
    width: 6px;
}

.px-pop__scroll::-webkit-scrollbar-thumb {
    background-color: #d4d4d8;
    border-radius: 9999px;
}

.px-pop__foot {
    margin: 0.25rem -0.25rem -0.25rem;
    padding: 0.5rem 0.625rem;
    border-top: 1px solid var(--border, #e4e4e7);
    text-align: center;
}

.px-pop__foot a,
.px-pop__foot button {
    border: 0;
    background: transparent;
    padding: 0;
    color: var(--accent-600, #4f46e5);
    font-size: 0.75rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.px-pop__foot a:hover,
.px-pop__foot button:hover {
    color: var(--accent-700, #4338ca);
    text-decoration: underline;
}

.px-pop__empty {
    padding: 1.5rem 0.75rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #a1a1aa;
}

/* ---- Notifications ----------------------------------------------------- */

.px-pop--notifications .px-pop__panel {
    width: 22rem;
}

.px-notif {
    display: block;
    position: relative;
    padding: 0.5rem 0.625rem 0.5rem 1.5rem;
    border-radius: var(--radius, 6px);
    color: var(--muted-foreground, #52525b);
    text-decoration: none;
    transition: background-color 0.12s ease;
}

[dir='rtl'] .px-notif {
    padding-left: 0.625rem;
    padding-right: 1.5rem;
}

.px-notif:hover,
.px-notif:focus-visible {
    background-color: var(--muted, #f4f4f5);
    color: var(--muted-foreground, #52525b);
    text-decoration: none;
}

/* Unread is a 6px accent dot in the gutter — the whole reason the row has a
   1.5rem inset. Read rows keep the inset so the two never jump. */
.px-notif--unread::before {
    content: '';
    position: absolute;
    top: 0.9375rem;
    inset-inline-start: 0.5rem;
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 9999px;
    background-color: var(--accent-600, #4f46e5);
}

.px-notif__msg {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.125rem;
    color: var(--muted-foreground, #52525b);
}

.px-notif--unread .px-notif__msg {
    font-weight: 600;
    color: var(--foreground, #0a0a0a);
}

.px-notif__msg b,
.px-notif__msg strong {
    font-weight: 700;
    color: var(--foreground, #0a0a0a);
}

.px-notif__time {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
    margin-top: 0.1875rem;
    font-size: 0.6875rem;
    font-weight: 500;
    color: #a1a1aa;
}

.px-notif__time > i {
    font-size: 0.6875rem;
}

/* ---- Today's profit ---------------------------------------------------- */

.px-pop--profit .px-pop__panel {
    width: 17.5rem;
}

.px-profit__headline {
    padding: 0.75rem 0.625rem 0.625rem;
}

.px-profit__label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    color: #a1a1aa;
    margin-bottom: 0.1875rem;
}

.px-profit__value {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    color: var(--foreground, #0a0a0a);
}

.px-profit__value--up {
    color: var(--success, #16a34a);
}

.px-profit__value--down {
    color: var(--danger, #dc2626);
}

/* A hairline grid rather than borders per cell: one background showing
   through 1px gaps keeps the rules perfectly even. */
.px-profit__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    margin: 0 0.25rem;
    background-color: var(--border, #e4e4e7);
    border: 1px solid var(--border, #e4e4e7);
    border-radius: var(--radius, 6px);
    overflow: hidden;
}

.px-profit__cell {
    padding: 0.5rem 0.625rem;
    background-color: var(--card, #fff);
}

.px-profit__cell-label {
    display: block;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #a1a1aa;
    margin-bottom: 0.125rem;
}

.px-profit__cell-value {
    display: block;
    font-size: 0.8125rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--foreground, #0a0a0a);
}

.px-profit__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 7.5rem;
    color: #a1a1aa;
    font-size: 0.75rem;
    font-weight: 600;
}

/* ---- Calculator -------------------------------------------------------- */

/*
 * The keypad was a five-colour toy: blue number keys, a red AC, an amber CE,
 * a green equals, each on a 2px fake bevel. Regrounded on the token neutrals
 * so it belongs to the same family as the menus beside it — one filled key
 * (equals, on the accent), one tinted key (clear, destructive), everything
 * else a quiet surface. `!important` throughout because the rules it replaces
 * in vendor.css are themselves `!important`.
 */

/* The calculator supplies its own 4px inset so that the identical markup sits
   flush inside both this panel and the Bootstrap popover the POS screen still
   opens it in. Hence a padding-less panel here. */
.px-pop--calculator .px-pop__panel {
    width: 15rem;
    padding: 0;
}

#calculator {
    padding: 0.25rem !important;
    background: transparent !important;
}

#calculator .px-pop__head {
    margin: -0.25rem -0.25rem 0.25rem;
}

#calc-display {
    display: block;
    width: 100% !important;
    box-sizing: border-box !important;
    height: auto !important;
    margin: 0 0 0.375rem !important;
    padding: 0.625rem 0.75rem !important;
    background-color: var(--muted, #f4f4f5) !important;
    border: 1px solid var(--border, #e4e4e7) !important;
    border-radius: var(--radius, 6px) !important;
    color: var(--foreground, #0a0a0a) !important;
    font-family: inherit !important;
    font-size: 1.375rem !important;
    font-weight: 700 !important;
    font-variant-numeric: tabular-nums !important;
    letter-spacing: -0.01em !important;
    text-align: right !important;
    box-shadow: none !important;
    outline: 0 !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

[dir='rtl'] #calc-display {
    text-align: left !important;
}

#calc-display:focus {
    border-color: color-mix(in srgb, var(--accent-600, #4f46e5) 55%, transparent) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring, #6366f1) 18%, transparent) !important;
}

#calc-grid {
    gap: 0.25rem !important;
}

#calculator .calc-btn,
.calc-btn {
    width: 100% !important;
    height: 2.25rem !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 1px solid var(--border, #e4e4e7) !important;
    border-radius: var(--radius, 6px) !important;
    background-color: var(--card, #fff) !important;
    color: var(--foreground, #0a0a0a) !important;
    font-family: inherit !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    font-variant-numeric: tabular-nums !important;
    line-height: 1 !important;
    box-shadow: none !important;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease !important;
}

#calculator .calc-btn:active,
.calc-btn:active {
    transform: none !important;
    background-color: var(--muted, #f4f4f5) !important;
}

#calculator .calc-btn:focus-visible,
.calc-btn:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--ring, #6366f1) 45%, transparent) !important;
    outline-offset: 1px;
}

#calculator .calc-btn-num,
.calc-btn-num {
    background-color: var(--card, #fff) !important;
    color: var(--foreground, #0a0a0a) !important;
}

#calculator .calc-btn-num:hover,
.calc-btn-num:hover {
    background-color: var(--muted, #f4f4f5) !important;
}

#calculator .calc-btn-op,
.calc-btn-op {
    background-color: var(--muted, #f4f4f5) !important;
    color: var(--muted-foreground, #52525b) !important;
    font-size: 0.9375rem !important;
}

#calculator .calc-btn-op:hover,
.calc-btn-op:hover {
    background-color: #e8e8ec !important;
    color: var(--foreground, #0a0a0a) !important;
}

#calculator .calc-btn-ac,
.calc-btn-ac {
    background-color: color-mix(in srgb, var(--danger, #dc2626) 8%, #fff) !important;
    border-color: color-mix(in srgb, var(--danger, #dc2626) 22%, transparent) !important;
    color: var(--danger, #dc2626) !important;
    font-size: 0.75rem !important;
    font-weight: 700 !important;
}

#calculator .calc-btn-ac:hover,
.calc-btn-ac:hover {
    background-color: color-mix(in srgb, var(--danger, #dc2626) 14%, #fff) !important;
}

#calculator .calc-btn-ce,
.calc-btn-ce {
    background-color: var(--muted, #f4f4f5) !important;
    color: var(--muted-foreground, #52525b) !important;
    font-size: 0.75rem !important;
    font-weight: 700 !important;
}

#calculator .calc-btn-ce:hover,
.calc-btn-ce:hover {
    background-color: #e8e8ec !important;
    color: var(--foreground, #0a0a0a) !important;
}

#calculator .calc-btn-eq,
.calc-btn-eq {
    background-color: var(--accent-600, #4f46e5) !important;
    border-color: var(--accent-600, #4f46e5) !important;
    color: #fff !important;
    font-size: 1rem !important;
    font-weight: 700 !important;
}

#calculator .calc-btn-eq:hover,
.calc-btn-eq:hover {
    background-color: var(--accent-700, #4338ca) !important;
    border-color: var(--accent-700, #4338ca) !important;
}

/* The history flyout is appended to <body> by calculator.js, so it cannot be
   styled through the panel — it is matched by id instead. */
#calc-hist-popup {
    position: fixed;
    z-index: 1200;
    padding: 0.25rem;
    background-color: var(--card, #fff);
    border: 1px solid var(--border, #e4e4e7);
    border-radius: var(--radius-lg, 10px);
    box-shadow:
        0 4px 6px -2px rgb(16 24 40 / 0.06),
        0 18px 36px -14px rgb(16 24 40 / 0.3);
}

#calc-hist-popup .calc-hist-head {
    padding: 0.375rem 0.5rem;
    border-bottom: 1px solid var(--border, #e4e4e7);
    margin-bottom: 0.25rem;
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #8a8a93;
}

#calc-hist-popup .calc-hist-entry {
    padding: 0.3125rem 0.5rem;
    border: 1px solid transparent;
    border-radius: var(--radius, 6px);
    background-color: transparent;
    cursor: pointer;
}

#calc-hist-popup .calc-hist-entry:hover {
    border-color: var(--border, #e4e4e7);
    background-color: var(--muted, #f4f4f5);
}

#calc-hist-popup .calc-hist-expr {
    font-family: inherit;
    font-size: 0.6875rem;
    color: #a1a1aa;
    font-variant-numeric: tabular-nums;
}

#calc-hist-popup .calc-hist-result {
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--foreground, #0a0a0a);
    font-variant-numeric: tabular-nums;
}

#calc-hist-popup .calc-hist-empty {
    padding: 1rem 0.5rem;
    text-align: center;
    font-size: 0.6875rem;
    font-weight: 600;
    color: #a1a1aa;
}

#calc-hist-popup #calc-hist-clear {
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.375rem;
    border: 0;
    border-top: 1px solid var(--border, #e4e4e7);
    background: transparent;
    color: var(--danger, #dc2626);
    font-size: 0.6875rem;
    font-weight: 700;
    cursor: pointer;
}

#calc-hist-popup #calc-hist-clear:hover {
    background-color: color-mix(in srgb, var(--danger, #dc2626) 8%, #fff);
}

/* ---- Small screens ----------------------------------------------------- */

@media (max-width: 480px) {
    .px-pop--notifications .px-pop__panel,
    .px-pop--profit .px-pop__panel,
    .px-pop--calculator .px-pop__panel {
        width: calc(100vw - 1rem);
    }
}
