:root {
    --brand: #f57224;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.5;
}

.page {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: 4rem;
}

.login-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    text-align: center;
}

.login-icon {
    width: 96px;
    height: 96px;
    border-radius: 20%;
    margin-bottom: 1rem;
}

.btn-google {
    display: inline-block;
    margin-top: 1.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--brand);
    color: #fff;
    text-decoration: none;
    border-radius: 999px;
    font-weight: 600;
}

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    padding: 1rem;
    font-weight: 700;
    font-size: 1.25rem;
    border-bottom: 1px solid #eee;
}

.tab-content {
    flex: 1;
    padding: 1rem;
}

.cart-empty {
    text-align: center;
    color: #777;
    margin-top: 3rem;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    max-width: 480px;
    margin: 0 auto;
    border-top: 1px solid #eee;
    background: #fff;
}

.bottom-nav-tab {
    flex: 1;
    text-align: center;
    padding: 0.75rem 0;
    text-decoration: none;
    color: #777;
    font-size: 0.85rem;
}

.bottom-nav-tab.active {
    color: var(--brand);
    font-weight: 600;
}

/* Shared row/card layout (cart rows, inventory rows, search results) */

.row-swatch {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 10px;
    overflow: hidden;
    background: #f2f2f2;
}

.row-swatch img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.swatch-placeholder {
    display: block;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(45deg, #eee, #eee 6px, #f6f6f6 6px, #f6f6f6 12px);
}

.row-info {
    flex: 1;
    min-width: 0;
}

.row-name {
    margin: 0;
    font-weight: 600;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-price {
    margin: 0.15rem 0 0;
    font-size: 0.85rem;
    color: #777;
}

.btn-icon {
    border: none;
    background: none;
    color: #777;
    font-size: 0.8rem;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    cursor: pointer;
}

.btn-danger {
    color: #c0392b;
}

/* Cart tab */

.cart-page {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.cart-search {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.75rem 2.75rem 0.75rem 1rem;
    border: 1px solid #ddd;
    border-radius: 999px;
    font-size: 16px;
}

[x-cloak] {
    display: none !important;
}

.search-clear {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: none;
    color: #999;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.25rem;
    cursor: pointer;
}

.search-results-header {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.35rem;
}

.search-collapse {
    border: none;
    background: none;
    color: var(--brand, #f57224);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
}

.search-results:not(:empty) {
    margin-top: 0.5rem;
    border: 1px solid #eee;
    border-radius: 12px;
    overflow: hidden;
}

.search-result-row,
.cart-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-bottom: 1px solid #eee;
    background: #fff;
}

.search-result-row:last-child,
.cart-row:last-child {
    border-bottom: none;
}

.btn-add-to-cart {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--brand);
    color: #fff;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.search-empty {
    padding: 0.75rem;
    color: #999;
    font-size: 0.9rem;
}

.cart-list {
    display: flex;
    flex-direction: column;
    border: 1px solid #eee;
    border-radius: 12px;
    overflow: hidden;
}

.qty-stepper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.qty-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid #ddd;
    background: #fff;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.qty-value {
    min-width: 1.25rem;
    text-align: center;
    font-weight: 600;
}

.cart-footer {
    position: sticky;
    bottom: 3.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border-top: 1px solid #eee;
}

.cart-footer-summary {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: #555;
}

.cart-footer-total {
    font-weight: 700;
    color: #111;
}

.cart-footer-empty {
    margin: 0;
    color: #999;
    font-size: 0.85rem;
}

.btn-checkout {
    position: relative;
    padding: 0.65rem 1.25rem;
    border: none;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.cart-footer-done {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    color: #2a9d5c;
    font-weight: 600;
}

.htmx-indicator {
    opacity: 0;
    transition: opacity 150ms ease-in;
}

.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator {
    opacity: 1;
}

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 0.5rem;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.spinner-dark {
    margin-left: 0;
    border-color: rgba(0, 0, 0, 0.15);
    border-top-color: var(--brand);
}

.sheet-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem 0;
    color: #777;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* Inventory tab */

.inventory-page {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.inventory-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-add-item {
    align-self: flex-start;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.btn-add-item.secondary {
    background: #fff;
    color: var(--brand);
    border: 1px solid var(--brand);
}

.inventory-list {
    display: flex;
    flex-direction: column;
    border: 1px solid #eee;
    border-radius: 12px;
    overflow: hidden;
}

.inventory-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-bottom: 1px solid #eee;
    background: #fff;
}

.inventory-row:last-child {
    border-bottom: none;
}

.row-actions {
    display: flex;
    gap: 0.25rem;
}

.inventory-empty {
    text-align: center;
    color: #999;
    padding: 2rem 1rem;
}

/* Checkout failures modal */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
}

.modal {
    background: #fff;
    border-radius: 16px;
    padding: 1.25rem;
    max-width: 480px;
    width: 100%;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.modal h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}

.modal-failure-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    overflow-y: auto;
}

.modal-failure-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}

