@import './design.css';

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 20px;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.logo {
  font-weight: 700;
  color: var(--blue);
  font-size: 1.15rem;
}
.logo-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.logo-img {
  display: block;
  height: 24px;
  width: auto;
}
.topbar nav a {
  color: var(--text);
  text-decoration: none;
  margin-left: 16px;
}
.topbar nav a:hover {
  color: var(--blue);
}

.hero {
  padding: 48px 0 24px;
}
.hero h1 {
  font-size: 2rem;
  margin: 0 0 8px;
}
.hero p {
  margin: 4px 0;
}

.muted {
  color: var(--muted);
  font-size: 0.92rem;
}
.opt {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.alert-warn {
  background: #fdf1ec;
  border: 1px solid #e8b08b;
  color: #9a4b1f;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.92rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0 40px;
}
@media (max-width: 640px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover {
  background: var(--blue-dark);
}
.btn-secondary {
  background: var(--blue-light);
  color: var(--blue-dark);
}
.btn-secondary:hover {
  background: #d8e8f6;
}
.btn-print {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 8px;
  padding: 6px 12px;
  margin-left: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}
.btn-print:hover {
  background: var(--blue-light);
}
.topbar nav button {
  vertical-align: middle;
}
.inline-form {
  display: inline-block;
  margin: 0;
}
.btn-logout {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  margin-left: 14px;
  padding: 0;
}
.btn-logout:hover {
  color: var(--blue);
}
.topbar nav a {
  margin-left: 16px;
}
.topbar nav a:first-child {
  margin-left: 0;
}

.form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin: 16px 0 40px;
}
.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}
.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}
.field input:focus,
.field select:focus {
  outline: 2px solid var(--blue);
  border-color: transparent;
}
.hint {
  display: block;
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}
.hint.warn {
  color: #c0392b;
}

.field input.input-invalid {
  border-color: #c0392b;
  outline: 1px solid #c0392b;
}
.field-error {
  color: #c0392b;
  font-size: 0.82rem;
  margin-top: 4px;
}

/* -- Единицы, live-CO2, индикатор, черновик -- */
.unit {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}
.range-hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 4px;
  min-height: 1em;
}
.live-co2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.82rem;
}
.badge {
  font-size: 0.78rem;
  white-space: nowrap;
}
.badge-ok {
  color: #1e7d3c;
}
.badge-warn {
  color: #b9770b;
}
.badge-high {
  color: #c0392b;
  font-weight: 700;
}
.co2-val {
  color: var(--muted);
}
.money-val {
  color: var(--green, #1e7d3c);
  font-weight: 600;
}
.money-save {
  color: var(--green, #1e7d3c);
}
.price-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.82rem;
}
.price-input {
  width: 90px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}
.payback {
  font-size: 0.8rem;
}
.eco-bonus,
.eco-rating {
  margin: 24px 0;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.eco-bonus {
  background: #f0faf3;
  border-color: #bfe6cc;
}
.eco-bonus-main {
  font-size: 1.05rem;
  margin: 6px 0;
}
.eco-eq {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}
.eco-eq-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.eco-rating {
  background: var(--blue-light, #eef4fb);
}
.eco-rating-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 700;
  margin: 6px 0;
}
.eco-rating-letter {
  font-size: 2rem;
  line-height: 1;
}
.eco-rating-range {
  font-size: 0.95rem;
}
.eco-bench {
  margin-top: 8px;
}
.btn-certificate {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 700;
  color: #7a5c12;
  background: linear-gradient(135deg, #f5e6b8, #e8cf8a);
  border: 1px solid #d4b25e;
  text-decoration: none;
  transition:
    box-shadow 0.2s,
    transform 0.2s;
}
.btn-certificate:hover {
  box-shadow: 0 4px 12px rgba(212, 178, 94, 0.4);
  transform: translateY(-1px);
  color: #5d450d;
}
.map-consent {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fafbfc;
}
.check-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}
.check-label input[type='checkbox'] {
  margin-top: 2px;
  accent-color: var(--blue, #1a6fb5);
}
.coord-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.coord-row .price-input {
  width: 110px;
}
.live-total {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--blue-dark);
  background: var(--blue-light);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 18px;
}
.draft-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #fff8e6;
  border: 1px solid #e8d39a;
  color: #7a5b12;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.draft-bar.hidden {
  display: none;
}
.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 6px 12px;
}
.btn-ghost:hover {
  background: #f1f5f9;
}

