/* ============================================================================
 * styles.css — оформление калькулятора (аккуратный рабочий интерфейс)
 * Адаптивная раскладка: десктоп — форма слева / 3D справа / результаты снизу;
 * телефон — всё в одну колонку.
 * ========================================================================== */

:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

h2 {
  font-size: 15px;
  margin: 0 0 10px;
}

/* ---- Верхняя панель ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 18px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.logo { font-weight: 700; font-size: 16px; }
.unit-pick { color: var(--muted); font-size: 13px; }
.unit-pick select { margin-left: 6px; }

/* ---- Раскладка ---- */
.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 14px;
  padding: 14px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.form { max-height: calc(100vh - 90px); overflow-y: auto; }
.results-panel { margin: 0 14px 14px; }

/* ---- Поля формы ---- */
.field { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.field input { display: block; width: 100%; }
label { font-size: 12px; color: var(--muted); }
input, select, button { font-family: inherit; font-size: 14px; }
input[type='number'], input[type='text'], select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  margin-top: 3px;
}
input:focus, select:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }

.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.grid3 label { display: flex; flex-direction: column; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
  margin-bottom: 8px;
}
.section-head h2 { margin: 0; }
.mini { width: auto; max-width: 170px; font-size: 12px; }

.vehicle-presets { display: flex; gap: 8px; margin-bottom: 10px; }
.vehicle-presets select { flex: 1; }

