/*
| Shared UI styles: the typeface, toast notifications and AJAX form states.
| Pairs with public/assets/js/app.js. Every colour falls back to a literal,
| so this file also works on pages that do not define the admin theme vars.
*/

/*
| One typeface for the whole product. Inter is the closest open face to Apple's
| SF Pro; on an Apple device the platform's own face comes first (it already
| carries optical sizing and tracking tuned for each size), everywhere else
| Inter is served from this site, so no page waits on a third party.
| The variable file carries every weight and the optical-size axis.
*/
@font-face {
    font-family: "Inter";
    src: url("../fonts/InterVariable.woff2") format("woff2");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

:root {
    --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI Variable Text", "Segoe UI",
                 system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------------------------------------------------------------- toasts */
.toast-stack {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(360px, calc(100vw - 32px));
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 12px 12px 14px;
    border-radius: var(--radius-lg);
    /* A floating layer: material and depth, no border, and no coloured stripe -
       the severity is the icon, which is where the eye already is. */
    background: var(--panel);
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    backdrop-filter: saturate(180%) blur(24px);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    line-height: 1.45;
    overflow: hidden;
    opacity: 0;
    transform: translateX(12px);
    transition: opacity .22s var(--ease-out, ease), transform .22s var(--ease-out, ease);
}

.toast.is-visible {
    opacity: 1;
    transform: translateX(0);
}

.toast.is-leaving {
    opacity: 0;
    transform: translateX(12px);
}

.toast-success { --toast-accent: var(--success-mark, #30a46c); }
.toast-error   { --toast-accent: var(--danger-mark, #e5484d); }
.toast-warning { --toast-accent: var(--warning-mark, #f5a623); }
.toast-info    { --toast-accent: var(--info-mark, #3b82f6); }

.toast-icon {
    flex: none;
    width: 18px;
    height: 18px;
    margin-top: 1px;
    border-radius: 50%;
    background: var(--toast-accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}

.toast-warning .toast-icon { color: #1d1d1f; }

.toast-body { flex: 1 1 auto; min-width: 0; }

.toast-title {
    font-weight: 600;
    margin-bottom: 1px;
    color: var(--heading);
}

.toast-message {
    color: var(--muted, #64748b);
    overflow-wrap: anywhere;
}

.toast-message ul {
    margin: 4px 0 0;
    padding-left: 18px;
}

.toast-close {
    flex: none;
    border: 0;
    background: transparent;
    color: var(--muted, #64748b);
    font-size: 18px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
    .toast-close:hover { color: var(--text, #0f172a); }
}
.toast-close:focus-visible { outline: 2px solid var(--toast-accent); outline-offset: 1px; }

.toast-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    width: 100%;
    background: var(--toast-accent);
    transform-origin: left center;
    animation: toast-countdown linear forwards;
}

@keyframes toast-countdown {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

@media (prefers-reduced-motion: reduce) {
    .toast { transition: none; }
    .toast-progress { animation: none; }
}

/* --------------------------------------------------------- line editor */
/*
| The repeating-rows control behind every document with line items.
| Pairs with public/assets/js/line-items.js.
*/
.line-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.line-search input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
}

/* The camera trigger scanner.js wires up - see data-scanner-camera. Absent
   on every screen but POS today, so this only ever sits beside the one
   input that has a second flex child. */
.scanner-camera-btn {
    flex: none;
    height: 46px;
    width: 46px;
    padding: 0;
    justify-content: center;
}

/*
| The same action as .scanner-camera-btn, sized for a thumb. Hidden by
| default and swapped in for the icon on a phone (see pos.css) - a camera is
| the exception on a counter screen and the rule on a handset, and one
| button cannot be both without reading as clutter on the desk.
|
| Not display:none here: it must stay reachable for a screen reader on the
| breakpoint that shows it, and pos.css is where that decision is made.
*/
.scanner-camera-cta {
    display: none;
    width: 100%;
    margin-top: 10px;
    height: 46px;
    gap: 8px;
    justify-content: center;
    font-size: 15px;
}

/* The picker. Absolutely placed so adding a row never shifts the page
   under a cashier's hands mid-scan. */
.line-results {
    position: absolute;
    z-index: 40;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 320px;
    overflow-y: auto;
    padding: 4px;
    background: var(--panel);
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    backdrop-filter: saturate(180%) blur(24px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.line-result {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name price" "meta stock";
    gap: 1px 12px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text, #0f172a);
    text-align: left;
    font-size: 13.5px;
    cursor: pointer;
}

.line-result:focus-visible { background: var(--panel-alt, #f1f5f9); }

@media (hover: hover) and (pointer: fine) {
    .line-result:hover { background: var(--panel-alt, #f1f5f9); }
}

.line-result.is-empty {
    display: block;
    color: var(--muted, #64748b);
    cursor: default;
}

.line-result-name  { grid-area: name; font-weight: 600; }
.line-result-meta  { grid-area: meta; font-size: 12.5px; color: var(--muted, #64748b); }
.line-result-price { grid-area: price; font-weight: 600; white-space: nowrap; }

.line-result-stock {
    grid-area: stock;
    font-size: 12.5px;
    color: var(--muted, #64748b);
    text-align: right;
    white-space: nowrap;
}

.line-result-stock.is-out { color: var(--danger, #dc2626); }

/* A quantity bumped by a repeat scan, so the eye catches which row moved. */
@keyframes line-flash {
    from { background: var(--brand-soft, #dbeafe); }
    to   { background: transparent; }
}

[data-line-row].is-flash > td { animation: line-flash .45s ease-out; }

[data-line-row] input[type="number"] { text-align: right; }

/* ----------------------------------------------------------- reports */

.report-card {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: border-color .14s, transform .14s;
}

@media (hover: hover) and (pointer: fine) {
    .report-card:hover {
        border-color: var(--brand, #2563eb);
        transform: translateY(-1px);
    }
}

/*
| Printing a report is the browser's job. A server-rendered PDF would be a
| dependency and a font-embedding problem for something every browser
| already does from the page - so the screen simply gets out of the way.
*/
@media print {
    .sidebar,
    .sidebar-backdrop,
    .header,
    .app-footer,
    .no-print,
    .page-actions,
    .list-toolbar,
    .list-footer,
    .toast-stack { display: none !important; }

    .app-main { margin: 0 !important; }
    .app-content { padding: 0 !important; }

    .card {
        border: 0 !important;
        box-shadow: none !important;
        break-inside: avoid;
    }

    .table th,
    .table td { padding: 4px 6px !important; font-size: 11px !important; }

    body { background: #fff !important; }
}

/* ------------------------------------------------- ajax form validation */
.is-invalid {
    border-color: var(--danger, #dc2626) !important;
}

.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, .28) !important;
}

/* Server-rendered errors use .field-error; JS-injected ones match it. */
.field-error {
    display: block;
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--danger, #dc2626);
}

/* Submit button while a request is in flight. */
.is-busy {
    position: relative;
    cursor: progress;
    opacity: .75;
}

.is-busy .btn-label { visibility: hidden; }

.is-busy::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-spin .6s linear infinite;
}

@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* The action on a toast ("Undo"): text in the accent, not a second button on a
   notification - it is a way back, offered, and easy to leave alone. */
.toast-action {
    display: inline-block;
    margin: 6px 0 0 -4px;
    padding: 4px 4px;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--brand-text, #b93a07);
    cursor: pointer;
    border-radius: 6px;
}

@media (hover: hover) and (pointer: fine) { .toast-action:hover { text-decoration: underline; text-underline-offset: 2px; } }
.toast-action:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring, rgba(234, 88, 12, .3)); }

/* The status switch on the plan list holds its label on one line. */
.table td .status-toggle { white-space: nowrap; }

/* Modules & Plans: a tick in a column per plan, with the plan's name kept short. */
.plan-matrix th.plan-matrix-plan { min-width: 120px; text-align: center; white-space: normal; }
.plan-matrix th.plan-matrix-plan span { display: block; font-weight: 400; }
.plan-matrix td.plan-matrix-tick { text-align: center; }
