/*
 * Home screen: the greeting hero with the company logo, four stat cards, and the module cards
 * as a 4-column grid (or a list). The shared `.hero` pieces the module screens reuse
 * (`.hero-date`, `.hero-controls`, the estate picker pill) live here too.
 */

.home {
  display: flex;
  flex-direction: column;
}

/* ---- Hero ----------------------------------------------------------------------------- */

.hero {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 134px;
  padding: 20px 24px;
  border-radius: var(--r-lg);
  overflow: hidden;
  color: var(--on-dark);
  background:
    url("../assets/hero.jpg") center / cover no-repeat,
    url("../assets/hero.svg") center / cover no-repeat,
    linear-gradient(90deg, #0f2a22, #2b7a58);
  isolation: isolate;
}

/* Darken the left so the title reads over any photo. */
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(90deg, rgba(9, 28, 21, 0.86) 0%, rgba(9, 28, 21, 0.62) 40%, rgba(9, 28, 21, 0.22) 75%, rgba(9, 28, 21, 0.4) 100%);
}

.hero--home {
  min-height: 168px;
  gap: 24px;
  padding: 26px 34px;
}

.hero--home .hero-text {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.hero--home .hero-title {
  font-size: clamp(1.625rem, 2.4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.hero-wave {
  display: inline-block;
  margin-left: 10px;
}

.hero-lead {
  max-width: 560px;
  font-size: var(--fs-18);
  font-weight: 500;
  line-height: 1.4;
  opacity: 0.95;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

.hero-logo {
  flex: none;
  margin-left: auto;
  width: clamp(150px, 14vw, 230px);
  height: auto;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.4));
}

.hero-leaf {
  width: 62px;
  height: 62px;
  color: var(--leaf);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.hero-title {
  font-size: var(--fs-34);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.hero-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hero-date {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-16);
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

.hero-date .icon {
  width: 22px;
  height: 22px;
}

.estate-picker {
  position: relative;
}

.estate-picker .pill--glass {
  min-height: 48px;
  padding: 0 16px 0 18px;
  font-size: var(--fs-16);
}

.estate-picker .pill--glass .icon {
  width: 20px;
  height: 20px;
}

.estate-picker .pill--glass .chev {
  width: 18px;
  height: 18px;
  margin-left: 2px;
}

/* ---- Stat cards ----------------------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  min-height: 100px;
}

.stat--link {
  color: inherit;
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.stat--link:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

.stat .tile-icon {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  background: #eaf8ec;
  color: #1e7920;
}

.stat .tile-icon--amber {
  background: #fff6e0;
  color: #f28c0a;
}

.stat .tile-icon .icon {
  width: 30px;
  height: 30px;
}

.stat-body {
  min-width: 0;
}

.stat-label {
  color: #68717a;
  font-size: var(--fs-16);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 2px;
}

.stat-number {
  font-size: var(--fs-28);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.stat-unit {
  font-size: var(--fs-18);
  font-weight: 600;
  color: var(--ink-2);
}

.badge--up {
  padding-left: 0;
  color: #1e7920;
  font-weight: 700;
}

.badge--up .icon {
  width: 16px;
  height: 16px;
}

/* ---- Modules -------------------------------------------------------------------------- */

.view-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.view-btn {
  display: grid;
  place-items: center;
  width: 46px;
  height: 36px;
  border-radius: 8px;
  color: var(--ink-3);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.view-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.view-btn[aria-pressed="true"] {
  background: #0f7a3a;
  color: #fff;
}

.view-btn .icon {
  width: 20px;
  height: 20px;
}

.modules {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.module {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "tile tile"
    "text arrow";
  align-items: center;
  column-gap: 12px;
  width: 100%;
  min-height: 138px;
  padding: 18px 20px 20px;
  text-align: left;
  overflow: clip;
  background: var(--surface);
  border-color: #e9eeee;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

/* The soft green sweep across the bottom-right corner. */
.module::after {
  content: "";
  position: absolute;
  right: -90px;
  bottom: -118px;
  width: 280px;
  height: 180px;
  border-radius: 50%;
  background: #e8f5e7;
  transform: rotate(-16deg);
  pointer-events: none;
}

.module > * {
  position: relative;
  z-index: 1;
}

.module-tile {
  grid-area: tile;
  width: 46px;
  height: 46px;
  margin-bottom: 14px;
  border-radius: 12px;
  background: #e6f6e9;
  color: #1e7920;
}

.module-tile .icon {
  width: 24px;
  height: 24px;
}

.module-text {
  grid-area: text;
  min-width: 0;
}

.module-title {
  font-size: var(--fs-20);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.module-tagline {
  margin-top: 4px;
  color: #5b6670;
  font-size: var(--fs-15);
  font-weight: 500;
  line-height: 1.3;
}

.module-arrow {
  grid-area: arrow;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e9f5eb;
  color: #1e7920;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.module-arrow .icon {
  width: 22px;
  height: 22px;
}

.module:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: #cfe6d4;
}

.module:hover .module-arrow {
  background: #0f7a3a;
  color: #fff;
  transform: translateX(2px);
}

.module:focus-visible {
  box-shadow: var(--focus);
}

.modules-empty {
  grid-column: 1 / -1;
  padding: 24px 0;
  color: var(--ink-2);
}

/* List view: one row per module. */
.modules--list {
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.modules--list .module {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "tile text arrow";
  column-gap: 16px;
  min-height: 0;
  padding: 12px 16px;
}

.modules--list .module::after {
  display: none;
}

.modules--list .module-tile {
  margin: 0;
}

.modules--list .module-title {
  font-size: var(--fs-18);
}

.modules--list .module-tagline {
  margin-top: 2px;
  font-size: var(--fs-14);
}

/* ---- Responsive ----------------------------------------------------------------------- */

@media (max-width: 1399.98px) {
  .module {
    padding: 16px 18px 18px;
    min-height: 128px;
  }

  .module-title {
    font-size: var(--fs-18);
  }

  .module-tagline {
    font-size: var(--fs-14);
  }
}

@media (max-width: 1199.98px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .modules {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }

  .hero--home {
    padding: 22px 26px;
  }

  .hero-lead {
    font-size: var(--fs-16);
  }

  .hero-logo {
    width: clamp(120px, 16vw, 180px);
  }

  .hero-title {
    font-size: var(--fs-28);
  }
}

@media (max-width: 899.98px) {
  .hero {
    flex-wrap: wrap;
    padding: 18px 18px 16px;
    min-height: 0;
  }

  .hero--home {
    gap: 14px;
    padding: 20px 18px;
  }

  .hero--home .hero-title {
    font-size: var(--fs-24);
  }

  .hero-lead {
    font-size: var(--fs-15);
  }

  .hero-logo {
    width: 120px;
    margin-left: 0;
  }

  .hero-leaf {
    width: 44px;
    height: 44px;
  }

  .hero-title {
    font-size: var(--fs-24);
  }

  .hero-controls {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }

  .estate-picker .pill--glass {
    min-height: 44px;
    font-size: var(--fs-15);
  }

  .modules {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-title {
    font-size: var(--fs-20);
  }

  .stat {
    padding: 14px 16px;
    gap: 14px;
    min-height: 0;
  }

  .stat .tile-icon {
    width: 46px;
    height: 46px;
  }

  .stat .tile-icon .icon {
    width: 24px;
    height: 24px;
  }

  .stat-label {
    font-size: var(--fs-14);
    white-space: normal;
  }

  .stat-number {
    font-size: var(--fs-22, 1.375rem);
  }

  .stat-unit {
    font-size: var(--fs-15);
  }
}

/* Phones: every card is a row, whichever view is chosen. */
@media (max-width: 639.98px) {
  .hero--home .hero-text {
    width: 100%;
  }

  .hero-logo {
    width: 110px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat .badge {
    white-space: normal;
    text-align: left;
  }

  .stat {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
  }

  .stat-value {
    gap: 2px 8px;
  }

  .modules {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .module {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "tile text arrow";
    column-gap: 14px;
    min-height: 0;
    padding: 12px 14px;
  }

  .module::after {
    display: none;
  }

  .module-tile {
    margin: 0;
    width: 42px;
    height: 42px;
  }

  .module-tile .icon {
    width: 22px;
    height: 22px;
  }

  .module-title {
    font-size: var(--fs-16);
  }

  .module-tagline {
    margin-top: 2px;
    font-size: var(--fs-13);
  }

  .module-arrow {
    width: 36px;
    height: 36px;
  }

  .hero-date {
    font-size: var(--fs-14);
  }
}

/* ---- One-screen fit --------------------------------------------------------------------
 * On landscape layouts (desktops, laptops, tablets held sideways) a fit screen takes exactly
 * the viewport: the frame is one viewport tall and the main area takes what the top bar
 * leaves. On Home the hero and stats take what they need and the module grid shares the rest,
 * scrolling inside itself only when the screen is too short for its rows.
 */
@media (min-width: 900px) and (min-height: 560px) {
  .frame:has(.main.is-fit) {
    height: 100dvh;
    overflow: hidden;
  }

  .main.is-fit {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-top: clamp(10px, 2.2vh, 24px);
    padding-bottom: clamp(10px, 2.2vh, 24px);
  }

  .main.is-fit .home {
    flex: 1;
    min-height: 0;
  }

  /* Hero */
  .main.is-fit .hero--home {
    flex: none;
    min-height: 0;
    height: clamp(84px, 16vh, 180px);
    padding: 8px clamp(16px, 2vw, 34px);
    gap: clamp(10px, 1.4vw, 24px);
  }

  .main.is-fit .hero--home .hero-text {
    gap: clamp(2px, 0.8vh, 10px);
  }

  .main.is-fit .hero--home .hero-title {
    font-size: clamp(1.25rem, 3.6vh, 2.5rem);
  }

  .main.is-fit .hero-lead {
    font-size: clamp(0.8125rem, 1.8vh, 1.125rem);
    line-height: 1.3;
  }

  .main.is-fit .hero-logo {
    width: clamp(110px, 20vh, 230px);
  }

  /* Stats */
  .main.is-fit .stats {
    flex: none;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(8px, 1.4vh, 18px);
    margin-top: clamp(8px, 1.4vh, 18px);
  }

  .main.is-fit .stat {
    min-height: 0;
    padding: clamp(8px, 1.4vh, 20px) clamp(12px, 1.3vw, 22px);
    gap: clamp(8px, 1.1vw, 18px);
  }

  .main.is-fit .stat .tile-icon {
    width: clamp(32px, 6vh, 60px);
    height: clamp(32px, 6vh, 60px);
  }

  .main.is-fit .stat .tile-icon .icon {
    width: clamp(18px, 3vh, 30px);
    height: clamp(18px, 3vh, 30px);
  }

  .main.is-fit .stat-label {
    font-size: clamp(0.75rem, 1.6vh, 1rem);
  }

  .main.is-fit .stat-number {
    font-size: clamp(1rem, 2.8vh, 1.75rem);
  }

  .main.is-fit .stat-unit {
    font-size: clamp(0.8125rem, 1.8vh, 1.125rem);
  }

  .main.is-fit .badge {
    font-size: clamp(0.6875rem, 1.4vh, 0.8125rem);
  }

  /* Section head */
  .main.is-fit .section-head {
    flex: none;
    margin: clamp(8px, 1.8vh, 24px) 0 clamp(6px, 1.2vh, 16px);
    gap: 6px 16px;
  }

  .main.is-fit .section-title {
    font-size: clamp(1rem, 2.6vh, 1.625rem);
  }

  .main.is-fit .view-btn {
    width: clamp(36px, 5vh, 46px);
    height: clamp(28px, 4vh, 36px);
  }

  /* Module grid: the rows share what is left, on one screen, however many cards there are. The
   * grid has three rows (the design), so 12 cards make 4 columns and 14 make 5; each card is a
   * size container and drops its description, then its tile, when its row gets short. */
  .main.is-fit .modules {
    container-type: size;
    container-name: modules;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    gap: clamp(8px, 1.4vh, 18px);
  }

  .main.is-fit .module {
    container-type: size;
    container-name: card;
    min-height: 0;
    padding: clamp(6px, 1.4vh, 20px) clamp(10px, 1.2vw, 20px) clamp(6px, 1.5vh, 20px);
    column-gap: 8px;
  }

  .main.is-fit .module-tile {
    width: clamp(28px, 5vh, 46px);
    height: clamp(28px, 5vh, 46px);
    margin-bottom: clamp(4px, 1.2vh, 14px);
  }

  .main.is-fit .module-tile .icon {
    width: clamp(16px, 2.6vh, 24px);
    height: clamp(16px, 2.6vh, 24px);
  }

  .main.is-fit .module-title {
    font-size: clamp(0.8125rem, 2vh, 1.25rem);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .main.is-fit .module-tagline {
    margin-top: clamp(1px, 0.4vh, 4px);
    font-size: clamp(0.75rem, 1.5vh, 0.9375rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main.is-fit .module-arrow {
    width: clamp(26px, 4.4vh, 40px);
    height: clamp(26px, 4.4vh, 40px);
  }

  /* Short rows: the tile moves beside the title and the description goes. */
  @container modules (max-height: 350px) {
    .main.is-fit .module {
      grid-template-columns: auto minmax(0, 1fr) auto;
      grid-template-areas: "tile text arrow";
      column-gap: 10px;
    }

    .main.is-fit .module-tile {
      margin: 0;
      width: 32px;
      height: 32px;
    }

    .main.is-fit .module-tile .icon {
      width: 18px;
      height: 18px;
    }

    .main.is-fit .module-title {
      font-size: clamp(0.75rem, 1.9vh, 0.9375rem);
      line-height: 1.2;
      overflow-wrap: anywhere;
      -webkit-line-clamp: 3;
    }

    .main.is-fit .module-tagline {
      display: none;
    }
  }

  @container card (max-height: 100px) {
    .module-tagline {
      display: none;
    }

    .module-tile {
      margin-bottom: 4px;
    }
  }

  /* The list view: compact rows at their own height (never squeezed to fit), running down two
   * columns so all fourteen sit on one screen; a scroll inside only when the screen is too short. */
  .main.is-fit .modules--list {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 2px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(var(--list-rows, 7), max-content);
    grid-auto-rows: max-content;
    grid-auto-flow: column;
    align-content: start;
    gap: clamp(4px, 0.8vh, 10px);
  }

  .main.is-fit .modules--list .module {
    container-type: normal;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "tile text arrow";
    column-gap: 14px;
    padding: clamp(3px, 0.7vh, 10px) 16px;
  }

  .main.is-fit .modules--list .module-tile {
    margin: 0;
    width: clamp(32px, 4.4vh, 42px);
    height: clamp(32px, 4.4vh, 42px);
  }

  .main.is-fit .modules--list .module-title {
    font-size: clamp(0.875rem, 1.8vh, 1.0625rem);
    -webkit-line-clamp: 1;
  }

  .main.is-fit .modules--list .module-tagline {
    display: block;
    margin-top: 0;
    font-size: clamp(0.75rem, 1.4vh, 0.875rem);
  }

  .main.is-fit .modules--list .module-arrow {
    width: clamp(26px, 3.6vh, 34px);
    height: clamp(26px, 3.6vh, 34px);
  }
}


@media (min-width: 900px) and (max-width: 1199.98px) and (min-height: 560px) {
  .main.is-fit .modules:not(.modules--list) {
    grid-template-columns: repeat(var(--cols-narrow, 4), minmax(0, 1fr));
  }
}
