/* Smart Electric — Mini App
   Палитра: белый + синий/голубой. Мобильный-first (Telegram WebApp). */

:root {
  --bg: #eef4fb;
  --surface: #ffffff;
  --surface-2: #f6f9fd;
  --primary: #0a6cff;
  --primary-strong: #0552c9;
  --primary-soft: #e8f1ff;
  --accent: #0ea5e9;
  --accent-soft: #e0f4ff;
  --text: #0f2037;
  --muted: #5b6b82;
  --border: #dbe6f3;
  --ok: #138a44;
  --ok-soft: #e7f7ec;
  --bad: #d62828;
  --bad-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(15, 32, 55, 0.06), 0 6px 20px rgba(15, 32, 55, 0.06);
  --shadow-soft: 0 1px 2px rgba(15, 32, 55, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { min-height: 100dvh; }

/* --- Шапка ------------------------------------------------------------------ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 14px;
  background: linear-gradient(135deg, #0a6cff 0%, #0ea5e9 100%);
  color: #ffffff;
  box-shadow: 0 4px 18px rgba(10, 108, 255, 0.28);
}

.app-header__titles { min-width: 0; }

.app-header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 26px;
  line-height: 1;
  padding: 0 0 3px;
  cursor: pointer;
}

.icon-btn:active { background: rgba(255, 255, 255, 0.28); }

/* --- Контейнер -------------------------------------------------------------- */

.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px calc(24px + env(safe-area-inset-bottom, 0px));
}

/* --- Сетка главного экрана -------------------------------------------------- */

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 13px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: transform 0.06s ease, border-color 0.15s ease;
}

.tile:active { transform: scale(0.98); border-color: var(--accent); }

.tile__icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 21px;
  border-radius: 12px;
  background: var(--primary-soft);
}

.tile__title { font-size: 14.5px; font-weight: 650; line-height: 1.25; }
.tile__sub { font-size: 11.5px; color: var(--muted); line-height: 1.3; }

/* --- Карточки и секции ------------------------------------------------------ */

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

.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
}

.section-title {
  margin: 18px 4px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* --- Формы ------------------------------------------------------------------ */

.field { margin-bottom: 13px; }

.field:last-child { margin-bottom: 0; }

.field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.field__hint {
  margin: 5px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.35;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(10, 108, 255, 0.14);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235b6b82' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* Чекбокс-переключатель */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.switch span { font-size: 14px; font-weight: 600; }

.switch input { display: none; }

.switch .track {
  flex: 0 0 auto;
  width: 44px;
  height: 25px;
  border-radius: 999px;
  background: #cbd8e8;
  position: relative;
  transition: background 0.16s ease;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 32, 55, 0.3);
  transition: transform 0.16s ease;
}

.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(19px); }

/* --- Кнопки ----------------------------------------------------------------- */

.btn {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #ffffff;
  font-size: 15.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.06s ease;
}

.btn:active { background: var(--primary-strong); transform: scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn--ghost {
  background: var(--surface-2);
  color: var(--primary);
  border: 1px solid var(--border);
  font-weight: 650;
}

.btn--ghost:active { background: var(--primary-soft); }

/* --- Результат -------------------------------------------------------------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.stat__label { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.stat__value { font-size: 19px; font-weight: 750; color: var(--primary); }
.stat__value--ok { color: var(--ok); }
.stat__value--bad { color: var(--bad); }
.stat__value--lg { font-size: 22px; }

.report {
  margin: 0;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  overflow-x: auto;
}

.verdict {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

.verdict--ok { background: var(--ok-soft); color: var(--ok); }
.verdict--bad { background: var(--bad-soft); color: var(--bad); }

/* --- Таблицы (смета) -------------------------------------------------------- */

table.estimate {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.estimate th, table.estimate td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.estimate th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

table.estimate td.num { text-align: right; white-space: nowrap; }
table.estimate tr.total td { font-weight: 750; border-bottom: none; }

/* --- Прейскурант / списки --------------------------------------------------- */

.list-item {
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.list-item:active { border-color: var(--primary); }
.list-item .price { font-weight: 700; color: var(--primary); white-space: nowrap; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.chip {
  padding: 8px 13px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 650;
}

/* --- Схема щита ------------------------------------------------------------- */

.group-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
  background: var(--surface-2);
}

.group-box > label {
  display: block;
  margin: 9px 0 5px;
  font-size: 13px;
  font-weight: 600;
}

.group-box input,
.group-box select { background: #ffffff; }

.group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.group-title { font-weight: 700; font-size: 14px; }

.group-del {
  border: none;
  background: none;
  color: var(--bad);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* --- Toast ------------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: #0f2037;
  color: #ffffff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 13.5px;
  max-width: 88vw;
  box-shadow: 0 8px 24px rgba(15, 32, 55, 0.3);
  z-index: 50;
}

/* --- Загрузка --------------------------------------------------------------- */

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(10, 108, 255, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Широкие экраны --------------------------------------------------------- */

@media (min-width: 480px) {
  .home-grid { grid-template-columns: repeat(3, 1fr); }
}
