:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #dfe4ea;
  --text: #17202a;
  --muted: #677483;
  --sidebar: #17232d;
  --sidebar-hover: #223440;
  --primary: #18794e;
  --primary-hover: #11643f;
  --danger: #b42318;
  --warning: #9a6700;
  --radius: 6px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; stroke-width: 1.8; flex: 0 0 auto; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; min-height: 0; background: var(--sidebar); color: #dce5ea; display: flex; flex-direction: column; overflow: hidden; padding: 12px 10px; z-index: 20; }
.brand { display: flex; align-items: center; flex: 0 0 auto; gap: 9px; padding: 2px 8px 12px; color: #fff; font-size: 16px; font-weight: 700; }
.brand-mark { width: 30px; height: 30px; display: inline-grid; place-items: center; background: #e7f6ee; color: var(--primary); border-radius: 5px; font-size: 17px; font-weight: 800; }
.nav-list { display: grid; flex: 1 1 auto; min-height: 0; align-content: start; gap: 2px; overflow-y: auto; overscroll-behavior: contain; padding: 0 2px 8px 0; scrollbar-color: #526773 transparent; scrollbar-width: thin; }
.nav-list::-webkit-scrollbar { width: 6px; }
.nav-list::-webkit-scrollbar-track { background: transparent; }
.nav-list::-webkit-scrollbar-thumb { background: #526773; border-radius: 999px; }
.nav-list::-webkit-scrollbar-thumb:hover { background: #718894; }
.nav-item { min-height: 38px; display: flex; align-items: center; gap: 10px; padding: 0 10px; color: #b9c7cf; border-radius: 5px; border: 0; background: transparent; width: 100%; font-size: 13px; line-height: 1.2; text-align: left; }
.nav-item svg { width: 17px; height: 17px; }
.nav-item:hover, .nav-item.active { color: #fff; background: var(--sidebar-hover); }
.nav-item.active { box-shadow: inset 3px 0 #59c48a; }
.sidebar-footer { flex: 0 0 auto; border-top: 1px solid #31434f; padding-top: 8px; }
.button-reset { appearance: none; }
.main-area { min-width: 0; }
.topbar { height: 62px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 14px; padding: 0 28px; position: sticky; top: 0; z-index: 10; }
.topbar-title { font-size: 18px; font-weight: 700; }
.user-chip { margin-left: auto; display: flex; align-items: center; gap: 7px; color: var(--muted); }
.content { padding: 24px 28px 48px; max-width: 1600px; margin: 0 auto; }
.mobile-menu { display: none !important; }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric-card { min-height: 112px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr; gap: 8px; }
.metric-card > span { color: var(--muted); }
.metric-card > strong { font-size: 27px; align-self: end; }
.metric-card > svg { grid-row: 1 / 3; grid-column: 2; width: 24px; height: 24px; color: var(--primary); }
.metric-card:hover { border-color: #a9cdbb; }

.section-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 18px; }
.section-heading { min-height: 58px; padding: 13px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-heading h2 { margin: 0; font-size: 16px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); }
.section-copy { margin: 18px; color: var(--muted); }
.preview-name { margin: 18px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 5px; background: #f7faf8; font-weight: 650; overflow-wrap: anywhere; word-break: break-word; }
.form-section { padding-bottom: 18px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th { padding: 11px 14px; font-size: 12px; font-weight: 650; color: var(--muted); background: #f8fafb; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
td { padding: 12px 14px; border-bottom: 1px solid #edf0f2; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfb; }
td small { display: block; color: var(--muted); margin-top: 4px; }
.clickable { cursor: pointer; }
.product-row-link { color: inherit; text-decoration: none; }
.product-row-link:hover { color: var(--primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.product-row-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 2px; }
.numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty-cell { text-align: center; padding: 34px; color: var(--muted); }
.empty-state { display: grid; justify-items: center; gap: 8px; padding: 34px 24px 38px; color: var(--muted); text-align: center; }
.empty-state svg { width: 24px; height: 24px; color: var(--primary); }
.empty-state h3 { margin: 2px 0 0; color: var(--text); font-size: 17px; }
.empty-state p { max-width: 560px; margin: 0; line-height: 1.45; }
.actions { width: 54px; text-align: right; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar select { width: auto; min-width: 160px; }
.search-field { position: relative; flex: 1; min-width: 220px; }
.search-field svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-field input { padding-left: 39px; }
.result-summary { margin: 0 0 9px; color: var(--muted); }
.title-rules-table { min-width: 1120px; }
.title-rules-table td { vertical-align: top; }
.title-rules-table td:nth-child(1) { min-width: 230px; }
.title-rules-table td:nth-child(2) { min-width: 315px; }
.title-rules-table td:nth-child(3) { min-width: 285px; }
.title-singular-control { display: grid; grid-template-columns: 118px minmax(190px, 1fr); gap: 7px; }
.title-singular-control input, .title-singular-control select { min-height: 36px; padding: 6px 8px; }
.bulk-toolbar { min-height: 52px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 7px 10px; background: #fff; border: 1px solid var(--border); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
.bulk-toolbar > span { margin-right: auto; color: var(--muted); }
.bulk-toolbar select { width: auto; min-width: 170px; }
.select-cell { width: 44px; text-align: center; }

input, select, textarea { width: 100%; min-height: 40px; border: 1px solid #cbd3da; border-radius: 5px; background: #fff; color: var(--text); padding: 8px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(24, 121, 78, .11); }
input:disabled { background: #f3f5f6; color: #68737c; }
input[type="checkbox"] { width: 17px; min-height: 17px; accent-color: var(--primary); }
input[type="file"] { padding: 6px; }
label { display: grid; gap: 7px; color: #3e4952; font-weight: 600; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.stack-form { display: grid; gap: 15px; padding: 18px; }
.inline-form { display: flex; gap: 12px; align-items: end; }
.inline-form label { min-width: 220px; }
.compact-form { padding: 16px; }
.form-grid { display: grid; gap: 16px; padding: 18px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.required { color: var(--danger); }
.split-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.page-actions { margin-bottom: 12px; }
.action-row, .inline-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.action-row form, .inline-actions form { margin: 0; }
.inline-upload input[type="file"] { display: none; }
.compact-number { width: 84px; min-width: 84px; }
.stock-grid { padding: 18px; display: grid; gap: 10px; }
.stock-grid label { grid-template-columns: minmax(220px, 1fr) 180px; align-items: center; border-bottom: 1px solid #edf0f2; padding-bottom: 10px; }
.stock-grid label:last-child { border-bottom: 0; }
.stock-grid small { display: block; color: var(--muted); margin-top: 3px; font-weight: 400; }
.availability-grid { padding: 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.availability-item { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.availability-item span { color: var(--muted); }
.availability-item .available { color: var(--primary); }
.availability-item .on-order { color: var(--warning); }
.order-form { width: 90px; }
.order-form input { min-height: 36px; }
.action-group { display: flex; justify-content: flex-end; gap: 6px; }
.action-group form { display: contents; }
.pricing-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.weekday-field { grid-column: 1 / -1; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.weekday-field legend { padding: 0 5px; color: #3e4952; font-weight: 600; }
.weekday-field > div { display: flex; flex-wrap: wrap; gap: 14px; }
.rule-active { align-self: center; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.danger-button { color: var(--danger); }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; display: flex; justify-content: flex-end; background: linear-gradient(to top, var(--bg) 78%, transparent); }

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 5px; padding: 8px 14px; font-weight: 650; white-space: nowrap; }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { background: #fff; border-color: #c9d1d8; color: #34414b; }
.button.secondary:hover, .button.ghost:hover { background: #f1f4f5; }
.button.ghost { background: transparent; color: #46535d; }
.button.small { min-height: 34px; padding: 5px 10px; font-size: 13px; }
.button.full { width: 100%; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid #d4dae0; border-radius: 5px; color: #46535d; background: #fff; padding: 0; }
.icon-button:hover { background: #f0f3f4; }

.status { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; white-space: nowrap; background: #eef1f3; color: #56636d; }
.status-success { background: #e7f6ee; color: #176a45; }
.status-partial, .status-warning { background: #fff4d6; color: var(--warning); }
.status-source_unavailable { background: #fff4d6; color: var(--warning); }
.status-failed, .status-danger { background: #feeceb; color: var(--danger); }
.status-running { background: #e8f1fb; color: #175f9e; }
.status-duplicate { background: #eef1f3; color: #56636d; }
.status-muted { background: #eef1f3; color: #69757e; }

.alert { padding: 11px 14px; border-radius: 5px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: #eaf8f0; border-color: #b8dfc9; color: #176a45; }
.alert-warning { background: #fff7df; border-color: #ead59d; color: #765100; }
.alert-danger { background: #fff0ef; border-color: #efc1bd; color: #8e1d16; }
.detail-list { padding: 8px 18px; display: grid; grid-template-columns: repeat(3, 1fr); }
.detail-list > div { padding: 13px 0; display: grid; gap: 5px; border-bottom: 1px solid #edf0f2; }
.detail-list span { color: var(--muted); }
.detail-list .wide { grid-column: 1 / -1; }
.job-metrics .metric-card { min-height: 94px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 16px; color: var(--muted); }
.pagination a { width: 36px; height: 36px; display: grid; place-items: center; background: #fff; border: 1px solid var(--border); border-radius: 5px; }
.product-pagination { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 16px; color: var(--muted); }
.page-links { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 4px; }
.pagination-button, .page-link { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid var(--border); border-radius: 5px; background: #fff; color: #46535d; font-variant-numeric: tabular-nums; }
.pagination-button:hover, .page-link:hover { background: #f1f4f5; color: var(--text); }
.page-link.is-current { border-color: var(--primary); background: var(--primary); color: #fff; font-weight: 700; }
.page-link.is-current:hover { background: var(--primary-hover); color: #fff; }
.page-ellipsis { width: 22px; text-align: center; color: var(--muted); font-weight: 700; }
.page-count { padding: 0 5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.page-jump { display: flex; align-items: end; gap: 6px; }
.page-jump label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.page-jump input { width: 68px; min-height: 36px; padding: 5px 7px; text-align: center; }
.page-jump .icon-button { width: 36px; height: 36px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.switch { display: flex; align-items: center; gap: 8px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 38px; height: 22px; border-radius: 11px; background: #b8c1c8; position: relative; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; top: 3px; left: 3px; background: #fff; border-radius: 50%; transition: transform .15s ease; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(16px); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #edf1f3; }
.login-panel { width: min(390px, 100%); background: #fff; border: 1px solid var(--border); border-radius: 7px; box-shadow: 0 16px 40px rgba(23, 32, 42, .08); padding: 26px; }
.login-panel h1 { margin: 28px 18px 0; font-size: 23px; }
.login-brand { display: flex; align-items: center; gap: 10px; }
.error-state { text-align: center; padding: 80px 20px; }
.error-state > strong { font-size: 64px; color: #aeb8bf; }
.error-state h1 { margin: 8px 0 24px; }
.source-list { display: grid; }
.source-row { min-height: 62px; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--border); }
.source-row:first-child { border-top: 0; }
.source-row div { display: grid; gap: 3px; }
.source-row span { color: var(--muted); font-size: 13px; }
.supplier-export-form { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; min-width: 360px; }
.supplier-export-form > label { font-size: 12px; }
.supplier-export-form input[type="number"] { width: 76px; min-height: 36px; }
.api-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 0 18px; }
.category-map-form { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(110px, .6fr) 36px; gap: 7px; align-items: center; min-width: 460px; }
.product-media-grid { padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.product-media-item { aspect-ratio: 1; border: 1px solid var(--border); border-radius: 5px; display: grid; place-items: center; overflow: hidden; position: relative; background: #fff; }
.product-media-item img { width: 100%; height: 100%; object-fit: contain; }
.product-media-item small { position: absolute; left: 5px; bottom: 5px; background: rgba(255,255,255,.9); padding: 2px 4px; border-radius: 3px; }
.attribute-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 8px 16px 16px; }
.attribute-list > div { padding: 10px 0; display: grid; gap: 4px; border-bottom: 1px solid var(--border); }
.attribute-list span { color: var(--muted); }
.attribute-list strong { font-weight: 600; overflow-wrap: anywhere; }
.matching-metrics { margin-bottom: 18px; }
.matches-table { min-width: 980px; }
.matches-table td { vertical-align: top; }
.matches-table td:first-child { width: 28%; }
.matches-table td:nth-child(2) { width: 140px; }
.matches-table td:last-child { width: 170px; }
.matches-table td > small, .match-target + small { display: block; margin-top: 5px; color: var(--muted); overflow-wrap: anywhere; }
.match-target { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.candidate-list { display: grid; gap: 8px; margin-top: 8px; }
.candidate-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 9px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.candidate-row > div { display: grid; gap: 3px; }
.candidate-row span, .candidate-row small { color: var(--muted); overflow-wrap: anywhere; }
.phase-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 12px; margin: 0 0 18px; }
.phase-card { display: grid; gap: 10px; padding: 14px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.phase-card.selected { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.phase-card > div, .phase-actions { display: flex; align-items: center; gap: 8px; }
.phase-card > div strong { margin-right: auto; }
.phase-card small { color: var(--muted); line-height: 1.4; }
.phase-actions select { min-width: 0; flex: 1; }
.inline-heading { align-items: center; gap: 16px; }
.condition-variants-callout { background: #f7fbf9; }
.variant-list, .condition-builder { display: grid; gap: 12px; }
.title-variant-card, .condition-row { border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.title-variant-card { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 16px; }
.title-variant-card.is-disabled { opacity: .65; background: #fafafa; }
.title-variant-main { min-width: 0; }
.title-variant-heading, .variant-actions, .condition-row-heading, .condition-summary { display: flex; align-items: center; gap: 8px; }
.title-variant-heading { align-items: flex-start; }
.title-variant-heading h3, .condition-row-heading strong { margin: 0; }
.title-variant-heading p { margin: 4px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.priority-chip { display: inline-flex; flex: 0 0 24px; width: 24px; height: 24px; align-items: center; justify-content: center; border-radius: 50%; background: #eaf6ef; color: var(--success); font-size: 12px; font-weight: 700; }
.condition-summary { flex-wrap: wrap; margin-top: 12px; }
.condition-summary span { padding: 4px 8px; border-radius: 4px; background: #f1f5f7; color: #435162; font-size: 13px; }
.variant-preview { display: grid; gap: 3px; margin-top: 10px; padding: 10px 12px; border-left: 3px solid var(--primary); background: #f7fbf9; overflow-wrap: anywhere; }
.variant-preview span { color: var(--muted); font-size: 12px; }
.variant-actions { flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.variant-actions form { margin: 0; }
.condition-row { padding: 14px; }
.condition-row-heading { justify-content: space-between; margin-bottom: 12px; }
.compact-grid { gap: 12px; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -240px; width: 224px; transition: left .2s ease; box-shadow: 8px 0 30px rgba(0,0,0,.18); }
  .sidebar.open { left: 0; }
  .mobile-menu { display: inline-grid !important; }
  .metric-grid { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .split-layout { grid-template-columns: 1fr; }
  .pricing-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { flex-wrap: wrap; }
  .search-field { flex-basis: 100%; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 14px; }
  .content { padding: 16px 12px 40px; }
  .user-chip { font-size: 0; }
  .metric-grid { gap: 10px; }
  .metric-card { min-height: 96px; padding: 14px; }
  .metric-card > strong { font-size: 23px; }
  .form-grid.two, .detail-list { grid-template-columns: 1fr; }
  .pricing-form { grid-template-columns: 1fr; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form label { min-width: 0; }
  .stock-grid label { grid-template-columns: 1fr; }
  .toolbar select, .toolbar .button { flex: 1; }
  .products-table { table-layout: fixed; min-width: 0; }
  .products-table th:nth-child(4), .products-table td:nth-child(4),
  .products-table th:nth-child(6), .products-table td:nth-child(6),
  .products-table th:nth-child(7), .products-table td:nth-child(7),
  .products-table th:nth-child(8), .products-table td:nth-child(8),
  .products-table th:nth-child(10), .products-table td:nth-child(10),
  .products-table th:nth-child(11), .products-table td:nth-child(11) { display: none; }
  .products-table th:nth-child(1), .products-table td:nth-child(1) { width: 42px; }
  .products-table th:nth-child(2), .products-table td:nth-child(2) { width: 100px; }
  .products-table th:nth-child(5), .products-table td:nth-child(5) { width: 62px; }
  .products-table th:nth-child(9), .products-table td:nth-child(9) { width: 72px; }
  .products-table td { overflow-wrap: anywhere; }
  .bulk-toolbar { flex-wrap: wrap; }
  .bulk-toolbar > span { flex-basis: 100%; }
  .product-pagination { justify-content: flex-start; }
  .page-links { justify-content: flex-start; }
  .page-count { display: none; }
  .attribute-list { grid-template-columns: 1fr; }
  .inline-heading, .title-variant-card { align-items: stretch; flex-direction: column; }
  .variant-actions { justify-content: flex-start; }
}
