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

:root {
    --primary: #005f5a;
    --primary-dark: #004845;
    --primary-light: #e0f0ef;
    --bg: #f7f7fa;
    --card: #eaeaf2;
    --white: #ffffff;
    --text: #0f0f0f;
    --text-muted: rgba(15, 15, 15, 0.55);
    --border: #d4d4d4;
    --sage: #82917d;
    --error: #c71b1b;
    --error-bg: #fff0f0;
    --success: #15803d;
    --success-bg: #f0fdf4;
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 20px rgba(0, 95, 90, 0.13);
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
}

html,
body {
    height: 100%;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    overflow: hidden;
}

/* ── Brand Bar ───────────────────────────────────────── */
.brand-bar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.brand-logo-wrap {
    width: 38px;
    height: 38px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 5px;
}

.brand-logo-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: invert(1) brightness(10);
}

.brand-name {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}

.brand-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
}

.brand-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 400;
}

/* ── Controls Bar ────────────────────────────────────── */
.controls-bar {
    background: var(--primary);
    padding: 12px 20px;
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
}

.controls-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Scan input */
.scan-wrap {
    flex: 1 1 220px;
    position: relative;
    min-width: 0;
}

.scan-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    pointer-events: none;
    opacity: 0.75;
}

.scan-icon svg {
    width: 18px;
    height: 18px;
    fill: white;
}

#scanInput {
    width: 100%;
    padding: 11px 14px 11px 42px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: var(--r-md);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 1.5px;
    outline: none;
    transition:
        border-color 0.2s,
        background 0.2s,
        box-shadow 0.2s;
    -webkit-font-smoothing: antialiased;
}

#scanInput::placeholder {
    color: rgba(255, 255, 255, 0.65);
    font-weight: 400;
    letter-spacing: 2.5px;
    font-size: 14px;
}

#scanInput:focus {
    border-color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.22);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
}

/* User dropdown */
#userSelect {
    flex: 0 1 175px;
    padding: 11px 36px 11px 13px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: var(--r-md);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 14px;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(255,255,255,0.75)'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    transition:
        border-color 0.2s,
        background 0.2s;
    min-width: 0;
}

#userSelect:focus {
    border-color: rgba(255, 255, 255, 0.9);
    background-color: rgba(255, 255, 255, 0.22);
}

#userSelect option {
    background: var(--primary-dark);
    color: white;
    font-weight: 400;
}

/* Clear button */
.btn-clear {
    flex-shrink: 0;
    padding: 11px 18px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-radius: var(--r-md);
    background: transparent;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition:
        background 0.2s,
        border-color 0.2s,
        transform 0.1s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-clear:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.8);
}

.btn-clear:active {
    transform: scale(0.97);
}

/* ── Status Banner ───────────────────────────────────── */
#statusBanner {
    flex-shrink: 0;
    padding: 9px 20px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#statusBanner.active {
    display: flex;
}

#statusBanner.error {
    background: var(--error-bg);
    color: var(--error);
    border-bottom: 1px solid #fecaca;
}

#statusBanner.loading {
    background: var(--primary-light);
    color: var(--primary);
    border-bottom: 1px solid #a7d7d4;
}

.dot-spinner {
    display: inline-flex;
    gap: 4px;
}

.dot-spinner span {
    width: 5px;
    height: 5px;
    background: var(--primary);
    border-radius: 50%;
    animation: dotPulse 1.2s ease-in-out infinite;
}

.dot-spinner span:nth-child(2) {
    animation-delay: 0.2s;
}
.dot-spinner span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotPulse {
    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ── Main / Table ────────────────────────────────────── */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 16px 20px 20px;
    gap: 10px;
    overflow: hidden;
}

.table-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.table-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.count-pill {
    background: var(--primary);
    color: white;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 11px;
    border-radius: 99px;
    letter-spacing: 0.2px;
    transition: all 0.2s;
}

.count-pill.zero {
    background: var(--border);
    color: var(--text-muted);
}

/* Table wrapper — this scrolls */
.table-wrapper {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    background: var(--white);
    border: 1px solid var(--border);
    position: relative;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 380px;
}

/* Sticky header */
thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

thead tr {
    background: var(--primary);
}

thead th {
    padding: 13px 18px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    border-bottom: 2px solid var(--primary-dark);
}

thead th:first-child {
    width: 90px;
}
thead th:last-child {
    width: 200px;
}

/* Hidden code column — stores raw scan code for duplicate checking */
.col-code {
    display: none;
}

/* Queue status pill */
.queue-pill {
    background: var(--primary-light);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    padding: 2px 11px;
    border-radius: 99px;
    letter-spacing: 0.2px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.queue-pill.hidden {
    display: none;
}

/* Pending row */
.row-pending td {
    padding: 0;
}

.pending-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 18px;
    font-size: 13px;
    color: var(--text-muted);
}

