* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

nav {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 15px 0;
    border-bottom: 2px solid #333;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

nav .logo {
    font-size: 1.4em;
    font-weight: bold;
    color: #333;
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 15px;
}

.nav-links a {
    color: #555;
    text-decoration: none;
}

.nav-links a:hover {
    color: #000;
    text-decoration: underline;
}

.nav-auth {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-user {
    color: #555;
    font-size: 0.9em;
}

.logout-form {
    display: inline;
    margin: 0;
}

.btn-link {
    background: none;
    color: #555;
    border: none;
    padding: 0;
    font-size: 0.9em;
    cursor: pointer;
    text-decoration: none;
}

.btn-link:hover {
    color: #000;
    text-decoration: underline;
}

h1, h2 {
    margin-bottom: 15px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

th, td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid #ddd;
}

th {
    background: #f5f5f5;
    font-weight: 600;
}

a {
    color: #0066cc;
}

form {
    margin: 15px 0;
}

input[type="text"],
input[type="email"],
input[type="password"],
select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

button {
    padding: 8px 16px;
    background: #333;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

button:hover {
    background: #555;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
}

.category-filter {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.category-nav, .sort-filter, .filter-form, .add-form, .search-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.add-form input[type="text"] {
    width: 500px;
    max-width: 100%;
}

.search-form input[type="text"] {
    width: 400px;
    max-width: 100%;
}

.toolbar {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.toolbar .filter-form,
.toolbar .add-form {
    margin: 8px 0;
}

.empty {
    color: #888;
    padding: 20px 0;
}

.error {
    color: #cc0000;
    padding: 10px;
    background: #fff0f0;
    border: 1px solid #ffcccc;
    border-radius: 4px;
}

.flash {
    padding: 10px 15px;
    border-radius: 4px;
    margin-bottom: 15px;
}

.flash-success {
    color: #155724;
    background: #d4edda;
    border: 1px solid #c3e6cb;
}

.flash-info {
    color: #0c5460;
    background: #d1ecf1;
    border: 1px solid #bee5eb;
}

.flash-error {
    color: #721c24;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
}

.flash-warning {
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffeeba;
}

/* Product detail */
.product-detail .product-header {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.product-image {
    max-width: 250px;
    height: auto;
}

.product-info .price {
    font-size: 1.5em;
    font-weight: bold;
    color: #cc0000;
}

.inline-form {
    display: inline;
    margin: 0;
}

.action-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 15px;
}

.btn-danger {
    background: #cc0000;
}

.btn-danger:hover {
    background: #990000;
}

.mc-link {
    display: inline-block;
    margin: 10px 0;
}

/* Search results */
.search-results {
    display: grid;
    gap: 15px;
}

.search-card {
    display: flex;
    gap: 15px;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.search-card img {
    width: 100px;
    height: 100px;
    object-fit: contain;
}

.card-info h3 {
    margin-bottom: 5px;
}

.card-info .price {
    font-weight: bold;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bulk-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.original-price {
    text-decoration: line-through;
    color: #888;
    font-weight: normal;
}

.scraped-time {
    font-size: 0.85em;
    color: #888;
}

.products-table td:last-child {
    white-space: nowrap;
}

.stock-status {
    font-size: 1.2em;
    font-weight: bold;
}

.stock-status .store-name {
    font-weight: normal;
    font-size: 0.85em;
    color: #666;
}

.in-stock {
    color: #006600;
}

.out-of-stock {
    color: #cc0000;
}

.pagination {
    display: flex;
    gap: 15px;
    align-items: center;
    padding: 20px 0;
}

.result-count {
    color: #888;
    margin-bottom: 10px;
}

/* Collapsible section dropdowns */
.section-dropdown { margin: 15px 0; }
.section-dropdown summary { cursor: pointer; list-style: none; }
.section-dropdown summary::-webkit-details-marker { display: none; }
.section-dropdown summary h2 { display: inline; }
.section-dropdown summary::before { content: '\25b6'; display: inline-block; margin-right: 8px; transition: transform 0.15s; font-size: 0.7em; vertical-align: middle; }
.section-dropdown[open] summary::before { transform: rotate(90deg); }

/* Open box items */
.ob-side-price { font-size: 0.85em; color: #cc6600; font-weight: 600; margin-left: 8px; }
.sku { color: #888; font-size: 0.85em; }
.ob-price { font-weight: bold; color: #cc6600; }
.sold-item { color: #999; }
.sold-item td { text-decoration: line-through; }
.open-box-items details { margin-top: 15px; }
.open-box-items summary { cursor: pointer; color: #666; font-size: 0.9em; }

/* Refresh All */
#refresh-all-btn.hidden { display: none; }
#refresh-all-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.refresh-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1em;
    padding: 0 2px;
    color: #666;
    vertical-align: middle;
}
.refresh-btn:hover { color: #333; }
.refresh-btn:disabled { opacity: 0.4; cursor: not-allowed; }

tr.refreshing { opacity: 0.5; position: relative; }
tr.refreshing td:first-child::after {
    content: "↻";
    position: absolute;
    right: 10px;
    animation: spin 1s linear infinite;
    color: #666;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* Auth forms */
.auth-form {
    max-width: 400px;
    margin: 40px auto;
}

.auth-form h1 {
    margin-bottom: 20px;
}

.auth-form form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-form label {
    font-weight: 600;
    font-size: 0.9em;
    margin-top: 4px;
}

.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"] {
    width: 100%;
}

.auth-form button {
    margin-top: 12px;
}

.auth-form .remember-label {
    font-weight: normal;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.auth-link {
    margin-top: 15px;
    font-size: 0.9em;
    color: #666;
}

.store-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 8px 12px;
}

.store-option {
    font-weight: normal;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-hint {
    font-size: 0.8em;
    color: #888;
    margin-top: 4px;
}

.store-stock-summary {
    font-size: 0.8em;
    color: #888;
}

/* ── Sales ── */
.profit-positive { color: #006600; }
.profit-negative { color: #cc0000; }

.summary-row td { border-top: 2px solid #333; }

.sale-detail h2 { margin-top: 0; }
.sale-actions { display: flex; gap: 10px; align-items: center; margin: 10px 0; }

.sale-detail-layout {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 30px;
    align-items: start;
}

.sale-detail-tables {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
}

.sale-detail-tables > div { flex: 1 1 250px; }

.sale-kv-table th { white-space: nowrap; }
.sales-actions { margin-bottom: 15px; display: flex; gap: 10px; align-items: center; }
.sales-summary-actions { margin-top: 15px; margin-bottom: 0; }

/* ── Card-table layout (wider breakpoint for data-heavy tables) ── */
@media (max-width: 900px) {
    .card-table,
    .card-table tbody,
    .card-table tfoot,
    .card-table tr {
        display: block;
    }

    .card-table thead { display: none; }

    .card-table tbody tr,
    .card-table tfoot tr {
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: 14px 16px;
        margin-bottom: 12px;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    }

    .card-table td {
        padding: 6px 0;
        border-bottom: 1px solid #f0f0f0;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        font-size: 0.92em;
        line-height: 1.4;
    }

    .card-table td[data-label]:not(:first-child)::before,
    .schedule-c-table td:first-child[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.82em;
        color: #777;
        flex-shrink: 0;
        margin-right: 12px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }

    .card-table td:first-child {
        display: block;
        font-weight: 600;
        font-size: 1.05em;
        margin-bottom: 6px;
        padding-bottom: 8px;
        border-bottom: 2px solid #e8e8e8;
    }

    .card-table td:last-child {
        border-bottom: none;
    }

    /* Products table: tracked/actions stay inline */
    .products-table td[data-label="Tracked"],
    .products-table .cell-actions {
        border-bottom: none;
        display: inline-flex;
    }

    /* Hide empty placeholder cells (totals spacers, etc.) */
    .card-table td:not([data-label]):empty {
        display: none;
    }

    /* Schedule C: all cells use label+value layout, no card header */
    .schedule-c-table td:first-child {
        display: flex;
        font-weight: normal;
        font-size: 0.92em;
        margin-bottom: 0;
        padding-bottom: 6px;
        border-bottom: 1px solid #f0f0f0;
    }
}

/* ── Mobile responsive ── */
@media (max-width: 768px) {
    body { padding: 0 10px; }

    /* Nav: tighten and wrap properly */
    nav {
        gap: 8px 16px;
        padding: 10px 0;
        margin-bottom: 12px;
    }

    nav .logo {
        font-size: 1.2em;
    }

    .nav-links {
        gap: 10px;
        flex-wrap: wrap;
        font-size: 0.9em;
    }

    .nav-auth {
        font-size: 0.85em;
        gap: 8px;
    }

    h1 { font-size: 1.5em; margin-bottom: 10px; }

    /* Toolbar: stack forms vertically, full-width inputs */
    .filter-form,
    .add-form,
    .search-form {
        flex-wrap: wrap;
        gap: 8px;
    }

    .filter-form input[type="text"] {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }

    .filter-form select {
        flex: 1;
        min-width: 0;
    }

    .add-form input[type="text"],
    .search-form input[type="text"] {
        width: 100%;
    }

    #refresh-all-btn {
        width: 100%;
        padding: 10px;
    }

    .add-form {
        flex-direction: column;
    }

    .add-form button {
        align-self: flex-start;
    }

    /* Product detail header: stack on mobile */
    .product-detail .product-header {
        flex-direction: column;
    }

    .product-image {
        max-width: 100%;
    }

    .sale-detail-layout {
        grid-template-columns: 1fr;
    }

    /* Search cards: stack */
    .search-card {
        flex-direction: column;
    }

    .search-card img {
        width: 80px;
        height: 80px;
    }

    /* Pagination tighter */
    .pagination {
        gap: 10px;
        padding: 12px 0;
    }
}