/* ---- Карточки коробок ---- */
.box-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  background: #fafcff;
}
.box-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.box-head .b-name { flex: 1; font-weight: 600; }
.swatch { width: 16px; height: 16px; border-radius: 4px; flex: none; border: 1px solid rgba(0,0,0,0.15); }
.del {
  border: none; background: #fee2e2; color: var(--bad);
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; flex: none;
}
.del:hover { background: #fecaca; }
.order-badge {
  width: 22px; height: 22px; flex: none;
  display: grid; place-items: center;
  background: #1e293b; color: #fff;
  border-radius: 6px; font-size: 12px; font-weight: 700;
}
.move {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; flex: none;
  font-size: 13px; line-height: 1;
}
.move:hover:not(:disabled) { background: #eff6ff; border-color: var(--primary); }
.move:disabled { opacity: 0.35; cursor: default; }

.cmp-h { font-size: 13px; margin: 16px 0 6px; color: var(--muted); }
.cmp .cur { background: #eff6ff; }
.cmp .best { color: var(--ok); font-size: 12px; }
.box-flags { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 6px; }
.chk { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink); }
.chk input { width: auto; margin: 0; }
.color { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.color input[type='color'] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line); }

/* ---- Кнопки ---- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-d); }
.btn.ghost { background: #fff; color: var(--primary); border-color: #bfdbfe; }
.btn.wide { width: 100%; margin: 4px 0 0; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.actions { display: flex; gap: 8px; margin-top: 14px; position: sticky; bottom: 0; }
.actions .btn { flex: 1; }

/* ---- 3D-визуализация ---- */
.viz { display: flex; flex-direction: column; padding: 10px; }
.viz-toolbar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.views, .exports { display: flex; gap: 6px; flex-wrap: wrap; }
.scene {
  width: 100%;
  height: 540px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}
.hint { color: var(--muted); font-size: 12px; text-align: center; margin: 8px 0 0; }

/* Панель ручного перемещения коробок */
.move-panel {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fafcff;
}
.move-info { font-size: 13px; color: var(--ink); margin-bottom: 8px; }
.move-info.active { color: var(--primary); font-weight: 600; }
.move-ctrls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.move-ctrls .step { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.move-ctrls .step input { width: 62px; margin: 0; }
.move-ctrls .pad { display: flex; gap: 6px; flex-wrap: wrap; }
.move-ctrls .pad .btn:disabled { opacity: 0.4; cursor: default; }

/* ---- Результаты ---- */
.verdict { font-weight: 700; font-size: 15px; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.verdict.ok { background: #dcfce7; color: #166534; }
.verdict.bad { background: #fef3c7; color: #92400e; }

.bar {
  position: relative;
  height: 26px;
  background: #eef2f7;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 14px;
}
.bar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #60a5fa, #2563eb); }
.bar span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 600; font-size: 12px; color: #0f172a; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fafcff;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.metric span { color: var(--muted); font-size: 12px; }
.metric b { font-size: 16px; }

.bytype { width: 100%; border-collapse: collapse; font-size: 13px; }
.bytype th, .bytype td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.bytype th { color: var(--muted); font-weight: 600; }

/* ---- Алерты ---- */
.alert { border-radius: 8px; padding: 10px 12px; margin-top: 12px; font-size: 13px; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert.err { background: #fee2e2; color: #991b1b; }
.alert.warn { background: #fef3c7; color: #92400e; }
.alert.info { background: #dbeafe; color: #1e40af; }

/* ---- Тост ---- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Адаптив ---- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .form { max-height: none; overflow: visible; }
  .scene { height: 380px; }
}

/* ---- Печать / PDF ---- */
/* На экране область печати скрыта; заполняется и показывается только при печати. */
.print-area { display: none; }
.print-title { font-size: 18px; margin: 0 0 2px; }
.print-meta { color: #555; font-size: 12px; margin-bottom: 10px; }
.print-img { width: 100%; height: auto; border: 1px solid #ccc; border-radius: 6px; }
.print-block { margin-top: 12px; }
.print-views { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.print-view { margin: 0; }
.print-view img { width: 100%; height: auto; border: 1px solid #ccc; border-radius: 6px; display: block; }
.print-view figcaption { font-size: 12px; font-weight: 600; margin-top: 4px; }

@media print {
  /* Прячем весь интерфейс, показываем только аккуратную область печати */
  body > .topbar,
  body > .layout,
  body > .results-panel,
  body > .toast { display: none !important; }

  .print-area { display: block !important; }

  /* Внутри печати: компактно, без теней, без разрывов внутри блоков */
  .print-area .verdict,
  .print-area .bar,
  .print-area .metrics,
  .print-area table,
  .print-area .print-view,
  .print-area .alert { page-break-inside: avoid; }
  .print-area .print-views { page-break-inside: avoid; }
  .print-area .metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .print-area .metric { border: 1px solid #ddd; border-radius: 6px; padding: 6px 8px; }
  .print-area .bar { border: 1px solid #ddd; }
  @page { margin: 12mm; }
}

/* ============================================================================
 * Облачная часть: страница входа, верхняя панель, проекты, админка
 * ========================================================================== */

/* --- Страница входа / регистрации --- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 10px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.auth-logo { font-weight: 700; font-size: 18px; text-align: center; margin-bottom: 16px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; background: #eef2f7; padding: 4px; border-radius: 10px; }
.auth-tab {
  flex: 1; border: none; background: transparent; padding: 9px; border-radius: 8px;
  cursor: pointer; font-weight: 600; color: var(--muted);
}
.auth-tab.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.auth-form .field { margin-bottom: 12px; }
.consent { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; color: var(--muted); margin: 4px 0 14px; }
.consent input { margin-top: 2px; }
.auth-note { color: var(--muted); font-size: 12px; text-align: center; }

/* --- Верхняя облачная панель --- */
.cloud-bar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  background: #0f172a; color: #fff;
  padding: 8px 16px;
}
.cloud-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cloud-app { font-weight: 700; }
.cloud-proj { color: #cbd5e1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cloud-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cloud-user { color: #cbd5e1; font-size: 13px; margin: 0 6px; }
.cloud-bar .btn { background: #1e293b; color: #fff; border-color: #334155; }
.cloud-bar .btn:hover { background: #334155; }
.cloud-bar .btn.primary { background: var(--primary); border-color: var(--primary); }
.cloud-bar .btn.primary:hover { background: var(--primary-d); }
.cloud-bar .btn.danger { background: #7f1d1d; border-color: #991b1b; }

/* --- Панель со списком проектов --- */
.cloud-panel {
  position: fixed; top: 52px; right: 16px; z-index: 45;
  width: 340px; max-width: calc(100vw - 32px);
  max-height: 70vh; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15,23,42,0.18);
}
.cloud-panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.cloud-panel-list { padding: 8px; }
.cloud-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; }
.cloud-item:hover { background: #f8fafc; }
.cloud-item-main { flex: 1; cursor: pointer; min-width: 0; }
.cloud-item-name { font-weight: 600; }
.cloud-item-date { font-size: 12px; color: var(--muted); }
.cloud-empty { padding: 14px; color: var(--muted); font-size: 13px; }

/* --- Админ-панель --- */
.admin-wrap { max-width: 1000px; margin: 20px auto; padding: 0 16px; }
.admin-wrap .metrics { margin-bottom: 18px; }
.admin-table { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }

/* В облачной версии наверху липкая cloud-bar; собственный заголовок приложения
 * делаем обычным, чтобы две панели не накладывались. */
body .topbar { position: static; }

/* Проекты пользователя в админ-панели */
.proj-details > td { background: #f8fafc; }
.user-projects { padding: 6px 4px; }
.uproj { display: flex; align-items: center; gap: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.uproj:last-child { border-bottom: none; }
.uproj-name { font-weight: 600; flex: 1; }
.uproj-date { color: var(--muted); font-size: 12px; }
