/* Loyalty Admin styles. Brand tokens match src/Loyalty.Mobile/wwwroot/app.css; the MudBlazor theme (Theme/AdminTheme.cs)
   carries the same colours for the interactive pages, and the --ad-* tokens below are for everything outside MudBlazor: the
   first paint, the splash and the static /account pages. Dark mode follows the OS.
   Contrast (WCAG AA, 4.5:1 for text): text on cream 14:1, muted on cream 6.3:1, cream on green 10.9:1, dark text on gold 7.9:1.
   Never put gold text on cream or white (2.1:1). */
:root {
    --ad-bg: #f5efe3;
    --ad-surface: #fffdf8;
    --ad-text: #1d1a16;
    --ad-muted: #5e5649;
    --ad-accent: #0f3b2e;
    --ad-on-accent: #f5efe3;
    --ad-accent-hover: #082419;
    --ad-gold: #c9a24a;
    --ad-border: #e4dccb;
    --ad-input-border: #857d6d;
    --ad-danger: #a52a1f;
    --ad-danger-bg: #f9e6e3;
    --ad-success: #1e6b45;
    --ad-success-bg: #e3f1e9;
    --ad-info-bg: #e3ebe5;
    --ad-focus: #0f3b2e;
    --font-serif: Georgia, "Times New Roman", Times, serif;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --ad-bg: #0b1812;
        --ad-surface: #12241b;
        --ad-text: #f5efe3;
        --ad-muted: #cdc5b2;
        --ad-accent: #e8cf8f;
        --ad-on-accent: #082419;
        --ad-accent-hover: #f5e1a8;
        --ad-border: #24382d;
        --ad-input-border: #7d9a89;
        --ad-danger: #ff8a7a;
        --ad-danger-bg: #3a1a16;
        --ad-success: #59c58a;
        --ad-success-bg: #14301f;
        --ad-info-bg: #16301f;
        --ad-focus: #e8cf8f;
    }
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font-sans);
    background: var(--ad-bg);
    color: var(--ad-text);
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

h1:focus {
    outline: none;
}

/* ---- Boot splash: shown until the circuit connects and the layout has drawn ---- */

.boot-splash {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: var(--ad-bg);
    color: var(--ad-muted);
    font-size: 0.95rem;
}

.boot-splash-mark {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 4px solid var(--ad-border);
    border-top-color: var(--ad-accent);
    animation: boot-spin 0.9s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .boot-splash-mark { animation-duration: 3s; }
}

body:has(.mud-layout) .boot-splash,
body:has(.admin-loading) .boot-splash,
body:has(.admin-fatal) .boot-splash {
    display: none;
}

/* ---- Static account pages (sign-in, code, reset, invite) ---- */

.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
    box-sizing: border-box;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    margin-top: 6vh;
    padding: 28px 24px;
    box-sizing: border-box;
    background: var(--ad-surface);
    border: 1px solid var(--ad-border);
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.auth-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}

.auth-brand-mark {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: #0f3b2e url("/icons/icon-192.png") center / cover no-repeat;
}

.auth-product {
    margin: 0 0 4px;
    text-align: center;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ad-muted);
}

.auth-card h1 {
    margin: 4px 0 6px;
    text-align: center;
    font-family: var(--font-serif);
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--ad-text);
}

.auth-lead {
    margin: 0 0 20px;
    text-align: center;
    color: var(--ad-muted);
    line-height: 1.5;
}

.auth-field {
    display: block;
    margin-bottom: 16px;
}

.auth-field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

.auth-field input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    min-height: 48px;
    padding: 10px 12px;
    font: inherit;
    font-size: 1rem; /* 16px or more stops iOS zooming in on focus */
    color: var(--ad-text);
    background: var(--ad-surface);
    border: 1px solid var(--ad-input-border);
    border-radius: 10px;
}

.auth-field input:focus-visible {
    outline: 3px solid var(--ad-focus);
    outline-offset: 1px;
}

