:root {
  --ink: #1d211d;
  --muted: #6e726b;
  --paper: #f5f2eb;
  --panel: #fffdf8;
  --line: #ddd9d0;
  --lime: #d8f66c;
  --lime-dark: #617416;
  --red: #c74834;
  --red-bg: #fbe8e2;
  --amber: #ae6d19;
  --amber-bg: #fff0cf;
  --green: #357b55;
  --green-bg: #e3f2e8;
  --shadow: 0 18px 50px rgba(39, 39, 31, .07);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(97,116,22,.35); outline-offset: 2px; }

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template: 76px 1fr / 236px 1fr;
  grid-template-areas: "top top" "side main";
}

.topbar {
  grid-area: top;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(245,242,235,.92);
  backdrop-filter: blur(14px);
}

.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px; background: var(--ink); color: var(--lime); font: 800 25px/1 Georgia, serif; }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: -.04em; font-size: 18px; }
.brand small { color: var(--muted); margin-top: 2px; font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.cabinet-picker { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.cabinet-picker select, .filters select { border: 1px solid var(--line); color: var(--ink); background: var(--panel); border-radius: 11px; padding: 10px 34px 10px 12px; }
.safe-badge { display: flex; align-items: center; gap: 7px; background: var(--green-bg); color: var(--green); padding: 10px 12px; border-radius: 11px; font-size: 12px; font-weight: 700; }
.safe-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

.sidebar { grid-area: side; position: sticky; top: 76px; height: calc(100vh - 76px); display: flex; flex-direction: column; justify-content: space-between; padding: 24px 16px; border-right: 1px solid var(--line); }
.sidebar nav { display: grid; gap: 6px; }
.nav-item { width: 100%; border: 0; background: transparent; color: var(--muted); border-radius: 12px; padding: 12px; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; text-align: left; }
.nav-item span { font-size: 19px; line-height: 1; }
.nav-item b { font-size: 14px; font-weight: 650; }
.nav-item em { min-width: 24px; text-align: center; padding: 3px 6px; border-radius: 8px; background: rgba(29,33,29,.06); color: var(--muted); font: normal 700 10px/1 sans-serif; }
.nav-item:hover { background: rgba(255,255,255,.5); color: var(--ink); }
.nav-item.active { background: var(--ink); color: white; }
.nav-item.active span { color: var(--lime); }
.nav-item.active em { background: var(--lime); color: var(--ink); }
.sidebar-note { padding: 14px; border-radius: 14px; background: #eae6dc; }
.sidebar-note span, .sidebar-note small { display: block; }
.sidebar-note span { font-size: 12px; font-weight: 750; }
.sidebar-note small { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.4; }

main { grid-area: main; min-width: 0; padding: 38px clamp(24px, 4vw, 64px) 64px; }
main:focus { outline: none; }
.page { display: none; max-width: 1220px; margin: 0 auto; animation: appear .2s ease-out; }
.page.active { display: block; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 8px; color: var(--lime-dark); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(32px, 4vw, 50px); line-height: .98; letter-spacing: -.05em; }
h2 { margin-bottom: 0; font-size: 19px; letter-spacing: -.025em; }
.subtitle { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.period-switch { display: flex; gap: 3px; padding: 4px; border: 1px solid var(--line); background: #ebe7de; border-radius: 13px; }
.period-switch button { border: 0; background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 9px; font-size: 12px; font-weight: 700; }
.period-switch button.active { background: var(--panel); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.05); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { min-height: 142px; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { display: block; margin-top: 20px; font-size: clamp(27px, 3vw, 38px); line-height: 1; letter-spacing: -.05em; }
.stat-foot { display: block; margin-top: 10px; color: var(--muted); font-size: 11px; }
.stat.danger .stat-value { color: var(--red); }
.stat.good .stat-value { color: var(--green); }
.skeleton { background: linear-gradient(100deg,#fffdf8 30%,#eeebe3 48%,#fffdf8 66%); background-size: 300% 100%; animation: shine 1.4s infinite; }
@keyframes shine { to { background-position: -180% 0; } }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .8fr); gap: 16px; }
.panel { border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; padding: 20px 20px 14px; }
.panel-head .eyebrow { margin-bottom: 5px; }
.text-button, .quiet-button { border: 0; border-radius: 10px; background: transparent; color: var(--lime-dark); padding: 8px 9px; font-size: 12px; font-weight: 750; }
.text-button:hover, .quiet-button:hover { background: rgba(216,246,108,.35); }
.attention-list { padding: 0 10px 10px; }
.attention-item { display: grid; grid-template-columns: 32px minmax(0,1fr) auto; gap: 11px; align-items: center; padding: 11px 10px; border-top: 1px solid #ece8df; }
.plain-row { width: 100%; border-right: 0; border-bottom: 0; border-left: 0; background: transparent; color: inherit; text-align: left; }
.plain-row:hover { background: #faf8f2; }
.signal-dot { width: 8px; height: 8px; margin-left: 9px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 5px var(--amber-bg); }
.signal-dot.loss { background: var(--red); box-shadow: 0 0 0 5px var(--red-bg); }
.attention-item strong, .attention-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-item strong { font-size: 13px; }
.attention-item small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.attention-value { text-align: right; font-size: 12px; font-weight: 750; }
.empty-inline { padding: 34px 20px 42px; color: var(--muted); text-align: center; }

.system-status { padding: 0 20px 13px; }
.status-row { display: grid; grid-template-columns: 12px 1fr; gap: 11px; padding: 14px 0; border-top: 1px solid #ece8df; }
.status-light { width: 9px; height: 9px; margin-top: 3px; border-radius: 50%; background: #aaa; }
.status-light.on { background: var(--green); box-shadow: 0 0 0 4px var(--green-bg); }
.status-row strong, .status-row small { display: block; }
.status-row strong { font-size: 12px; }
.status-row small { margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.periods-panel { margin-top: 16px; }
.period-cards { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; padding: 0 20px 20px; }
.period-card { padding: 14px; border-radius: 13px; background: #f1eee7; }
.period-card span, .period-card strong, .period-card small { display: block; }
.period-card span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.period-card strong { margin-top: 7px; font-size: 13px; }
.period-card small { margin-top: 4px; color: var(--muted); font-size: 10px; }

.products-head { align-items: center; }
.quiet-button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
.filters { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.search-box { flex: 1; display: flex; align-items: center; gap: 8px; max-width: 420px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.search-box span { color: var(--muted); font-size: 18px; }
.result-count { margin-left: auto; color: var(--muted); font-size: 11px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th { padding: 13px 16px; background: #eeebe4; color: var(--muted); text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
td { padding: 15px 16px; border-top: 1px solid #ece8df; font-size: 12px; vertical-align: middle; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: #faf8f2; }
.product-name { max-width: 380px; }
.product-name strong, .product-name small { display: block; }
.product-name strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-name small { margin-top: 4px; color: var(--muted); }
.money.loss { color: var(--red); font-weight: 750; }
.tag { display: inline-block; padding: 5px 8px; border-radius: 8px; background: #eeece6; color: var(--muted); font-size: 10px; font-weight: 750; }
.tag.loss { color: var(--red); background: var(--red-bg); }
.tag.drop { color: var(--amber); background: var(--amber-bg); }
.row-button { border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.empty-state { padding: 70px 20px; text-align: center; color: var(--muted); }
.empty-state span { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--green-bg); color: var(--green); }
.empty-state h2 { margin: 14px 0 6px; color: var(--ink); }

.queue-summary, .pricing-summary { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-bottom: 16px; }
.queue-card, .price-card { min-height: 168px; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.queue-card span, .price-card span { color: var(--muted); font-size: 11px; }
.queue-card strong, .price-card strong { display: block; margin-top: 25px; font-size: 36px; letter-spacing: -.05em; }
.queue-card small, .price-card small { display: block; margin-top: 10px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.explainer, .coming-panel { display: flex; align-items: center; gap: 17px; padding: 22px; }
.explainer-icon { display: grid; place-items: center; flex: 0 0 44px; height: 44px; border-radius: 50%; background: var(--lime); font-weight: 850; }
.explainer h2, .coming-panel h2 { margin-bottom: 5px; }
.explainer p, .coming-panel p { margin-bottom: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.coming-mark { align-self: stretch; display: grid; place-items: center; min-width: 80px; border-radius: 13px; background: var(--ink); color: var(--lime); font-size: 25px; font-weight: 850; }

dialog { width: min(620px, calc(100vw - 28px)); border: 0; border-radius: 22px; padding: 0; background: var(--panel); color: var(--ink); box-shadow: 0 30px 90px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(24,27,24,.55); backdrop-filter: blur(3px); }
.dialog-close { position: absolute; top: 14px; right: 14px; z-index: 1; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--ink); font-size: 22px; }
.product-detail { padding: 30px; }
.product-detail h2 { max-width: 500px; margin: 8px 44px 7px 0; font-size: 25px; }
.detail-article { color: var(--muted); font-size: 11px; }
.detail-signal { margin: 22px 0; padding: 16px; border-radius: 13px; background: var(--amber-bg); }
.detail-signal.loss { background: var(--red-bg); }
.detail-signal strong, .detail-signal span { display: block; }
.detail-signal span { margin-top: 5px; font-size: 12px; line-height: 1.5; }
.detail-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; }
.detail-grid div { padding: 12px; border-radius: 11px; background: #f1eee7; }
.detail-grid span, .detail-grid strong { display: block; }
.detail-grid span { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.detail-grid strong { margin-top: 6px; font-size: 14px; }
.todo { margin: 22px 0 0; padding-left: 20px; }
.todo li { margin: 7px 0; font-size: 12px; line-height: 1.45; }
.error-banner { position: fixed; z-index: 50; right: 20px; bottom: 20px; max-width: 420px; padding: 14px 18px; border-radius: 12px; background: #582117; color: white; box-shadow: var(--shadow); font-size: 12px; }
.error-banner.success { background: #285d40; }
.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; }

@media (max-width: 920px) {
  .app-shell { grid-template: 68px 1fr 68px / 1fr; grid-template-areas: "top" "main" "side"; }
  .topbar { padding: 0 18px; }
  .sidebar { position: fixed; z-index: 30; top: auto; bottom: 0; left: 0; right: 0; height: 68px; padding: 7px 10px max(7px, env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--line); background: rgba(245,242,235,.96); backdrop-filter: blur(14px); }
  .sidebar nav { grid-template-columns: repeat(4, 1fr); gap: 3px; }
  .nav-item { display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 7px 3px; text-align: center; }
  .nav-item span { font-size: 17px; }
  .nav-item b { font-size: 9px; }
  .nav-item em, .sidebar-note { display: none; }
  main { padding: 28px 20px 48px; }
  .overview-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .brand small, .cabinet-picker > span, .safe-badge { display: none; }
  .cabinet-picker select { max-width: 155px; }
  .page-head { display: block; }
  .page-head .period-switch { width: 100%; margin-top: 20px; }
  .period-switch button { flex: 1; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { min-height: 116px; padding: 16px; }
  .stat-value { margin-top: 15px; }
  .period-cards, .queue-summary, .pricing-summary { grid-template-columns: 1fr; }
  .filters { flex-wrap: wrap; }
  .search-box { flex-basis: 100%; max-width: none; }
  .result-count { margin-left: 0; }
  .products-head .quiet-button { margin-top: 18px; }
  .detail-grid { grid-template-columns: repeat(2,1fr); }
  .coming-panel { align-items: stretch; }
  .coming-mark { min-width: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

/* Дела: очередь предложений и лента решённого. */
.todo-heading { font-size: 15px; margin: 18px 0 10px; color: var(--muted, #6b7280); }
.todo-card { padding: 16px 18px; margin-bottom: 10px; }
.todo-card.done { opacity: .68; }
.todo-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.todo-card p { margin: 10px 0 0; }
.todo-change { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.todo-change span { font-variant-numeric: tabular-nums; }
.todo-open { display: block; margin-top: 13px; }

dialog.todo-dialog { width: min(1060px, calc(100vw - 28px)); max-height: calc(100vh - 28px); overflow: auto; }
.todo-presentation { padding: clamp(24px, 4vw, 48px); }
.todo-presentation > h2 { max-width: 800px; margin: 6px 48px 10px 0; font-size: clamp(25px, 4vw, 42px); line-height: 1.06; letter-spacing: -.04em; }
.todo-conclusion { max-width: 780px; margin: 0 0 30px; color: var(--muted); font-size: 15px; line-height: 1.55; }
.comparison-section, .reason-section, .source-section { margin-top: 30px; }
.comparison-section h3, .reason-section h3, .source-section h3 { margin: 0 0 12px; font-size: 15px; }
.comparison-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.comparison-grid article { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: #faf8f2; }
.comparison-grid article > span { color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.comparison-grid p { margin: 12px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.65; }
.description-compare p { max-height: 440px; overflow: auto; padding-right: 5px; }
.comparison-grid del { background: #f8dcd5; color: #8c2f20; text-decoration-thickness: 1px; }
.comparison-grid ins { background: #e1f1ba; color: #334308; text-decoration: none; }
.reason-section ul, .source-section ul { margin: 0; padding-left: 20px; }
.reason-section li, .source-section li { margin: 9px 0; line-height: 1.5; }
.source-section li span { display: block; margin-top: 4px; font-size: 12px; }
.source-section a { color: var(--lime-dark); font-weight: 700; }
.keyword-list { display: flex; flex-wrap: wrap; gap: 7px; }
.keyword-list span { padding: 6px 9px; border-radius: 999px; background: #eeeadf; font-size: 11px; }
.decision-actions { position: sticky; bottom: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 34px -12px 0; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,253,248,.94); backdrop-filter: blur(12px); }
.decision-actions button { min-height: 48px; border-radius: 12px; font-weight: 800; }
.decision-actions button:disabled { cursor: wait; opacity: .55; }
.decision-apply { border: 0; background: var(--ink); color: white; }
.decision-reject { border: 1px solid var(--line); background: var(--panel); color: var(--red); }
.decision-note, .decision-result { color: var(--muted); font-size: 11px; text-align: center; }
.decision-result { margin-top: 30px; padding: 16px; border-radius: 13px; background: var(--green-bg); color: var(--green); font-weight: 700; }

@media (max-width: 700px) {
  .comparison-grid { grid-template-columns: 1fr; }
  .description-compare p { max-height: none; }
  .decision-actions { grid-template-columns: 1fr; }
}