/* Крупные кнопки и touch-оптимизация */
.btn-lg {
  padding: 14px 22px;
  font-size: 1.05rem;
  border-radius: 10px;
  width: 100%;
  margin-top: 6px;
}
button,
.btn,
input[type='number'],
input[type='text'],
input[type='email'],
input[type='password'],
select {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.form input[type='number'],
.form input[type='text'],
.form input[type='email'],
.form input[type='password'],
.form select {
  padding: 12px 14px;
  min-height: 46px;
  font-size: 1rem;
}

/* -- Страница ошибки -- */
.error-page {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 28px;
  margin: 40px 0;
  text-align: center;
}
.error-icon {
  width: 72px;
  height: 72px;
  color: var(--blue);
}
.error-code {
  font-size: 64px;
  font-weight: 700;
  color: var(--blue);
  line-height: 1;
  margin-top: 8px;
}
.error-page h1 {
  font-size: 22px;
  margin: 12px 0 8px;
}
.error-details {
  display: inline-block;
  text-align: left;
  margin: 8px auto 20px;
}
.error-page .btn {
  margin-top: 8px;
}

/* -- Список отчётов -- */
.report-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 24px;
}
.report-card {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.report-card:hover {
  border-color: var(--blue);
  box-shadow: 0 2px 8px rgba(26, 111, 181, 0.12);
}
.rc-name {
  font-weight: 700;
}
.rc-type {
  color: var(--muted);
  font-size: 0.85rem;
}
.rc-co2 {
  font-weight: 700;
  color: var(--blue);
  white-space: nowrap;
}
.rc-date {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}
@media (max-width: 560px) {
  .report-card {
    grid-template-columns: 1fr auto;
    row-gap: 4px;
  }
  .rc-type {
    display: none;
  }
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 20px 0 8px;
}
.empty-state {
  text-align: center;
  padding: 26px;
  color: var(--muted);
}

/* -- Диаграмма выбросов (SVG донат) -- */
.chart-wrap {
  display: flex;
  align-items: center;
  gap: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin: 12px 0 24px;
  flex-wrap: wrap;
}
.chart-donut {
  width: 230px;
  height: 230px;
  flex: 0 0 auto;
}
.donut-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 34;
}
.donut-seg {
  fill: none;
  stroke-width: 34;
  stroke-linecap: butt;
}
.donut-total {
  font-size: 22px;
  font-weight: 700;
  fill: var(--ink, #1f2d3d);
}
.donut-label {
  font-size: 11px;
  fill: var(--muted);
}
.chart-legend {
  flex: 1 1 240px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.legend-name {
  flex: 1 1 auto;
}
.legend-val {
  font-weight: 700;
}
.legend-pct {
  color: var(--muted);
  min-width: 48px;
  text-align: right;
}
@media (max-width: 560px) {
  .chart-donut {
    margin: 0 auto;
  }
}

.summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin: 16px 0 24px;
}
.summary-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.big-number {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--blue);
  display: block;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.table th,
.table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.table th {
  background: var(--blue-light);
}
.total-row {
  font-weight: 700;
  background: var(--blue-light);
}
.th-cell {
  width: 40%;
  font-weight: 700;
  background: var(--blue-light);
  white-space: nowrap;
}

.tips {
  padding-left: 20px;
}
.tips li {
  margin: 8px 0;
}

.disclaimer {
  margin-top: 24px;
}

.footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  margin-top: 40px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* -- Иконки, бары, анимации -- */
.card {
  transition:
    box-shadow var(--transition),
    transform var(--transition);
}
.field-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  vertical-align: -3px;
  margin-right: 6px;
}
.icon-svg {
  width: 100%;
  height: 100%;
  display: block;
}
.field[data-resource='electricity'] .field-icon {
  color: #3b82f6;
}
.field[data-resource='gas'] .field-icon {
  color: #f59e0b;
}
.field[data-resource='water'] .field-icon {
  color: #22d3ee;
}
.field[data-resource='waste'] .field-icon {
  color: #a16207;
}
.field[data-resource='petrol'] .field-icon {
  color: #a855f7;
}

.bar-list {
  margin: 12px 0 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}
.bar-ico {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}
.bar-name {
  width: 120px;
  font-weight: 600;
  flex: 0 0 auto;
}
.bar-track {
  flex: 1 1 auto;
  background: var(--blue-light);
  border-radius: 6px;
  height: 12px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.4s ease;
}
.bar-val {
  width: 130px;
  text-align: right;
  color: var(--muted);
  flex: 0 0 auto;
}

/* Fade-in при загрузке отчёта */
.report-page .summary,
.report-page .chart-wrap,
.report-page .table {
  animation: ecoFadeIn 0.4s ease backwards;
}
.report-page h2 {
  animation: ecoFadeIn 0.4s ease 0.08s backwards;
}
.report-page .tips,
.report-page .bar-list,
.report-page .disclaimer {
  animation: ecoFadeIn 0.4s ease 0.16s backwards;
}

.table-wrap {
  overflow-x: auto;
}

/* Печать: убрать шапку/кнопки, компактные цвета */
/* Планировщик целей: прогресс-бар */
.goal-card {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 18px 0;
}
.goal-card h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}
.goal-progress {
  height: 14px;
  background: #eef1f6;
  border-radius: 8px;
  overflow: hidden;
  margin: 10px 0 6px;
}
.goal-bar {
  height: 100%;
  background: linear-gradient(90deg, #1e9e50, #58c46c);
  border-radius: 8px;
  transition: width 0.4s ease;
}
.goal-remain {
  margin: 0;
}

/* Динамика по месяцам (SVG-график в дашборде) */
.history-card {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 18px 0;
}
.history-card h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}
.history-chart {
  width: 100%;
  height: auto;
  margin-top: 8px;
}
.history-label {
  font-size: 0.85rem;
  fill: var(--muted);
}
.history-line {
  fill: none;
  stroke: var(--blue, #3b82f6);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.history-dot {
  fill: var(--blue, #3b82f6);
  stroke: #fff;
  stroke-width: 1.5;
}
.history-empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--muted);
}

