/* Brand Theme — the shared design system for the order entry pages.
 *
 * Fonts come from jsDelivr because that is the one external host the app's
 * CSP already allows (see app/__init__.py: style-src and font-src both list
 * cdn.jsdelivr.net). Google Fonts is NOT allowed and will fail silently.
 * Oswald carries headings and figures, Roboto carries body copy — both are
 * what wisewaysupply.com runs, so the portal reads as the same company as
 * the storefront. Each @import has a real fallback stack behind it in
 * --font-display / --font-body, so a blocked CDN degrades instead of breaking.
 */
@import url("https://cdn.jsdelivr.net/npm/@fontsource/oswald@5/400.css");
@import url("https://cdn.jsdelivr.net/npm/@fontsource/oswald@5/500.css");
@import url("https://cdn.jsdelivr.net/npm/@fontsource/roboto@5/400.css");
@import url("https://cdn.jsdelivr.net/npm/@fontsource/roboto@5/500.css");
@import url("https://cdn.jsdelivr.net/npm/@fontsource/roboto@5/700.css");

:root {
    /* Brand — overridden per-customer by an inline <style> on each page.
       --brand-primary is the mark's own color; --brand-action is the fill
       behind white button text, which differs for PWS (see app/brands.py). */
    --brand-primary: #2C7C35;
    --brand-action: #2C7C35;
    --brand-primary-hover: #22632A;
    --brand-accent: #2C7C35;

    /* Fixed chrome. The app bar stays charcoal for every brand so a logo
       never has to sit on its own color. */
    --chrome: #232527;
    --chrome-text: #FFFFFF;
    --chrome-muted: #A7ADB1;

    --color-danger: #9B3B34;
    --color-danger-hover: #7E2F29;
    --color-text: #17181A;
    --color-body: #3A3D40;
    --color-text-light: #4A4F53;
    --color-text-muted: #62676B;
    --color-bg: #FFFFFF;
    --color-bg-muted: #F7F8F9;
    --color-page: #F2F4F5;
    --color-border: #E1E5E7;
    --color-border-strong: #C9CED2;
    --color-border-light: #EDF0F1;

    --font-display: Oswald, "Arial Narrow", "Roboto Condensed", Impact, sans-serif;
    --font-body: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    --font-family: var(--font-body);
    --font-size-base: 1rem;
    --font-size-sm: 0.85rem;
    --font-size-lg: 1.1rem;
    --font-size-h1: 1.8rem;
    --font-size-h2: 1.5rem;

    /* Square corners, like the buttons on the .com */
    --radius: 2px;
    --radius-lg: 3px;

    /* Nothing tappable is allowed under this. */
    --tap: 44px;
}

/* ── Accessibility ─────────────────────────────────────────────────── */

.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--brand-action);
    color: #fff;
    padding: 10px 20px;
    z-index: 9999;
    font-size: 16px;
    font-weight: 500;
    text-decoration: none;
    border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { top: 0; }

*:focus-visible {
    outline: 3px solid var(--brand-action);
    outline-offset: 2px;
}
.app-bar *:focus-visible,
.app-tabs .nav-link:focus-visible {
    outline-color: #fff;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── App bar ───────────────────────────────────────────────────────── */

.app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: 60px;
    box-sizing: border-box;
    padding: 0 12px;
    background: var(--chrome);
}

.app-bar-logo {
    display: flex;
    align-items: center;
    background: #fff;
    border-radius: var(--radius);
    padding: 5px 8px;
    flex-shrink: 0;
}
/* Height is per-brand: the trimmed marks range from 1.1:1 (Northport's round
   badge) to 5.1:1 (the PWS wordmark), so one height would leave some tiny and
   others overflowing. Each page sets --nav-logo-height from the brand. */
.app-bar-logo img {
    display: block;
    width: auto;
    height: var(--nav-logo-height, 28px);
    max-width: 148px;
    object-fit: contain;
}

.app-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.app-bar-who {
    text-align: right;
    min-width: 0;
}
.app-bar-who .who-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--chrome-text);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-bar-who .who-meta {
    font-size: 10.5px;
    letter-spacing: 0.06em;
    color: var(--chrome-muted);
    line-height: 1.25;
    white-space: nowrap;
}
.app-bar-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--brand-action);
    color: #fff;
    font-size: 12.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.app-bar-logout {
    display: flex;
    align-items: center;
    height: 34px;
    padding: 0 11px;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: var(--radius);
    color: #E3E6E8;
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 500;
    white-space: nowrap;
}
.app-bar-logout:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* The second color in a mark — Park's green, Stearns' gold. Brands whose mark
   is one color get a solid rule in that color instead. */