.auth-field .auth-hint {
    margin: 6px 0 0;
    font-size: 0.82rem;
    color: var(--ad-muted);
}

.auth-field .validation-message,
.auth-field-error {
    margin: 6px 0 0;
    font-size: 0.85rem;
    color: var(--ad-danger);
}

.auth-code input {
    text-align: center;
    font-size: 1.6rem;
    letter-spacing: 0.4em;
    font-variant-numeric: tabular-nums;
}

.auth-button {
    display: block;
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    font: inherit;
    font-weight: 600;
    font-size: 1rem;
    color: var(--ad-on-accent);
    background: var(--ad-accent);
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}

.auth-button:hover {
    background: var(--ad-accent-hover);
}

.auth-button:focus-visible {
    outline: 3px solid var(--ad-focus);
    outline-offset: 2px;
}

.auth-links {
    margin: 18px 0 0;
    text-align: center;
    font-size: 0.92rem;
}

.auth-links a {
    display: inline-block;
    padding: 10px 6px;
    color: var(--ad-accent);
    font-weight: 600;
}

.auth-alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.95rem;
    line-height: 1.45;
    border: 1px solid transparent;
}

.auth-alert-error {
    color: var(--ad-danger);
    background: var(--ad-danger-bg);
    border-color: var(--ad-danger);
}

.auth-alert-success {
    color: var(--ad-success);
    background: var(--ad-success-bg);
    border-color: var(--ad-success);
}

.auth-alert-info {
    color: var(--ad-text);
    background: var(--ad-info-bg);
    border-color: var(--ad-border);
}

.auth-facts {
    margin: 0 0 20px;
    padding: 12px 14px;
    background: var(--ad-info-bg);
    border-radius: 10px;
    line-height: 1.5;
}

/* ---- Interactive shell ---- */

.admin-loading-body {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
}

.admin-fatal {
    max-width: 480px;
    margin: 12vh auto 0;
    padding: 0 16px;
}

.admin-brand {
    margin-right: 16px;
    white-space: nowrap;
}

.admin-venue-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* Everything but the account button (44px) and the app bar's padding. */
    max-width: calc(100vw - 112px);
    font-family: var(--font-serif);
    font-size: 1.1rem;
    font-weight: 600;
}

.admin-venue-static {
    margin-left: 4px;
}

.admin-venue-menu .mud-button-root {
    text-transform: none;
    min-height: 44px;
}

.admin-venue-menu .mud-button-label {
    max-width: calc(100vw - 132px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-serif);
    font-size: 1.1rem;
    font-weight: 600;
}

.admin-venue-current {
    font-weight: 700;
}

.admin-account-card {
    padding: 12px 16px;
    max-width: 280px;
}

.admin-account-card .mud-typography {
    overflow-wrap: anywhere;
}

.admin-container {
    padding-top: 16px;
    padding-bottom: 24px;
}

.admin-main-mobile {
    /* Room for the bottom nav (60px) and the home indicator. */
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.admin-sidenav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 8px;
}

.admin-sidenav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 0 14px;
    border-radius: 10px;
    color: var(--mud-palette-drawer-text);
    text-decoration: none;
    font-weight: 500;
}

.admin-sidenav-link:hover {
    background: var(--mud-palette-action-default-hover);
}

.admin-sidenav-link:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: -2px;
}

.admin-sidenav-link.active {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

.admin-sidenav-link.active .mud-icon-root {
    color: inherit;
}

/* Touch targets are at least 44px. MudBlazor's small buttons and icon buttons are smaller. */
.mud-button-root,
.mud-icon-button,
.mud-menu-item,
.mud-nav-link {
    min-height: 44px;
}

.mud-icon-button {
    min-width: 44px;
}

.admin-touch {
    min-width: 44px;
    min-height: 44px;
}

/* Never scroll the page sideways at 360px. */
.mud-main-content,
.admin-container {
    overflow-x: clip;
}

/* ---- Page furniture ---- */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin-bottom: 16px;
}

.page-head h1 {
    margin: 0;
}

