:root {
  font: 16px/1.5 system-ui, sans-serif;
  color: #202c25;
  background: #f4f3ec;
  color-scheme: light;
  --ink: #203d30;
  --muted: #526357;
  --line: #d8dfd5;
  --paper: #fffef9;
  --accent: #2c5743;
  --shadow: 0 10px 24px #203d300c;
}
body { margin: 0; }
.login-panel { max-width: 34rem; margin: 2rem auto; }
.login-panel h2 { margin: .25rem 0; font-size: clamp(1.7rem, 5vw, 2.3rem); letter-spacing: -.035em; }
.eyebrow { color: var(--muted); text-transform: uppercase; font-size: .75rem; letter-spacing: .12em; }
.button-link { display: inline-flex; padding: .55rem .8rem; border-radius: .68rem; background: var(--accent); color: white; text-decoration: none; font-weight: 650; }
#bot-login-code input { width: 8rem; letter-spacing: .25em; font-size: 1.3rem; }
#bot-login-code .controls { margin-top: .8rem; }
[hidden] { display: none !important; }
.subnav { display: flex; flex-wrap: wrap; gap: .45rem; margin: .75rem 0 1rem; }
.subnav button { color: var(--ink); background: var(--paper); border: 1px solid var(--line); }
.subnav button[aria-pressed="true"], .subnav button:hover:not(:disabled) { color: white; background: var(--accent); }
#segment-fields { grid-column: 1 / -1; min-width: 0; border: 1px solid var(--line); border-radius: .7rem; }
#leads, #customers, #inventory { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); gap: .65rem; align-items: start; }
#leads .lead, #customers .lead { min-width: 0; }
.lead summary { cursor: pointer; font-weight: 650; color: var(--ink); overflow-wrap: anywhere; }
.lead summary small { display: block; font-weight: 400; color: var(--muted); }
.photo-field, #product-content label, #new-product > label, #content-fields > label { display: grid; gap: .4rem; margin-block: .7rem; }
.photo-field input, #product-content select, #product-content textarea, #new-product textarea { width: 100%; max-width: 100%; min-width: 0; }
.photo-grid { display: flex; gap: .5rem; flex-wrap: wrap; align-items: start; }
.photo-grid figure { margin: 0; display: grid; gap: .2rem; width: 7rem; }
.photo-grid img { width: 7rem; height: 7rem; object-fit: contain; border-radius: .5rem; background: #eff2eb; }
.photo-grid button { min-height: 2rem; font-size: .8rem; padding: .2rem; }
#channel-materials { margin-bottom: .8rem; }
.exchange-options { border-top: 1px solid var(--line); padding-block: .7rem; }
.exchange-options summary { cursor: pointer; color: var(--ink); font-weight: 650; }
#product-content .exchange-options label:has(input[type=checkbox]) { display: flex; align-items: center; gap: .6rem; }
#product-content .exchange-options input[type=checkbox] { width: 1.15rem; min-height: auto; accent-color: var(--accent); }
#tilda-editor, #tilda-storefront { color: var(--accent); text-underline-offset: .2rem; }
#exchange-state { font-weight: 600; }
.invoice-line { margin: .5rem 0; }
.invoice-line select { max-width: 100%; }
main { max-width: 72rem; margin: auto; padding: clamp(1rem, 3vw, 2.25rem) clamp(.85rem, 3vw, 1.75rem) 5.5rem; }
.app-header {
  color: #fffef7; background: linear-gradient(124deg, #172e23, #2e5945);
  border-radius: 1.35rem; padding: clamp(1.4rem, 5vw, 3.2rem);
  margin-bottom: 1.15rem; box-shadow: 0 12px 34px #182d2225;
}
.app-header p { margin: .35rem 0 0; color: #e0eadf; }
.app-header .brand, .eyebrow { font-size: .75rem; letter-spacing: .15em; text-transform: uppercase; font-weight: 750; }
.app-header .brand { color: #efce92; }
h1 { margin: .18em 0 .18em; line-height: 1.08; font-size: clamp(2rem, 6vw, 3.45rem); letter-spacing: -.045em; }
h2 { margin: 0; font-size: 1.2rem; overflow-wrap: anywhere; }
.section-intro { margin: 1.55rem 0 1.15rem; }
.section-intro h2 { font-size: clamp(1.65rem, 5vw, 2.35rem); letter-spacing: -.035em; }
.section-intro p { margin: .2rem 0; color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; }
form .controls { margin-top: .4rem; }
.toolbar { margin-bottom: 1rem; }
nav.toolbar { padding: .55rem; background: var(--paper); border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); }
nav.toolbar #sign-out { margin-left: auto; }
input, select, textarea, button {
  font: inherit; border: 1px solid #aab9ac; border-radius: .68rem; padding: .53rem .76rem;
  box-sizing: border-box; min-height: 2.65rem;
}
input, select, textarea { color: inherit; background: #fff; }
input { min-width: 0; width: min(18rem, 100%); }
button {
  border-color: transparent; background: var(--accent); color: white; cursor: pointer;
  font-weight: 650; transition: background-color .15s, border-color .15s, box-shadow .15s;
}
button:hover:not(:disabled) { background: #224735; box-shadow: 0 4px 12px #203d3024; }
button.quiet, .toolbar button[aria-pressed="false"] { color: var(--ink); background: #f2f6ef; border-color: #d7e0d6; }
button.quiet:hover:not(:disabled), .toolbar button[aria-pressed="false"]:hover { background: #e4eee4; }
button:disabled { cursor: default; opacity: .58; }
:focus-visible { outline: 3px solid #a36c31; outline-offset: 2px; }
.lead, .panel, #sign-in {
  border: 1px solid var(--line); border-radius: 1rem; background: var(--paper);
  padding: clamp(.85rem, 2vw, 1.35rem); box-shadow: var(--shadow);
}
.lead { margin: 0 0 .75rem; }
.pulse { margin-bottom: 1rem; }
.pulse-heading { justify-content: space-between; }
.pulse-heading h2 { font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.035em; }
.pulse-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: .9rem 0 .45rem; gap: .65rem; }
.pulse-metrics div { padding: .75rem; border-radius: .7rem; background: #eff3ed; }
.pulse-metrics div:first-child { background: #e2ecdf; }
.pulse-metrics dt, #pulse-note { font-size: .84rem; color: var(--muted); }
.pulse-metrics dd { margin: 0; font-size: clamp(1.1rem, 2.4vw, 1.75rem); color: var(--ink); font-weight: 700; overflow-wrap: anywhere; }
#pulse-note { margin: .6rem 0 0; }
#pulse-dates input { width: auto; }
#pulse-daily { margin-top: 1.3rem; }
#pulse-daily h3 { margin: 0 0 .5rem; font-size: 1.05rem; }
.pulse-table-wrap { overflow-x: auto; }
.pulse-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.pulse-table th, .pulse-table td { padding: .5rem .55rem; text-align: right; border-bottom: 1px solid var(--line); }
.pulse-table th:first-child { text-align: left; }
.pulse-table thead { color: var(--muted); font-size: .84rem; }
.pulse-table tbody th, .pulse-table td { white-space: nowrap; font-weight: 500; }
.pulse-table td:nth-child(2) { font-weight: 700; }
.pulse-table meter { display: block; width: 100%; max-width: 8rem; margin: .17rem 0 0 auto; height: .32rem; border: 0; background: #e9eee7; border-radius: .3rem; }
.pulse-table meter::-webkit-meter-bar { background: #e9eee7; border: 0; }
.pulse-table meter::-webkit-meter-optimum-value { background: #538265; }
.pulse-table meter::-moz-meter-bar { background: #538265; }
#pulse-pages { justify-content: flex-end; margin-top: .7rem; }
#pulse-page-label { font-size: .85rem; color: var(--muted); }
@media (max-width: 32rem) {
  .pulse-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #pulse-period { gap: .3rem; }
  #pulse-period button { padding-inline: .55rem; }
  .pulse-table th, .pulse-table td { padding: .45rem .18rem; font-size: .78rem; }
}
#sign-in { max-width: 33rem; }
.lead p { margin: .35rem 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { color: var(--muted); }
.status-control { margin-top: .85rem; }
.order { margin-top: 1rem; padding-top: .85rem; border-top: 1px solid #d0d2c5; }
.order h3 { margin: 0 0 .35rem; font-size: 1rem; }
.order input { width: 9rem; }
.order-item { align-items: end; margin-bottom: .5rem; }
.order-item label { display: grid; gap: .2rem; }
.order-item select { max-width: min(18rem, 78vw); }
.order-item input[name="product_name"] { width: min(14rem, 100%); }
.order-item input[name="quantity"] { width: 5rem; }
.segments { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .75rem; align-items: end; margin-bottom: 1rem; }
.segments label { display: grid; gap: .2rem; }
.segments input { width: 100%; box-sizing: border-box; }
.segments select { width: 100%; min-width: 0; }
#receipt { grid-template-columns: repeat(auto-fit, minmax(min(13rem, 100%), 1fr)); }
#inventory { margin-top: .75rem; }
.marketing-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 1rem; align-items: start; }
.marketing-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.marketing-grid { margin-bottom: 1rem; }
.marketing-grid:has(#marketing-form[hidden]) { grid-template-columns: minmax(0, 1fr); }
#marketing-drafts .controls[hidden] { display: none; }
.marketing-grid h3 { margin: 0 0 .65rem; font-size: 1.15rem; }
#marketing-form label { display: grid; gap: .26rem; margin-bottom: .75rem; font-weight: 600; }
#marketing-form :is(input, select, textarea) { width: 100%; min-width: 0; font-weight: 400; }
#marketing-form textarea { resize: vertical; }
.queue-header { justify-content: space-between; margin-bottom: .7rem; }
.queue-header h3 { margin: 0; }
.marketing-card { border-top: 1px solid var(--line); padding: .8rem 0; }
.marketing-card-heading { justify-content: space-between; }
.marketing-card h4 { margin: 0; overflow-wrap: anywhere; }
.marketing-card > p, .marketing-card details { margin: .3rem 0 .55rem; }
.marketing-card summary { cursor: pointer; color: var(--accent); font-weight: 650; }
.draft-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.table-scroll { overflow: auto; max-height: 26rem; margin: .7rem 0; }
.table-scroll table { width: 100%; border-collapse: collapse; }
.table-scroll th, .table-scroll td { text-align: left; padding: .36rem; border-bottom: 1px solid var(--line); }
.table-scroll th { position: sticky; top: 0; background: white; }
.table-scroll input { width: 7rem; }
#inventory-view > .panel, #marketing-view > .panel { margin-bottom: .8rem; }
#agent-hub [hidden] { display: none !important; }
#agent-hub details, #agent-assignment, #agent-credential { margin-block: .8rem; }
#agent-hub summary { cursor: pointer; font-weight: 650; }
#agent-brief-fields, #agent-assignment > label, #agent-brief-fields label, #agent-credential label {
  display: grid; gap: .35rem; margin-block: .5rem;
}
#agent-assignment textarea { width: 100%; box-sizing: border-box; }
#agent-key { width: min(100%, 35rem); font-family: monospace; }
.badge { padding: .2rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: #e8ece7; }
.badge-review { color: #674112; background: #f6e6c6; }
.badge-approved { color: #21553d; background: #dcefe3; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#notice:not(:empty) {
  position: fixed; z-index: 2; inset: auto max(1rem, calc((100vw - 72rem) / 2)) .8rem auto;
  max-width: min(29rem, calc(100vw - 2rem)); margin: 0; padding: .66rem .95rem;
  color: #fff; background: var(--ink); border-radius: .7rem; box-shadow: 0 5px 24px #203d3033;
}
@media (max-width: 48rem) {
  .marketing-grid { grid-template-columns: 1fr; }
}
@media (max-width: 30rem) {
  nav.toolbar { gap: .35rem; }
  nav.toolbar button { padding-inline: .6rem; }
  nav.toolbar #sign-out { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { button { transition: none; } }
.device-tools { display: flex; gap: .65rem; align-items: flex-start; justify-content: space-between; margin: 0 0 .65rem; }
#device-settings { flex: 1; min-width: 0; }
#device-settings summary { width: fit-content; padding: .55rem .8rem; color: var(--ink); cursor: pointer; font-weight: 650; }
.device-panel { margin-top: .4rem; padding: 1rem; background: var(--paper); border: 1px solid var(--line); border-radius: .85rem; }
.device-panel h3 { margin-bottom: .3rem; }
.device-panel p { margin: .4rem 0 .7rem; }
.short-label { display: none; }
.order-toast-choice { display: inline-flex; align-items: center; gap: .5rem; }
.order-toast-choice input { width: 1.15rem; min-height: 1.15rem; accent-color: var(--accent); }
#new-order-banner { position: sticky; top: max(.3rem,env(safe-area-inset-top)); z-index: 2; padding: .55rem .8rem; margin: .6rem 0;
  background: #e0eddf; color: var(--ink); border: 1px solid #abc6ac; border-radius: .8rem; box-shadow: var(--shadow); }
#new-order-label { font-weight: 650; margin-right: auto; }
#connection-note { position: sticky; bottom: 0; background: #fff3d9; color: #533b19; padding: .65rem; border-radius: .6rem; }
@media (max-width: 45rem) {
  body { -webkit-text-size-adjust: 100%; }
  main { padding: max(.65rem,env(safe-area-inset-top)) max(.7rem,env(safe-area-inset-right)) calc(6rem + env(safe-area-inset-bottom)) max(.7rem,env(safe-area-inset-left)); }
  .app-header { border-radius: .95rem; padding: .85rem 1rem; margin-bottom: .55rem; }
  .app-header h1 { font-size: 1.55rem; margin: .12em 0; }
  .app-header p:last-child { display: none; }
  .device-tools { margin-bottom: .7rem; gap: .3rem; }
  .device-tools #sign-out { font-size: .88rem; }
  #device-settings summary { padding-left: .25rem; min-height: 44px; box-sizing: border-box; }
  .device-tools:has(details[open]) { flex-wrap: wrap; }
  #device-settings[open] { flex-basis: 100%; }
  #main-nav { position: fixed; inset: auto 0 0; z-index: 4; display: grid; grid-template-columns: repeat(5,minmax(0,1fr));
    gap: .12rem; margin: 0; padding: .28rem max(.22rem,env(safe-area-inset-right)) calc(.28rem + env(safe-area-inset-bottom)) max(.22rem,env(safe-area-inset-left));
    border-radius: .9rem .9rem 0 0; box-shadow: 0 -3px 16px #203d3015; }
  #main-nav button { min-height: 48px; padding: .28rem .06rem; font-size: clamp(.67rem,2.8vw,.88rem); border: 0; }
  #main-nav button[aria-pressed=false] { background: transparent; }
  #main-nav .long-label { display: none; }
  #main-nav .short-label { display: inline; }
  #notice:not(:empty) { inset: auto .65rem calc(4.35rem + env(safe-area-inset-bottom)); max-width: none; pointer-events: none; }
  #connection-note { bottom: calc(3.75rem + env(safe-area-inset-bottom)); }
  :is(button, select, input:not([type=checkbox]), summary) { min-height: 44px; }
  :is(input,select,textarea,fieldset,details,.segments > *, .controls > *, section, form) { min-width: 0; max-width: 100%; box-sizing: border-box; }
  input,select,textarea { font-size: 16px; }
  textarea { width: 100%; }
  .segments { grid-template-columns: repeat(auto-fit,minmax(min(100%,13rem),1fr)); }
  .marketing-fields { grid-template-columns: minmax(0,1fr); }
  .order-item { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
  .order-item label:first-child, .order-item label:has(select) { grid-column: 1/-1; }
  .order-item label input, .order-item label select { width: 100%; max-width: 100%; }
  .lead, .panel, .marketing-card, #agent-key, .photo-field { overflow-wrap: anywhere; }
  .table-scroll { overscroll-behavior-x: contain; }
  #stock-document .table-scroll { max-height: 56vh; max-height: 56dvh; }
  #stock-document thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #stock-lines { display: block; }
  #stock-lines tr { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: .2rem .55rem; padding: .45rem; border-bottom: 1px solid var(--line); }
  #stock-lines td { display: grid; align-content: end; border: 0; padding: .15rem 0; }
  #stock-lines td:first-child { grid-column: 1/-1; font-weight: 650; }
  #stock-lines td:nth-child(2) { grid-column: 1/-1; display: block; color: var(--muted); font-size: .85rem; }
  #stock-lines td:nth-child(2)::before { content: "По учёту · "; }
  #stock-lines td:nth-child(3)::before { content: "Единица ввода"; }
  #stock-lines td:nth-child(4)::before { content: "Факт / расход"; }
  #stock-lines td::before { font-size: .82rem; color: var(--muted); }
  #stock-lines input, #stock-lines select { width: 100%; }
  .lead { scroll-margin-top: .6rem; }
  .controls { row-gap: .5rem; }
  .photo-field input { padding-inline: .25rem; }
}
