:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --text: #1e1c19;
  --muted: #77716a;
  --border: #e6e0d9;
  --brand: #24211d;
  --brand-soft: #ece7e1;
  --accent: #9b7653;
  --success: #16794b;
  --warning: #a86808;
  --danger: #b53a3a;
  --info: #3667a6;
  --shadow-sm: 0 1px 2px rgba(31, 28, 24, .06);
  --shadow-md: 0 14px 34px rgba(31, 28, 24, .09);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --sidebar: 260px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
aside { position: sticky; top: 0; height: 100vh; padding: 24px 18px; background: #1e1b18; color: #fff; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(145deg,#c3a17f,#8f6a49); font-weight: 800; }
.brand b, .brand small { display: block; }
.brand small { margin-top: 2px; color: rgba(255,255,255,.58); }
nav { display: grid; gap: 8px; }
nav button { width: 100%; min-height: 44px; padding: 0 14px; border: 0; border-radius: 12px; background: transparent; color: rgba(255,255,255,.68); text-align: left; transition: .2s ease; }
nav button:hover { background: rgba(255,255,255,.07); color: #fff; }
nav button.active { background: #fff; color: #201d1a; font-weight: 700; box-shadow: var(--shadow-sm); }
.aside-foot { margin-top: auto; display: flex; gap: 9px; align-items: center; padding: 14px 10px 0; color: rgba(255,255,255,.65); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #57b77f; box-shadow: 0 0 0 4px rgba(87,183,127,.13); }
.dot.demo { background: #d3a851; box-shadow: 0 0 0 4px rgba(211,168,81,.13); }

main { min-width: 0; padding: 28px 34px 50px; }
header { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 26px; }
h1 { margin: 4px 0 0; font-size: clamp(26px, 3vw, 38px); line-height: 1.1; letter-spacing: -.035em; }
h2 { margin: 0; font-size: 21px; }
p { line-height: 1.55; }
.eyebrow { margin: 0; font-size: 11px; font-weight: 800; letter-spacing: .16em; color: var(--accent); }
.header-actions, .setting-actions, .panel-head { display: flex; align-items: center; gap: 10px; }

button.primary, button.ghost { min-height: 42px; border-radius: 12px; padding: 0 15px; font-weight: 700; border: 1px solid transparent; transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
button.primary { background: var(--brand); color: #fff; box-shadow: 0 8px 18px rgba(36,33,29,.14); }
button.primary:hover { transform: translateY(-1px); box-shadow: 0 12px 22px rgba(36,33,29,.18); }
button.ghost { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-sm); }
button.ghost:hover { background: var(--surface-2); }
button.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
button.wide { width: 100%; }

.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: .4; transform: translateY(3px); } }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stats article, .panel, .table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.stats article { padding: 18px; }
.stats span { display: block; color: var(--muted); font-size: 13px; }
.stats strong { display: block; margin-top: 7px; font-size: 28px; letter-spacing: -.04em; }

.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 180px auto auto auto; gap: 10px; margin-bottom: 14px; }
.search input, select, .settings input { width: 100%; min-height: 42px; border: 1px solid var(--border); border-radius: 12px; padding: 0 13px; background: var(--surface); color: var(--text); outline: none; }
input:focus, select:focus { border-color: #b59a81; box-shadow: 0 0 0 4px rgba(181,154,129,.14); }

.table-card { overflow: hidden; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1180px; }
th { position: sticky; top: 0; z-index: 1; padding: 13px 12px; background: #f4f0eb; color: #625b54; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; text-align: left; border-bottom: 1px solid var(--border); }
td { padding: 11px 12px; border-bottom: 1px solid #eee9e3; vertical-align: middle; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #fcfaf7; }
tbody tr.is-dirty { background: #fff9ed; }
td input, td select { width: 100%; min-width: 82px; min-height: 36px; border: 1px solid transparent; border-radius: 9px; padding: 0 9px; background: transparent; }
td input:hover, td select:hover { border-color: var(--border); background: #fff; }
td input:focus, td select:focus { background: #fff; }
.product-cell { min-width: 210px; }
.product-name { font-weight: 700; }
.product-meta { margin-top: 3px; color: var(--muted); font-size: 12px; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.success { color: var(--success); background: #eaf7f0; }
.badge.warning { color: var(--warning); background: #fff2da; }
.badge.neutral { color: #67615a; background: #efebe6; }
.switch { position: relative; width: 42px; height: 24px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #d4cec7; transition: .2s; }
.switch span:before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.18); transition: .2s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span:before { transform: translateX(18px); }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }

.sync-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.panel { padding: 22px; }
.panel p:not(.eyebrow) { color: var(--muted); }
.log-panel { min-height: 270px; }
.panel-head { justify-content: space-between; }
.log { margin-top: 16px; display: grid; gap: 8px; font-size: 13px; }
.log-entry { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.settings { max-width: 690px; }
.settings label { display: grid; gap: 7px; margin-top: 16px; font-size: 13px; font-weight: 700; }
.setting-actions { margin-top: 18px; }
.hint { font-size: 13px; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: 360px; padding: 13px 16px; border-radius: 12px; background: #201d1a; color: #fff; box-shadow: var(--shadow-md); opacity: 0; pointer-events: none; transform: translateY(12px); transition: .2s ease; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 1100px) {
  .toolbar { grid-template-columns: 1fr 180px auto; }
  .toolbar button:nth-of-type(3), .toolbar button:nth-of-type(4) { grid-column: auto; }
}
@media (max-width: 840px) {
  .app-shell { grid-template-columns: 1fr; }
  aside { position: static; height: auto; padding: 14px; flex-direction: row; align-items: center; gap: 12px; overflow-x: auto; }
  .brand { padding: 0; min-width: max-content; }
  .brand small, .aside-foot { display: none; }
  nav { display: flex; margin-left: auto; }
  nav button { width: auto; min-width: max-content; }
  main { padding: 22px 18px 40px; }
  header { align-items: flex-start; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .search { grid-column: 1 / -1; }
  .sync-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  header { flex-direction: column; }
  .header-actions { width: 100%; }
  .header-actions button { flex: 1; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stats article { padding: 15px; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar .search { grid-column: auto; }
  .setting-actions { flex-direction: column-reverse; align-items: stretch; }
}
