/* Shared ledger primitives — pantry manifest + item sheet */

/* Zone / filter chips */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.filter-chips--scroll {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: var(--space-xs);
    -webkit-overflow-scrolling: touch;
}

.chip {
    flex-shrink: 0;
    min-height: 36px;
    padding: 0 var(--space-md);
    border-radius: 20px;
    background: transparent;
    border: 1px solid var(--color-ink);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--color-text);
    transition:
        background 0.2s var(--ease-master),
        color 0.2s var(--ease-master),
        transform var(--duration-press) var(--ease-master);
}

.chip.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.chip:active {
    transform: scale(0.96);
}

/* Manifest tally */
.manifest-tally {
    --tally-btn-size: 32px;
    --tally-gap: 12px;
    --tally-num-size: 1.75rem;
    --tally-num-width: 2.15rem;
    --tally-step: 2.125rem;
    display: grid;
    grid-template-columns: var(--tally-btn-size) var(--tally-num-width) var(--tally-btn-size);
    gap: var(--tally-gap);
    align-items: center;
    flex-shrink: 0;
}

.tally-count {
    font-family: var(--font-display);
    font-size: var(--tally-num-size);
    font-weight: 700;
    width: 100%;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    color: var(--color-text);
    display: block;
    justify-self: center;
}

.tally-count-slot {
    display: block;
    height: var(--tally-step);
    overflow: hidden;
}

.tally-count-track {
    display: flex;
    flex-direction: column;
    transform: translateY(0);
    will-change: transform;
}

.tally-count-digit {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--tally-step);
    line-height: 1;
    flex-shrink: 0;
}

.tally-count--empty {
    color: var(--color-clay);
}

.tally-count--editable {
    cursor: text;
    position: relative;
}

.tally-count--editing .tally-count-slot {
    visibility: hidden;
}

.tally-count-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: none;
    border-bottom: 1px solid var(--color-ink);
    background: transparent;
    font: inherit;
    font-family: var(--font-display);
    font-size: inherit;
    font-weight: 700;
    text-align: center;
    color: inherit;
    outline: none;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

.tally-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--color-text-muted);
    color: var(--color-text);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition:
        transform var(--duration-press) var(--ease-master),
        background 0.2s var(--ease-master),
        border-color 0.2s var(--ease-master);
}

.tally-btn:active {
    transform: scale(0.9);
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.tally-btn--trash {
    color: var(--color-clay);
    border-color: var(--color-clay);
}

.tally-btn--trash:active {
    background: var(--color-clay);
    border-color: var(--color-clay);
    color: white;
}

.tally-btn--trash .material-symbols-outlined {
    font-size: 1.1rem;
}

/* Ledger form fields */
.ledger-field {
    margin-bottom: var(--space-lg);
}

.ledger-field--inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
}

.ledger-field--inline .ledger-label {
    margin-bottom: 0;
}

.ledger-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.ledger-input,
.ledger-textarea {
    width: 100%;
    padding: var(--space-sm) 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(44, 42, 41, 0.2);
    border-radius: 0;
    outline: none;
    font-size: 1rem;
    color: var(--color-text);
    transition: border-color 0.2s var(--ease-master);
}

.ledger-input:focus,
.ledger-textarea:focus {
    border-bottom-width: 2px;
    border-bottom-color: var(--color-ink);
    padding-bottom: calc(var(--space-sm) - 1px);
}

.ledger-textarea {
    min-height: 80px;
    resize: vertical;
}

/* Item sheet shell */
.item-sheet {
    width: 100%;
    max-height: calc(100dvh - var(--bottom-nav-offset) - var(--space-md));
    max-height: calc(100vh - var(--bottom-nav-offset) - var(--space-md));
    overflow-y: auto;
    background: var(--color-surface);
    border-radius: 4px 4px 0 0;
    padding: var(--space-lg) var(--space-md);
    padding-bottom: calc(var(--bottom-nav-offset) + var(--space-lg));
    box-shadow: var(--shadow-card);
    transform: translateY(100%);
    transition: transform var(--duration-sheet) var(--ease-master);
}

.sheet-overlay.is-open .item-sheet {
    transform: translateY(0);
}

.sheet-overlay.is-closing .item-sheet {
    transform: translateY(100%);
}

.item-sheet-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid rgba(44, 42, 41, 0.1);
}

.item-sheet-title {
    flex: 1;
    min-width: 0;
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}

.item-sheet-dismiss {
    flex-shrink: 0;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 300;
    line-height: 1;
    color: var(--color-text-muted);
    transition: color 0.2s var(--ease-master);
}

.item-sheet-dismiss:active {
    color: var(--color-text);
}

.item-sheet-body .filter-chips {
    margin-bottom: var(--space-lg);
}

.item-sheet-form {
    display: flex;
    flex-direction: column;
}

.item-sheet-submit {
    width: 100%;
    min-height: var(--touch-lg);
    margin-top: var(--space-md);
    padding: 0 var(--space-lg);
    border: none;
    border-radius: var(--radius);
    background: var(--color-primary);
    color: white;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.06em;
    box-shadow: var(--shadow-fab);
    transition: transform var(--duration-press) var(--ease-master);
}

.item-sheet-submit:active {
    transform: scale(0.98);
}

.item-sheet-submit:disabled {
    opacity: 0.6;
}

