:root {
  --primary: #1997d1;
  --secondary: #f6c54d;
  --text: #153142;
  --bg: #eef7fc;
  --white: #ffffff;
  --danger: #c53d3d;
  --success: #1a8f4c;
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow: 0 14px 32px rgba(10, 54, 78, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #d7eef9 0%, var(--bg) 46%, #e8f6fd 100%);
  min-height: 100vh;
}

.app {
  width: min(980px, 94%);
  margin: 2rem auto 2.5rem;
  display: grid;
  gap: 1.2rem;
}

.header {
  background: linear-gradient(140deg, var(--primary), #0e7aac);
  color: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  animation: fadeSlideIn 0.6s ease-out;
  display: flex;
  gap: 1rem;
  align-items: center;
}

.header-logo {
  background: var(--white);
  border-radius: 14px;
  padding: 0.45rem 0.65rem;
  flex-shrink: 0;
}

.header-logo img {
  display: block;
  width: clamp(92px, 16vw, 130px);
  height: auto;
}

.header-copy {
  min-width: 0;
  margin-left: auto;
  text-align: right;
}

.header h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.35rem, 2.8vw, 2rem);
}

.header p {
  margin: 0;
  opacity: 0.95;
}

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  box-shadow: var(--shadow);
  animation: fadeSlideIn 0.7s ease-out;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.input-group {
  display: grid;
  gap: 0.34rem;
}

.input-group label {
  font-size: 0.92rem;
  font-weight: 600;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid #c6dce7;
  border-radius: var(--radius-md);
  padding: 0.72rem 0.82rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(25, 151, 209, 0.18);
}

.section-title {
  background: rgba(246, 197, 77, 0.24);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  font-weight: 700;
  color: #614a0e;
}

.full-width {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  gap: 0.72rem;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.72rem 1.14rem;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s, opacity 0.2s;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button[type="submit"] {
  background: var(--primary);
  color: var(--white);
}

button.secondary {
  background: #ecf5fa;
  color: #224657;
}

.hidden {
  display: none;
}

.print-only {
  display: none;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}

.results h2 {
  margin: 0;
}

.print-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.8rem;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin-bottom: 1rem;
}

.summary-item {
  border: 1px solid #d8e8f1;
  border-radius: var(--radius-md);
  padding: 0.8rem;
  display: grid;
  gap: 0.4rem;
}

.summary-item span {
  font-size: 0.87rem;
}

.summary-item strong {
  font-size: 1.06rem;
}

.summary-item.highlight {
  background: #fff8e6;
  border-color: #f3d27a;
}

.savings-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.8rem;
}

.savings-percent {
  font-size: 1.24rem;
  text-align: right;
  white-space: nowrap;
}

.chart-wrap {
  border-radius: var(--radius-md);
  padding: 1rem;
  background: linear-gradient(180deg, #f6fbfe 0%, #eef8fc 100%);
  border: 1px solid #d6e9f3;
}

.chart {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.3rem;
  align-items: end;
}

.bar-group {
  display: grid;
  gap: 0.55rem;
  justify-items: center;
}

.bar-label,
.bar-value {
  font-weight: 700;
}

.bar-track {
  width: 100%;
  max-width: 170px;
  height: 220px;
  border-radius: 12px;
  padding: 8px;
  background: repeating-linear-gradient(
    to top,
    rgba(25, 151, 209, 0.08) 0,
    rgba(25, 151, 209, 0.08) 22px,
    rgba(25, 151, 209, 0.14) 22px,
    rgba(25, 151, 209, 0.14) 24px
  );
  display: flex;
  align-items: flex-end;
}

.bar {
  width: 100%;
  height: var(--h);
  border-radius: 10px;
  transform-origin: bottom;
  animation: growBar 0.8s ease-out;
}

.bar.before {
  background: linear-gradient(180deg, #f8d77f 0%, var(--secondary) 100%);
}

.bar.after {
  background: linear-gradient(180deg, #65bee7 0%, var(--primary) 100%);
}

.bar.forecast {
  background: linear-gradient(180deg, #79caeb 0%, var(--primary) 100%);
}

.forecast-wrap {
  margin-top: 1rem;
}

.forecast-wrap h3 {
  margin: 0 0 0.9rem;
  font-size: 1.04rem;
}

.forecast-note {
  margin: -0.2rem 0 1.35rem;
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.35;
}

.cost-breakdown {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.cost-card {
  border: 1px solid #d8e8f1;
  border-radius: 12px;
  padding: 0.7rem;
  background: #fbfdff;
}

.cost-card h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.cost-card p {
  margin: 0.2rem 0;
  font-size: 0.86rem;
}

.forecast-chart {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  align-items: end;
}

.bar-subvalue {
  font-size: 0.82rem;
  font-weight: 400;
  color: #2a4f63;
  text-align: center;
}

.positive {
  color: var(--success);
}

.negative {
  color: var(--danger);
}

@keyframes growBar {
  from {
    height: 0;
  }
  to {
    height: var(--h);
  }
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 760px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-copy {
    margin-left: 0;
    text-align: left;
  }

  .results-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid,
  .summary,
  .chart,
  .forecast-chart,
  .cost-breakdown {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }

  .bar-track {
    max-width: 100%;
  }
}

@media print {
  @page {
    margin: 10mm;
  }

  :root {
    --text: #0f2f45;
  }

  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app {
    width: 100%;
    margin: 0;
    gap: 0;
  }

  .header,
  .card:first-of-type,
  .no-print {
    display: none !important;
  }

  .card {
    box-shadow: none;
    border: none;
    animation: none;
    border-radius: 0;
    padding: 0;
  }

  .results {
    display: block !important;
  }

  .print-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 0.6rem;
  }

  .print-logo {
    display: block;
    margin-bottom: 0;
  }

  .print-logo img {
    display: block;
    width: 120px;
    height: auto;
  }

  .print-date {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
  }

  .summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chart {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.8rem;
  }

  .forecast-chart {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 0.7rem;
  }

  .cost-breakdown {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.7rem;
  }

  .chart-wrap {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-top: 0.7rem;
  }

  .bar-track {
    height: 140px;
    max-width: 100%;
    background: #eef7fc;
    border: 1px solid #c9dbe6;
  }

  .bar {
    animation: none;
    border: 1px solid #5aaad2;
  }

  .bar.before {
    background: #f6c54d !important;
    border-color: #e2b138;
  }

  .bar.after {
    background: #1997d1 !important;
    border-color: #1684b8;
  }

  .bar.forecast {
    background: #1997d1 !important;
    border-color: #1684b8;
  }

  .bar-value {
    font-size: 0.93rem;
  }

  .bar-subvalue {
    font-size: 0.78rem;
  }

  .bar {
    min-height: 4px;
  }
}
