:root {
  --bg: var(--tg-theme-secondary-bg-color, #f3f5f2);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-2: #edf2ef;
  --text: var(--tg-theme-text-color, #17211e);
  --muted: var(--tg-theme-hint-color, #66736e);
  --line: rgba(31, 63, 54, .13);
  --brand: var(--tg-theme-button-color, #2d5b50);
  --brand-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #c78a32;
  --danger: #b13a42;
  --success: #287653;
  --radius: 20px;
  --shadow: 0 12px 36px rgba(29, 55, 47, .09);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-width: 300px; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.hidden { display: none !important; }

.skip-link { position: fixed; left: 12px; top: -60px; z-index: 100; padding: 10px 14px; background: var(--surface); border-radius: 10px; }
.skip-link:focus { top: 12px; }
.app-shell { width: min(1180px, 100%); min-height: 100vh; margin: 0 auto; padding-bottom: calc(86px + var(--safe-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 80px; padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 14px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 1px 0 0; max-width: 75vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(21px, 5vw, 30px); letter-spacing: -.03em; }
.eyebrow { margin: 0; color: var(--brand); font-size: 11px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
#view { padding: 18px 16px 28px; outline: none; }

.bottom-nav { position: fixed; z-index: 30; bottom: 0; left: 50%; translate: -50%; display: grid; grid-template-columns: repeat(4, 1fr); width: min(1180px, 100%); min-height: calc(68px + var(--safe-bottom)); padding: 7px 8px var(--safe-bottom); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(20px); border-top: 1px solid var(--line); }
.bottom-nav button { position: relative; display: grid; place-items: center; gap: 2px; min-width: 0; padding: 6px 2px; color: var(--muted); background: transparent; border: 0; border-radius: 14px; font-size: 11px; font-weight: 700; }
.bottom-nav button > span:first-child { font-size: 22px; line-height: 1; }
.bottom-nav button.active { color: var(--brand); background: var(--surface-2); }
.badge { position: absolute; top: 2px; left: calc(50% + 9px); min-width: 19px; height: 19px; padding: 0 5px; border: 2px solid var(--surface); border-radius: 20px; background: var(--danger); color: white; font-size: 10px; line-height: 15px; }

.icon-button { display: inline-grid; flex: 0 0 auto; place-items: center; width: 42px; height: 42px; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); font-size: 22px; box-shadow: 0 5px 14px rgba(20, 50, 40, .06); }
.hero { position: relative; overflow: hidden; padding: 24px; border-radius: 28px; color: white; background: linear-gradient(135deg, #214c42, #3f7668 68%, #b88235); box-shadow: var(--shadow); }
.hero::after { content: ""; position: absolute; width: 180px; height: 180px; right: -54px; top: -65px; border: 36px solid rgba(255,255,255,.10); border-radius: 50%; }
.hero h2 { position: relative; max-width: 700px; margin: 5px 0 8px; font-size: clamp(26px, 7vw, 42px); line-height: 1.04; letter-spacing: -.04em; }
.hero p { position: relative; max-width: 620px; margin: 0; color: rgba(255,255,255,.82); line-height: 1.55; }

.toolbar { display: flex; align-items: center; gap: 10px; margin: 18px 0; }
.search { display: flex; flex: 1; gap: 8px; padding: 5px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 5px 20px rgba(20, 50, 40, .04); }
.search input { min-width: 0; flex: 1; padding: 9px 10px; border: 0; outline: none; background: transparent; color: var(--text); }
.search button { padding: 8px 12px; border: 0; border-radius: 11px; background: var(--surface-2); color: var(--text); }
.chips { display: flex; gap: 8px; margin: 14px -16px 18px; padding: 0 16px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); font-weight: 700; }
.chip.active { border-color: var(--brand); background: var(--brand); color: var(--brand-text); }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin: 22px 0 12px; }
.section-head h2, .section-head h3 { margin: 0; letter-spacing: -.02em; }
.section-head p { margin: 4px 0 0; color: var(--muted); }
.product-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.product-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 7px 25px rgba(24, 53, 45, .05); }
.product-image { position: relative; aspect-ratio: 1.18; display: grid; place-items: center; overflow: hidden; background: linear-gradient(145deg, #e1ebe6, #f5eee2); color: var(--brand); font-size: 36px; }
.product-image img { width: 100%; height: 100%; object-fit: cover; }
.kind-label { position: absolute; left: 9px; top: 9px; padding: 5px 8px; border-radius: 999px; background: rgba(255,255,255,.90); color: #1f4037; font-size: 10px; font-weight: 800; backdrop-filter: blur(7px); }
.product-info { padding: 12px; }
.product-info h3 { min-height: 2.55em; margin: 0 0 8px; overflow: hidden; font-size: 15px; line-height: 1.27; }
.price-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.price { font-weight: 850; letter-spacing: -.02em; }
.old-price { color: var(--muted); font-size: 12px; text-decoration: line-through; }
.card-actions { display: flex; gap: 8px; margin-top: 11px; }
.card-actions .button { width: 100%; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 10px 15px; border: 1px solid transparent; border-radius: 13px; background: var(--brand); color: var(--brand-text); font-weight: 800; text-align: center; text-decoration: none; }
.button.secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button.ghost { background: var(--surface-2); color: var(--brand); }
.button.danger { background: var(--danger); color: white; }
.button.small { min-height: 34px; padding: 7px 10px; font-size: 12px; }
.button:disabled { cursor: not-allowed; opacity: .52; }
.button:focus-visible, .chip:focus-visible, .icon-button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 2px; }

.stack { display: grid; gap: 12px; }
.panel, .list-card, .state-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 28px rgba(24, 53, 45, .05); }
.panel { padding: 18px; }
.list-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; padding: 16px; }
.list-card h3, .list-card h4 { margin: 0 0 4px; }
.list-card p { margin: 2px 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.state-card { display: grid; justify-items: center; gap: 8px; margin: 30px auto; padding: 40px 24px; text-align: center; }
.state-card h2 { margin: 4px 0 0; }
.state-card p { max-width: 500px; margin: 0; color: var(--muted); line-height: 1.55; }
.status { display: inline-flex; align-items: center; width: max-content; padding: 5px 9px; border-radius: 999px; background: var(--surface-2); color: var(--brand); font-size: 11px; font-weight: 800; }
.status.cancelled { background: #f8e5e6; color: #94353b; }
.status.completed, .status.paid { background: #e1f1e8; color: #246849; }
.muted { color: var(--muted); }
.danger-text { color: var(--danger); }

.quantity { display: inline-grid; grid-template-columns: 36px minmax(28px, auto) 36px; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.quantity button { height: 36px; border: 0; background: var(--surface-2); color: var(--text); font-weight: 900; }
.quantity span { padding: 0 7px; text-align: center; font-weight: 800; }
.cart-line { grid-template-columns: 1fr auto; }
.totals { display: grid; gap: 9px; margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.totals div { display: flex; justify-content: space-between; gap: 16px; }
.totals .grand { font-size: 19px; font-weight: 850; }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; font-weight: 800; }
.field input, .field textarea, .field select { width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 13px; outline: none; background: var(--surface); color: var(--text); }
.field textarea { min-height: 96px; resize: vertical; }
.field small { color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 9px; }
.check input { width: 19px; height: 19px; accent-color: var(--brand); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form input, .inline-form select { flex: 1 1 150px; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; }
.gallery .product-image { flex: 0 0 100%; scroll-snap-align: center; aspect-ratio: 1.25; border-radius: 17px; }
.detail-price { margin: 14px 0 4px; font-size: 24px; font-weight: 900; }
.detail-copy { color: var(--muted); white-space: pre-wrap; line-height: 1.55; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; overflow-x: auto; border-radius: 14px; background: var(--surface-2); }
.segmented button { min-width: max-content; padding: 9px 12px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 800; }
.segmented button.active { background: var(--surface); color: var(--brand); box-shadow: 0 3px 12px rgba(20,50,40,.08); }

.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.metric { padding: 16px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 6px; font-size: 22px; letter-spacing: -.03em; }
.admin-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.admin-actions button { min-height: 86px; padding: 13px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); color: var(--text); text-align: left; font-weight: 800; }
.admin-actions button span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; font-weight: 500; }

dialog { width: min(680px, calc(100% - 20px)); max-height: min(88vh, 880px); padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 25px; background: var(--surface); color: var(--text); box-shadow: 0 30px 90px rgba(10,30,24,.30); }
dialog::backdrop { background: rgba(10, 25, 21, .55); backdrop-filter: blur(3px); }
.modal-head { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 17px 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.modal-head h2 { margin: 2px 0 0; font-size: 21px; }
.modal-body { padding: 18px; overflow-y: auto; max-height: calc(88vh - 78px); }
.toast-region { position: fixed; z-index: 100; left: 50%; bottom: calc(82px + var(--safe-bottom)); translate: -50%; display: grid; gap: 8px; width: min(420px, calc(100% - 28px)); pointer-events: none; }
.toast { padding: 13px 15px; border-radius: 14px; background: #14251f; color: white; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { background: #872f35; }
.busy { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(245,247,245,.48); backdrop-filter: blur(2px); }
.spinner { width: 28px; height: 28px; border: 3px solid color-mix(in srgb, var(--brand) 20%, transparent); border-top-color: var(--brand); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }
@keyframes toast-in { from { translate: 0 10px; opacity: 0; } }

@media (min-width: 720px) {
  .app-shell { padding-left: 104px; padding-bottom: 0; }
  .topbar { padding-left: 30px; padding-right: 30px; }
  #view { padding: 26px 30px 50px; }
  .bottom-nav { top: 0; bottom: 0; left: max(0px, calc(50% - 590px)); translate: 0; width: 104px; min-height: 100vh; padding: calc(90px + env(safe-area-inset-top, 0px)) 10px 20px; grid-template-columns: 1fr; grid-template-rows: repeat(4, 76px); align-content: start; border-top: 0; border-right: 1px solid var(--line); }
  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .admin-actions { grid-template-columns: repeat(3, 1fr); }
  .toast-region { bottom: 25px; }
}

@media (min-width: 1040px) {
  .product-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (prefers-color-scheme: dark) {
  :root { --surface-2: #22312d; --line: rgba(215, 235, 228, .13); --shadow: 0 12px 36px rgba(0,0,0,.18); }
  .hero { background: linear-gradient(135deg, #173c34, #2c6154 68%, #765426); }
  .product-image { background: linear-gradient(145deg, #21372f, #3b3328); }
  .kind-label { background: rgba(20,35,30,.88); color: #e5f5ef; }
  .busy { background: rgba(12,20,17,.5); }
}

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