* {
    box-sizing: border-box;
}

:root {
    --money-column-width: 86px;
}

body {
    margin: 0;
    background: #f6f7f9;
    color: #1f2933;
    font: 14px/1.4 Arial, sans-serif;
}

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

.page {
    padding: 20px;
}

.topbar {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    margin-bottom: 10px;
}

h1,
h2 {
    margin: 0 0 10px;
}

.muted {
    color: #667085;
}

.brand {
    align-items: baseline;
    display: flex;
    flex: 0 0 auto;
    gap: 12px;
}

.brand h1 {
    font-size: 20px;
}

.actions,
.toolbar,
.inline-form {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.toolbar {
    flex: 0 0 auto;
    margin-bottom: 0;
    min-width: 220px;
}

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

.toolbar select {
    min-width: 260px;
}

.file-status {
    color: #475467;
    white-space: nowrap;
}

.topbar-spacer {
    flex: 1 1 auto;
}

.user-status {
    color: #475467;
    flex: 0 0 auto;
    text-align: right;
    white-space: nowrap;
}

.column-menu {
    position: relative;
}

.column-menu summary {
    display: inline-flex;
    list-style: none;
}

.column-menu summary::-webkit-details-marker {
    display: none;
}

.column-list {
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    display: grid;
    gap: 8px;
    max-height: 360px;
    min-width: 220px;
    overflow: auto;
    padding: 10px;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 20;
}

.button,
button {
    background: #1d4ed8;
    border: 1px solid #1d4ed8;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    padding: 8px 12px;
}

.muted-button {
    background: #fff;
    color: #1f2933;
    border-color: #d0d5dd;
}

input,
select {
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font: inherit;
    padding: 8px 10px;
}

label {
    display: grid;
    gap: 5px;
}

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

.auth-box {
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 8px;
    margin: 10vh auto 0;
    max-width: 360px;
    padding: 24px;
}

.form {
    display: grid;
    gap: 12px;
}

.alert,
.empty {
    background: #fff4ed;
    border: 1px solid #ffd6ae;
    border-radius: 6px;
    color: #9a3412;
    margin-bottom: 14px;
    padding: 10px 12px;
}

.table-wrap {
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 8px;
    max-height: calc(100vh - 130px);
    overflow: auto;
}

table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

.price-table {
    margin: 0 auto;
    min-width: max-content;
    width: max-content;
}

th,
td {
    border-bottom: 1px solid #e4e7ec;
    border-right: 1px solid #e4e7ec;
    padding: 7px 9px;
    text-align: left;
    white-space: nowrap;
}

.offer-price-column {
    border-right: 1px solid #f97316;
}

[data-column="manufacturer"],
[data-column="article"],
[data-column="quantity"] {
    width: 1%;
}

th[data-column="manufacturer"],
th[data-column="article"],
th[data-column="quantity"] {
    min-width: max-content;
}

td[data-column="sale"],
td[data-column="purchase"],
[data-column^="price"],
td[data-column="base_price"],
td[data-column="required_price"],
td[data-column="minimum_price"],
td[data-column="price_for_list"],
td[data-column="dynamic"] {
    max-width: var(--money-column-width);
    min-width: var(--money-column-width);
    width: var(--money-column-width);
}

[data-column="required_markup_percent"],
[data-column="price_for_list_markup_percent"] {
    max-width: 64px;
    min-width: 64px;
    width: 64px;
}

[data-column="price1"].offer-price-column {
    border-left: 1px solid #f97316;
}

th.offer-price-column {
    border-top: 1px solid #f97316;
    color: #f97316;
    text-align: center;
}

tbody tr:last-child td.offer-price-column {
    border-bottom: 1px solid #f97316;
}

[data-column="minimum_price"] {
    border-right: 0;
}

[data-column="price_for_list"] {
    border-left: 1px solid #16a34a;
    border-right: 1px solid #e4e7ec;
}

[data-column="price_for_list_markup_percent"] {
    border-right: 1px solid #16a34a;
}

th[data-column="price_for_list"],
th[data-column="price_for_list_markup_percent"] {
    border-top: 1px solid #16a34a;
    color: #16a34a;
}

tbody tr:last-child td[data-column="price_for_list"],
tbody tr:last-child td[data-column="price_for_list_markup_percent"] {
    border-bottom: 1px solid #16a34a;
}

td[data-column="sale"],
td[data-column="purchase"],
td[data-column^="price"],
td[data-column="base_price"],
td[data-column="required_price"],
td[data-column="minimum_price"],
td[data-column="price_for_list"],
td[data-column="dynamic"],
td[data-column="required_markup_percent"],
td[data-column="price_for_list_markup_percent"] {
    text-align: right;
}

th:last-child,
td:last-child {
    border-right: 0;
}

[data-column].is-hidden {
    display: none;
}

tr.is-filtered {
    display: none;
}

th {
    background: #f9fafb;
    font-weight: 600;
    position: sticky;
    top: 0;
    vertical-align: top;
    z-index: 1;
}

th:has(.column-menu[open]) {
    z-index: 30;
}

th:has(.header-search.is-open) {
    z-index: 25;
}

.th-controls {
    align-items: center;
    display: flex;
    gap: 6px;
    justify-content: space-between;
}

.header-actions {
    display: inline-flex;
    gap: 4px;
}

.header-icon {
    align-items: center;
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 5px;
    color: #1f2933;
    cursor: pointer;
    display: inline-flex;
    flex: 0 0 auto;
    height: 24px;
    justify-content: center;
    line-height: 1;
    min-width: 24px;
    padding: 0 6px;
}

.header-search {
    align-items: center;
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 5px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    display: none;
    gap: 4px;
    margin-top: 0;
    min-width: 150px;
    padding: 2px 6px;
    position: absolute;
    top: calc(100% + 6px);
    z-index: 25;
}

.header-search.is-open {
    display: flex;
}

.header-search input {
    border: 0;
    min-width: 0;
    padding: 2px 0;
    width: 112px;
}

.header-search input:focus {
    outline: 0;
}

.search-clear {
    align-items: center;
    background: transparent;
    border: 0;
    color: #667085;
    cursor: pointer;
    display: inline-flex;
    height: 22px;
    justify-content: center;
    padding: 0;
    width: 22px;
}

.search-clear:hover {
    color: #1f2933;
}

.name-column {
    max-width: 260px;
    min-width: 260px;
    width: 260px;
}

.clipped {
    overflow: hidden;
    text-overflow: ellipsis;
}

.price-cell {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: #1f2933;
    justify-content: flex-end;
    min-width: 0;
    padding: 4px 6px;
    text-align: right;
    width: 100%;
}

.price-cell.ours {
    background: #dcfce7;
}

.price-cell.selected-base {
    border-color: #2563eb;
    box-shadow: 0 0 0 1px #2563eb inset;
}

.note {
    color: #dc2626;
    font-weight: 600;
}

.dynamic.negative {
    color: #dc2626;
}

.dynamic.positive {
    color: #16a34a;
}

.markup.negative {
    color: #dc2626;
}

.markup.positive {
    color: #16a34a;
}

.grid {
    display: grid;
    gap: 24px;
}

.admin-title {
    flex: 1 1 auto;
}

.admin-grid {
    display: grid;
    gap: 16px;
}

.admin-card {
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 8px;
    overflow: hidden;
}

.admin-card-header {
    align-items: center;
    background: #f9fafb;
    border-bottom: 1px solid #e4e7ec;
    display: flex;
    justify-content: space-between;
    padding: 12px 14px;
}

.admin-card-header h2 {
    margin: 0;
}

.admin-form,
.admin-edit-form {
    align-items: end;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(150px, 1fr) minmax(180px, 1fr) minmax(260px, 2fr) auto auto;
    padding: 14px;
}

.admin-form label,
.admin-edit-form label {
    min-width: 0;
}

.admin-form input,
.admin-form select,
.admin-edit-form input,
.admin-edit-form select {
    width: 100%;
}

.admin-form:not(.price-form) {
    grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) minmax(110px, 140px) auto;
}

.formula-field {
    min-width: 260px;
}

.admin-check {
    align-self: center;
    padding-bottom: 8px;
    white-space: nowrap;
}

.simple-table {
    background: #fff;
    border: 0;
    border-top: 1px solid #e4e7ec;
    margin-top: 0;
}

.admin-table th {
    position: static;
}

.admin-table td,
.admin-table th {
    vertical-align: middle;
}

.icon-button {
    align-items: center;
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 5px;
    color: #1f2933;
    height: 30px;
    justify-content: center;
    line-height: 1;
    padding: 0;
    width: 30px;
}

.icon-button:hover {
    background: #f9fafb;
}

.price-edit-row {
    display: none;
}

.price-edit-row.is-open {
    display: table-row;
}

.price-edit-row td {
    background: #f9fafb;
    padding: 0;
}

.edit-actions {
    align-items: end;
    display: flex;
    gap: 8px;
}

@media (max-width: 760px) {
    .page {
        padding: 12px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .brand {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .toolbar,
    .toolbar select {
        width: 100%;
    }

    .admin-form,
    .admin-form:not(.price-form),
    .admin-edit-form {
        grid-template-columns: 1fr;
    }

    .admin-check {
        padding-bottom: 0;
    }
}
