:root {
    --bg: #f7f8fa;
    --panel: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #d9dee7;
    --primary: #155eef;
    --primary-hover: #0f49bd;
    --danger: #c03744;
    --success: #0f7b4b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 0 28px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.brand {
    font-size: 18px;
    font-weight: 700;
}

.nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav a,
.nav button {
    border-radius: 6px;
    color: var(--muted);
    padding: 8px 12px;
    font-weight: 600;
}

.nav a.active,
.nav a:hover,
.nav button:hover {
    background: #eef4ff;
    color: var(--primary);
}

.nav-form {
    margin: 0;
}

.nav button {
    border: 0;
    background: transparent;
    cursor: pointer;
    font: inherit;
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto 56px;
}

.page-head,
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-head h1,
.panel-head h2 {
    margin: 0;
}

.page-head h1 {
    font-size: 28px;
}

.panel-head h2 {
    font-size: 18px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

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

.dashboard-metrics {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric,
.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.metric {
    padding: 18px;
}

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

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

.metric strong.metric-name {
    font-size: 20px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.panel {
    margin-bottom: 18px;
    padding: 18px;
    overflow-x: auto;
}

.notice {
    border-radius: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.notice.success {
    background: #ecfdf3;
    color: var(--success);
}

.notice.error {
    background: #fff1f3;
    color: var(--danger);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 11px 10px;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.num {
    text-align: right;
}

.empty {
    color: var(--muted);
    text-align: center;
}

.actions,
.form-actions,
.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.button:hover {
    background: var(--primary-hover);
}

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

.button.secondary:hover {
    background: #f2f4f7;
}

.button.danger {
    border-color: var(--danger);
    background: #fff;
    color: var(--danger);
}

.button.small {
    min-height: 32px;
    padding: 5px 10px;
}

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

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

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

.mapping-create-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 160px auto;
    gap: 16px;
    align-items: end;
}

.mapping-form-actions {
    display: flex;
    align-items: center;
}

.mapping-table {
    table-layout: fixed;
}

.mapping-table th:nth-child(1),
.mapping-table td:nth-child(1) {
    width: 120px;
}

.mapping-table th:nth-child(2),
.mapping-table td:nth-child(2) {
    width: 180px;
}

.mapping-table th:nth-child(3),
.mapping-table td:nth-child(3) {
    width: 100px;
}

.mapping-table th:nth-child(4),
.mapping-table td:nth-child(4) {
    width: 140px;
}

.mapping-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-text-input {
    min-width: 0;
    width: 140px;
    min-height: 32px;
    padding: 5px 8px;
}

.quantity-input {
    width: 80px;
    min-height: 32px;
    padding: 5px 8px;
}

.form-section-title {
    grid-column: 1 / -1;
    margin: 10px 0 0;
    border-bottom: 1px solid var(--line);
    padding-bottom: 8px;
    font-size: 16px;
}

.field-help {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.auth-panel {
    width: min(460px, 100%);
    margin: 48px auto;
}

label span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
    padding: 8px 10px;
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check input {
    width: 18px;
    min-height: 18px;
}

.check span {
    margin: 0;
}

.form-actions {
    grid-column: 1 / -1;
}

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

.filter-bar select {
    max-width: 260px;
}

.filter-bar select.per-page-select {
    max-width: 140px;
}

.filter-bar input {
    max-width: 360px;
}

.ajax-pager {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.ajax-pager.top {
    margin: 0 0 12px;
}

.ajax-pager.bottom {
    margin-top: 16px;
}

.pager-jump {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    margin-left: 8px;
}

.pager-jump input {
    width: 72px;
    min-height: 32px;
    padding: 5px 8px;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.status {
    border-radius: 999px;
    background: #eef2f6;
    padding: 3px 8px;
    font-weight: 700;
}

.status.success {
    background: #dcfae6;
    color: var(--success);
}

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

@media (max-width: 760px) {
    .app-header,
    .page-head {
        align-items: stretch;
        flex-direction: column;
    }

    .nav,
    .metrics,
    .form-grid,
    .filter-bar,
    .mapping-create-form {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }
}