.brand-rule {
    height: 3px;
    display: flex;
    background: var(--brand-primary);
}
.brand-rule span {
    width: 96px;
    background: var(--brand-accent);
}

/* ── Tab strip ─────────────────────────────────────────────────────── */

.app-tabs {
    display: flex;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 900;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.app-tabs::-webkit-scrollbar { display: none; }

.app-tabs .nav-link {
    flex: 1 0 auto;
    min-width: 92px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    text-decoration: none;
    font-family: var(--font-display);
    font-size: 13.5px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}
.app-tabs .nav-link:hover { color: var(--color-text); }
.app-tabs .nav-link.active {
    color: var(--color-text);
    border-bottom-color: var(--brand-primary);
}

/* ── Page ──────────────────────────────────────────────────────────── */

body {
    background-color: var(--color-page);
    font-family: var(--font-body);
    margin: 0;
    padding: 0;
    color: var(--color-body);
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 900px;
    margin: 14px auto;
    padding: 16px;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
}
.header h2 {
    font-family: var(--font-display);
    font-size: 1.7rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--color-text);
    margin: 0;
}
/* The in-body logo banner is gone — the app bar carries the mark now. Any
   page still rendering one gets it small rather than 400px wide. */
.header img {
    max-width: 200px;
    margin-bottom: 0;
}

.kicker {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-text-light);
}
.figure {
    font-family: var(--font-display);
    font-weight: 500;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

/* ── Buttons ───────────────────────────────────────────────────────── */

button.btn,
form#order-form button.btn,
.admin-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 10px 18px;
    background-color: var(--brand-action) !important;
    color: #fff !important;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-decoration: none;
}
button.btn:hover,
form#order-form button.btn:hover,
.admin-button:hover {
    background-color: var(--brand-primary-hover) !important;
}
button.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Secondary — the quiet sibling. Used for Cancel, Update, Templates. */
.btn-secondary,
.tpl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 10px 16px;
    background: var(--color-bg) !important;
    color: var(--color-body) !important;
    border: 1.5px solid var(--color-border-strong);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}
.btn-secondary:hover,
.tpl-btn:hover {
    background: var(--color-bg-muted) !important;
    border-color: var(--color-text-muted);
}

form#order-form button.delete-btn,
form#order-form button.btn-danger,
button.btn-danger,
.delete-btn {
    background-color: var(--color-bg) !important;
    color: var(--color-danger) !important;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 8px 12px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}
form#order-form button.delete-btn:hover,
form#order-form button.btn-danger:hover,
button.btn-danger:hover,
.delete-btn:hover {
    background-color: #FBF2F1 !important;
    border-color: var(--color-danger);
}

/* A chip is a small, non-primary control: saved templates, date filters. */
.chip {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 13px;
    border: 1.5px solid var(--color-border-strong);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.chip:hover { background: var(--color-bg-muted); }
.chip.active {
    background: var(--chrome);
    border-color: var(--chrome);
    color: #fff;
}

/* ── Inputs ────────────────────────────────────────────────────────── */

/* 16px everywhere: anything smaller makes iOS zoom the page on focus. */
.add-part-form input[type="text"],
input[type="text"],
input[type="search"],
input[type="password"],
input[type="date"],
textarea,
select {
    padding: 0 14px;
    min-height: 50px;
    font-family: var(--font-body);
    font-size: 16px;
    border: 1.5px solid var(--color-border-strong);
    border-radius: var(--radius);
    box-sizing: border-box;
    background-color: var(--color-bg);
    color: var(--color-text);
}
textarea { padding: 12px 14px; }

.field-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-text-light);
    margin-bottom: 6px;
}

/* ── Quantity stepper ──────────────────────────────────────────────── */
/* Replaces the bare number box. The <input> keeps its name, value and
   data-multiplier so the existing submit and rounding logic is untouched —
   the buttons only nudge the input and re-fire its events. */

.qty-stepper {
    display: inline-flex;
    align-items: center;
    border: 1.5px solid var(--color-border-strong);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--color-bg);
}
/* Scoped to these two classes, not to `.qty-stepper button`: the scan page has
   its own larger stepper (.qty-stepper-btn, 56px for one-handed use at the
   shelf) inside the same wrapper, and a bare element selector here outranks
   its class and would silently shrink it. */
.qty-stepper .qty-down,
.qty-stepper .qty-up {
    width: var(--tap);
    height: var(--tap);
    flex-shrink: 0;
    border: none;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 21px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}