.item-sheet-error {
    margin: var(--space-sm) 0 0;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    background: var(--color-danger-bg);
    color: var(--color-clay);
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.4;
}

.item-sheet-danger {
    width: 100%;
    min-height: var(--touch-min);
    margin-top: var(--space-sm);
    padding: 0;
    border: none;
    background: none;
    color: var(--color-clay);
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    transition: opacity 0.2s var(--ease-master);
}

.item-sheet-danger:active {
    opacity: 0.65;
}

/* Photo attachment */
.photo-attach {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
}

.photo-attach-trigger {
    width: 100%;
    aspect-ratio: 4 / 3;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    overflow: hidden;
    padding: 0;
    transition:
        border-color 0.25s var(--ease-master),
        box-shadow 0.25s var(--ease-master);
}

.photo-attach-trigger.has-image {
    border-color: transparent;
}

.photo-attach-trigger:active {
    border-color: var(--color-primary);
}

.photo-attach-trigger .material-symbols-outlined {
    font-size: 1.75rem;
    transition: transform 0.3s var(--ease-master), opacity 0.25s var(--ease-master);
}

.photo-attach-trigger:active .material-symbols-outlined {
    transform: scale(0.88);
}

.photo-attach-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.25s var(--ease-master);
}

.photo-attach-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-sm);
    animation: photoFadeIn 0.35s var(--ease-master) both;
}

.photo-attach-img.hidden {
    animation: none;
}

@keyframes photoFadeIn {
    from { opacity: 0; transform: scale(1.04); }
    to   { opacity: 1; transform: scale(1); }
}

.photo-attach-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.photo-attach-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    min-height: var(--touch-min);
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sharp);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    transition:
        color 0.2s var(--ease-master),
        border-color 0.2s var(--ease-master),
        background 0.2s var(--ease-master),
        transform var(--duration-press) var(--ease-master),
        opacity 0.2s var(--ease-master);
}

.photo-attach-action .material-symbols-outlined {
    font-size: 1.15rem;
    transition: transform var(--duration-press) var(--ease-master);
}

.photo-attach-action:active {
    color: var(--color-text);
    border-color: var(--color-primary);
    background: var(--color-surface-2);
    transform: scale(0.96);
}

.photo-attach-action:active .material-symbols-outlined {
    transform: scale(0.88);
}

.photo-attach-action.hidden {
    display: none;
}

.photo-attach-action--danger {
    color: var(--color-danger);
    border-color: rgba(184, 92, 56, 0.2);
}

.photo-attach-action--danger:active {
    color: var(--color-danger);
    border-color: rgba(184, 92, 56, 0.5);
    background: rgba(184, 92, 56, 0.08);
}

.photo-attach-action--restore {
    color: var(--color-primary);
    border-color: rgba(122, 139, 118, 0.25);
    animation: photoRestoreIn 0.3s var(--ease-master) both;
}

.photo-attach-action--restore:active {
    color: var(--color-primary-dark);
    border-color: rgba(122, 139, 118, 0.5);
    background: rgba(122, 139, 118, 0.08);
}

@keyframes photoRestoreIn {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* Swipe row (pantry manifest + grocery list) */
.pantry-manifest .swipe-row,
.grocery-list .swipe-row {
    position: relative;
    overflow: hidden;
    background: var(--color-bg);
}

.pantry-manifest .swipe-row-actions,
.grocery-list .swipe-row-actions {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
    box-sizing: border-box;
}

.pantry-manifest .swipe-row-actions--trailing,
.grocery-list .swipe-row-actions--trailing {
    right: 0;
}

.pantry-manifest .swipe-row-actions--leading,
.grocery-list .swipe-row-actions--leading {
    left: 0;
}

.pantry-manifest .swipe-action,
.grocery-list .swipe-action {
    width: 72px;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xs);
    text-align: center;
    line-height: 1.2;
    transition: transform var(--duration-press) var(--ease-master);
}

.pantry-manifest .swipe-action:active,
.grocery-list .swipe-action:active {
    transform: scale(0.96);
}

.pantry-manifest .swipe-action-edit {
    background: var(--color-text);
    color: white;
}

.grocery-list .swipe-action-toss {
    background: var(--color-clay);
    color: white;
}

.grocery-list .swipe-action-stock {
    background: var(--color-primary);
    color: white;
}

.grocery-list .swipe-action-buy {
    background: var(--color-text);
    color: white;
}

.pantry-manifest .swipe-row-content,
.grocery-list .swipe-row-content {
    position: relative;
    z-index: 1;
    width: 100%;
    box-sizing: border-box;
    background: var(--color-bg);
    transition: transform 0.4s var(--ease-master);
    will-change: transform;
    touch-action: pan-y;
}

/* Gap rides with the row text; swipe travel stops at the button edge */
.pantry-manifest .swipe-row-content--trailing-action,
.grocery-list .swipe-row-content--trailing-action {
    padding-right: var(--space-md);
}

.pantry-manifest .swipe-row-content--leading-action,
.grocery-list .swipe-row-content--leading-action {
    padding-left: var(--space-md);
}

.pantry-manifest .swipe-row-content.is-dragging,
.grocery-list .swipe-row-content.is-dragging {
    transition: none;
}

.pantry-manifest .manifest-row {
    touch-action: pan-y;
}
