:root {
    --brand: #2563eb;
    --ink: #111827;
    --muted: #6b7280;
    --line: #d1d5db;
    --line-strong: #9ca3af;
    --surface: #ffffff;
    --page: #f3f4f6;
    --nav: #111827;
    --nav-soft: #1f2937;
    --ok: #047857;
    --danger: #b42318;
    --warning-bg: #fff7ed;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.45;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-panel,
.panel,
.metric,
.scan-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: 0 1px 0 rgba(17, 24, 39, 0.04);
}

.auth-panel {
    width: min(420px, 100%);
    padding: 28px;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto auto 1fr;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 22px;
    min-height: 62px;
    background: var(--nav);
    color: #fff;
    border-bottom: 3px solid var(--brand);
}

.topbar-row,
.topbar-user,
.topbar-menu,
.topnav {
    display: flex;
    align-items: center;
}

.topbar-row {
    justify-content: space-between;
    width: 100%;
}

.topbar-menu {
    gap: 14px;
}

.topbar-user {
    gap: 22px;
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 800;
    letter-spacing: 0;
    white-space: nowrap;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    width: 26px;
    height: 26px;
    border-radius: 3px;
    background: var(--brand);
    box-shadow: inset 0 -8px 0 rgba(255, 255, 255, 0.15);
}

.topnav {
    gap: 4px;
    overflow-x: auto;
}

.topnav a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 0 11px;
    border-radius: 3px;
    color: #d1d5db;
    font-size: 14px;
    font-weight: 650;
    white-space: nowrap;
}

.topnav a:hover {
    background: var(--nav-soft);
    color: #fff;
    text-decoration: none;
}

.topbar-user {
    gap: 12px;
    color: #d1d5db;
    font-size: 14px;
    white-space: nowrap;
}

.topbar-menu form {
    margin: 0;
}

.menu-toggle {
    display: none;
}

.main {
    width: min(1240px, 100%);
    margin: 0 auto;
    padding: 24px 22px 44px;
}

.main.scan-main {
    width: min(720px, 100%);
}

.page-title {
    margin: 0 0 18px;
    font-size: 28px;
    line-height: 1.15;
    letter-spacing: 0;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 14px;
}

.task-list {
    display: grid;
    gap: 10px;
}

.task-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
    color: var(--ink);
}

.warehouse-task-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
}

.task-card-main {
    min-width: 0;
}

.task-card-main strong,
.task-card-main span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-card:hover {
    border-color: var(--brand);
    text-decoration: none;
}

.task-card strong,
.task-card span {
    display: block;
}

.task-card span {
    color: var(--muted);
    font-size: 13px;
}

.task-progress {
    min-width: 130px;
    text-align: right;
}

.task-progress span {
    white-space: nowrap;
}

.task-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.task-summary > div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
}

.scan-summary > div {
    min-width: 0;
    padding: 10px;
}

.scan-summary .muted {
    font-size: 11px;
    line-height: 1.2;
}

.scan-summary strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-summary span,
.task-summary strong {
    display: block;
}

.scan-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.scan-progress .progress {
    flex: 0 1 220px;
    height: 12px;
}

.scan-progress strong {
    white-space: nowrap;
}

.sync-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.scan-work-panel {
    padding: 14px;
}

.compact-panel {
    margin-top: 12px;
}

.empty-state {
    text-align: center;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px 16px;
}

.form-actions {
    margin-top: 20px;
}

.section-gap {
    margin-top: 16px;
}

.panel,
.metric,
.scan-panel {
    padding: 18px;
}

.panel h2 {
    margin: 0 0 8px;
    font-size: 17px;
}

.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.section-heading h2 {
    margin: 0;
}

.panel-note {
    margin-top: 16px;
    padding: 12px;
    border-left: 3px solid var(--brand);
    background: #f9fafb;
    color: #374151;
    font-size: 14px;
}

.filter-panel {
    margin-bottom: 16px;
}

.metric strong {
    display: block;
    font-size: 30px;
}

.muted {
    color: var(--muted);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.table-actions form {
    margin: 0;
}

.link-button {
    min-height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--brand);
    font: inherit;
    font-weight: 600;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--brand);
    border-radius: 3px;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.button:hover,
button:hover {
    filter: brightness(0.96);
    text-decoration: none;
}

.button.secondary,
button.secondary {
    background: #fff;
    color: var(--ink);
    border-color: var(--line-strong);
}

button.compact {
    min-height: 32px;
    padding: 0 10px;
    font-size: 13px;
}

label {
    display: block;
    margin: 14px 0 6px;
    color: #374151;
    font-size: 13px;
    font-weight: 750;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    background: #fff;
    padding: 9px 11px;
    color: var(--ink);
    font: inherit;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid color-mix(in srgb, var(--brand), transparent 72%);
    outline-offset: 1px;
    border-color: var(--brand);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0;
}

.checkbox-row input {
    width: auto;
    min-height: auto;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 3px;
    background: #e5e7eb;
    color: #374151;
    font-size: 12px;
    font-weight: 750;
}

