/* ==========================================================================
   Colour tokens, taken from jickdeal.com.
   The HSL triplets below are that site's palette verbatim, so changing a
   value here re-tints the whole app. Everything under them maps the tokens
   onto the Bootstrap 5.3 variables that actually paint the components.
   ========================================================================== */

:root {
    --background: 210 17% 99%;
    --foreground: 224 71% 4%;
    --card: 0 0% 100%;
    --primary: 256 98% 55%;
    --primary-foreground: 0 0% 98%;
    --secondary: 215 28% 94%;
    --muted: 215 28% 94%;
    --muted-foreground: 215 20% 45%;
    --destructive: 0 84% 60%;
    --border: 215 28% 84%;
    --ring: 256 98% 55%;
    --radius: 0.4rem;
}

/* jickdeal.com's .dark palette. Everything mapped from these tokens below
   switches automatically; only values Bootstrap needs as raw numbers, and
   shades that must lighten to stay readable, are restated for dark. */
:root[data-bs-theme="dark"] {
    --background: 222 84% 5%;
    --foreground: 0 0% 98%;
    --card: 222 84% 5%;
    --primary: 256 98% 55%;
    --primary-foreground: 0 0% 98%;
    --secondary: 217 33% 17%;
    --muted: 217 33% 17%;
    --muted-foreground: 215 20% 65%;
    --destructive: 0 72% 51%;
    --border: 217 33% 17%;
    --ring: 256 98% 55%;
}

/* -------------------------------------------------------------------------
   Bootstrap globals.
   Where Bootstrap composes a colour as rgba(var(--x-rgb), opacity) it needs a
   numeric triplet, which CSS cannot derive from HSL -- those are given as the
   computed value beside the token they come from.
   ------------------------------------------------------------------------- */

:root {
    /* white page, gray text */
    --bs-body-bg: hsl(var(--background));
    --bs-body-bg-rgb: 252, 252, 253;
    --bs-body-color: hsl(var(--muted-foreground));   /* #5C6F8A, 5.1:1 on white */
    --bs-body-color-rgb: 92, 111, 138;

    /* headings stay near-black so the hierarchy still reads */
    --bs-emphasis-color: hsl(var(--foreground));
    --bs-emphasis-color-rgb: 3, 7, 17;
    --bs-heading-color: hsl(var(--foreground));

    --bs-primary: hsl(var(--primary));               /* #581CFD, 7.0:1 on white */
    --bs-primary-rgb: 88, 28, 253;
    --bs-primary-text-emphasis: hsl(256 98% 40%);
    --bs-primary-bg-subtle: hsl(256 98% 96%);
    --bs-primary-border-subtle: hsl(256 98% 86%);

    --bs-danger: hsl(var(--destructive));
    --bs-danger-rgb: 239, 67, 67;

    --bs-secondary-color: hsl(var(--muted-foreground));
    --bs-secondary-bg: hsl(var(--secondary));
    --bs-tertiary-bg: hsl(var(--muted));

    --bs-border-color: hsl(var(--border));
    --bs-border-color-translucent: hsl(var(--border));

    --bs-link-color: hsl(256 98% 47%);
    --bs-link-color-rgb: 65, 2, 237;
    --bs-link-hover-color: hsl(256 98% 40%);
    --bs-link-hover-color-rgb: 55, 2, 202;

    --bs-border-radius: var(--radius);
    --bs-focus-ring-color: hsl(var(--ring) / 0.25);
}

/* Dark: only what cannot be derived from a token in CSS. */
:root[data-bs-theme="dark"] {
    --bs-body-bg-rgb: 2, 8, 23;
    --bs-body-color-rgb: 148, 163, 184;             /* #94A3B8, 7.8:1 on the dark ground */
    --bs-emphasis-color-rgb: 250, 250, 250;
    --bs-danger-rgb: 220, 40, 40;

    /* #581CFD is only 2.9:1 against the dark ground -- fine as a button fill
       with white text, unreadable as a label. Text-like uses lighten. */
    --bs-link-color: hsl(256 98% 70%);
    --bs-link-color-rgb: 144, 104, 253;
    --bs-link-hover-color: hsl(256 98% 78%);
    --bs-link-hover-color-rgb: 178, 151, 254;
    --bs-primary-text-emphasis: hsl(256 98% 75%);
    --bs-primary-bg-subtle: hsl(256 60% 14%);
    --bs-primary-border-subtle: hsl(256 60% 28%);
}