.qty-stepper .qty-down:hover,
.qty-stepper .qty-up:hover { background: var(--color-bg-muted); }
.qty-stepper .qty-down { border-right: 1.5px solid var(--color-border); }
.qty-stepper .qty-up { border-left: 1.5px solid var(--color-border); }

.qty-stepper .qty-down ~ input[type="number"] {
    width: 56px;
    height: var(--tap);
    min-height: 0;
    box-sizing: border-box;
    border: none;
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    color: var(--color-text);
    background: var(--color-bg);
    padding: 0;
    -moz-appearance: textfield;
}
.qty-stepper .qty-down ~ input[type="number"]::-webkit-outer-spin-button,
.qty-stepper .qty-down ~ input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ── Product photo ─────────────────────────────────────────────────── */
/* Eclipse returns an imageUrl with every product (api_client.py). The tile is
   what shows when it returns nothing, which is common enough to design for. */

.line-photo {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    background: #F1F3F4;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.line-photo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.line-photo.is-empty::after {
    content: "";
    width: 22px;
    height: 22px;
    background-color: #A8AEB2;
    -webkit-mask: var(--photo-glyph) center / contain no-repeat;
    mask: var(--photo-glyph) center / contain no-repeat;
}
:root {
    --photo-glyph: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='2'/%3E%3Ccircle cx='8.5' cy='9.5' r='1.7'/%3E%3Cpath d='M21 15l-5-5L7 19'/%3E%3C/svg%3E");
}

/* ── Order table (desktop) ─────────────────────────────────────────── */

.order-table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
}
.order-table th,
.order-table td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--color-border-light);
    vertical-align: middle;
}
.order-table th {
    color: var(--color-text-light);
    background-color: var(--color-bg-muted);
    border-bottom: 1px solid var(--color-border);
    font-family: var(--font-body);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.order-table td.num,
.order-table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ── Totals & the sticky action bar ────────────────────────────────── */

.totals {
    text-align: right;
    margin: 16px 0;
    font-size: var(--font-size-base);
    color: var(--color-body);
    font-variant-numeric: tabular-nums;
}
.totals p { margin: 4px 0; }

/* The order total and Submit ride at the bottom of the viewport instead of
   scrolling away under the lines. */
.order-bar {
    position: sticky;
    bottom: 0;
    z-index: 800;
    background: var(--color-bg);
    border-top: 1px solid #DFE3E5;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    margin: 16px -16px -16px;
}
.order-bar-figures {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 11px;
}
.order-bar-small {
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}
.order-bar-total { text-align: right; }
.order-bar-total .kicker-xs {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}
.order-bar-total .amount {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 500;
    line-height: 1.1;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}
.order-bar .btn-submit {
    width: 100%;
    min-height: 54px;
    font-size: 17px;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

/* ── Pills & alerts ────────────────────────────────────────────────── */

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 9px;
    border-radius: var(--radius);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}
.pill-good { background: #E7F1E9; color: #1F5C2B; }
.pill-info { background: #E6EEF6; color: #1B4A78; }
.pill-flat { background: #EFF1F2; color: #43484C; }
.pill-warn { background: #FBF0D8; color: #6E5307; }

.alert {
    padding: 12px 14px;
    margin-bottom: 12px;
    border-radius: var(--radius);
    font-size: 14px;
    background-color: #FBF2F1;
    border: 1px solid #E8CFCC;
    color: #7E2F29;
}
.alert-danger {
    background-color: #FBF2F1;
    border-color: #E8CFCC;
    color: #7E2F29;
}

/* ── Modals ────────────────────────────────────────────────────────── */

.modal-content {
    background-color: var(--color-bg);
    padding: 20px;
    border-radius: var(--radius-lg);
}
.modal-content h3 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--color-text);
    margin: 0 0 12px;
}
#modal-po-input {
    width: 100%;
    box-sizing: border-box;
    margin: 12px 0;
}

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .container {
        max-width: 100%;
        margin: 0;
        padding: 14px;
        border: none;
        border-radius: 0;
        background: transparent;
    }
    .order-bar {
        margin: 14px -14px -14px;
        padding-left: 14px;
        padding-right: 14px;
    }
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    .header h2 { font-size: 1.3rem; }
    .app-bar-who .who-name { max-width: 130px; }
    .action-buttons > * { flex: 1 1 140px; }
}

@media (max-width: 480px) {
    .app-bar { padding: 0 10px; }
    .app-bar-logo img { max-width: 112px; }
    .app-bar-who { display: none; }
    .app-tabs .nav-link {
        font-size: 12.5px;
        min-width: 78px;
        padding: 0 8px;
    }
    .order-bar-total .amount { font-size: 25px; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
