/* Brand overrides on top of the shadcn-style tokens in lib.css */
:root {
    --primary: rgb(174 154 96);
    --primary-foreground: rgb(250 250 250);
    --ring: rgb(174 154 96);
    --radius-medium: 0.5rem;
    --radius-large: 0.75rem;
    --logo-bar-h: 56px;
    --container-pad: 14px;
}

@media (min-width: 640px) {
    :root {
        --logo-bar-h: 64px;
        --container-pad: 1rem;
    }
}

/* ---------- Apps launcher (used elsewhere) ---------- */
.apps {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.apps .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 20px;
}

.apps .nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.apps a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-decoration: none;
    color: var(--foreground);
    margin: 1rem;
    border: 1px solid var(--border);
    width: 100px;
    height: 100px;
    border-radius: var(--radius-medium);
    font-size: 12px;
    gap: 5px;
    background-color: var(--card);
    box-shadow: var(--shadow-small);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

@media (hover: hover) {
    .apps a:hover {
        transform: translateY(-4px);
        box-shadow: var(--shadow-large);
    }
}

.sunshine-glow {
    background: linear-gradient(180deg, #E7F5FD 0%, #FCEBE0 100%);
}

/* ---------- Autocomplete ---------- */
.autocomp {
    background: var(--card);
    border-radius: var(--radius-medium);
    border: 1px solid var(--border);
    text-align: left;
    max-height: 50vh;
    overflow-y: auto;
}

.autocomp-item {
    padding: var(--space-3);
    cursor: pointer;
    border-radius: var(--radius-small);
}

.autocomp-item:hover,
.autocomp-sel {
    background: var(--accent);
}

/* ---------- App chrome (top logo bar) ---------- */
header {
    background: var(--background);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--container-pad);
    height: var(--logo-bar-h);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

header img {
    height: 28px;
    width: auto;
}

@media (min-width: 640px) {
    header img {
        height: 36px;
    }
}

.header-offset {
    padding-top: var(--logo-bar-h);
}

/* ---------- Page header (compact, sticky, solid) ---------- */
.page-header {
    position: sticky;
    top: var(--logo-bar-h);
    z-index: 10;
    background: var(--background);
    border-bottom: 1px solid var(--border);
    margin-inline: calc(-1 * var(--container-pad));
    padding: 10px var(--container-pad);
    margin-block-end: var(--space-4);

    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "back title";
    align-items: center;
    gap: var(--space-3);
}

.page-header.no-back {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "title";
}

.page-back {
    grid-area: back;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-medium);
    background: var(--card);
    color: var(--foreground);
    text-decoration: none;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
    flex-shrink: 0;
}

.page-back:hover,
.page-back:focus-visible {
    background: var(--accent);
    color: var(--foreground);
    text-decoration: none;
    outline: none;
}

.page-back svg {
    width: 18px;
    height: 18px;
}

.page-back-text {
    display: none;
    margin-left: 6px;
    font-size: var(--text-7);
    font-weight: var(--font-medium);
}

.page-title-block {
    grid-area: title;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.page-title-block h1 {
    margin: 0;
    font-size: 1rem;
    font-weight: var(--font-semibold);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-subtitle {
    margin: 0;
    font-size: var(--text-8);
    color: var(--muted-foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

@media (min-width: 640px) {
    .page-header {
        padding: var(--space-3) var(--container-pad);
        gap: var(--space-4);
    }

    .page-back {
        width: auto;
        height: 38px;
        padding: 0 var(--space-3);
    }

    .page-back-text {
        display: inline;
    }

    .page-title-block h1 {
        font-size: var(--text-4);
    }

    .page-subtitle {
        font-size: var(--text-7);
    }
}

/* ---------- Item cards (batch view + dashboard) ---------- */
.items-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 640px) {
    .items-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-4);
    }
}

@media (min-width: 1024px) {
    .items-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1440px) {
    .items-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.item-card {
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

@media (hover: hover) {
    .item-card:hover {
        box-shadow: var(--shadow-medium);
        border-color: color-mix(in srgb, var(--foreground) 18%, var(--border));
        transform: translateY(-2px);
    }
}

.item-media {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    isolation: isolate;
}

.item-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    cursor: pointer;
    transition: transform var(--transition);
}

@media (hover: hover) {
    .item-media a:hover img {
        transform: scale(1.04);
    }
}

/* Top gradient so floating badges stay readable on bright photos */
.item-media:has(img)::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 64px;
    background: linear-gradient(to bottom,
        rgba(0, 0, 0, .42) 0%,
        rgba(0, 0, 0, .15) 60%,
        rgba(0, 0, 0, 0) 100%);
    pointer-events: none;
    z-index: 1;
}

/* Floating item-number badge */
.item-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: var(--text-8);
    font-weight: var(--font-semibold);
    letter-spacing: 0.02em;
    color: #fff;
    background: rgba(0, 0, 0, .55);
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: var(--radius-full);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: none;
}

