:root {
    --bg: #f4f7f6;
    --text: #17211f;
    --muted: #66736f;
    --line: #d9e2df;
    --panel: #ffffff;
    --accent: #0f766e;
    --danger: #b42318;
    --warning: #a15c07;
    --ok: #16724a;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 Arial, sans-serif;
}
.topbar {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    padding: 22px 28px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
}
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 24px; margin-bottom: 6px; }
h2 { font-size: 20px; margin-bottom: 0; }
h3 { font-size: 16px; margin: 22px 0 10px; }
.status { display: grid; gap: 6px; min-width: 280px; color: var(--muted); }
.tabs {
    display: flex;
    gap: 6px;
    padding: 14px 28px 0;
    overflow-x: auto;
}
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 8px 13px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    font: inherit;
}
button:hover, .button:hover { filter: brightness(.95); }
button.danger { background: var(--danger); border-color: var(--danger); margin-top: 12px; }
.tabs button {
    background: #e5eeeb;
    color: var(--text);
    border-color: var(--line);
}
.tabs button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
main { padding: 18px 28px 36px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}
.notice, .api-errors {
    margin: 14px 28px 0;
    padding: 12px 14px;
    border-radius: 6px;
    background: #e9f7ef;
    border: 1px solid #b7e0c2;
}
.notice.error, .api-errors {
    background: #fff0ed;
    border-color: #ffc7bd;
}
.api-errors div { margin-top: 6px; font-family: Consolas, monospace; font-size: 12px; }
.table-tools, .filters, .actions-row, .settings-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 12px 0;
}
input, select {
    min-height: 36px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
}
input[type="search"] { min-width: min(360px, 100%); }
.num-input { width: 110px; }
.table-wrap {
    width: 100%;
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}
th, td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
th {
    position: sticky;
    top: 0;
    background: #eef4f2;
    cursor: pointer;
    white-space: nowrap;
}
tbody tr:hover { outline: 2px solid #b7d8d2; outline-offset: -2px; }
.row-danger { background: #fff3f0; }
.row-warning { background: #fff8e8; }
.row-ok { background: #f0faf4; }
.muted { color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 6px; }
.settings-form {
    align-items: flex-start;
    flex-direction: column;
    max-width: 520px;
}
.settings-form label { display: grid; gap: 6px; width: 100%; }
.settings-form input { width: 100%; }
@media (max-width: 760px) {
    .topbar { display: block; padding: 18px; }
    .tabs, main { padding-left: 14px; padding-right: 14px; }
    .panel-head { display: block; }
}

.sales-summary { margin: 18px 0; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.sales-summary > h3:first-child { margin-top: 0; }
.sales-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 16px 0; }
.sales-metric { padding: 14px; background: #eef4f2; border-radius: 6px; }
.sales-metric > span { display: block; color: var(--muted); }
.sales-metric strong { display: block; margin-top: 6px; font-size: 28px; }
.sales-metric .sales-change { font-size: 18px; }
.sales-down { color: var(--danger); }
.sales-demand-wrap { max-height: 420px; }
.sales-demand-bar { width: 130px; height: 7px; margin-top: 7px; background: #e5eeeb; border-radius: 4px; overflow: hidden; }
.sales-demand-bar span { display: block; height: 100%; background: var(--accent); }

.sales-product-filter { flex-basis: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.sales-product-filter summary { cursor: pointer; font-weight: bold; }
.sales-product-filter > p { margin: 12px 0; }
.sales-product-options { max-height: 280px; overflow: auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 6px; }
.sales-product-option { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.sales-product-option[hidden] { display: none; }
.sales-product-option input { min-height: auto; margin-top: 4px; }
.sales-product-option small { display: block; color: var(--muted); }

.sales-product-photo { position: relative; flex: 0 0 64px; width: 64px; height: 85px; border-radius: 5px; background: #eef4f2; overflow: hidden; }
.sales-product-photo > span { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 11px; color: var(--muted); }
.sales-product-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.sales-summary { margin: 18px 0; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.sales-summary > h3:first-child { margin-top: 0; }
.sales-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 16px 0; }
.sales-metric { padding: 14px; background: #eef4f2; border-radius: 6px; }
.sales-metric > span { display: block; color: var(--muted); }
.sales-metric strong { display: block; margin-top: 6px; font-size: 28px; }
.sales-metric .sales-change { font-size: 18px; }
.sales-down { color: var(--danger); }
.sales-demand-wrap { max-height: 420px; }
.sales-demand-bar { width: 130px; height: 7px; margin-top: 7px; background: #e5eeeb; border-radius: 4px; overflow: hidden; }
.sales-demand-bar span { display: block; height: 100%; background: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; }
.settings-form {
    align-items: flex-start;
    flex-direction: column;
    max-width: 520px;
}
.settings-form label { display: grid; gap: 6px; width: 100%; }
.settings-form input { width: 100%; }
@media (max-width: 760px) {
    .topbar { display: block; padding: 18px; }
    .tabs, main { padding-left: 14px; padding-right: 14px; }
    .panel-head { display: block; }
}

.sales-sort-button { min-height: 28px; padding: 2px 7px; margin-left: 4px; background: transparent; border-color: var(--line); color: var(--accent); font-size: 18px; line-height: 1; }

.sales-demand-wrap th { z-index: 2; }
.sales-demand-wrap .sales-product-photo { z-index: 0; }

#products-table th { z-index: 2; }
#products-table .sales-product-photo { z-index: 0; }

#stocks-table th, #stocks-total-table th { z-index: 2; }
#stocks-table .sales-product-photo, #stocks-total-table .sales-product-photo { z-index: 0; }

#home-table th, #order-table th { z-index: 2; }
#home-table .sales-product-photo, #order-table .sales-product-photo { z-index: 0; }
