/* ── Калькулятор асфальта ────────────────────────────────────────────────
   Палитра: тёплый чёрный, оранжевый акцент, нейтральные серые.
   Цветовых акцентов ровно один — оранжевый; всё остальное — градации серого. */

:root {
  color-scheme: dark;

  --bg: #0a0b0c;
  --surface: #15181b;
  --surface-2: #1c2124;
  --surface-3: #252c30;

  --line: #2a3236;
  --line-2: #384147;

  --text: #eef1f3;
  --text-2: #a3adb3;
  --muted: #737e84;

  --accent: #ff9f2e;
  --accent-hi: #ffd07a;
  --accent-lo: #f07d1a;
  --accent-dim: rgba(255, 159, 46, 0.12);
  --accent-line: rgba(255, 159, 46, 0.38);
  --accent-glow: rgba(255, 159, 46, 0.16);
  --danger: #e8736c;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 22px;

  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background:
    radial-gradient(115% 55% at 50% -8%, #1a1712 0%, transparent 62%),
    var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; -webkit-user-select: none; user-select: none; }

.app-shell {
  width: min(100%, 460px);
  margin: 0 auto;
  padding:
    calc(14px + env(safe-area-inset-top)) 14px
    calc(284px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Шапка ──────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 0;
}

.brand-mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--accent-line);
  border-radius: 10px;
  background: linear-gradient(155deg, rgba(255, 159, 46, 0.16), transparent 70%);
  color: var(--accent);
}

.brand-mark svg { width: 20px; height: 20px; }

h1 {
  flex: 1;
  margin: 0;
  font-size: 1.08rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

/* ── Переключатель режимов ──────────────────────────────────────────────── */

.mode-switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}

.mode-switch__thumb {
  position: absolute;
  z-index: 0;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  border: 1px solid var(--accent-line);
  border-radius: 10px;
  background: linear-gradient(160deg, rgba(255, 159, 46, 0.2), rgba(255, 159, 46, 0.06));
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  transition: transform 260ms cubic-bezier(0.32, 0.72, 0, 1);
}

.mode-btn {
  position: relative;
  z-index: 1;
  min-height: 36px;
  padding: 5px 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: color 200ms ease;
}

.mode-btn.is-active { color: var(--accent-hi); }

/* ── Результат ──────────────────────────────────────────────────────────── */

.result-card {
  position: relative;
  overflow: hidden;
  height: 112px;
  padding: 13px 16px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-xl);
  background:
    radial-gradient(120% 90% at 4% 0%, rgba(255, 159, 46, 0.16) 0%, transparent 58%),
    linear-gradient(158deg, #241d13 0%, var(--surface) 68%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05) inset,
    0 14px 32px rgba(0, 0, 0, 0.42);
  transition: border-color 200ms ease;
}

.reset-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(21, 24, 27, 0.72);
  color: var(--muted);
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease, transform 80ms ease;
}

.reset-btn svg { width: 15px; height: 15px; }
.reset-btn:hover { color: var(--text-2); border-color: var(--line-2); background: var(--surface-2); }
.reset-btn:active { color: var(--accent); border-color: var(--accent-line); transform: rotate(-18deg) scale(0.94); }

.result-view { width: 100%; }
.result-view[hidden] { display: none; }

.result-card.is-invalid { border-color: rgba(232, 115, 108, 0.6); }

