* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f2f2f2;
    color: #111;
}

.container {
    padding: 16px;
    padding-bottom: 90px;
    max-width: 960px;
    margin: 0 auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.title {
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
}

.icon-btn,
.header-spacer {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.icon-btn {
    color: #111;
    text-decoration: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.icon-btn--button {
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
}

.icon-btn:active {
    background: rgba(0,0,0,0.06);
}

.stats {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.card {
    flex: 1;
    background: #ffffff;
    border-radius: 0;
    padding: 14px 10px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.card h3 {
    font-size: 12px;
    margin: 0;
    color: #666;
}

.card h2 {
    margin: 6px 0 0;
    font-size: 20px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 15px;
}

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

.button-card {
    display: block;
    background: #ffffff;
    padding: 20px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    color: #000;
    border-radius: 0;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.full-width-btn {
    display: block;
    background: #ffffff;
    padding: 18px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    font-weight: 600;
    margin-bottom: 14px;
    text-decoration: none;
    color: #000;
    border-radius: 0;
    min-height: 56px;
}

.full-width-btn:active {
    transform: translateY(1px);
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    width: 100%;
    background: #ffffff;
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    border-top: 1px solid #ddd;
}

.bottom-nav div {
    font-size: 18px;
}

.section-card,
.mapping-card {
    background: #ffffff;
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    border-radius: 0;
}

.section-title {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.helper-text {
    margin: 10px 0 0;
    color: #666;
    font-size: 13px;
    line-height: 1.35;
}

.muted-text {
    color: #666;
    font-size: 14px;
    line-height: 1.35;
}

.form-group label {
    font-size: 13px;
    margin-top: 10px;
    display: block;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    margin-top: 4px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    background: #fff;
    border-radius: 0;
}

.form-group input[type="file"] {
    border-style: dashed;
}

.primary-btn {
    width: 100%;
    min-height: 44px;
    padding: 12px;
    background: black;
    color: white;
    border: none;
    font-weight: 700;
    font-size: 15px;
}

.primary-btn:disabled {
    opacity: 0.55;
}

.primary-btn:active {
    transform: translateY(1px);
}

.inline-form {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.inline-form input {
    flex: 1;
    padding: 6px;
}

.inline-form button {
    padding: 6px 12px;
}

.sku-title {
    font-weight: bold;
    margin-bottom: 8px;
}

.order-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.order-left {
    flex: 1;
}

.order-right {
    text-align: right;
}

.empty-state {
    text-align: center;
    padding: 40px 10px;
    color: #777;
}

.empty-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.alert {
    padding: 12px;
    border: 1px solid #ddd;
    background: #fff;
    font-size: 14px;
    margin-bottom: 12px;
}

.alert--error {
    border-color: #f5c2c7;
    background: #fdecea;
    color: #b00020;
}

.alert--success {
    border-color: #b7dfc6;
    background: #e7f5ee;
    color: #137333;
}

.scanner-video {
    width: 100%;
    background: #000;
    display: block;
}

.scan-hint {
    margin-top: 10px;
    color: #666;
    font-size: 13px;
    line-height: 1.35;
}

.input-icon {
    display: flex;
    align-items: center;
    border: 1px solid #ccc;
    padding: 10px;
    background: #fff;
}

.input-icon span {
    margin-right: 8px;
}

.input-icon input {
    border: none;
    outline: none;
    width: 100%;
}

.secondary-btn {
    width: 100%;
    min-height: 44px;
    padding: 12px;
    margin-top: 10px;
    border: 1px solid #ccc;
    background: #f7f7f7;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    color: #111;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.secondary-btn--mini {
    width: auto;
    min-height: 40px;
    padding: 10px 12px;
    margin-top: 0;
    font-size: 14px;
}

.primary-btn--mini {
    width: auto;
    min-height: 40px;
    padding: 10px 12px;
    font-size: 14px;
}

.secondary-btn:hover {
    background: #eee;
}

.secondary-btn:active {
    transform: translateY(1px);
}

.danger-btn {
    min-height: 40px;
    padding: 10px 12px;
    border: 1px solid #b00020;
    background: #b00020;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

.danger-btn:active {
    transform: translateY(1px);
}

.scanner {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.table th,
.table td {
    padding: 12px;
    border-bottom: 1px solid #eee;
    font-size: 14px;
    vertical-align: top;
}

.table-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}

.table-actions .secondary-btn--mini,
.table-actions .danger-btn {
    margin-top: 0;
}

.table th {
    color: #666;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-size: 12px;
}

.text-right {
    text-align: right;
}

.nowrap {
    white-space: nowrap;
}

.wrap-anywhere {
    overflow-wrap: anywhere;
    word-break: break-word;
}

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

.bottom-bar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    z-index: 1000;
    width: calc(100% - 32px);
    padding: 12px 16px 18px;
    background: rgba(255,255,255,0.95);
    border-top: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 960px;
}

.bottom-bar .secondary-btn,
.bottom-bar .primary-btn,
.bottom-bar .danger-btn {
    margin-top: 0;
}

@media (min-width: 520px) {
    .bottom-bar.bottom-bar--two {
        flex-direction: row;
        justify-content: center;
    }

    .bottom-bar.bottom-bar--two > * {
        max-width: 320px;
    }
}

.combo-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.combo-row {
    display: grid;
    grid-template-columns: 1fr 90px;
    gap: 10px;
    align-items: center;
}

.combo-row select {
    margin: 0;
}

.combo-row .qty-input {
    margin: 0;
    text-align: right;
}

.done {
    color: #137333;
    font-weight: 700;
}

.table tr.done {
    background: #e7f5ee;
}

.tab-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.tab-toggle__item {
    min-height: 44px;
    padding: 12px;
    border: 1px solid #ccc;
    background: #f7f7f7;
    color: #111;
    text-decoration: none;
    font-weight: 800;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.tab-toggle__item.is-active {
    background: #111;
    border-color: #111;
    color: #fff;
}

.tab-toggle__item:active {
    transform: translateY(1px);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
}

.modal.is-open {
    display: flex;
}

.modal__sheet {
    width: 100%;
    max-width: 560px;
    background: #fff;
    border-radius: 0;
    padding: 16px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.35);
    border: 1px solid rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal__sheet .danger-btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.modal__title {
    font-weight: 800;
    font-size: 16px;
}

/* ── AI Chat ──────────────────────────────────────────────────────────────── */

.ai-fab {
    position: fixed;
    bottom: 20px;
    right: 16px;
    z-index: 3000;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: #111;
    color: #fff;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.ai-fab:active {
    transform: scale(0.96);
    background: #333;
}

.ai-modal {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: none;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0,0,0,0.45);
    padding: 0;
}
.ai-modal.is-open {
    display: flex;
}

.ai-modal__sheet {
    width: 100%;
    max-width: 560px;
    height: 78vh;
    max-height: 640px;
    background: #fff;
    border-radius: 18px 18px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
}

.ai-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}
.ai-modal__title {
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ai-modal__close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
}
.ai-modal__close:hover { background: #f0f0f0; }

.ai-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

/* Bubbles */
.ai-bubble {
    max-width: 88%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
}
.ai-bubble--user {
    align-self: flex-end;
    background: #111;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-bubble--ai {
    align-self: flex-start;
    background: #f2f2f2;
    color: #111;
    border-bottom-left-radius: 4px;
}
.ai-bubble--typing {
    align-self: flex-start;
    background: #f2f2f2;
    color: #888;
    font-style: italic;
    border-bottom-left-radius: 4px;
}

/* Issue cards inside AI bubble */
.ai-issue-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 10px 12px;
    margin-top: 6px;
    font-size: 13px;
}
.ai-issue-card + .ai-issue-card { margin-top: 6px; }
.ai-issue-card__title {
    font-weight: 700;
    margin-bottom: 3px;
    color: #111;
}
.ai-issue-card__reason {
    color: #555;
    margin-bottom: 4px;
}
.ai-issue-card__fix {
    font-size: 12px;
    color: #222;
    background: #f7f7f7;
    border-radius: 6px;
    padding: 5px 8px;
    margin-bottom: 4px;
}
.ai-issue-card__confidence {
    font-size: 11px;
    color: #999;
}
.ai-action-btn {
    display: inline-block;
    margin-top: 6px;
    padding: 5px 12px;
    background: #111;
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
}
.ai-action-btn:hover { background: #333; }

/* Stuck-orders table inside bubble */
.ai-group-block {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 8px 12px;
    margin-top: 6px;
    font-size: 13px;
}
.ai-group-block__heading {
    font-weight: 700;
    margin-bottom: 4px;
}
.ai-group-block__row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 0;
    font-size: 12px;
    color: #444;
    border-bottom: 1px solid #f0f0f0;
}
.ai-group-block__row:last-child { border-bottom: none; }

.ai-chat__input-row {
    display: flex;
    gap: 8px;
    padding: 10px 12px 14px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}
.ai-chat__input {
    flex: 1;
    border: 1.5px solid #ddd;
    border-radius: 22px;
    padding: 9px 14px;
    font-size: 14px;
    outline: none;
    background: #fafafa;
}
.ai-chat__input:focus { border-color: #111; background: #fff; }
.ai-chat__send {
    background: #111;
    color: #fff;
    border: none;
    border-radius: 22px;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}
.ai-chat__send:active { background: #333; }
.ai-chat__send:disabled { background: #ccc; cursor: default; }

/* Multi-issue modal cards (in existing order-level modals) */
.ai-debug-issues { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.ai-debug-card {
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
}
.ai-debug-card__title  { font-weight: 700; margin-bottom: 3px; }
.ai-debug-card__reason { color: #555; margin-bottom: 5px; }
.ai-debug-card__fix    { background: #f5f5f5; border-radius: 6px; padding: 6px 8px; margin-bottom: 5px; font-size: 12.5px; }
.ai-debug-card__conf   { font-size: 11px; color: #999; }

/* ── AI chat: stat cards grid ────────────────────────────────────────────── */
.ai-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 6px;
    margin-top: 6px;
}
.ai-stat-card {
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    padding: 8px 10px;
    text-align: center;
}
.ai-stat-card__label {
    font-size: 10px;
    color: #888;
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.ai-stat-card__value {
    font-size: 15px;
    font-weight: 700;
}

/* ── AI chat: mini table ─────────────────────────────────────────────────── */
.ai-table-wrap {
    overflow-x: auto;
    margin-top: 6px;
    border-radius: 8px;
    border: 1px solid #e8e8e8;
}
.ai-mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.ai-mini-table th {
    background: #f5f5f5;
    padding: 5px 8px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 1px solid #e8e8e8;
    white-space: nowrap;
}
.ai-mini-table td {
    padding: 5px 8px;
    border-bottom: 1px solid #f0f0f0;
    color: #333;
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-mini-table tr:last-child td { border-bottom: none; }

/* ── AI chat: suggestion chips ───────────────────────────────────────────── */
.ai-chip {
    display: inline-block;
    background: #f0f0f0;
    border-radius: 12px;
    padding: 2px 9px;
    font-size: 12px;
    cursor: pointer;
    margin: 2px 1px;
    color: #333;
    border: 1px solid #ddd;
    transition: background 0.1s;
}
.ai-chip:hover { background: #e0e0e0; }
