/* ==========================================================================
   Калькулятор алюминиевого металлопроката — тёмно-синяя тема
   Mobile-first: базовые стили рассчитаны на узкие экраны,
   десктоп добавляется через @media (min-width: 880px).
   ========================================================================== */

:root {
  --bg:         #080d1a;
  --bg-2:       #0b1120;
  --card:       #111b30;
  --card-2:     #16223a;
  --input:      #0d1525;
  --ink:        #e6edf7;
  --ink-dim:    #aebccd;
  --muted:      #7e8ea6;
  --line:       #21324e;
  --line-soft:  #1a2740;
  --accent:     #3b82f6;
  --accent-d:   #2563eb;
  --accent-dk:  #1d4ed8;
  --accent-soft:#16294d;
  --navy:       #0f172a;
  --err:        #f87171;
  --err-bg:     #241115;
  --radius:     14px;
  --radius-sm:  11px;
  --shadow:     0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
  --tap:        44px;   /* минимальная зона касания */
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  overflow-x: hidden;
  /* Сдерживающие меры против механического копирования интерфейса.
     Поля ввода и результат остаются выделяемыми — иначе ломается
     доступность и работа со сметой. */
  -webkit-user-select: none;
  user-select: none;
}

/* Текст, который пользователь вправе выделять и копировать */
input, select, textarea,
.rows dd, .result-title, .total-value,
.copyright, .foot p {
  -webkit-user-select: text;
  user-select: text;
}

img { -webkit-user-drag: none; }

/* ============================ ШАПКА ============================ */
.hero {
  background: linear-gradient(140deg, var(--navy) 0%, #16305c 55%, var(--accent-dk) 100%);
  color: #fff;
  padding: 26px 16px 34px;
  padding-top: calc(26px + env(safe-area-inset-top));
}

.hero-inner {
  max-width: 1060px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
}

/* Логотип: белая плашка, чтобы знак читался на тёмно-синем градиенте */
.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  padding: 10px 16px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .28);
  line-height: 0;
  transition: box-shadow .15s, transform .15s;
}

.brand-logo {
  display: block;
  width: auto;
  height: 52px;
  max-width: 100%;
  -webkit-user-drag: none;
  user-drag: none;
}

.hero-text { min-width: 0; }

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.3rem, 5vw, 2.1rem);
  line-height: 1.2;
  letter-spacing: .2px;
}

.lead {
  margin: 0;
  font-size: .92rem;
  opacity: .85;
  max-width: 60ch;
}

/* ============================ РАСКЛАДКА ============================ */
.wrap {
  max-width: 1060px;
  margin: -20px auto 0;
  padding: 0 12px 32px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 24px 0 12px;
  font-size: 1rem;
  font-weight: 650;
}

.card h2:first-child { margin-top: 0; }

.step {
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .82rem;
  font-weight: 700;
}

/* ============================ ТИПЫ ПРОКАТА ============================ */
.shapes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.shape {
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
  min-height: var(--tap);
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--input);
  color: var(--ink);
  transition: border-color .15s, background .15s, box-shadow .15s;
}

.shape .shape-name { display: block; font-weight: 600; font-size: .88rem; line-height: 1.25; }
.shape .shape-sub  { display: block; font-size: .74rem; color: var(--muted); margin-top: 2px; }

.shape[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.shape[aria-pressed="true"] .shape-sub { color: #93b4e0; }

/* ============================ ПОЛЯ ВВОДА ============================ */
.fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field label {
  display: block;
  font-size: .84rem;
  color: var(--muted);
  margin-bottom: 5px;
}

.input-wrap { position: relative; }

/* font-size 16px обязателен: иначе iOS Safari увеличивает масштаб при фокусе */
input, select {
  width: 100%;
  font: inherit;
  font-size: 16px;
  min-height: var(--tap);
  color: var(--ink);
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 54px 11px 12px;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}

input::placeholder { color: #5c6b82; }

select {
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* Стрелка select не должна перекрываться блоком .unit */
select option { background: var(--card); color: var(--ink); }

input:focus-visible, select:focus-visible,
.btn:focus-visible, .shape:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.28);
}

input.invalid { border-color: var(--err); background: var(--err-bg); }

.unit {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: .8rem;
  color: var(--muted);
  pointer-events: none;
}

.field-qty { margin-top: 14px; }

.note { font-size: .8rem; color: var(--muted); margin: 12px 0 0; }

/* ============================ КНОПКИ ============================ */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 auto;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--ink);
  transition: border-color .15s, background .15s, transform .06s;
}