.res-subhead {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.res-hero {
  display: block;
  margin-top: 3px;
  background: linear-gradient(168deg, var(--accent-hi) 6%, var(--accent) 52%, var(--accent-lo) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: clamp(2.2rem, 10.5vw, 2.85rem);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.042em;
  line-height: 1.04;
}

.lb-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.res-lb {
  background: linear-gradient(168deg, var(--accent-hi) 6%, var(--accent) 58%, var(--accent-lo) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: clamp(1.4rem, 6.8vw, 1.9rem);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.028em;
  line-height: 1.1;
  white-space: nowrap;
}

.res-caption {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

/* ── Поля ───────────────────────────────────────────────────────────────── */

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start;
  gap: 7px;
  margin: 0;
}

.field {
  padding: 9px 11px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  transition: border-color 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.field[hidden] { display: none; }
.field.span-2 { grid-column: 1 / -1; }

/* Опорные величины, которые мастер задаёт сам */
.field-key {
  border-color: var(--accent-line);
  background: linear-gradient(168deg, rgba(255, 159, 46, 0.07), var(--surface) 62%);
}

.field-key .stepper input { color: var(--accent); }

.field.is-editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Расчётная сторона пары L/B */
.field.is-derived {
  opacity: 0.55;
  border-style: dashed;
}

.field.is-derived .stepper input { color: var(--text-2); }

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.79rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Метка «площадь посчитана из сторон» */
.field label .tag {
  margin-left: 7px;
  padding: 2px 7px;
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent-hi);
  font-size: 0.66rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  vertical-align: 1px;
}

.field label .tag[hidden] { display: none; }

/* Ширина × Длина внутри плашки площади */
.wl-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
  transition: opacity 180ms ease;
}

.wl-row.is-derived { opacity: 0.45; }

.wl-x {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
}

.subfield {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 8px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.subfield label {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
}

.subfield input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.02rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  caret-color: transparent;
}

.density-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.density-head > label {
  margin: 0;
  line-height: 1.08;
  overflow: visible;
}

.mini-stepper {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 5px;
}

.mini-stepper .step-btn {
  height: 38px;
  border-radius: 8px;
  font-size: 1rem;
}

.mini-stepper .input-wrap,
.mini-stepper input { height: 38px; }

.mini-stepper input {
  flex: none;
  width: auto;
  max-width: calc(100% - 1.8em);
  padding: 0;
  text-align: right;
  font-size: 0.98rem;
}

.mini-stepper .input-unit { font-size: 0.98rem; }

.subfield input:focus { outline: none; }

.subfield.is-editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.stepper {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  gap: 6px;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.38em;
  min-width: 0;
  height: 44px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.3);
  transition: border-color 150ms ease;
}

.input-unit {
  flex: none;
  color: var(--muted);
  font-size: 1.2rem;
  font-weight: 400;
  line-height: 1;
  opacity: 0.56;
  pointer-events: none;
}

.field:not(.span-2) .stepper { grid-template-columns: 40px minmax(0, 1fr) 40px; }

/* Рабочая величина режима: с ней возятся чаще всего */
.field-hero .stepper { grid-template-columns: 52px minmax(0, 1fr) 52px; gap: 8px; }
.field-hero .step-btn { height: 52px; font-size: 1.42rem; }
.field-hero .stepper input { height: 100%; font-size: 1.48rem; font-weight: 700; }
.field-hero .input-wrap { height: 52px; }
.field-hero .input-unit { font-size: 1.48rem; }
.field-hero label { font-size: 0.82rem; }

.step-btn {
  display: grid;
  place-items: center;
  height: 44px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: background 130ms ease, border-color 130ms ease, color 130ms ease, transform 80ms ease;
}

.step-btn:hover { background: var(--surface-3); color: var(--text); }

.step-btn:active,
.step-btn.holding {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(0.93);
}

.stepper input {
  flex: none;
  width: auto;
  max-width: calc(100% - 1.6em);
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: right;
  font-size: 1.2rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  cursor: pointer;
  caret-color: transparent;
  transition: border-color 150ms ease;
}

.stepper input:focus { outline: none; }
.field.is-editing .input-wrap { border-color: var(--accent-line); }
.input-wrap:has(input[aria-invalid="true"]) { border-color: var(--danger); }
.stepper input[aria-invalid="true"] { color: var(--danger); }

:where(button, input):focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 1px;
}

