:root {
    color-scheme: light;
    --bg: #f4f2e9;
    --surface: #fffdf7;
    --surface-2: #f8f5e9;
    --line: rgba(36, 48, 31, .12);
    --text: #24301f;
    --muted: #6d7766;
    --primary: #4f8e18;
    --primary-2: #6c9e19;
    --success: #57971b;
    --warning: #a86818;
    --danger: #bd4b3f;
    --header-bg: rgba(244, 242, 233, .92);
    --nav-bg: rgba(255, 253, 247, .97);
    --card-bg: rgba(255, 253, 247, .9);
    --track: rgba(36, 48, 31, .1);
    --hero-bg: linear-gradient(145deg, #5c991d, #315f12 68%);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d160c;
    --surface: #172314;
    --surface-2: #20301a;
    --line: rgba(255, 255, 255, .09);
    --text: #f6f8f0;
    --muted: #9fab96;
    --primary: #6f9f1d;
    --primary-2: #a3ca2e;
    --success: #83bd25;
    --warning: #bd7b26;
    --danger: #ef7461;
    --header-bg: rgba(13, 22, 12, .9);
    --nav-bg: rgba(16, 28, 13, .97);
    --card-bg: rgba(23, 35, 20, .82);
    --track: rgba(255, 255, 255, .07);
    --hero-bg: linear-gradient(145deg, rgba(79, 142, 24, .34), rgba(23, 35, 20, .96) 64%);
}

* { box-sizing: border-box; }
/* Nothing on a phone should scroll sideways. Individual components manage
   their own shrinking, but this is the backstop: one over-wide element
   anywhere should not drag the whole page off-screen. */
html { background: var(--bg); overflow-x: hidden; }
body { max-width: 100%; margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
button, input { font: inherit; }
a { color: inherit; text-decoration: none; }

/* AI composition state: reserved for the short wait before response content
   appears. Longer operations should replace this with explicit step text. */
.ai-typing-indicator {
    display: flex;
    width: fit-content;
    max-width: 100%;
    min-height: 36px;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--line));
    border-radius: 13px;
    color: var(--text);
    background: color-mix(in srgb, var(--primary) 6%, var(--surface));
    box-shadow: 0 6px 20px rgba(36, 48, 31, .06);
    font-size: 11px;
    line-height: 1.25;
}
.ai-typing-indicator[hidden] { display: none; }
.ai-typing-indicator__mark {
    display: grid;
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(145deg, var(--primary-2), var(--primary));
    box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 25%, transparent);
}
.ai-typing-indicator__spark {
    width: 7px;
    height: 7px;
    border: 2px solid #fff;
    border-radius: 2px 6px 2px 6px;
    transform: rotate(45deg);
}
.ai-typing-indicator__content { display: flex; min-width: 0; align-items: baseline; gap: 7px; }
.ai-typing-indicator__label { overflow: hidden; font-weight: 720; text-overflow: ellipsis; white-space: nowrap; }
.ai-typing-indicator__dots { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 3px; }
.ai-typing-indicator__dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary-2);
    animation: ai-typing-dot 1.15s cubic-bezier(.4, 0, .2, 1) infinite;
}
.ai-typing-indicator__dots span:nth-child(2) { animation-delay: 140ms; }
.ai-typing-indicator__dots span:nth-child(3) { animation-delay: 280ms; }
.ai-typing-indicator__stop {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    gap: 5px;
    margin-left: 3px;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    background: var(--surface);
    font-size: 10px;
    font-weight: 750;
    cursor: pointer;
}
.ai-typing-indicator__stop span { width: 7px; height: 7px; border-radius: 2px; background: currentColor; }
.ai-typing-indicator__stop:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 28%, transparent); outline-offset: 2px; }
@keyframes ai-typing-dot {
    0%, 60%, 100% { opacity: .38; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

.pwa-body {
    min-height: 100dvh;
    background:
        radial-gradient(circle at 92% -10%, rgba(143, 189, 28, .2), transparent 34%),
        radial-gradient(circle at 4% 12%, rgba(168, 104, 24, .1), transparent 27%),
        var(--bg);
}

.pwa-app { width: min(100%, 720px); max-width: 100%; min-width: 0; min-height: 100dvh; margin: 0 auto; }
.pwa-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: max(12px, env(safe-area-inset-top)) 18px 10px;
    border-bottom: 1px solid var(--line);
    background: var(--header-bg);
    backdrop-filter: blur(18px);
}

.pwa-brand { display: flex; align-items: center; gap: 11px; }
.pwa-brand__mark {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 13px;
    overflow: hidden;
    padding: 3px;
    background: #f8f6ee;
    box-shadow: 0 8px 26px rgba(78, 142, 24, .24);
}
.pwa-brand__mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
.pwa-brand div { display: flex; flex-direction: column; }
.pwa-brand strong { font-size: 15px; }
.pwa-brand small { color: var(--muted); font-size: 11px; }
.pwa-header__actions { display: flex; align-items: center; gap: 7px; }
.pwa-header__actions form { margin: 0; }
.pwa-theme-toggle {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
}
.pwa-refresh-button span { display: block; font-size: 21px; line-height: 1; }
.pwa-refresh-button.is-loading span { animation: pwa-refresh-spin .8s linear infinite; }
.pwa-refresh-button:disabled { cursor: wait; opacity: .65; }
.pwa-refresh-status {
    position: fixed;
    z-index: 40;
    top: calc(78px + env(safe-area-inset-top, 0px));
    left: 50%;
    width: max-content;
    max-width: calc(100% - 32px);
    transform: translateX(-50%);
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 12px 34px rgba(0, 0, 0, .18);
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}
.pwa-refresh-status--error { color: var(--danger); }
@keyframes pwa-refresh-spin { to { transform: rotate(360deg); } }
.pwa-install {
    border: 1px solid rgba(163, 202, 46, .45);
    border-radius: 999px;
    padding: 7px 13px;
    color: var(--primary-2);
    background: rgba(111, 159, 29, .12);
}

.pwa-content { min-width: 0; padding: 22px 16px calc(92px + var(--safe-bottom)); overflow-x: hidden; }
.pwa-page-title { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.pwa-page-title h1 { margin: 2px 0 0; font-size: clamp(25px, 7vw, 34px); letter-spacing: -.8px; }
.pwa-page-title time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pwa-eyebrow { color: var(--primary-2); font-size: 11px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }

.pwa-hero-card {
    position: relative;
    overflow: hidden;
    padding: 22px;
    border: 1px solid rgba(163, 202, 46, .26);
    border-radius: 22px;
    color: #fff;
    background: var(--hero-bg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
}
.pwa-hero-card::after {
    content: "";
    position: absolute;
    width: 150px;
    height: 150px;
    right: -54px;
    top: -74px;
    border-radius: 50%;
    background: rgba(189, 123, 38, .16);
}
.pwa-today-total { position: relative; z-index: 1; }
.pwa-today-total span { color: #d9ee9e; font-size: 11px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.pwa-today-total strong { display: block; margin: 7px 0 21px; font-size: clamp(38px, 12vw, 56px); line-height: .96; letter-spacing: -2.2px; }
.pwa-yesterday-panel { position: relative; z-index: 1; margin-bottom: 15px; padding: 11px; border: 1px solid rgba(255, 255, 255, .16); border-radius: 14px; background: rgba(255, 255, 255, .07); }
.pwa-yesterday-panel__title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.pwa-yesterday-panel__title span { color: rgba(255, 255, 255, .92); font-size: 11px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.pwa-yesterday-panel__title small { color: rgba(255, 255, 255, .5); font-size: 9px; }
.pwa-yesterday-sales { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pwa-yesterday-sales div { display: flex; min-width: 0; min-height: 62px; flex-direction: column; justify-content: center; gap: 5px; padding: 9px 10px; border-radius: 10px; background: rgba(8, 22, 11, .3); }
.pwa-yesterday-sales small { color: rgba(255, 255, 255, .62); font-size: 10px; line-height: 1.2; }
.pwa-yesterday-sales b { overflow: hidden; color: #fff; font-size: clamp(16px, 4.5vw, 20px); letter-spacing: -.3px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-yesterday-sales em { color: rgba(255, 255, 255, .52); font-size: 9px; font-style: normal; }
.pwa-hero-meta { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .12); }
.pwa-hero-meta div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.pwa-hero-meta small { color: rgba(255, 255, 255, .66); font-size: 10px; text-transform: uppercase; }
.pwa-hero-meta b { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }

.pwa-section { margin-top: 26px; }
.pwa-section__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.pwa-section__head h2 { margin: 0; font-size: 17px; letter-spacing: -.2px; }
.pwa-section__head span { color: var(--muted); font-size: 11px; }

.pwa-stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.pwa-stat-card {
    display: flex;
    min-width: 0;
    min-height: 112px;
    flex-direction: column;
    justify-content: space-between;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card-bg);
}
.pwa-stat-card > span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.pwa-stat-card > strong { overflow: hidden; font-size: clamp(20px, 6vw, 27px); line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
.pwa-stat-card > small { color: var(--muted); font-size: 10px; }
.pwa-stat-card--wide { grid-column: 1 / -1; min-height: 96px; }
.pwa-stat-card--profit > strong, .pwa-stat-card--stock > strong { color: var(--success); }
.pwa-stat-card--negative > strong { color: var(--danger); }
.pwa-stat-card--stock { cursor: pointer; }

.pwa-attention-list { display: grid; gap: 9px; }
.pwa-attention, .pwa-attention-clear {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card-bg);
}
.pwa-attention--danger { border-left: 4px solid var(--danger); }
.pwa-attention--warning { border-left: 4px solid var(--warning); }
.pwa-attention__icon, .pwa-attention-clear > span {
    display: grid;
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    place-items: center;
    border-radius: 10px;
    font-weight: 900;
}
.pwa-attention--danger .pwa-attention__icon { color: var(--danger); background: rgba(189, 75, 63, .12); }
.pwa-attention--warning .pwa-attention__icon { color: var(--warning); background: rgba(168, 104, 24, .12); }
.pwa-attention__body { min-width: 0; }
.pwa-attention__body > strong, .pwa-attention-clear strong { display: block; font-size: 13px; }
.pwa-attention__body p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.pwa-attention__body p b { color: var(--text); }
.pwa-attention-clear { align-items: center; }
.pwa-attention-clear > span { color: var(--success); background: rgba(87, 151, 27, .12); }
.pwa-attention-clear div { display: flex; flex-direction: column; gap: 3px; }
.pwa-attention-clear small { color: var(--muted); font-size: 10px; }

.pwa-method-note, .pwa-readiness-empty {
    padding: 16px;
    border: 1px solid rgba(79, 142, 24, .28);
    border-radius: 18px;
    background: rgba(79, 142, 24, .08);
}
.pwa-method-note strong { font-size: 13px; }
.pwa-method-note p, .pwa-readiness-empty p { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.pwa-variety-readiness { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.pwa-variety-readiness div { display: flex; min-width: 0; flex-direction: column; padding: 13px 10px; border: 1px solid var(--line); border-radius: 15px; background: var(--card-bg); }
.pwa-variety-readiness strong { font-size: 23px; }
.pwa-variety-readiness span { color: var(--muted); font-size: 9px; }
.pwa-variety-list, .pwa-pattern-list { display: grid; gap: 9px; }
.pwa-variety-card, .pwa-pattern-card { padding: 14px; border: 1px solid var(--line); border-radius: 17px; background: var(--card-bg); }
.pwa-variety-card__head { display: flex; align-items: center; gap: 10px; }
.pwa-variety-card__head > div:last-child { display: flex; min-width: 0; flex-direction: column; }
.pwa-variety-card__head strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-variety-card__head small { color: var(--muted); font-size: 10px; }
.pwa-variety-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 13px; }
.pwa-variety-metrics div { display: flex; min-width: 0; flex-direction: column; gap: 3px; padding: 9px; border-radius: 12px; background: var(--surface-2); }
.pwa-variety-metrics span { color: var(--muted); font-size: 8px; line-height: 1.25; text-transform: uppercase; }
.pwa-variety-metrics strong { font-size: 18px; }
.pwa-variety-metrics small { color: var(--muted); font-size: 8px; line-height: 1.25; }
.pwa-pattern-card { border-left: 4px solid var(--warning); }
.pwa-pattern-card__head { display: flex; justify-content: space-between; gap: 10px; }
.pwa-pattern-card__head > strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-pattern-card__head b { color: var(--warning); font-size: 16px; }
.pwa-pattern-card p { margin: 7px 0; color: var(--muted); font-size: 10px; line-height: 1.4; }
.pwa-pattern-card > div:not(.pwa-pattern-card__head) { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.pwa-pattern-card > div:not(.pwa-pattern-card__head) span { color: var(--muted); font-size: 9px; }
.pwa-pattern-card > div:not(.pwa-pattern-card__head) strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-pattern-card > small { display: block; margin-top: 7px; color: var(--muted); font-size: 9px; }
.pwa-readiness-empty { text-align: center; }
.pwa-readiness-empty > span { display: grid; width: 38px; height: 38px; margin: 0 auto; place-items: center; border-radius: 50%; color: #fff; background: var(--primary); font-weight: 800; }
.pwa-readiness-empty h2 { margin: 11px 0 0; font-size: 16px; }
.pwa-readiness-empty small { display: block; margin-top: 8px; color: var(--warning); font-size: 10px; }
.pwa-methodology ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.pwa-methodology li + li { margin-top: 6px; }

.pwa-user-list, .pwa-sale-list, .pwa-stock-list { display: grid; gap: 9px; }
.pwa-user-card, .pwa-sale-row, .pwa-stock-row {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card-bg);
}
.pwa-user-card { display: flex; align-items: center; gap: 12px; padding: 13px; }
.pwa-avatar { display: grid; width: 42px; height: 42px; flex: 0 0 42px; place-items: center; border-radius: 13px; color: var(--primary-2); background: rgba(111, 159, 29, .16); font-weight: 800; }
.pwa-avatar--customer { color: var(--success); background: rgba(66, 211, 155, .12); }
.pwa-avatar--shift { color: var(--warning); background: rgba(255, 189, 89, .12); }
.pwa-user-card__body { min-width: 0; flex: 1; }
.pwa-user-card__body > div:first-child { display: flex; justify-content: space-between; gap: 10px; }
.pwa-user-card__body strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-user-card__body b { font-size: 13px; white-space: nowrap; }
.pwa-user-card__body small { color: var(--muted); font-size: 10px; }
.pwa-customer-label { color: var(--success); font-weight: 700; }
.pwa-progress { height: 4px; margin: 8px 0 6px; overflow: hidden; border-radius: 99px; background: var(--track); }
.pwa-progress span { display: block; height: 100%; max-width: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--success)); }
/* Depleting variant: the bar shows stock remaining, so a short bar is the
   alarming one and the usual green-for-more reading would be inverted. */
.pwa-progress--depleting span { background: linear-gradient(90deg, var(--danger), var(--warning)); }
/* Ranking bars sit inside a dense list row, so they need to read at a
   glance rather than recede: full height with a track dark enough to show
   where the bar ends on a pale card. 3px against the default track was
   effectively invisible on a phone. */
.pwa-progress--slim {
    height: 7px;
    width: 100%;
    margin: 7px 0 4px;
    background: rgba(36, 48, 31, .16);
}
[data-theme="dark"] .pwa-progress--slim { background: rgba(255, 255, 255, .14); }

.pwa-payment-card-list { display: grid; gap: 12px; }
.pwa-user-payment-card { padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--card-bg); }
.pwa-user-payment-card__head { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 11px; }
.pwa-user-payment-card__head > div:nth-child(2) { display: flex; min-width: 0; flex-direction: column; }
.pwa-user-payment-card__head strong { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-user-payment-card__head small { color: var(--muted); font-size: 10px; }
.pwa-user-payment-card__head > b { font-size: 14px; white-space: nowrap; }
.pwa-payment-bar { display: flex; height: 8px; margin: 14px 0 9px; overflow: hidden; border-radius: 99px; background: var(--track); }
.pwa-payment-bar span { display: block; min-width: 3px; height: 100%; }
.pwa-payment-bar span:nth-child(4n+1) { background: var(--primary); }
.pwa-payment-bar span:nth-child(4n+2) { background: var(--success); }
.pwa-payment-bar span:nth-child(4n+3) { background: var(--warning); }
.pwa-payment-bar span:nth-child(4n+4) { background: var(--danger); }
.pwa-payment-methods { display: grid; }
.pwa-payment-method { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 9px 0; }
.pwa-payment-method + .pwa-payment-method { border-top: 1px solid var(--line); }
.pwa-payment-method__name { display: flex; min-width: 0; align-items: center; gap: 8px; }
.pwa-payment-method__name i { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--primary); }
.pwa-payment-method:nth-child(4n+2) .pwa-payment-method__name i { background: var(--success); }
.pwa-payment-method:nth-child(4n+3) .pwa-payment-method__name i { background: var(--warning); }
.pwa-payment-method:nth-child(4n+4) .pwa-payment-method__name i { background: var(--danger); }
.pwa-payment-method__name strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-payment-method__metrics { display: flex; flex-direction: column; align-items: end; }
.pwa-payment-method__metrics b { font-size: 12px; }
.pwa-payment-method__metrics span { color: var(--muted); font-size: 9px; white-space: nowrap; }

.pwa-sale-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 13px; }
.pwa-sale-row time { color: var(--primary-2); font-size: 11px; font-weight: 700; }
.pwa-sale-row div { display: flex; min-width: 0; flex-direction: column; }
.pwa-sale-row strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-sale-row small { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-sale-row > b { font-size: 12px; white-space: nowrap; }
.pwa-load-sentinel { padding: 14px; color: var(--muted); font-size: 11px; text-align: center; }

.pwa-alert-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.pwa-alert-summary div { display: flex; flex-direction: column; padding: 15px 11px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.pwa-alert-summary strong { font-size: 25px; }
.pwa-alert-summary span { color: var(--muted); font-size: 10px; }
.pwa-alert-summary .danger strong { color: var(--danger); }
.pwa-alert-summary .warning strong { color: var(--warning); }
.pwa-alert-summary .today strong { color: var(--success); }

.pwa-stock-tools { position: sticky; top: 72px; z-index: 10; margin: 18px -4px 12px; padding: 8px 4px; background: var(--header-bg); backdrop-filter: blur(14px); }
.pwa-stock-tools input { width: 100%; border: 1px solid var(--line); border-radius: 14px; outline: none; padding: 12px 14px; color: var(--text); background: var(--surface); }
.pwa-stock-tools input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(111, 159, 29, .16); }
.pwa-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.pwa-chips button { border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; color: var(--muted); background: transparent; }
.pwa-chips button.active { border-color: var(--primary); color: #fff; background: var(--primary); }
/* Anchor variant: the cover-period chips change a query parameter, so they
   are links rather than the JS-driven filter buttons above. */
.pwa-chip-label { align-self: center; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.pwa-chip-link { border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; color: var(--muted); font-size: 12px; }
.pwa-chip-link.active { border-color: var(--primary); color: #fff; background: var(--primary); }
.pwa-restock-export { display:flex;align-items:center;justify-content:center;gap:7px;width:100%;padding:10px 14px;border:1px solid var(--primary);border-radius:13px;color:var(--primary);font-size:12px;font-weight:750;background:var(--surface); }
.pwa-restock-export:active { color:#fff;background:var(--primary); }

/* Product names run long (and are often Arabic), so the text column must be
   allowed to shrink below its content width. Without `width: 0; flex: 1 1 0`
   a nowrap name sets the row's minimum width and pushes the whole page into
   horizontal scroll — `min-width: 0` alone is not enough here. */
.pwa-stock-list { width: 100%; min-width: 0; overflow: hidden; }
.pwa-stock-row {
    display: flex;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    overflow: hidden;
    gap: 12px;
    padding: 13px;
}
.pwa-stock-row__main { display: flex; width: 0; min-width: 0; flex: 1 1 0; flex-direction: column; align-items: flex-start; gap: 3px; }
.pwa-stock-row__main strong { max-width: 100%; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-stock-row__main small { max-width: 100%; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
/* Opt a list into full product names over multiple lines. The default row
   keeps one line per product so a long alert list stays scannable; where
   the name itself is the point, truncating it hides what was being read.
   `overflow-wrap: anywhere` covers unbroken codes with no space to break at. */
.pwa-stock-row--wrap { align-items: flex-start; }
.pwa-stock-row--wrap .pwa-stock-row__main strong,
.pwa-stock-row--wrap .pwa-stock-row__main small {
    overflow: visible;
    overflow-wrap: anywhere;
    text-overflow: clip;
    white-space: normal;
}

.pwa-status { border-radius: 999px; padding: 3px 7px; font-size: 9px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.pwa-status--zero { color: var(--danger); background: rgba(255, 107, 122, .12); }
.pwa-status--minimum { color: var(--warning); background: rgba(255, 189, 89, .12); }
.pwa-status--day { color: var(--success); background: rgba(66, 211, 155, .1); }
.pwa-stock-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.pwa-stock-level { display: flex; max-width: 40%; flex: 0 0 auto; flex-direction: column; align-items: end; overflow: hidden; text-align: right; }
.pwa-stock-level b { font-size: 19px; }
.pwa-stock-level small { color: var(--muted); font-size: 10px; }

/* Card index. Two columns so each card stays a comfortable tap target on a
   phone, with a wide modifier for anything that warrants a full row. */
.pwa-menu-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pwa-menu-card {
    display: flex;
    min-height: 128px;
    min-width: 0;
    flex-direction: column;
    justify-content: flex-end;
    gap: 3px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--card-bg);
    color: inherit;
}
.pwa-menu-card:active { transform: scale(.99); }
.pwa-menu-card__glyph { margin-bottom: auto; font-size: 26px; line-height: 1; }
.pwa-menu-card strong { font-size: 14px; }
.pwa-menu-card small { color: var(--muted); font-size: 10px; line-height: 1.35; }
.pwa-menu-card--wide { grid-column: 1 / -1; min-height: 0; }
.pwa-menu-grid .pwa-empty { grid-column: 1 / -1; }

.pwa-empty { padding: 28px 18px; border: 1px dashed var(--line); border-radius: 16px; color: var(--muted); text-align: center; }
.pwa-freshness { margin: 22px 0 0; color: var(--muted); font-size: 10px; text-align: center; }
.pwa-offline { display: grid; min-height: 62dvh; place-items: center; align-content: center; text-align: center; }
.pwa-offline div { display: grid; width: 64px; height: 64px; place-items: center; border-radius: 20px; color: var(--primary-2); background: var(--surface); font-size: 28px; }
.pwa-offline h1 { margin: 18px 0 8px; }
.pwa-offline p { max-width: 330px; margin: 0 0 18px; color: var(--muted); }
.pwa-offline button { border: 0; border-radius: 12px; padding: 11px 18px; color: #fff; background: var(--primary); }

.pwa-nav {
    position: fixed;
    z-index: 30;
    right: 0;
    bottom: 0;
    left: 0;
    /* Flex, not grid: tabs are permission-gated so the count varies per
       user, and a flex row cannot wrap (nowrap is the default) no matter
       how many render or how narrow the screen. Grid track sizing kept
       finding ways to spill a tab onto a second line. */
    display: flex;
    overflow: hidden;
    width: min(100%, 720px);
    margin: 0 auto;
    padding: 8px 12px calc(8px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    background: var(--nav-bg);
    backdrop-filter: blur(18px);
}
/* flex: 1 1 0 with min-width: 0 — equal shares that may shrink below their
   label, so tabs never push the bar wider than the screen. */
.pwa-nav a { display: flex; min-width: 0; min-height: 48px; flex: 1 1 0; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 13px; color: var(--muted); }
.pwa-nav a span { font-size: 20px; line-height: 1; }
.pwa-nav a small { max-width: 100%; overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.pwa-nav a.active { color: #fff; background: var(--primary); }

@media (min-width: 600px) {
    .pwa-content { padding-right: 24px; padding-left: 24px; }
}

.pwa-export-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pwa-export-actions .pwa-restock-export { flex: 1 1 120px; justify-content: center; }

@media (prefers-reduced-motion: reduce) {
    .ai-typing-indicator__dots span { animation: none; opacity: .78; }
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

/* Sales Insights: decision-first cards with touch-safe period controls. */
.pwa-insights-periods {
    position: sticky;
    z-index: 10;
    top: 72px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 0 0 14px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--header-bg);
    backdrop-filter: blur(14px);
}
.pwa-insights-period {
    display: grid;
    min-width: 0;
    min-height: 44px;
    place-items: center;
    border-radius: 11px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-align: center;
}
.pwa-insights-period.active { color: #fff; background: var(--primary); }
.pwa-insights-period:focus-visible,
.pwa-insight-row:focus-visible { outline: 3px solid var(--warning); outline-offset: 2px; }

.pwa-insights-hero {
    display: grid;
    gap: 16px;
    overflow: hidden;
    padding: 20px;
    border-radius: 22px;
    color: #fff;
    background: var(--hero-bg);
    box-shadow: 0 16px 38px rgba(36, 48, 31, .16);
}
.pwa-insights-hero__lead { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; }
.pwa-insights-hero__lead > span { color: rgba(255, 255, 255, .78); font-size: 12px; font-weight: 700; }
.pwa-insights-hero__lead > strong { margin: 5px 0 9px; font-size: clamp(31px, 10vw, 45px); font-variant-numeric: tabular-nums; letter-spacing: -1.2px; }
.pwa-insights-hero__metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pwa-insights-hero__metrics div { min-width: 0; padding: 12px; border: 1px solid rgba(255, 255, 255, .15); border-radius: 14px; background: rgba(255, 255, 255, .1); }
.pwa-insights-hero__metrics span,
.pwa-insights-hero__metrics small { display: block; color: rgba(255, 255, 255, .76); font-size: 10px; }
.pwa-insights-hero__metrics strong { display: block; margin: 4px 0; overflow-wrap: anywhere; font-size: 17px; font-variant-numeric: tabular-nums; }

.pwa-trend-badge { display: inline-flex; min-height: 25px; align-items: center; border-radius: 99px; padding: 4px 8px; font-size: 10px; font-weight: 800; line-height: 1.25; }
.pwa-trend-badge.up { color: #315f12; background: #e8f7d7; }
.pwa-trend-badge.down { color: #8f3028; background: #ffe2dd; }
.pwa-trend-badge.neutral { color: rgba(255, 255, 255, .85); background: rgba(255, 255, 255, .13); }
[data-theme="dark"] .pwa-trend-badge.up { color: #dff4c7; background: rgba(131, 189, 37, .2); }
[data-theme="dark"] .pwa-trend-badge.down { color: #ffd8d1; background: rgba(239, 116, 97, .2); }

.pwa-insight-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 10px; }
.pwa-insight-kpis div { display: flex; min-width: 0; min-height: 82px; flex-direction: column; justify-content: center; padding: 13px; border: 1px solid var(--line); border-radius: 16px; background: var(--card-bg); }
.pwa-insight-kpis strong { overflow-wrap: anywhere; font-size: 20px; font-variant-numeric: tabular-nums; }
.pwa-insight-kpis span { margin-top: 4px; color: var(--muted); font-size: 11px; }

.pwa-insight-heading > div { min-width: 0; }
.pwa-insight-heading h2 { margin-top: 2px; }
.pwa-insight-heading > span { max-width: 48%; text-align: right; }
.pwa-insight-list { display: grid; gap: 9px; }
.pwa-insight-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    min-width: 0;
    min-height: 76px;
    align-items: center;
    gap: 12px;
    padding: 13px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--primary);
    border-radius: 16px;
    background: var(--card-bg);
    transition: border-color 180ms ease, background-color 180ms ease;
}
.pwa-insight-row--down { border-left-color: var(--danger); }
.pwa-insight-row:active { background: var(--surface-2); }
.pwa-insight-row__body { min-width: 0; }
.pwa-insight-row__title { display: flex; min-width: 0; align-items: flex-start; justify-content: space-between; gap: 8px; }
.pwa-insight-row__title strong { min-width: 0; overflow-wrap: anywhere; font-size: 13px; line-height: 1.4; }
.pwa-insight-row__body > small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.pwa-insight-row__value { display: flex; max-width: 118px; flex-direction: column; align-items: flex-end; text-align: right; }
.pwa-insight-row__value strong { overflow-wrap: anywhere; font-size: 14px; font-variant-numeric: tabular-nums; }
.pwa-insight-row__value span { margin-top: 3px; color: var(--muted); font-size: 9px; }

.pwa-insight-watch { margin-top: 22px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.pwa-insight-watch summary { display: flex; min-height: 44px; cursor: pointer; align-items: center; justify-content: space-between; gap: 12px; list-style: none; }
.pwa-insight-watch summary::-webkit-details-marker { display: none; }
.pwa-insight-watch summary span { display: flex; flex-direction: column; }
.pwa-insight-watch summary strong { margin-top: 2px; font-size: 15px; }
.pwa-insight-watch summary b { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 50%; color: var(--danger); background: rgba(189, 75, 63, .12); }
.pwa-insight-watch > p { margin: 4px 0 12px; color: var(--muted); font-size: 10px; line-height: 1.45; }

.pwa-insight-rank { min-height: 82px; color: inherit; }
.pwa-insight-rank__number { display: grid; width: 28px; height: 28px; flex: 0 0 28px; place-items: center; border-radius: 9px; color: var(--primary); background: rgba(79, 142, 24, .11); font-size: 11px; font-weight: 850; }
.pwa-insight-ratios { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.pwa-insight-ratios div { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--card-bg); }
.pwa-insight-ratios span,
.pwa-insight-ratios small { display: block; color: var(--muted); font-size: 10px; line-height: 1.4; }
.pwa-insight-ratios strong { display: block; margin: 5px 0; overflow-wrap: anywhere; font-size: 18px; font-variant-numeric: tabular-nums; }
.pwa-insight-methodology { margin-top: 24px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.pwa-insight-methodology summary { display: flex; min-height: 44px; cursor: pointer; align-items: center; font-size: 12px; font-weight: 800; }
.pwa-insight-methodology[open] summary { margin-bottom: 10px; }

@media (min-width: 600px) {
    .pwa-insights-hero { grid-template-columns: 1.15fr .85fr; align-items: end; }
    .pwa-insight-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
