:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e3e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --err: #b91c1c;
  --err-bg: #fef2f2;
  /* Тени-«рамки» вместо сплошных border для объёмных поверхностей.
     Слой 1 — кольцо 1px, слой 2 — лёгкий подъём, слой 3 — мягкая тень. */
  --shadow-border:
    0 0 0 1px rgba(0, 0, 0, .06),
    0 1px 2px -1px rgba(0, 0, 0, .06),
    0 2px 4px 0 rgba(0, 0, 0, .04);
  --shadow-border-hover:
    0 0 0 1px rgba(0, 0, 0, .08),
    0 1px 2px -1px rgba(0, 0, 0, .08),
    0 2px 4px 0 rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;   /* на macOS текст рендерится тоньше/чётче */
  -moz-osx-font-smoothing: grayscale;
  text-wrap: pretty;                      /* без «висячих» одиночных слов в коротком тексте */
}
h1, h2, h3 { text-wrap: balance; }        /* ровные по длине строки в заголовках */

/* --- Topbar --- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border-bottom: 1px solid var(--line);  /* разделитель — оставляем border */
  padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; }
.nav a {
  color: var(--muted); text-decoration: none; margin-left: 18px;
  padding: 6px 2px; border-bottom: 2px solid transparent;
  transition: color .15s ease-out, border-color .15s ease-out;
}
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--primary); border-bottom-color: var(--primary); }
.logout-link { color: var(--muted); text-decoration: none; font-size: 14px; transition: color .15s ease-out; }
.logout-link:hover { color: var(--err); }

/* --- Нижний таб-бар (виден только на мобильном, см. media-запрос) --- */
.tabbar { display: none; }
.tab { text-decoration: none; }

.container { max-width: 960px; margin: 24px auto; padding: 0 16px; }