.item-media-empty {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    color: var(--muted-foreground);
    background:
        repeating-linear-gradient(45deg,
            transparent 0,
            transparent 12px,
            color-mix(in srgb, var(--border) 50%, transparent) 12px,
            color-mix(in srgb, var(--border) 50%, transparent) 13px);
    cursor: pointer;
    transition: color var(--transition-fast), background-color var(--transition-fast);
}

.item-media-empty:focus-visible {
    color: var(--primary);
    background-color: color-mix(in srgb, var(--primary) 6%, transparent);
    outline: none;
}

@media (hover: hover) {
    .item-media-empty:hover {
        color: var(--primary);
        background-color: color-mix(in srgb, var(--primary) 6%, transparent);
    }
}

.item-media-empty .icon {
    width: 28px;
    height: 28px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.item-media-empty .label {
    font-size: var(--text-7);
    font-weight: var(--font-medium);
}

.item-media-empty-hint {
    font-size: var(--text-8);
    color: var(--muted-foreground);
    margin-top: -2px;
}

/* Status pill (approved / pending) sits top-right of the weaver image */
.status-pill {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    font-size: var(--text-8);
    font-weight: var(--font-semibold);
    letter-spacing: 0.01em;
    line-height: 1;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: none;
    user-select: none;
}

.status-pill svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.status-pill.status-approved {
    color: #fff;
    background: color-mix(in srgb, var(--success) 88%, transparent);
    border-color: color-mix(in srgb, #fff 25%, transparent);
}

.status-pill.status-pending {
    color: #fff;
    background: color-mix(in srgb, var(--warning) 90%, transparent);
    border-color: color-mix(in srgb, #fff 25%, transparent);
}

/* Subtle ring around approved photos so they're recognisable at a glance */
.item-media.is-approved {
    box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--success) 70%, transparent);
}

/* "Change/Replace" floating action — bottom-right so it doesn't collide with status pill */
.item-media-action {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 2;
}

.item-media-action .change-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 6px 8px;
    font-size: var(--text-8);
    font-weight: var(--font-medium);
    color: #fff;
    background: rgba(0, 0, 0, .55);
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: var(--radius-full);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
    user-select: none;
    line-height: 1;
}

.item-media-action .change-btn:active {
    transform: scale(.97);
}

@media (hover: hover) {
    .item-media-action .change-btn:hover {
        background: rgba(0, 0, 0, .72);
        border-color: rgba(255, 255, 255, .32);
    }
}