@media print {
  .no-print {
    display: none !important;
  }
  body {
    background: #fff;
  }
  .summary,
  .table,
  .card {
    box-shadow: none;
  }
}

/* Mobile-first */
@media (max-width: 560px) {
  .topbar-inner {
    flex-direction: column;
    height: auto;
    padding: 8px 0;
    gap: 6px;
  }
  .topbar nav a {
    margin-left: 10px;
  }
  .btn-print {
    margin-left: 10px;
  }
  .hero h1 {
    font-size: 1.5rem;
  }
  .big-number {
    font-size: 1.4rem;
  }
  .table th,
  .table td {
    padding: 8px;
    font-size: 0.85rem;
  }
}

/* -- ФИЧИ: тренды на дашборде -- */
.trends-card {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 18px 0;
}
.trend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
}
.trend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--blue-light);
  border-radius: 8px;
  padding: 8px 12px;
}
.trend-name {
  font-weight: 600;
}
.trend-badge {
  font-weight: 700;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.85rem;
}
.trend-up {
  color: #c0392b;
}
.trend-down {
  color: #1e7d3c;
}
.trend-flat {
  color: #5b6b7b;
}
.trend-up .trend-badge,
.trend-badge.trend-up {
  background: #fdecea;
}
.trend-down .trend-badge,
.trend-badge.trend-down {
  background: #e8f8ef;
}
.trend-flat .trend-badge,
.trend-badge.trend-flat {
  background: #eef1f6;
}
.rc-trend {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}
.rc-main {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  flex: 1;
  color: var(--text);
  text-decoration: none;
}
.rc-delete {
  margin-left: 8px;
}
.btn-danger {
  background: #fdecea;
  color: #c0392b;
  border: 1px solid #f0b2a8;
}
.btn-danger:hover {
  background: #f9d4cd;
}
@media (max-width: 560px) {
  .rc-main {
    grid-template-columns: 1fr auto;
    row-gap: 4px;
  }
  .rc-type {
    display: none;
  }
}

/* -- Кнопка переключения темы -- */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  margin-left: 12px;
  vertical-align: middle;
  transition: background var(--transition);
}
.theme-toggle:hover {
  background: var(--blue-light);
}
.lang-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  margin-left: 12px;
  vertical-align: middle;
  color: var(--muted);
  transition: background var(--transition);
}
.lang-toggle:hover {
  background: var(--blue-light);
}

/* -- Карточки-метрики на дашборде -- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin: 18px 0;
}
.metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  border-radius: 12px;
}
.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}
.metric-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}
.metric-unit {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 4px;
}
@media (max-width: 768px) {
  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .metric-value {
    font-size: 1.6rem;
  }
}

/* -- Тёмная тема: подстройка компонентов со светлыми акцентами -- */
[data-theme='dark'] .eco-bonus {
  background: #17281f;
  border-color: #2a4a38;
}
[data-theme='dark'] .alert-warn {
  background: #2e2418;
  border-color: #5a4526;
  color: #e6c393;
}
[data-theme='dark'] .draft-bar {
  background: #2e2718;
  border-color: #5a4a26;
  color: #e6d093;
}
[data-theme='dark'] .btn-danger {
  background: #3a2320;
  border-color: #5a3630;
  color: #e88b7e;
}
[data-theme='dark'] .btn-danger:hover {
  background: #4a2c28;
}
[data-theme='dark'] .trend-up .trend-badge,
[data-theme='dark'] .trend-badge.trend-up {
  background: #3a2320;
}
[data-theme='dark'] .trend-down .trend-badge,
[data-theme='dark'] .trend-badge.trend-down {
  background: #17281f;
}
[data-theme='dark'] .trend-flat .trend-badge,
[data-theme='dark'] .trend-badge.trend-flat {
  background: #2e3843;
}
[data-theme='dark'] .theme-toggle:hover,
[data-theme='dark'] .btn-ghost:hover {
  background: var(--blue-light);
}

/* -- Баннер о недоступности БД -- */
.db-warning {
  background: #fff3cd;
  border-bottom: 1px solid #e0c96a;
  color: #7a5b12;
  text-align: center;
  padding: 8px 14px;
  font-size: 0.95rem;
  font-weight: 600;
}
[data-theme='dark'] .db-warning {
  background: #3a3118;
  border-color: #5a4a26;
  color: #e6d093;
}

/* Пометка «демо-коэффициенты» в методологии */
.demo-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #7a5b12;
  background: #fff3d6;
  border: 1px solid #e8d39a;
  border-radius: 999px;
  vertical-align: middle;
}
