/* Tab button styles */
.tab-buttons {
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    display: flex;
    text-wrap: nowrap;
    gap: 0.25rem;
    padding-bottom: 0.25rem;
    padding-right: 0.25rem;
    scrollbar-gutter: stable both-edges;
}

.product-sku {
    text-wrap: nowrap;
}

.product-name {
    width: 20ch
}

body {
    margin: 0;
    padding: 0.5rem clamp(0.5rem, 2vw, 1.25rem) 0.5rem;
    max-width: 100%;
}

main#app-shell {
    display: block;
    width: 100%;
    margin-inline: auto;
}

section#tab-shell {
    display: block;
}

#tabs {
    display: block;
}

.tabs {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.stock-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    line-height: 1.2;
}

.stock-meta .title-meta {
    font-weight: 600;
    color: var(--text-main);
}

.stock-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-gutter: stable both-edges;
}

.stock-actions button {
    flex: 0 0 auto;
    white-space: nowrap;
}


.tab-buttons button {
    margin: 0;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 0.25rem 0.25rem 0 0;
    background: var(--background);
    cursor: pointer;
}

.tab-buttons button.active {
    background: var(--text-main);
    color: var(--background);
}

.count {
    text-align: center;
    vertical-align: top;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}


.table-container {
    overflow: auto;
    flex: initial;
    max-height: min(90svh, calc(100svh - 5rem));
    min-height: 280px;
    scrollbar-gutter: stable both-edges;
    /* This is the scroll container for sticky positioning */
}

.listing-table {
    word-wrap: normal;
    table-layout: auto;
    border-collapse: collapse;
    width: 100%;
}

.listing-table tr:nth-of-type(even)>td:first-child,
.listing-table tr:nth-of-type(even)>th:first-child {
    background: var(--background);
}

.listing-table tr:nth-of-type(odd)>td:first-child,
.listing-table tr:nth-of-type(odd)>th:first-child {
    background: var(--background-body);
}

.listing-table tbody tr:nth-of-type(even) td:not(:first-child),
.listing-table tbody tr:nth-of-type(even) th:not(:first-child) {
    background: var(--background);
}

.listing-table tbody tr:nth-of-type(odd) td:not(:first-child),
.listing-table tbody tr:nth-of-type(odd) th:not(:first-child) {
    background: var(--background-body);
}

/* Make the leftmost column sticky so SKU stays visible when horizontally scrolling */
.listing-table th:first-child,
.listing-table td:first-child {
    position: -webkit-sticky;
    position: sticky;
    left: 0;
    z-index: 3;
    /* Drop shadow on the right to separate from scrolled content */
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.2);
}

/* Apply striping to even rows in first column */
.listing-table tr:nth-of-type(even) td:first-child {
    background: var(--background);
}

/* Apply striping to odd rows in first column */
.listing-table tr:nth-of-type(odd) td:first-child {
    background: var(--background-body);
}

/* Sticky header row (first row in thead) */
.listing-table thead tr:first-child th {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 2;
    /* Solid background for header row */
    background: var(--background) !important;
    /* Set explicit height to control totals positioning */
    height: 2.5rem;
    line-height: 2.5rem;
    padding: 0 0.5rem;
}

/* Ensure header first cell stays solid and doesn't get striping */
.listing-table thead tr:first-child th:first-child {
    background: var(--background) !important;
}

/* Sticky totals row (second row in thead) */
.listing-table thead tr.totals-row th,
.listing-table thead tr.totals-row td {
    position: -webkit-sticky;
    position: sticky;
    /* Position exactly 2.5rem below the top (where header ends) */
    top: 2.5rem;
    z-index: 2;
    /* Solid background for totals row */
    background: var(--background) !important;
    padding: 0.5rem;
    /* Drop shadow on the bottom to separate from scrolled content */
    /*box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);*/
}

/* Ensure totals row first cell stays solid and doesn't get striping */
.listing-table thead tr.totals-row td:first-child,
.listing-table thead tr.totals-row th:first-child {
    background: var(--background) !important;
}

/* Fill any gap above the totals row with a pseudo-element */
.listing-table thead tr.totals-row th::before,
.listing-table thead tr.totals-row td::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--background);
    z-index: 4;
}

/* Subtle right shadow to visually separate the sticky column from scrolled content */
.listing-table th:first-child:not(.static-head),
.listing-table td:first-child:not(.static-head) {
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.2);
}

/* Top-left corner cells need higher z-index to appear above everything */
.listing-table thead tr:first-child th:first-child {
    z-index: 4;
    background: var(--background) !important;
    /* Right shadow only, no bottom shadow since cell below is also sticky */
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.2);
}

.listing-table thead tr.totals-row th:first-child {
    z-index: 4;
    background: var(--background) !important;
    /* Right shadow only, no bottom shadow since cells below are also sticky */
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.2);
}

#tab-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow: visible;
}

/* Product header in table row header cell */
.product-header {
    text-align: left;
    font-weight: normal;
}

.product-header .product-sku {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
    font-family: monospace;
}

.product-header .product-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
    display: block;
}

.product-header .product-name {
    display: block;
    max-width: 20ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.variant {
    display: inline-block;
    max-width: 20ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Status styles */
.stock-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.stock-header h2 {
    margin: 0;
}

.stock-header small {
    color: var(--text-muted);
}

.button-group {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 1rem;
}

.export-button:hover {
    background: var(--text-main);
    color: var(--background);
}

.export-button:active {
    transform: translateY(1px);
}

.stock-actions button.ghost {
    border-color: var(--border);
    background: var(--background);
}

.stock-actions button.ghost:hover {
    background: var(--border);
    color: var(--text-main);
}

/* Dialog cosmetics to better match the page (keeps native semantics) */
dialog#export-dialog {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: inherit;
    max-width: 420px;
}

dialog#export-dialog header {
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

/* Make the button-group inside dialogs feel compact */
dialog#export-dialog .button-group {
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

form#export-form {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 0.5rem;
}

/* Small screens: don't float the export button (stack naturally) */
@media (max-width: 520px) {
    body {
        padding: 0.5rem;
    }

    .stock-actions {
        justify-content: flex-start;
        gap: 0.4rem;
    }
}

/* Unknown SKU styling */
.unknown-badge {
    display: inline-block;
    background: #ffb3b3;
    color: #700;
    padding: 0 6px;
    border-radius: 4px;
    margin-right: 6px;
    font-size: 0.85em;
    text-transform: lowercase;
}

/* Totals row at top of table */
.totals-row {
    border-bottom: 2px solid rgba(100, 200, 100, 0.4);
}

.totals-row th {
    font-weight: 700;
    text-align: left;
}

.totals-row .total-count {
    font-weight: 700;
    text-align: center;
    font-size: 1.05rem;
}

/* Count cells with badges */
td.count,
td.total-count {
    position: relative;
    vertical-align: top;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.count-value {
    display: block;
    line-height: 1.4;
}

.change-badge {
    display: block;
    font-size: 0.65rem;
    font-weight: 500;
    padding: 1px 4px;
    border-radius: 2px;
    margin-top: 3px;
    opacity: 0.7;
}

.change-badge.positive {
    background: rgba(100, 200, 100, 0.3);
    color: var(--text-bright);
}

.change-badge.negative {
    background: rgba(200, 100, 100, 0.3);
    color: var(--text-bright);
}