/* Surfaces that were literal white in light mode follow the card token. */
.bg-surface {
    background-color: hsl(var(--card));
}

/* Cards sit pure white on the very slightly cool page ground. */
.card {
    --bs-card-bg: hsl(var(--card));
    --bs-card-border-color: hsl(var(--border));
}

/* -------------------------------------------------------------------------
   Buttons. Bootstrap compiles these per-class, so the brand ones are retinted
   here.

   .btn-success carries the brand colour rather than Bootstrap green: in this
   app it marks "add" actions, which are calls to action rather than status,
   and the source palette has no green. Green and red survive only where they
   encode meaning -- the +/- commission figures.
   ------------------------------------------------------------------------- */

.btn-primary,
.btn-success {
    --bs-btn-color: hsl(var(--primary-foreground));
    --bs-btn-bg: hsl(var(--primary));
    --bs-btn-border-color: hsl(var(--primary));
    --bs-btn-hover-color: hsl(var(--primary-foreground));
    --bs-btn-hover-bg: hsl(256 98% 48%);
    --bs-btn-hover-border-color: hsl(256 98% 46%);
    --bs-btn-active-color: hsl(var(--primary-foreground));
    --bs-btn-active-bg: hsl(256 98% 44%);
    --bs-btn-active-border-color: hsl(256 98% 42%);
    --bs-btn-disabled-color: hsl(var(--primary-foreground));
    --bs-btn-disabled-bg: hsl(var(--primary));
    --bs-btn-disabled-border-color: hsl(var(--primary));
    --bs-btn-focus-shadow-rgb: 88, 28, 253;
}

.btn-outline-primary {
    --bs-btn-color: hsl(256 98% 47%);
    --bs-btn-border-color: hsl(var(--border));
    --bs-btn-hover-color: hsl(var(--primary-foreground));
    --bs-btn-hover-bg: hsl(var(--primary));
    --bs-btn-hover-border-color: hsl(var(--primary));
    --bs-btn-active-color: hsl(var(--primary-foreground));
    --bs-btn-active-bg: hsl(256 98% 48%);
    --bs-btn-active-border-color: hsl(256 98% 48%);
    --bs-btn-disabled-color: hsl(256 98% 47%);
    --bs-btn-disabled-border-color: hsl(var(--border));
    --bs-btn-focus-shadow-rgb: 88, 28, 253;
}

.btn-outline-secondary {
    --bs-btn-color: hsl(var(--muted-foreground));
    --bs-btn-border-color: hsl(var(--border));
    --bs-btn-hover-color: hsl(var(--foreground));
    --bs-btn-hover-bg: hsl(var(--muted));
    --bs-btn-hover-border-color: hsl(var(--border));
    --bs-btn-active-color: hsl(var(--foreground));
    --bs-btn-active-bg: hsl(var(--secondary));
    --bs-btn-active-border-color: hsl(var(--border));
}

/* The flat destructive red is readable as a fill but not as a label, so the
   outline variant uses a darker shade for its text. */
.btn-outline-danger {
    --bs-btn-color: hsl(0 74% 42%);
    --bs-btn-border-color: hsl(var(--border));
    --bs-btn-hover-bg: hsl(var(--destructive));
    --bs-btn-hover-border-color: hsl(var(--destructive));
    --bs-btn-active-bg: hsl(0 74% 48%);
    --bs-btn-active-border-color: hsl(0 74% 48%);
}

/* -------------------------------------------------------------------------
   Forms, nav and the remaining brand-tinted components.
   ------------------------------------------------------------------------- */

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: hsl(256 98% 75%);
    box-shadow: 0 0 0 0.25rem hsl(var(--ring) / 0.25);
}

.form-check-input:checked {
    background-color: hsl(var(--primary));
    border-color: hsl(var(--primary));
}