.modal-failure-list small {
    color: #999;
    white-space: nowrap;
}

/* Bottom sheet (inventory add/edit) */

.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
}

.sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 480px;
    max-height: 75vh;
    margin: 0 auto 45px;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 1rem;
    transform: translateY(100%);
    transition: transform 250ms ease;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
}

.sheet.open {
    transform: translateY(0);
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    margin-bottom: 0.75rem;
    flex-shrink: 0;
}

#sheet-form {
    overflow-y: auto;
    min-height: 0;
}

.sheet-close {
    border: none;
    background: none;
    font-size: 1rem;
    cursor: pointer;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 0.75rem;
}

.form-field input,
.form-field textarea {
    padding: 0.6rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    color: #111;
    font-family: inherit;
}

.form-field textarea {
    resize: vertical;
    font-family: ui-monospace, monospace;
    font-size: 0.8rem;
}

.import-setup-steps {
    margin: 0 0 0.75rem;
    padding-left: 1.25rem;
    font-size: 0.85rem;
    color: #555;
}

.import-setup-steps li {
    margin-bottom: 0.5rem;
}

.import-setup-steps code {
    display: inline-block;
    margin-top: 0.25rem;
    padding: 0.35rem 0.5rem;
    background: #f2f2f2;
    border-radius: 6px;
    font-size: 0.75rem;
    word-break: break-all;
}

.sheet-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.btn-primary {
    padding: 0.55rem 1.25rem;
    border: none;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary {
    padding: 0.55rem 1.25rem;
    border: 1px solid #ddd;
    border-radius: 999px;
    background: #fff;
    color: #555;
    cursor: pointer;
}

/* Scan tab */

.scan-page {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.scan-page form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.scan-mode-toggle {
    display: flex;
    gap: 0.5rem;
}

.scan-mode-btn {
    flex: 1;
    padding: 0.6rem;
    border: 2px solid #ddd;
    border-radius: 12px;
    background: none;
    color: #777;
    font-weight: 600;
    cursor: pointer;
}

.scan-mode-btn.active {
    border-color: var(--brand);
    color: var(--brand);
}

.scan-dropzone {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2.5rem 1rem;
    border: 2px dashed #ddd;
    border-radius: 16px;
    color: #777;
    cursor: pointer;
}

.scan-dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.scan-dropzone.chosen {
    border-color: var(--brand);
    color: var(--brand);
    font-weight: 600;
}

.scan-page .btn-primary {
    text-align: center;
}

.scan-page .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.scan-review-hint {
    color: #777;
    font-size: 0.85rem;
    margin: 0 0 0.75rem;
}

.scan-review-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid #eee;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    background: #fff;
}

.scan-review-row.unmatched {
    opacity: 0.6;
}

.scan-review-info {
    flex: 1;
    min-width: 0;
}

.scan-review-name {
    margin: 0;
    font-weight: 600;
    font-size: 0.95rem;
}

.scan-review-raw,
.scan-review-nomatch {
    margin: 0.15rem 0 0;
    font-size: 0.8rem;
    color: #999;
}

.scan-review-qty {
    width: 3rem;
    padding: 0.35rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    text-align: center;
}

.scan-empty,
.scan-error {
    text-align: center;
    color: #999;
    padding: 2rem 1rem;
}

/* Profile tab */

.profile-page {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.profile-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid #eee;
    border-radius: 12px;
}

.profile-avatar img,
.profile-avatar .swatch-placeholder {
    display: block;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
}

.profile-info {
    min-width: 0;
}

.profile-name {
    margin: 0;
    font-weight: 700;
}

.profile-email {
    margin: 0.15rem 0 0;
    color: #777;
    font-size: 0.85rem;
}

.btn-signout {
    align-self: flex-start;
}

.lazada-session-card {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
}

.profile-lazada-status {
    margin: 0;
    font-size: 0.9rem;
}

.status-ok {
    color: #2a9d5c;
    font-weight: 600;
}

.status-missing {
    color: #999;
    font-weight: 600;
}

.lazada-session-details summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--brand);
    font-weight: 600;
}

.lazada-session-details form {
    margin-top: 0.75rem;
}