.page-sub {
    margin: 2px 0 0;
    color: var(--mud-palette-text-secondary);
}

.card-link {
    display: block;
    text-decoration: none;
    color: inherit;
    border-radius: var(--mud-default-borderradius);
}

.card-link:focus-visible {
    outline: 3px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

.item-card {
    padding: 14px 16px;
}

.item-card + .item-card,
.card-link + .card-link {
    margin-top: 10px;
}

.item-title {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.item-meta {
    color: var(--mud-palette-text-secondary);
    font-size: 0.875rem;
    overflow-wrap: anywhere;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.filter-chip {
    min-height: 44px;
}

.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 16px;
    margin: 0;
}

.kv dt {
    color: var(--mud-palette-text-secondary);
}

.kv dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.card-number {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
}

.section-title {
    margin: 24px 0 8px;
}

/* ---- Stamp grid ---- */

.stamp-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0;
}

.stamp {
    width: 28px;
    height: 28px;
    box-sizing: border-box;
    border-radius: 50%;
    border: 2px solid var(--mud-palette-primary);
    background: transparent;
}

.stamp.filled {
    background: #c9a24a;
    border-color: var(--mud-palette-primary);
}

.stamp-total {
    font-variant-numeric: tabular-nums;
}

@media (max-width: 599px) {
    .stamp {
        width: 24px;
        height: 24px;
    }
}

/* ---- Tables and lists ---- */

.admin-table {
    width: 100%;
}

.admin-table tbody tr {
    position: relative;
    cursor: pointer;
}

/* Stretches the name's link over the whole row, so the row is one big (keyboard-reachable) link. */
.admin-table a.row-link::after {
    content: "";
    position: absolute;
    inset: 0;
}

.admin-table a.row-link {
    color: inherit;
    font-weight: 600;
    text-decoration: none;
}

.admin-table a.row-link:hover,
.admin-table a.row-link:focus-visible {
    text-decoration: underline;
}

.empty-state {
    padding: 32px 16px;
    text-align: center;
    color: var(--mud-palette-text-secondary);
}

.form-narrow {
    max-width: 640px;
}

.helper-text {
    color: var(--mud-palette-text-secondary);
    font-size: 0.875rem;
    margin: 2px 0 0;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding: 12px 0;
    margin-top: 16px;
    background: var(--mud-palette-background);
    border-top: 1px solid var(--mud-palette-lines-default);
}

@media (max-width: 959px) {
    .sticky-actions {
        bottom: calc(60px + env(safe-area-inset-bottom));
    }
}

/* Product picker: options from the synced till menu. Variants sit indented under their parent's name. */
.product-option {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 2px 0;
}

.product-option.is-variant {
    margin-left: 12px;
    padding-left: 12px;
    border-left: 2px solid var(--mud-palette-lines-default);
}

.product-option-title {
    font-weight: 500;
    overflow-wrap: anywhere;
}

.product-option-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}

.product-tag {
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 999px;
    padding: 0 8px;
    line-height: 1.5;
}

.product-tag.missing,
.product-warning {
    color: var(--mud-palette-warning);
}

.product-tag.missing {
    border-color: var(--mud-palette-warning);
}

.product-warning {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    margin: 2px 0;
    font-size: 0.875rem;
}

/* The POS connection section of Settings */
.pos-connection {
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    padding: 12px;
    margin-bottom: 12px;
}

.pos-gateway {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pos-gateway code {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 0.8125rem;
}

.pos-steps {
    margin: 4px 0 0;
    padding-left: 20px;
}

.pos-steps li {
    margin-bottom: 4px;
}

@media print {
    .mobile-bottom-nav,
    .mud-appbar,
    .mud-drawer {
        display: none !important;
    }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* A snackbar must not cover the bottom nav on a phone: it would block the very tabs a person reaches for next. */
@media (max-width: 959px) {
    .mud-snackbar-location-bottom-center {
        bottom: calc(72px + env(safe-area-inset-bottom));
    }
}