.list-group-item {
    --bs-list-group-active-bg: hsl(var(--primary));
    --bs-list-group-active-border-color: hsl(var(--primary));
    --bs-list-group-action-hover-bg: hsl(var(--muted));
    --bs-list-group-border-color: hsl(var(--border));
}

.table {
    --bs-table-border-color: hsl(var(--border));
}

.table-light {
    --bs-table-bg: hsl(var(--muted));
    --bs-table-color: hsl(var(--foreground));
}

/* Brand and destructive labels lighten on the dark ground. */
:root[data-bs-theme="dark"] .btn-outline-primary {
    --bs-btn-color: hsl(256 98% 70%);
}

:root[data-bs-theme="dark"] .btn-outline-danger {
    --bs-btn-color: hsl(0 74% 68%);
}

/* ==========================================================================
   App-specific pieces Bootstrap has no component for.
   ========================================================================== */

/* Sign-in page: no nav, so centre the card in the viewport. */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem 0;
}

/* Who is signed in, tucked to the right of the centred title. */
.header-account {
    position: absolute;
    top: 50%;
    right: 0.75rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

/* Bottom tab bar. Fixed to the bottom so the tabs stay under the thumb on a
   phone, which is where this app is actually used. */
.app-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1030;
    background-color: hsl(var(--card));
    border-top: 1px solid hsl(var(--border));
    /* Clear the iOS home indicator. */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.app-nav-list {
    display: flex;
    align-items: stretch;
    margin: 0;
    padding: 0;
    list-style: none;
    max-width: 720px;
    margin-inline: auto;
}

.app-nav-list > li {
    flex: 1 1 0;
    min-width: 0;
}

.app-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.5rem 0.15rem calc(0.5rem + 2px);
    text-decoration: none;
    color: hsl(var(--muted-foreground));
    font-size: 0.68rem;
    line-height: 1.2;
    /* The active tab draws this border in the brand colour. */
    border-top: 2px solid transparent;
    margin-top: -1px;
    transition: color 0.15s ease-in-out;
}

.app-nav-link i {
    font-size: 1.05rem;
}

.app-nav-link span {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-nav-link:hover,
.app-nav-link:focus-visible {
    color: hsl(256 98% 47%);
}

.app-nav-link.active {
    color: hsl(256 98% 47%);
    border-top-color: hsl(var(--primary));
    background-color: hsl(var(--primary) / 0.06);
}

:root[data-bs-theme="dark"] .app-nav-link:hover,
:root[data-bs-theme="dark"] .app-nav-link:focus-visible,
:root[data-bs-theme="dark"] .app-nav-link.active {
    color: hsl(256 98% 70%);
}

:root[data-bs-theme="dark"] .app-nav-link.active {
    background-color: hsl(var(--primary) / 0.18);
}

/* Keep page content clear of the fixed bar, and lift the toasts above it. */
body {
    padding-bottom: 4.75rem;
}

#toast-container {
    margin-bottom: 4.25rem;
}


.table td,
.table th {
    vertical-align: middle;
}

/* Money columns line up when the digits are tabular. */
.num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.product-thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    cursor: zoom-in;
}

/* Shop autocomplete: a plain dropdown positioned under the input. */
.suggestions {
    position: absolute;
    z-index: 1000;
    width: 100%;
    max-height: 220px;
    overflow-y: auto;
}

/* The report page hides its figures until the eye is clicked. */
.blurred {
    filter: blur(7px);
    user-select: none;
}

/* Printing: memos and summaries are the whole point of this app. */
@media print {
    /* Paper is always light, whichever theme is on screen. */
    :root,
    :root[data-bs-theme="dark"] {
        --background: 0 0% 100%;
        --foreground: 0 0% 0%;
        --card: 0 0% 100%;
        --muted-foreground: 0 0% 20%;
        --border: 0 0% 60%;
        --bs-body-color-rgb: 51, 51, 51;
        --bs-body-bg-rgb: 255, 255, 255;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        padding-bottom: 0 !important;
    }

    .app-nav {
        display: none !important;
    }

    .card {
        border-color: #000 !important;
        break-inside: avoid;
    }

    a[href]::after {
        content: none !important;
    }
}