/* --- Panels --- */
.panel {
  background: var(--panel); border-radius: 14px;
  box-shadow: var(--shadow-border);
  padding: 20px 22px; margin-bottom: 18px;
}
.panel h2 { margin: 0 0 6px; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  border: none; background: #fff; color: var(--text);
  border-radius: 9px; padding: 9px 16px; min-height: 40px;   /* зона нажатия >= 40px */
  font-size: 15px; text-decoration: none; box-shadow: var(--shadow-border);
  transition-property: background-color, box-shadow, scale;  /* перечисляем явно, не transition:all */
  transition-duration: .15s; transition-timing-function: ease-out;
}
.btn:hover { background: #f3f4f6; box-shadow: var(--shadow-border-hover); }
.btn:active:not(:disabled) { scale: .96; }                   /* тактильный отклик на нажатие */
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px -1px rgba(0, 0, 0, .25); }
.btn.primary:hover { background: var(--primary-dark); box-shadow: 0 2px 5px -1px rgba(37, 99, 235, .4); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: #f3f4f6; }
.btn.small { padding: 6px 11px; min-height: 34px; font-size: 13px; }
.btn.danger { color: var(--err); box-shadow: inset 0 0 0 1px #f3c2c2; }
.btn.danger:hover { background: var(--err-bg); }
.btn:disabled { opacity: .6; cursor: default; }

/* --- Uploader --- */
.uploader { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0 6px; }
.uploader input[type=file] { flex: 1; min-width: 200px; }

/* --- Card layout --- */
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 800px) { .card-grid { grid-template-columns: 1fr; } }
/* Появление карточки: левая (предпросмотр) и правая (форма) въезжают со сдвигом во времени */
.card-grid > div { animation: fadeInUp .4s ease-out both; }
.card-grid > .card-right { animation-delay: .1s; }

.preview-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.preview-img {
  width: 100%; border-radius: 8px; background: #fff; display: block;
  outline: 1px solid rgba(0, 0, 0, .1); outline-offset: -1px;  /* нейтральный контур у картинки */
}
.preview-controls { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.preview-controls .spacer { flex: 1; }

/* --- Forms --- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-top: 6px; }
.form-grid label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .search, .inline select {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
  font-size: 15px; color: var(--text); background: #fff; width: 100%;
  font-variant-numeric: tabular-nums;   /* ровные по ширине цифры в ИНН/счетах/суммах */
}
input:focus, select:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.form-grid input.missing, .form-grid select.missing {
  border-color: #f59e0b; background: #fffbeb;
}
.form-grid input.missing::placeholder { color: #b45309; }

.actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.inline { display: flex; gap: 10px; align-items: center; }

/* --- Alerts --- */
.alert { border-radius: 9px; padding: 11px 14px; margin: 10px 0; border: 1px solid var(--line); }
.alert.ok { background: var(--ok-bg); color: var(--ok); border-color: #a7f3d0; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }
.alert.error { background: var(--err-bg); color: var(--err); border-color: #fecaca; }

/* --- Result --- */
.result { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 16px; }  /* разделитель — border */
.files { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

/* --- Customers --- */
.search { max-width: 360px; margin: 8px 0 14px; }
.cust-list { display: flex; flex-direction: column; gap: 10px; }
.cust-card {
  display: flex; justify-content: space-between; align-items: center;
  border-radius: 10px; padding: 12px 14px;
  box-shadow: var(--shadow-border); transition: box-shadow .15s ease-out;
}
.cust-card:hover { box-shadow: var(--shadow-border-hover); }
.cust-info { display: flex; flex-direction: column; gap: 2px; }
.cust-info span { font-variant-numeric: tabular-nums; }
.cust-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* --- Trucks / assets --- */
.trucks-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.truck-row {
  display: flex; justify-content: space-between; align-items: center;
  border-radius: 8px; padding: 8px 12px; box-shadow: var(--shadow-border);
}
.assets-row { display: flex; gap: 18px; flex-wrap: wrap; }
.asset-cell {
  border-radius: 10px; padding: 14px; flex: 1; min-width: 240px;
  display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-border);
}

/* --- Login --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border-radius: 16px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .05), 0 12px 32px -8px rgba(0, 0, 0, .18);
  padding: 32px 30px; width: min(340px, 92vw); text-align: center;
  display: flex; flex-direction: column; gap: 12px;
  animation: fadeInUp .4s ease-out both;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-logo { font-size: 40px; }
.login-card input { border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; font-size: 16px; }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 12px 22px; border-radius: 10px; color: #fff; z-index: 50; font-size: 14px;
  box-shadow: 0 8px 24px -6px rgba(0, 0, 0, .35);
  animation: toastIn .2s ease-out;
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--err); }

/* --- Одноразовые анимации появления --- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); filter: blur(4px); }
  to   { opacity: 1; transform: translateY(0);    filter: blur(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* --- Мобильная адаптация: нижний таб-бар как в приложении --- */
@media (max-width: 760px) {
  .nav-desktop { display: none; }              /* верхнее меню прячем — навигация снизу */
  .container { margin: 14px auto; padding: 0 12px calc(74px + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 14px; }
  .panel { padding: 16px; }
  .card-grid { grid-template-columns: 1fr; gap: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid input, .form-grid select { font-size: 16px; }  /* 16px — iOS не зумит поле при фокусе */
  .assets-row { flex-direction: column; }
  .toast { bottom: calc(82px + env(safe-area-inset-bottom)); }  /* выше таб-бара */

  .tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--panel);
    border-top: 1px solid var(--line);
    box-shadow: 0 -2px 12px -6px rgba(0, 0, 0, .15);
    padding-bottom: env(safe-area-inset-bottom);  /* отступ под «домашнюю» полосу iPhone */
  }
  .tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 8px 4px 7px; min-height: 56px;
    color: var(--muted); font-size: 11px; line-height: 1;
    transition: color .15s ease-out, scale .12s ease-out;
  }
  .tab .tab-ico { font-size: 21px; line-height: 1; }
  .tab.active { color: var(--primary); }
  .tab:active { scale: .92; }                   /* отклик на тап */
}

/* Уважаем системную настройку «уменьшить движение» */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
