* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
}

.page-boende .app-container {
  width: 100%;
  max-width: 32rem;
  margin: 0 auto;
  padding: 1.75rem var(--page-pad-x) max(3rem, calc(1rem + env(safe-area-inset-bottom))) var(--page-pad-x-right);
}

/* Stronger page title: Boende is number-heavy; extra size aids scan (scoped, not a bare h1). */
.page-boende .ds-page-header__title {
  font-size: 1.75rem;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.settings-bar--card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* ==================== Settings bar ==================== */

.settings-bar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.s-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.s-field {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.s-field--wide { flex: 2 1 0; }

.s-field > span {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.s-text {
  width: 100%;
  padding: 0.65rem 0.75rem;
  min-height: 2.5rem;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--text-primary);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.s-text:focus {
  outline: none;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.s-input-wrap {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  overflow: hidden;
  height: 2.5rem;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.s-input-wrap:focus-within {
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.s-input-wrap input {
  flex: 1;
  min-width: 0;
  padding: 0 0.65rem;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: right;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.s-input-wrap input:focus { outline: none; }

.s-suffix {
  display: flex;
  align-items: center;
  padding: 0 0.7rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.s-select-wrap {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  height: 2.5rem;
  position: relative;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.s-select-wrap:focus-within {
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.s-select-wrap::after {
  content: "";
  position: absolute;
  right: 0.75rem;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text-secondary);
  transform: translateY(-25%);
}

.s-select-wrap select {
  flex: 1;
  min-width: 0;
  padding: 0 1.8rem 0 0.75rem;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  border: none;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.s-select-wrap select:focus { outline: none; }

/* ==================== Overview KPI cards ==================== */

.overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

.overview[hidden] { display: none; }

.kpi {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem 0.9rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.kpi--wide { grid-column: 1 / -1; }

.kpi-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.kpi-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1;
}

.kpi-icon--teal  { background: var(--brand-teal-soft); color: var(--brand-teal); }
.kpi-icon--blue  { background: var(--accent-soft); color: var(--accent); }
.kpi-icon--rose  { background: var(--run-warm-bg); color: var(--run-warm); }

.kpi-label {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-body {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.kpi-value {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.kpi-unit {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.kpi-sub {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.15rem 0.45rem;
  font-size: 0.6875rem;
  font-weight: 700;
  border-radius: 99px;
  font-variant-numeric: tabular-nums;
}

.kpi-trend--up   { color: var(--brand-teal); background: var(--brand-teal-soft); }
.kpi-trend--down { color: var(--run-warm);   background: var(--run-warm-bg); }

/* ==================== Section head ==================== */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0 0.1rem 0.65rem;
}

.section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.section-meta {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* ==================== Housings grid ==================== */

.housings {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

/* ==================== Housing card ==================== */

.housing {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.housing.cheapest {
  box-shadow: 0 0 0 2px var(--brand-teal), var(--shadow-md);
}

.housing-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.95rem 1rem 0.65rem;
}

.housing-name {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  border: none;
  background: transparent;
  padding: 0.2rem 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.housing-name:focus {
  outline: none;
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  margin-left: -0.4rem;
}

.housing-name::placeholder { color: var(--text-secondary); opacity: 0.6; }

.housing-badges {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.cheapest-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--brand-teal);
  border-radius: 99px;
}

.housing-actions {
  display: flex;
  gap: 0.15rem;
  flex-shrink: 0;
}

.hc-btn {
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease, color 0.12s ease;
}

.hc-btn:active { background: var(--surface-hover); }
.hc-del:active { color: var(--danger); background: var(--run-warm-bg); }

/* ==================== Hero / summary ==================== */

.hero {
  padding: 0.25rem 1rem 1rem;
}

.hero-main {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hero-value {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.housing.cheapest .hero-value {
  color: var(--brand-teal);
}

.hero-unit {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.hero-diff {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 99px;
  font-variant-numeric: tabular-nums;
}

.hero-diff--more {
  color: var(--danger);
  background: var(--run-warm-bg);
}

.hero-diff--less {
  color: var(--brand-teal);
  background: var(--brand-teal-soft);
}

/* ==================== Split bar ==================== */

.split-wrap {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.split-bar {
  display: flex;
  height: 0.4rem;
  border-radius: 99px;
  overflow: hidden;
  background: var(--surface-2);
}

.split-seg {
  height: 100%;
  transition: flex 0.25s ease;
}

.split-seg--p1 { background: var(--accent); }
.split-seg--p2 { background: var(--brand-teal); }

.split-legend {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.split-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.split-item--right { text-align: right; align-items: flex-end; }

.si-name {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.si-name::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.split-item--right .si-name::before { background: var(--brand-teal); }

.si-val {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ==================== Mini stat strip ==================== */

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 0 1rem 0.85rem;
  background: var(--divider);
  border-radius: var(--radius-xs);
  overflow: hidden;
}

.strip-cell {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0.65rem;
  background: var(--surface-2);
}

.strip-label {
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strip-val {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==================== Input fields ==================== */

.fields {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.5rem 0.75rem;
}

.field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-xs);
  transition: background 0.15s ease;
}

.field:hover { background: var(--surface-2); }
.field:focus-within { background: var(--surface-2); }

.field-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  flex: 0 0 5.5rem;
}

.field-input {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  min-width: 0;
}

.field-input input {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding: 0.3rem 0;
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: right;
  color: var(--text-primary);
  border: none;
  background: transparent;
  font-variant-numeric: tabular-nums;
  touch-action: manipulation;
  border-radius: 4px;
}

.field-input input:focus {
  outline: none;
  color: var(--accent);
}

.field-input input::placeholder {
  color: var(--text-secondary);
  opacity: 0.45;
  font-weight: 500;
}

.field-input input::-webkit-outer-spin-button,
.field-input input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.field-input input[type="number"] {
  -moz-appearance: textfield;
}

.field-suffix {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 1rem;
  text-align: left;
}

/* ==================== Add button ==================== */

.add-wrap {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 0 0;
  flex-wrap: wrap;
}

.add-housing-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.3rem;
  min-height: 2.75rem;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 99px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(47, 107, 255, 0.26);
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.15s ease, transform 0.1s ease, background 0.15s ease;
}

.add-housing-btn:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(47, 107, 255, 0.22);
}

.add-housing-btn .plus {
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1;
  opacity: 0.9;
}

.add-housing-btn--ghost {
  color: var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.add-housing-btn--ghost:active {
  background: var(--accent-soft);
  box-shadow: var(--shadow-xs);
}

/* ==================== Desktop ==================== */

@media (min-width: 640px) {
  .page-boende .app-container {
    max-width: 72rem;
    margin: 0 auto;
    padding-top: 2.5rem;
  }

  .settings-bar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    padding: 1.15rem 1.35rem;
    max-width: 52rem;
    margin-left: auto;
    margin-right: auto;
  }

  .s-row {
    flex: 1 1 auto;
    min-width: 12rem;
  }

  .overview {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.85rem;
  }

  .kpi--wide { grid-column: auto; }

  .kpi {
    padding: 1rem 1.1rem;
  }

  .kpi-value { font-size: 1.5rem; }

  .housings {
    grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
    gap: 1rem;
  }

  .add-housing-btn:hover {
    box-shadow: var(--shadow-md);
  }
}

@media (min-width: 900px) {
  .settings-bar { max-width: 60rem; }
}
