:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --line: #e2e5e9;
    --ink: #202328;
    --muted: #6b7178;
    --accent: #1f5fbf;
    --accent-bar: #ea6a1e;
}

* { box-sizing: border-box; }

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

.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--accent); color: #fff; padding: 0 16px; height: 48px;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.brand span { color: var(--accent-bar); }
.top-actions { display: flex; align-items: center; gap: 14px; }
.top-actions a { color: #fff; text-decoration: none; opacity: .9; }
.top-actions .who { opacity: .9; font-size: 13px; }
.logout-form { display: inline; margin: 0; }
.linkbtn { background: none; border: 0; color: #fff; cursor: pointer; font: inherit; opacity: .9; padding: 0; }
.linkbtn:hover { text-decoration: underline; }

/* login */
.login-wrap { display: flex; justify-content: center; padding: 60px 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; width: 340px; }
.login-brand { font-weight: 700; font-size: 18px; margin-bottom: 10px; }
.login-brand span { color: var(--accent-bar); }
.login-card h1 { font-size: 18px; margin: 0 0 16px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.login-card input { display: block; width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 4px; margin-top: 4px; }
.login-card button { width: 100%; padding: 10px; border: 0; border-radius: 4px; background: var(--accent-bar); color: #fff; font-weight: 600; cursor: pointer; margin-top: 6px; }
.login-error { background: #fdecea; color: #d33a2c; padding: 8px 10px; border-radius: 4px; margin-bottom: 12px; font-size: 13px; }
.login-back { display: inline-block; margin-top: 14px; color: var(--accent); text-decoration: none; font-size: 13px; }

.content { flex: 1; padding: 12px; }

.statusbar {
    display: flex; justify-content: space-between;
    background: #2a2e34; color: #c7ccd2; padding: 6px 16px; font-size: 12px;
}

/* two-column search layout */
.search-layout { display: grid; grid-template-columns: 260px 1fr; gap: 12px; align-items: start; }

.search-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 14px; }
.panel-title { font-size: 15px; margin: 0 0 10px; }
.term { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 10px; }

/* search history dropdown */
.term-wrap { position: relative; }
.history-dd { position: absolute; top: 34px; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 0 0 4px 4px; box-shadow: 0 6px 16px rgba(0,0,0,.10); z-index: 30; max-height: 280px; overflow: auto; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.history-item:hover { background: #eef2f7; }
.history-item .hf { color: var(--muted); font-size: 11px; white-space: nowrap; }
.fields { border: 0; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 4px; }
.fields label, .similar { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.similar { margin-bottom: 12px; }
.btn-search {
    width: 100%; padding: 9px; border: 0; border-radius: 4px;
    background: var(--accent-bar); color: #fff; font-weight: 600; cursor: pointer;
}
.btn-search:disabled { opacity: .6; cursor: default; }

/* recent articles */
.recent { margin-bottom: 12px; }
.recent-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.recent-chip { display: inline-block; background: #eef1f5; border: 1px solid var(--line); border-radius: 12px; padding: 2px 8px; margin: 0 4px 4px 0; font-size: 12px; color: var(--accent); text-decoration: none; }
.recent-chip:hover { text-decoration: underline; }

/* filters */
.filters { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.filters-title { font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.flt { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 6px; }
.flt-sel { margin-top: 8px; }
.flt-sel span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.flt-sel select { width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 4px; }
.results-meta .muted { color: var(--muted); }

/* results */
.results { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; min-height: 300px; }
.hint { padding: 24px; color: var(--muted); }
.results-meta { padding: 8px 12px; border-bottom: 1px solid var(--line); color: var(--muted); }
.rm-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sort-box { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.sort-box select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; font-size: 12px; }
.enriching { color: var(--accent); }

.group-header {
    background: var(--accent-bar); color: #fff; padding: 5px 12px; font-weight: 600; font-size: 13px;
}

.row { display: grid; grid-template-columns: 28px 44px 1fr 185px 120px; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); align-items: center; }
.row-cart { display: flex; flex-direction: column; gap: 5px; align-items: stretch; }
.row-cart .qty { align-self: center; }
.cart-btn.sm { height: 28px; width: 100%; font-size: 13px; flex: 0 0 auto; }
.cart-flash { margin: 8px 12px; padding: 6px 10px; background: #fff4e6; border: 1px solid #f0c48a; color: #b45f06; border-radius: 4px; font-size: 13px; }
.load-more-wrap { padding: 14px; text-align: center; border-top: 1px solid var(--line); }
.load-more { padding: 8px 22px; border: 1px solid var(--accent); background: #fff; color: var(--accent); border-radius: 4px; font-weight: 600; cursor: pointer; }
.load-more:hover { background: var(--accent); color: #fff; }
.row-stock { display: flex; align-items: center; justify-content: center; }
.row-thumb { display: flex; align-items: center; justify-content: center; }
.row-thumb img { max-width: 40px; max-height: 40px; object-fit: contain; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.row-title { font-weight: 600; }
.row-sub { color: var(--muted); font-size: 13px; }
.row-sub .via { color: #7a4a12; }
.via-oem { color: #1e7a34; }
.via-oes { color: #7a4a12; }
.via-tag { font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 3px; margin-left: 4px; white-space: nowrap; }
.via-tag.ok { background: #e6f4ea; color: #1e7a34; }
.via-tag.warn { background: #fdf0e3; color: #b45f06; }
.row-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.row-dims { color: var(--ink); font-size: 12px; margin-top: 3px; }
.row-wh { margin-top: 6px; font-size: 12px; }
.row-wh > summary { cursor: pointer; color: var(--accent); }
.row-wh > summary:hover { text-decoration: underline; }
.row-wh .kv { margin-top: 4px; max-width: 100%; }
.row-wh .kv td { padding: 2px 4px; }
.row-wh .kv .k { font-size: 11px; }
/* on the detail page the row-wh lives in the price column, left-aligned */
.row-price .row-wh { text-align: left; }
.erp-badge { display: inline-block; margin-left: 6px; background: #eef2f7; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; font-size: 10px; font-weight: 700; vertical-align: middle; }
.stock-label { font-weight: 600; }
.row-price { text-align: right; }
.price { font-weight: 700; }
.price.muted { color: var(--muted); font-weight: 400; }
.price-kind { font-size: 11px; color: var(--accent); }

.row-title a { color: var(--accent); text-decoration: none; }
.row-title a:hover { text-decoration: underline; }
.hint.error { color: #d33a2c; }

/* "Замени" action (direct search by the article's own code) */
.row-actions { margin-top: 4px; }
.replace-btn {
    display: inline-flex; align-items: center; gap: 4px;
    background: #fff4e6; border: 1px solid #f0c48a; color: #b45f06;
    border-radius: 4px; padding: 2px 8px; font-size: 12px; font-weight: 600;
    cursor: pointer; text-decoration: none;
}
.replace-btn:hover { background: #ffe8cc; }
.d-mid .replace-btn { margin-top: 8px; }

/* article detail page */
.detail-page { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 16px 20px; }
.back { display: inline-block; margin-bottom: 12px; color: var(--accent); text-decoration: none; }
.back:hover { text-decoration: underline; }
.detail-back { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.detail-back .back { margin-bottom: 0; }
.back-alt { color: var(--muted); }
.detail-head { display: grid; grid-template-columns: auto 1fr 300px; gap: 20px; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 12px; }
.d-mid { min-width: 0; }
.d-block { margin-top: 14px; }
.d-block h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); margin: 0 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 3px; }

/* buy box (price / stock / quantity / cart / warehouses) */
.d-buy { background: #fafbfc; border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
.d-buy .d-price { text-align: left; }
.d-buy .d-stock { justify-content: flex-start; }
.buy-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: #fff; }
.qty-btn { border: 0; background: #eef1f5; width: 28px; height: 30px; font-size: 16px; line-height: 1; cursor: pointer; }
.qty-btn:hover { background: #e2e6eb; }
.qty-input { width: 46px; height: 30px; border: 0; text-align: center; font-size: 14px; }
.cart-btn { flex: 1; height: 32px; border: 0; border-radius: 4px; background: var(--accent-bar); color: #fff; font-weight: 600; cursor: pointer; }
.cart-btn:hover { background: #d65f18; }
.buy-note { margin-top: 8px; font-size: 12px; color: var(--muted); }
@media (max-width: 860px) { .detail-head { grid-template-columns: 1fr; } }
.detail-img { width: 110px; height: 110px; object-fit: contain; border: 1px solid var(--line); border-radius: 4px; background: #fff; flex-shrink: 0; }
.d-headtext { flex: 1; }
.d-title { font-size: 20px; font-weight: 700; }
.d-sub { color: var(--muted); margin-top: 2px; }
.d-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.d-price-box { text-align: right; }
.d-price { font-size: 20px; font-weight: 700; }
.d-stock { margin-top: 4px; font-weight: 600; display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.detail-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .detail-cols { grid-template-columns: 1fr; } }
.panel-wide { grid-column: 1 / -1; }
.kv.veh .v { width: 60%; }
.kv.veh .reftype { text-align: left; color: var(--ink); }
.panel h2 { font-size: 14px; margin: 0 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 4px 6px; border-bottom: 1px solid #f0f1f3; vertical-align: top; }
.kv .k { color: var(--muted); width: 45%; }
.kv .v { font-weight: 500; }
.muted { color: var(--muted); }

/* collapsible reference groups */
details.mfr { border-bottom: 1px solid #f0f1f3; }
details.mfr > summary { cursor: pointer; padding: 6px 4px; font-weight: 600; list-style: revert; }
details.mfr > summary:hover { color: var(--accent); }
details.mfr .kv td { padding-left: 18px; }
details.mfr .cnt { color: var(--muted); font-weight: 400; font-size: 12px; }
details.oes { margin-top: 12px; border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px; }
details.oes > summary { cursor: pointer; padding: 6px 2px; font-weight: 600; color: var(--accent-bar); }
.reftype { color: var(--muted); font-size: 11px; text-align: right; }

/* add OEM/OES (Admin/Seller) */
details.add-ref { margin-top: 12px; border: 1px dashed var(--line); border-radius: 4px; padding: 2px 10px; }
details.add-ref > summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: 6px 0; }
.add-ref-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; padding: 8px 0; }
.add-ref-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.add-ref-form input, .add-ref-form select { padding: 6px; border: 1px solid var(--line); border-radius: 4px; font-size: 13px; }
.add-ref-form input { min-width: 130px; }
.btn-add-ref { padding: 7px 16px; border: 0; border-radius: 4px; background: var(--accent-bar); color: #fff; font-weight: 600; cursor: pointer; }
.btn-add-ref:disabled { opacity: .6; cursor: default; }
.add-ref-msg { flex-basis: 100%; font-size: 12px; color: var(--accent); margin-top: 2px; }
/* small ✕ button to remove a wrongly-entered OEM/OES number (staff only) */
.btn-del-ref { padding: 0 6px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: #d33a2c; font-size: 13px; line-height: 1.6; cursor: pointer; }
.btn-del-ref:hover { background: rgba(211,58,44,.12); border-color: rgba(211,58,44,.4); }
.btn-del-ref:disabled { opacity: .4; cursor: default; }
table.kv td.c { text-align: right; width: 1%; white-space: nowrap; }
/* recognised-manufacturer chips under the number field */
.ref-brand-hints { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.brand-chip { padding: 2px 10px; border: 1px solid var(--line); border-radius: 12px; background: #f3f6f9; color: #33475b; font-size: 12px; cursor: pointer; }
.brand-chip:hover { border-color: var(--accent-bar); }
.brand-chip.active { background: var(--accent-bar); color: #fff; border-color: var(--accent-bar); }

/* detail header row: title left, edit buttons filling the empty space on the right */
.d-headrow { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }

/* edit action buttons in the detail header (like the desktop) */
.edit-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.d-headrow .edit-bar { margin-top: 0; flex-direction: column; align-items: stretch; flex-shrink: 0; }
.edit-hint { grid-column: 1 / -1; font-size: 11px; color: var(--muted); margin-top: 2px; }
.price-last { font-size: 14px; margin-bottom: 8px; padding: 6px 10px; background: #f0f4f9; border-radius: 4px; }
.edit-btn { background: #5a9c3e; border: 0; color: #fff; border-radius: 4px; padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
.edit-btn:hover { background: #4d8834; }
.edit-btn.active { background: #3d6c29; box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.btn-cancel { background: #eef1f5; border: 1px solid var(--line); color: var(--ink); border-radius: 4px; padding: 7px 14px; font-weight: 600; cursor: pointer; }
.btn-cancel:hover { background: #e2e6eb; }

/* ERP extended-data editor (Admin / privileged Seller) */
.edit-panel { margin: 12px 0; border: 1px solid var(--accent-bar); border-radius: 6px; padding: 10px 16px; background: #fffaf5; }
.edit-title { font-size: 15px; margin: 0 0 8px; color: var(--accent-bar); }
.edit-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; padding: 4px 0 6px; }
.edit-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.edit-form label.wide { grid-column: 1 / -1; }
.edit-form input, .edit-form textarea { padding: 6px; border: 1px solid var(--line); border-radius: 4px; font-size: 13px; font-family: inherit; }
.edit-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; margin-top: 4px; }

/* image gallery on the detail page */
.detail-gallery { flex-shrink: 0; width: 110px; }
.no-img { width: 110px; height: 110px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--line); border-radius: 4px; color: var(--muted); font-size: 12px; text-align: center; }
.detail-img { cursor: zoom-in; }
.thumbs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; max-width: 120px; }
.thumb { width: 32px; height: 32px; object-fit: contain; border: 1px solid var(--line); border-radius: 3px; background: #fff; cursor: pointer; }
.thumb:hover { border-color: var(--accent); }

/* manufacturer catalogue links */
.mfr-links { list-style: none; margin: 0; padding: 0; }
.mfr-links li { padding: 4px 0; border-bottom: 1px solid #f0f1f3; }
.mfr-links a { color: var(--accent); text-decoration: none; font-weight: 600; }
.mfr-links a:hover { text-decoration: underline; }
.mfr-links .ext { color: var(--muted); font-weight: 400; }

/* lightbox */
.lb-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.78); z-index: 100; display: flex; align-items: center; justify-content: center; }
.lb-inner { position: relative; max-width: 92vw; max-height: 92vh; }
.lb-img { max-width: 92vw; max-height: 92vh; object-fit: contain; background: #fff; border-radius: 4px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); border: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 34px; line-height: 1; width: 46px; height: 64px; cursor: pointer; border-radius: 4px; }
.lb-nav:hover { background: rgba(0,0,0,.7); }
.lb-prev { left: -10px; }
.lb-next { right: -10px; }
.lb-count { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 12px; }
.lb-close { position: absolute; top: -14px; right: -14px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #fff; color: #202328; font-size: 20px; line-height: 1; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.lb-close:hover { background: #f0f1f3; }

/* ============================ Поставки / Settings ============================ */
.settings-page { max-width: 1100px; margin: 0 auto; padding: 8px 4px 40px; }
.settings-page h1 { font-size: 1.4rem; margin: 8px 0 14px; }
.settings-tabs { display: flex; gap: 4px; border-bottom: 2px solid #e3e6ea; margin-bottom: 16px; }
.settings-tabs .stab {
    background: none; border: none; padding: 10px 18px; cursor: pointer;
    font-size: .95rem; color: #5a6472; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.settings-tabs .stab.on { color: #16324f; font-weight: 600; border-bottom-color: #2e7d32; }
.settings-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.settings-toolbar select { padding: 6px 10px; border: 1px solid #cfd6dd; border-radius: 6px; }

.hint.ok  { background: #eaf6ea; color: #1e5a24; border: 1px solid #bfe0c0; }
.hint.err { background: #fdecec; color: #a12626; border: 1px solid #f0c2c2; }

.utable, .ptable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.utable th, .utable td, .ptable th, .ptable td {
    text-align: left; padding: 8px 10px; border-bottom: 1px solid #eef1f4; vertical-align: top;
}
.utable thead th, .ptable thead th { color: #5a6472; font-weight: 600; border-bottom: 2px solid #e3e6ea; }
.utable tr.inactive { color: #9aa4b0; }
.utable .row-actions { white-space: nowrap; text-align: right; }

.linklike { background: none; border: none; color: #1769aa; cursor: pointer; padding: 2px 6px; font-size: .88rem; }
.linklike:hover { text-decoration: underline; }
.linklike.danger { color: #b23b3b; }

.rolechip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; font-weight: 600; }
.rolechip.r-admin  { background: #efe3fb; color: #6a2fb0; }
.rolechip.r-seller { background: #e3eefb; color: #1f5fa8; }
.rolechip.r-buyer  { background: #eef2f5; color: #4a5560; }

.tag.warn { color: #c07800; font-weight: 700; }

.fgrid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 10px 18px; margin: 10px 0; }
.fgrid label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: #5a6472; }
.fgrid input, .fgrid select { padding: 7px 9px; border: 1px solid #cfd6dd; border-radius: 6px; font-size: .92rem; }
.fchecks { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 6px 0 12px; }
.fchecks .chk, .ptable .chk { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: #33404d; }
.ptable td select { padding: 5px 8px; border: 1px solid #cfd6dd; border-radius: 6px; }
.edit-btn.save { background: #2e7d32; color: #fff; border-color: #2e7d32; }

/* ---- Увоз (Excel) ---- */
.imp-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.imp-chip { padding: 3px 10px; border-radius: 12px; font-size: .82rem; font-weight: 600; }
.imp-chip.new { background: #eaf6ea; color: #1e5a24; }
.imp-chip.upd { background: #e3eefb; color: #1f5fa8; }
.imp-chip.dup { background: #fdf0e3; color: #b45f06; }
.imp-chip.err { background: #fdecec; color: #a12626; }
.imp-problems { margin: 8px 0; }
.imp-problems summary { cursor: pointer; color: var(--accent); }