.pending-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(0, 95, 90, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

.pending-label {
    font-style: italic;
}

.pending-code {
    font-family: "Courier New", monospace;
    font-size: 12px;
    color: var(--text);
    opacity: 0.6;
}

/* Already-packed row */
.row-already-packed td {
    background: #fff0f0 !important;
    color: #c71b1b;
}

.row-already-packed .country-badge {
    background: #fecaca;
    color: #991b1b;
}

.row-already-packed .name-cell {
    color: #c71b1b;
    font-weight: 600;
}

.row-already-packed .tag-pill {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #991b1b;
}

/* Error row */
.row-error td {
    padding: 0;
}

.error-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 18px;
    background: var(--error-bg);
    font-size: 13px;
}

.error-icon {
    color: var(--error);
    font-weight: 700;
    flex-shrink: 0;
}

.error-msg {
    color: var(--error);
    flex: 1;
}

.error-code {
    font-family: "Courier New", monospace;
    font-size: 11px;
    color: var(--error);
    opacity: 0.55;
}

tbody tr {
    border-bottom: 1px solid var(--card);
    animation: rowIn 0.28s ease-out;
    transition: background 0.15s;
}

@keyframes rowIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

tbody tr:nth-child(odd) {
    background: var(--white);
}
tbody tr:nth-child(even) {
    background: #f4f4f8;
}
tbody tr:hover {
    background: var(--primary-light) !important;
}
tbody tr:last-child {
    border-bottom: none;
}

tbody td {
    padding: 12px 18px;
    font-size: 14px;
    color: var(--text);
    vertical-align: middle;
}

.country-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 800;
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 99px;
    letter-spacing: 0.8px;
}

.name-cell {
    font-weight: 500;
    font-size: 14px;
}

.tag-pill {
    display: inline-block;
    background: #f3f4f6;
    color: #374151;
    font-family: "Courier New", "SF Mono", monospace;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: var(--r-sm);
    border: 1px solid #e5e7eb;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

/* Empty state */
.empty-state {
    padding: 64px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-muted);
}

.empty-icon {
    width: 56px;
    height: 56px;
    background: var(--card);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-icon svg {
    width: 26px;
    height: 26px;
    stroke: var(--text-muted);
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.empty-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
}

.empty-hint {
    font-size: 13px;
    color: var(--border);
    text-align: center;
    max-width: 260px;
}

/* ── Auth Modal ──────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.hidden {
    display: none;
}

.modal-card {
    background: var(--white);
    border-radius: var(--r-lg);
    padding: 30px 28px 26px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
    animation: modalIn 0.22s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.94) translateY(12px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-icon {
    width: 44px;
    height: 44px;
    background: var(--primary-light);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.modal-icon svg {
    width: 22px;
    height: 22px;
    stroke: var(--primary);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.modal-title {
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.modal-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 22px;
}

.field-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.field-input {
    display: block;
    width: 100%;
    padding: 11px 13px;
    border: 2px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 15px;
    color: var(--text);
    outline: none;
    transition:
        border-color 0.18s,
        box-shadow 0.18s;
    margin-bottom: 14px;
    background: var(--white);
}

.field-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 95, 90, 0.1);
}

.modal-error {
    font-size: 13px;
    color: var(--error);
    display: none;
    margin-bottom: 14px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

.btn-ghost {
    padding: 11px 18px;
    background: transparent;
    color: var(--text-muted);
    border: 2px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition:
        background 0.2s,
        border-color 0.2s;
}

.btn-ghost:hover {
    background: var(--card);
    border-color: #bbb;
}

.btn-primary {
    flex: 1;
    padding: 11px 18px;
    background: var(--primary);
    color: white;
    border: 2px solid transparent;
    border-radius: var(--r-sm);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition:
        background 0.2s,
        transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.btn-primary:hover {
    background: var(--primary-dark);
}
.btn-primary:active {
    transform: scale(0.98);
}
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Inline spinner for buttons */
.btn-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.55s linear infinite;
    display: none;
}

.btn-primary.loading .btn-spinner {
    display: block;
}
.btn-primary.loading .btn-text {
    opacity: 0.8;
}

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

/* ── Toast ───────────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: var(--text);
    color: white;
    padding: 10px 22px;
    border-radius: 99px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    z-index: 2000;
    opacity: 0;
    transition:
        opacity 0.25s,
        transform 0.25s;
    pointer-events: none;
    white-space: nowrap;
}

#toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#toast.ok {
    background: var(--success);
}
#toast.fail {
    background: var(--error);
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 620px) {
    .brand-divider,
    .brand-subtitle {
        display: none;
    }

    .controls-inner {
        gap: 8px;
    }

    .scan-wrap {
        flex: 1 1 100%;
        order: 1;
    }
    #userSelect {
        flex: 1 1 auto;
        order: 2;
        min-width: 0;
    }
    .btn-clear {
        order: 3;
    }

    main {
        padding: 12px;
    }

    thead th,
    tbody td {
        padding: 11px 12px;
    }

    .tag-pill {
        max-width: 130px;
        font-size: 11px;
    }
}

@media (min-width: 621px) and (max-width: 960px) {
    .scan-wrap {
        flex: 1 1 240px;
    }
    #userSelect {
        flex: 0 1 150px;
    }
}

/* Scrollbar styling */
.table-wrapper::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.table-wrapper::-webkit-scrollbar-track {
    background: transparent;
}
.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 99px;
}
.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #b4b4b4;
}
