:root {
    --bg: #f6f7f8;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #111315;
    --muted: #64748b;
    --obsidian: #121316;
    --obsidian-hover: #24272d;
    --gold: #eab308;
    --gold-hover: #facc15;
    --gold-text: #92400e;
    --gold-soft: #fef9c3;
    --primary: #121316;
    --primary-hover: #24272d;
    --success: #059669;
    --success-hover: #047857;
    --warning: #b45309;
    --danger: #dc2626;
    --radius: 12px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}
body.modal-open { overflow: hidden; }

.hidden { display: none !important; }

.topbar {
    background: var(--obsidian);
    color: #fff;
    padding: 0.72rem 1.35rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    border-bottom: 1px solid #23262d;
}
.topbar-left { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-badge {
    display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 0.25rem 0.5rem; border-radius: 9px;
    background: #1b1d22; border: 1px solid #30343e; line-height: 1;
}
.brand-am { font-weight: 800; font-size: 15px; color: #ffffff; letter-spacing: 0.03em; }
.brand-auto {
    font-weight: 700; font-size: 8.5px; color: var(--gold); letter-spacing: 0.16em;
    margin-top: 2px; border-top: 1px solid rgba(234, 179, 8, 0.55); padding-top: 2px;
}
.brand-title { font-weight: 700; font-size: 15px; color: #ffffff; }
.brand-sub { font-size: 11px; color: #9ca3af; }

.client-switcher { display: flex; align-items: center; gap: 0.5rem; font-size: 13px; color: #d1d5db; }
.client-switcher select {
    background: #1d2026; color: #fff; border: 1px solid #323640;
    padding: 0.36rem 0.65rem; border-radius: 999px; font-weight: 600;
}
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.topbar .btn-primary {
    background: var(--gold); color: var(--obsidian); font-weight: 700; border-color: var(--gold);
}
.topbar .btn-primary:hover { background: var(--gold-hover); border-color: var(--gold-hover); }
.topbar .btn-secondary {
    background: #ffffff; color: var(--obsidian); border-color: #ffffff;
}
.topbar .btn-secondary:hover { background: #f3f4f6; }
.topbar .btn-ghost {
    background: #1d2026; color: #e5e7eb; border-color: #323640;
}
.topbar .btn-ghost:hover { background: #272b33; color: #ffffff; border-color: #4b5563; }

.tabs-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.35rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    overflow-x: auto;
}
.tab-btn {
    background: none; border: none; border-bottom: 2px solid transparent;
    padding: 0.8rem 0.9rem; cursor: pointer; font-weight: 600; color: var(--muted);
    display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--obsidian); border-bottom-color: var(--gold); }
.tabs-right { margin-left: auto; }
.decode-alert { font-size: 12px; color: var(--warning); font-weight: 600; }

.count-pill {
    background: #f1f5f9; color: #334155;
    padding: 0.1rem 0.48rem; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.count-pill.accent { background: var(--gold-soft); color: var(--gold-text); border: 1px solid rgba(234, 179, 8, 0.45); }

.container { padding: 1.1rem 1.35rem 2.25rem; max-width: 1600px; margin: 0 auto; }

.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem;
}
.toolbar-filters { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; flex: 1; }
.search-input { min-width: 280px; max-width: 420px; flex: 1; }

.dest-pills { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.dest-pill {
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    padding: 0.3rem 0.65rem; border-radius: 999px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.dest-pill.active { background: var(--obsidian); color: var(--gold-hover); border-color: var(--obsidian); }

.dispatch-bar {
    background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: var(--radius);
    padding: 0.7rem 0.9rem; margin-bottom: 0.75rem;
    display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap;
}
.dispatch-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.table-wrap {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow-x: auto; box-shadow: 0 1px 3px rgba(17, 19, 21, 0.04);
}
.orders-table { width: 100%; border-collapse: collapse; text-align: left; }
.orders-table th {
    background: #fafafa; border-bottom: 1px solid var(--border);
    padding: 0.6rem 0.7rem; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap;
}
.orders-table th.sortable-th { cursor: pointer; user-select: none; transition: color 0.15s ease, background-color 0.15s ease; }
.orders-table th.sortable-th:hover { color: var(--obsidian); background: #f3f4f6; }
.orders-table th.sortable-th.sorted { color: var(--obsidian); border-bottom: 2px solid var(--gold); }
.sort-arrow { display: inline-block; margin-left: 0.25rem; font-size: 10px; opacity: 0.45; }
.orders-table th.sortable-th.sorted .sort-arrow { opacity: 1; color: var(--warning); }
.orders-table td {
    border-bottom: 1px solid #f1f5f9; padding: 0.6rem 0.7rem; vertical-align: top;
}
.orders-table.compact td, .orders-table.compact th { padding: 0.4rem 0.5rem; font-size: 12.5px; text-transform: none; letter-spacing: normal; }
.orders-table tr:hover td { background: #fafafa; }
.orders-table tr.row-legacy td { background: #fafafa; color: var(--muted); }

.po-link { font-weight: 700; color: var(--obsidian); }
.sub-muted { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.qty-badge {
    display: inline-block; font-weight: 700; background: #fffbeb; color: #92400e;
    border: 1px solid #fde68a; padding: 0.15rem 0.5rem; border-radius: 6px; white-space: nowrap;
}
.qty-badge.neg { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

.badge {
    display: inline-block; font-size: 11px; font-weight: 600;
    padding: 0.14rem 0.5rem; border-radius: 999px; white-space: nowrap;
}
.badge-verified { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-override { background: #fef9c3; color: #854d0e; border: 1px solid #eab308; }
.badge-needs_review { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.badge-unparsed { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.badge-dest { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.badge-legacy { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

.sku-preview { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: #334155; margin-top: 3px; }
.actions-cell { white-space: nowrap; display: flex; gap: 0.3rem; flex-wrap: wrap; }

.btn {
    border: 1px solid transparent; border-radius: 999px; padding: 0.45rem 0.88rem;
    font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 0.3rem;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-sm { padding: 0.28rem 0.65rem; font-size: 12px; }
.btn-primary { background: var(--obsidian); color: #fff; border-color: var(--obsidian); }
.btn-primary:hover { background: var(--obsidian-hover); border-color: var(--gold); }
.btn-secondary { background: #262930; color: #fff; }
.btn-secondary:hover { background: #111315; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #f8fafc; border-color: #cbd5e1; }

.input, .textarea {
    width: 100%; border: 1px solid var(--border); border-radius: 6px;
    padding: 0.42rem 0.6rem; font-size: 13px; background: #fff; font-family: inherit;
}
select.input { width: auto; }
.input-sm { width: auto; padding: 0.32rem 0.5rem; font-size: 12.5px; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; font-size: 13px; }
.checkbox-inline.strong { font-weight: 600; color: #065f46; }
.table-footer { padding: 0.6rem 0.25rem; font-size: 12px; color: var(--muted); }

/* Modals */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 2rem 1rem; overflow-y: auto; z-index: 100;
}
.modal {
    background: var(--surface); border-radius: 10px; width: 100%; max-width: 640px;
    margin: auto 0; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.modal-lg { max-width: 960px; }
.modal-header {
    padding: 0.85rem 1.1rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { margin: 0; font-size: 16px; }
.close-btn { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 1rem 1.1rem; }
.modal-footer {
    padding: 0.75rem 1.1rem; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 0.5rem;
}

.form-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.65rem;
}
.form-grid label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 12px; font-weight: 600; color: var(--muted); }
.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 780px) { .split-grid { grid-template-columns: 1fr; } }

.info-box {
    background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
    padding: 0.6rem 0.75rem; margin-bottom: 0.75rem; font-size: 13px;
}
.hint { font-size: 12px; color: var(--muted); margin: 0 0 0.5rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.45rem; }
.section-head h3 { margin: 0; font-size: 13.5px; }

.tsv-box {
    background: var(--obsidian); color: #f8fafc; border-radius: 8px; padding: 0.75rem;
    font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
    margin: 0; overflow-x: auto; white-space: pre; min-height: 140px;
}
.sku-editor-rows { display: flex; flex-direction: column; gap: 0.4rem; }
.sku-row { display: grid; grid-template-columns: 1fr 80px 32px; gap: 0.35rem; align-items: center; }

.preview-meta { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }
.preview-meta label { font-size: 12px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 0.35rem; }

.toast {
    position: fixed; bottom: 1.25rem; right: 1.25rem;
    background: var(--obsidian); color: #fff; padding: 0.65rem 1rem;
    border: 1px solid #2c3038; border-radius: 999px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); z-index: 200; font-size: 13px;
}
.toast.error { background: var(--danger); }

.autocomplete-wrap { position: relative; margin-top: 0.25rem; }
.autocomplete-menu {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 150;
    margin-top: 3px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
    max-height: 240px; overflow-y: auto;
}
.autocomplete-item {
    padding: 0.48rem 0.65rem; cursor: pointer; display: flex;
    align-items: center; justify-content: space-between; gap: 0.6rem;
    border-bottom: 1px solid #f1f5f9; font-size: 13px; color: var(--text);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.active { background: #fefce8; color: #111315; }
.autocomplete-meta { display: inline-flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }
.field-legacy-note { font-size: 11px; font-weight: 400; color: var(--warning); }
.desc-status-box {
    margin-top: 0.45rem; padding: 0.45rem 0.65rem; border-radius: 6px;
    border: 1px solid var(--border); background: #f8fafc;
    display: flex; flex-direction: column; gap: 0.25rem; font-size: 12px;
}
.desc-status-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.conflict-box {
    background: #fffbeb; border: 1px solid #f59e0b; color: #92400e;
    border-radius: 6px; padding: 0.5rem 0.65rem; margin-bottom: 0.55rem; font-size: 12px;
    display: flex; flex-direction: column; gap: 0.35rem;
}
.conflict-box-actions { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.info-merge-box {
    background: #ecfdf5; border: 1px solid #34d399; color: #065f46;
    border-radius: 6px; padding: 0.5rem 0.65rem; font-size: 12px;
}

.badge-secondary { background: #e2e8f0; color: #1e293b; }
.guide-flow {
    display: flex; align-items: center; justify-content: center; gap: 0.65rem; flex-wrap: wrap;
    background: #f8fafc; border: 1px solid var(--border); border-radius: 8px;
    padding: 0.65rem 0.85rem; margin-bottom: 0.85rem;
}
.guide-stage { display: flex; align-items: center; gap: 0.4rem; }
.guide-stage-note { font-size: 12px; color: var(--muted); }
.guide-arrow { font-weight: 700; color: var(--muted); font-size: 15px; }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 0.75rem; }
.guide-card {
    background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 0.9rem;
}
.guide-card h3 { margin: 0 0 0.45rem; font-size: 13.5px; color: #0f172a; }
.guide-card ul { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.38rem; font-size: 12.5px; color: #334155; }
@media (max-width: 520px) { .guide-grid { grid-template-columns: 1fr; } }

.siblings-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.45rem;
}
.stage-totals-bar { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.orders-table tr.row-current-line td { background: #fefce8; }

.inline-form { display: inline-flex; margin: 0; }
.user-chip {
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: #1d2026; border: 1px solid #323640; border-radius: 999px;
    padding: 0.28rem 0.65rem; font-size: 12px; color: #e5e7eb; max-width: 240px;
}
.user-chip-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role-tag {
    background: rgba(234, 179, 8, 0.18); color: var(--gold); border: 1px solid rgba(234, 179, 8, 0.45);
    padding: 0.05rem 0.4rem; border-radius: 999px; font-size: 10.5px; font-weight: 700; text-transform: uppercase;
}

.invite-user-form {
    display: grid; grid-template-columns: 1.4fr 1fr 110px auto; gap: 0.5rem; margin-bottom: 0.85rem;
}
.invite-user-form input, .invite-user-form select {
    padding: 0.48rem 0.65rem; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px;
}
@media (max-width: 720px) { .invite-user-form { grid-template-columns: 1fr; } }

.auth-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 1.5rem; background: radial-gradient(circle at top, #1f232b 0%, #121316 65%);
}
.auth-shell { width: 100%; max-width: 440px; }
.auth-card {
    background: var(--surface); border: 1px solid #2b2f38; border-radius: 16px;
    padding: 1.75rem; box-shadow: 0 24px 55px rgba(0, 0, 0, 0.35);
}
.auth-brand {
    display: flex; align-items: center; gap: 0.85rem;
    padding-bottom: 1.1rem; margin-bottom: 1.15rem; border-bottom: 1px solid var(--border);
}
.auth-title { margin: 0; font-size: 18px; font-weight: 800; color: var(--obsidian); }
.auth-subtitle { margin: 0.15rem 0 0; font-size: 12px; color: var(--muted); }
.auth-copy { margin: 0 0 1.1rem; font-size: 13.5px; line-height: 1.5; color: #334155; }
.auth-alert {
    border-radius: 10px; padding: 0.8rem 0.9rem; margin-bottom: 1rem; font-size: 13px; line-height: 1.45;
}
.auth-alert-danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.auth-alert-warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.auth-alert-title { font-weight: 700; margin-bottom: 0.25rem; }
.auth-denied-email { margin-top: 0.45rem; font-size: 12.5px; word-break: break-all; }
.auth-setup-list { margin: 0.45rem 0; padding-left: 1.2rem; }
.auth-redirect-hint { margin: 0.55rem 0 0; font-size: 12px; word-break: break-all; }
.btn-google-signin {
    display: flex; align-items: center; justify-content: center; gap: 0.65rem;
    width: 100%; padding: 0.72rem 1rem; border-radius: 10px;
    background: var(--obsidian); color: #ffffff; border: 1px solid var(--obsidian);
    font-weight: 600; font-size: 14px; text-decoration: none;
    transition: background-color 0.15s ease, transform 0.1s ease;
}
.btn-google-signin:hover { background: var(--obsidian-hover); }
.btn-google-signin:active { transform: translateY(1px); }
.google-g-icon { flex-shrink: 0; background: #fff; border-radius: 50%; padding: 2px; }
.auth-footnote { margin: 1rem 0 0; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.45; }