/* ── Тип смеси ──────────────────────────────────────────────────────────── */

.mixes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 0;
}

.mix-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 90ms ease;
}

.mix-btn:hover { border-color: var(--line-2); background: var(--surface-2); }
.mix-btn:active { transform: scale(0.97); }

.mix-btn .m-name {
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 500;
}
.mix-btn .m-val {
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.mix-btn.is-active {
  border-color: var(--accent-line);
  background: linear-gradient(168deg, rgba(255, 159, 46, 0.18), rgba(255, 159, 46, 0.05));
  color: var(--accent-hi);
}

.mix-btn.is-active .m-name { color: var(--accent-hi); }
.mix-btn.is-active .m-val { color: var(--accent); }

/* ── Собственная клавиатура ─────────────────────────────────────────────── */

.keypad {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(calc(100% - 28px), 432px);
  padding: 6px 7px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #171b1e, #101315);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -14px 34px rgba(0, 0, 0, 0.5);
  animation: keypad-in 220ms cubic-bezier(0.32, 0.72, 0, 1);
  opacity: 0.2;
  pointer-events: none;
  transition: opacity 180ms ease;
}

body.keypad-open .keypad {
  opacity: 1;
  pointer-events: auto;
}

@keyframes keypad-in {
  from { transform: translate(-50%, 100%); }
  to   { transform: translate(-50%, 0); }
}

.keypad-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 3px 5px;
}