.btn:active { transform: scale(.985); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ============================ РЕЗУЛЬТАТ ============================ */
.result-title { margin: 0 0 12px; font-weight: 650; font-size: .98rem; }

.rows { margin: 0; border-top: 1px solid var(--line); }

.rows > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.rows dt { font-size: .85rem; color: var(--muted); }

.rows dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

.total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  background: linear-gradient(120deg, var(--navy), var(--accent-dk));
  color: #fff;
}

.total-label { font-size: .9rem; opacity: .85; }
.total-value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

#errorBox:not(:empty) { color: var(--err); }

.noscript {
  max-width: 1060px;
  margin: 12px auto;
  padding: 12px 16px;
  background: var(--err-bg);
  border: 1px solid var(--err);
  border-radius: 10px;
  color: var(--err);
}

/* ============================ ПОДВАЛ ============================ */
.foot { max-width: 1060px; margin: 0 auto; padding: 0 12px 28px; }
.foot p { font-size: .78rem; color: var(--muted); }

.copyright {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
  font-size: .74rem;
  color: #6b7a90;
}

/* ============================ HOVER (только для мыши) ============================ */
@media (hover: hover) and (pointer: fine) {
  .brand:hover { box-shadow: 0 4px 16px rgba(0, 0, 0, .35); transform: translateY(-1px); }
  .shape:hover { border-color: #2d4a6f; }
  .btn:hover   { border-color: #2d4a6f; }
  .btn-primary:hover { background: var(--accent-d); border-color: var(--accent-d); }
  input:hover:not(:focus), select:hover:not(:focus) { border-color: #2d4a6f; }
}

/* ============================ ПЛАНШЕТ / УЗКИЙ ДЕСКТОП ============================ */
@media (min-width: 560px) {
  .hero-inner {
    flex-direction: row;
    align-items: center;
    gap: 22px;
  }
  .brand-logo { height: 62px; }
  .shapes { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .fields { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .field-qty { max-width: 220px; }
  .wrap { padding: 0 16px 36px; }
  .card { padding: 20px; }
  .hero { padding: 30px 16px 38px; padding-top: calc(30px + env(safe-area-inset-top)); }
}

/* ============================ ДЕСКТОП ============================ */
@media (min-width: 880px) {
  .wrap {
    grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr);
    gap: 20px;
    padding: 0 20px 40px;
    margin-top: -22px;
  }
  .card { padding: 22px; }
  .hero { padding: 34px 20px 42px; padding-top: calc(34px + env(safe-area-inset-top)); }
  .hero-inner { gap: 28px; }
  .brand { padding: 12px 18px; border-radius: 20px; }
  .brand-logo { height: 72px; }
  .lead { font-size: 1rem; }
  .result { position: sticky; top: 20px; }
  .actions { flex-wrap: nowrap; }
  .btn { flex: 0 0 auto; }
  .foot { padding: 0 20px 40px; }
}

/* ============================ ОЧЕНЬ УЗКИЕ ЭКРАНЫ ============================ */
@media (max-width: 359px) {
  .shapes { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.2rem; }
  .total-value { font-size: 1.15rem; }
}

/* ============================ 404 ============================ */
.page-404 {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.page-404-main {
  text-align: center;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.page-404-code {
  font-size: clamp(3rem, 12vw, 5rem);
  margin: 8px 0 0;
  color: var(--accent);
  line-height: 1;
}

.page-404-text {
  color: var(--muted);
  margin: 0 0 10px;
  font-size: 1rem;
}

.page-404-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ============================ ПЕЧАТЬ / PDF ============================ */
@media print {
  body { background: #fff; color: #000; }
  .hero { background: none; color: #000; padding: 0 0 12px; }
  .actions, .shapes, .fields, .foot { display: none; }
  .card { border: 1px solid #999; box-shadow: none; background: #fff; }
  .total { background: none; color: #000; border: 1px solid #999; }
}

/* ============================ АНИМАЦИИ ============================ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}