.error {
    padding: 10px 12px;
    border: 1px solid #fecaca;
    border-radius: 3px;
    background: #fff1f0;
    color: var(--danger);
}

.logo-preview {
    display: flex;
    align-items: center;
    min-height: 56px;
    margin-bottom: 8px;
}

.logo-preview img {
    max-width: 180px;
    max-height: 54px;
}

.impersonation-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 10px 16px;
    background: var(--warning-bg);
    border-bottom: 1px solid #fed7aa;
    color: #9a3412;
    font-weight: 700;
}

.scan-input {
    height: 64px;
    font-size: 26px;
    letter-spacing: 0;
}

.scan-status {
    margin-top: 14px;
    padding: 14px;
    border-radius: 3px;
    background: #eef4ff;
    color: #1d4ed8;
    font-weight: 750;
}

.scan-status.ok {
    background: #ecfdf3;
    color: var(--ok);
}

.scan-status.error {
    background: #fff1f0;
    color: var(--danger);
}

.scan-status.warning {
    background: #fff7ed;
    color: #9a3412;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
}

.progress {
    display: inline-flex;
    width: 90px;
    height: 8px;
    margin-right: 8px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: #f3f4f6;
    vertical-align: middle;
}

.progress span {
    display: block;
    background: var(--brand);
}

.batch-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.batch-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
}

.batch-card.is-complete {
    border-color: color-mix(in srgb, var(--ok), transparent 55%);
    background: #f0fdf4;
}

.batch-card-main {
    min-width: 0;
}

.batch-card-main .muted,
.batch-card-main small,
.batch-card-stock {
    font-size: 12px;
}

.batch-card-main strong {
    display: block;
    overflow-wrap: anywhere;
    font-size: 24px;
    line-height: 1.05;
}

.batch-card-main small,
.batch-card-stock {
    color: var(--muted);
}

.batch-card-counts {
    min-width: 96px;
    text-align: right;
}

.batch-card-counts span {
    display: block;
    font-size: 18px;
    font-weight: 800;
}

.batch-card-counts small {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.batch-card-counts .progress {
    margin-top: 5px;
    margin-right: 0;
}

.batch-card-stock {
    grid-column: 1 / -1;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.pagination a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: #fff;
    color: var(--ink);
    font-weight: 700;
}

.pagination a.active,
.pagination a:hover {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
    text-decoration: none;
}

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

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f9fafb;
    color: #374151;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

tr:last-child td {
    border-bottom: 0;
}

@media (max-width: 760px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        padding: 12px 14px;
    }

    .topbar-row {
        gap: 10px;
    }

    .brand-mark {
        width: 22px;
        height: 22px;
    }

    .topbar-user {
        align-items: flex-end;
        gap: 8px;
        font-size: 12px;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .topbar-menu {
        display: none;
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

    .topbar-menu.is-open {
        display: flex;
    }

    .topnav {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
        width: 100%;
    }

    .topnav a {
        min-height: 34px;
        padding: 0 8px;
        background: var(--nav-soft);
    }

    .topbar-menu button,
    .topbar-menu form {
        width: 100%;
    }

    .main {
        padding: 14px 10px 28px;
    }

    .page-title {
        margin-bottom: 12px;
        font-size: 22px;
    }

    .grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .task-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .scan-title {
        margin-bottom: 8px;
        font-size: 20px;
    }

    .scan-summary {
        margin-bottom: 8px;
    }

    .scan-summary > div {
        padding: 7px;
    }

    .scan-summary strong {
        font-size: 13px;
    }

    .scan-work-panel {
        padding: 10px;
    }

    .scan-progress {
        gap: 8px;
        margin-bottom: 8px;
    }

    .scan-progress .progress {
        flex-basis: 130px;
        max-width: 52vw;
    }

    .scan-input {
        height: 54px;
        font-size: 22px;
    }

    .scan-status {
        margin-top: 10px;
        padding: 10px;
        font-size: 13px;
    }

    .batch-card {
        grid-template-columns: minmax(0, 1fr) auto;
        padding: 10px;
    }

    .batch-card-main strong {
        font-size: 20px;
    }

    .batch-card-counts {
        min-width: 82px;
    }

    .actions .button,
    .actions button {
        width: 100%;
    }

    .impersonation-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .table-wrap {
        overflow-x: visible;
        border: 0;
        background: transparent;
    }

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
        width: 100%;
    }

    thead {
        display: none;
    }

    tr {
        margin-bottom: 10px;
        border: 1px solid var(--line);
        border-radius: 4px;
        background: #fff;
    }

    td {
        display: grid;
        grid-template-columns: minmax(96px, 38%) 1fr;
        gap: 8px;
        padding: 8px 10px;
        border-bottom: 1px solid #eef0f3;
        white-space: normal;
        word-break: break-word;
    }

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 800;
        text-transform: uppercase;
    }

    td:last-child {
        border-bottom: 0;
    }

    .table-actions {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
    }

    .warehouse-task-card {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        padding: 10px;
    }

    .task-progress {
        min-width: 92px;
        text-align: right;
    }

    .task-progress .progress {
        width: 56px;
        margin-right: 4px;
    }
}