.item-media-action .change-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.item-media-uploading {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    background: color-mix(in srgb, var(--background) 78%, transparent);
    color: var(--muted-foreground);
    font-size: var(--text-7);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.item-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

@media (min-width: 640px) {
    .item-content {
        padding: var(--space-4);
        gap: var(--space-3);
    }
}

.item-code {
    display: block;
    width: 100%;
    font-family: var(--font-mono);
    font-size: var(--text-8);
    color: var(--muted-foreground);
    background: var(--muted);
    padding: 5px 10px;
    border-radius: var(--radius-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

/* Barcode sits directly below the design image — always full card width,
   never shared with another element in a multi-column row. */
.item-code-barcode {
    grid-column: 1 / -1;   /* safety: span all columns if ever inside a grid */
    align-self: stretch;
    flex-shrink: 0;
}

.item-attrs {
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
}

@media (min-width: 640px) {
    .item-attrs {
        gap: var(--space-3) var(--space-4);
    }
}

.item-attr {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.item-attr dt {
    font-size: var(--text-8);
    color: var(--muted-foreground);
    font-weight: var(--font-medium);
    line-height: 1.3;
}

.item-attr dd {
    margin: 0;
    font-size: var(--text-7);
    color: var(--foreground);
    word-break: break-word;
    line-height: 1.35;
}

.item-attrs-empty {
    color: var(--muted-foreground);
    font-size: var(--text-8);
    text-align: center;
    padding: var(--space-2) 0;
    font-style: italic;
}

/* ---------- Reference images strip (top of card content) ---------- */
.ref-strip {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px dashed color-mix(in srgb, var(--border) 80%, transparent);
}

.ref-strip-head {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.ref-strip-label {
    font-size: var(--text-8);
    color: var(--muted-foreground);
    font-weight: var(--font-medium);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ref-strip-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: var(--font-semibold);
    color: var(--muted-foreground);
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    line-height: 1;
}

.ref-strip-scroll {
    position: relative;
    margin: 0 -2px;
}

.ref-strip-items {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding: 0 2px 6px;
    scroll-snap-type: x proximity;
    scroll-padding-left: 2px;
}

.ref-strip-items::-webkit-scrollbar {
    height: 6px;
}

.ref-strip-items::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--border) 80%, transparent);
    border-radius: var(--radius-full);
}

/* Right-edge gradient + chevron — visible only when content overflows
   AND the user hasn't scrolled to the end yet. Pure visual affordance. */
.ref-strip-fade {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 6px;
    width: 56px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    color: var(--foreground);
    pointer-events: none;
    background: linear-gradient(
        to right,
        color-mix(in srgb, var(--card) 0%, transparent) 0%,
        color-mix(in srgb, var(--card) 70%, transparent) 55%,
        var(--card) 100%
    );
    opacity: 0;
    transition: opacity 0.18s ease;
}

.ref-strip-scroll.has-overflow .ref-strip-fade {
    opacity: 1;
}

.ref-strip-scroll.has-overflow.at-end .ref-strip-fade {
    opacity: 0;
}

.ref-strip-fade svg {
    width: 18px;
    height: 18px;
    color: var(--muted-foreground);
    animation: ref-strip-nudge 1.6s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
    .ref-strip-fade svg {
        animation: none;
    }
}

@keyframes ref-strip-nudge {
    0%, 60%, 100% { transform: translateX(0); opacity: 0.85; }
    30% { transform: translateX(3px); opacity: 1; }
}

.ref-thumb {
    flex: 0 0 auto;
    width: 168px;
    height: 168px;
    border-radius: var(--radius-medium);
    overflow: hidden;
    border: 1px solid var(--border);
    text-decoration: none;
    display: block;
    background: var(--muted);
    transition: transform var(--transition-fast), border-color var(--transition-fast);
    scroll-snap-align: start;
}

.ref-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

@media (hover: hover) {
    .ref-thumb:hover {
        border-color: color-mix(in srgb, var(--foreground) 25%, var(--border));
        transform: translateY(-1px);
    }
}

@media (min-width: 640px) {
    .ref-thumb {
        width: 192px;
        height: 192px;
    }
}

/* ---------- Empty / loading states ---------- */
.state-block {
    text-align: center;
    padding: var(--space-12) var(--space-4);
    color: var(--muted-foreground);
    font-size: var(--text-7);
}

/* ---------- Mobile-only visibility helpers ---------- */
.show-sm-up {
    display: none;
}

@media (min-width: 640px) {
    .show-sm-up {
        display: inline;
    }
}