.keypad-label {
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.keypad-cancel {
  flex: none;
  min-height: 25px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease, border-color 130ms ease;
}

.keypad-cancel:hover { background: var(--surface-3); color: var(--text); border-color: var(--line-2); }
.keypad-cancel:active { transform: scale(0.96); }

/* Экранчик набора: значение уходит в поле только по галочке */
.keypad-display {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 8px;
  min-height: 38px;
  margin-bottom: 5px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background:
    radial-gradient(120% 130% at 100% 0%, rgba(255, 159, 46, 0.09) 0%, transparent 60%),
    rgba(0, 0, 0, 0.34);
  transition: border-color 160ms ease;
}

.kd-value {
  color: var(--text-2);
  font-size: 1.55rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 160ms ease;
}

.kd-unit {
  flex: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

/* Набранное значение — оранжевым, старое — приглушённым */
.keypad-display.is-typed { border-color: var(--accent-line); }
.keypad-display.is-typed .kd-value { color: var(--accent-hi); }
.keypad-display.is-out { border-color: rgba(232, 115, 108, 0.55); }
.keypad-display.is-out .kd-value { color: var(--danger); }

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.key {
  min-height: 36px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.12rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 100ms ease, border-color 100ms ease, transform 70ms ease;
}

.key:active {
  background: var(--surface-3);
  border-color: var(--accent-line);
  transform: scale(0.95);
}

.key-fn { color: var(--text-2); font-size: 1.05rem; }

.key:disabled {
  opacity: 0.3;
  cursor: default;
  transform: none;
}
.key-wide { grid-column: span 2; }

.key-ok {
  grid-row: span 2;
  border-color: var(--accent-line);
  background: linear-gradient(168deg, rgba(255, 159, 46, 0.22), rgba(255, 159, 46, 0.07));
  color: var(--accent-hi);
  font-size: 1.3rem;
}

/* ── Адаптив ────────────────────────────────────────────────────────────── */

@media (max-width: 344px) {
  .field:not(.span-2) .stepper { grid-template-columns: 34px minmax(0, 1fr) 34px; }
  .field label { font-size: 0.74rem; }
  .mode-btn { font-size: 0.79rem; }
}

/* Телефон: вся рабочая часть помещается над постоянной клавиатурой. */
@media (max-width: 520px) {
  :root { --keypad-space: calc(218px + env(safe-area-inset-bottom)); }

  body { overflow: hidden; }

  .app-shell {
    height: calc(100dvh - var(--keypad-space));
    min-height: 0;
    padding: calc(6px + env(safe-area-inset-top)) 14px 4px;
    gap: 7px;
    overflow: hidden;
    touch-action: pan-y;
  }

  .topbar { min-height: 28px; padding-top: 0; }
  .brand-mark { width: 28px; height: 28px; border-radius: 8px; }
  .brand-mark svg { width: 17px; height: 17px; }
  h1 { font-size: 1rem; }
  .reset-btn { width: 28px; height: 28px; }

  .mode-switch { padding: 3px; }
  .mode-switch__thumb {
    top: 3px;
    left: 3px;
    width: calc(50% - 3px);
    height: calc(100% - 6px);
  }
  .mode-btn { min-height: 30px; padding: 3px 6px; font-size: 0.8rem; }

  .result-card { height: 106px; padding: 10px 14px; }
  .res-hero { margin-top: 1px; font-size: clamp(2rem, 10vw, 2.65rem); }
  .lb-row { margin-top: 2px; }
  .res-caption { margin-top: 3px; font-size: 0.7rem; }

  .fields { gap: 7px; }
  .field { padding: 6px 8px 7px; border-radius: 15px; }
  .field label { margin-bottom: 4px; font-size: 0.74rem; }

  .density-head { gap: 8px; margin-bottom: 5px; }
  .density-head > label { min-width: 66px; margin: 0; font-size: 0.7rem; }
  .mixes { gap: 4px; }
  .mix-btn {
    gap: 0;
    min-height: 34px;
    padding: 3px 2px;
    border-radius: 9px;
  }
  .mix-btn .m-name { font-size: 0.62rem; line-height: 1.05; }
  .mix-btn .m-val { font-size: 0.75rem; line-height: 1.05; }

  .stepper { grid-template-columns: 40px minmax(0, 1fr) 40px; gap: 5px; }
  .step-btn, .input-wrap { height: 38px; }
  .stepper input, .input-unit { font-size: 1.08rem; }

  .field-hero .stepper { grid-template-columns: 40px minmax(0, 1fr) 40px; gap: 5px; }
  .field-hero .step-btn, .field-hero .input-wrap { height: 40px; }
  .field-hero .stepper input, .field-hero .input-unit { font-size: 1.25rem; }
  .field-hero label { font-size: 0.75rem; }

  .wl-row { gap: 5px; margin-top: 4px; }
  .subfield { gap: 2px; padding: 4px 5px 5px; }
  .subfield label { margin: 0; font-size: 0.62rem; }
  .mini-stepper { grid-template-columns: 30px minmax(0, 1fr) 30px; gap: 4px; }
  .mini-stepper .step-btn,
  .mini-stepper .input-wrap,
  .mini-stepper input { height: 30px; }
  .mini-stepper .step-btn { font-size: 0.95rem; }
  .mini-stepper input, .mini-stepper .input-unit { font-size: 0.88rem; }

  /* Пара L/B на обратном расчёте: геометрия как у компактной пары площади. */
  #cell-input-length .stepper,
  #cell-input-width .stepper {
    grid-template-columns: 32px minmax(0, 1fr) 32px;
    gap: 4px;
  }
  #cell-input-length .step-btn,
  #cell-input-width .step-btn,
  #cell-input-length .input-wrap,
  #cell-input-width .input-wrap {
    height: 32px;
  }
  #cell-input-length .stepper input,
  #cell-input-width .stepper input,
  #cell-input-length .input-unit,
  #cell-input-width .input-unit {
    font-size: 0.95rem;
  }

  .keypad {
    padding: 5px 7px calc(6px + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
  }
  .keypad-head { padding-bottom: 4px; }
  .keypad-cancel { min-height: 23px; }
  .keypad-display { min-height: 32px; margin-bottom: 4px; padding: 4px 10px; }
  .kd-value { font-size: 1.35rem; }
  .keypad-grid { gap: 4px; }
  .key { min-height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
