/* Home: the signed-in landing screen (#welcomeScreen), inside the app
   shell (shell.css, which also defines the --h-* palette, the sidebar and
   the account menu).

   Layout by width:
     >= 1280px   two columns (hero + shortcuts | overview + activity)
     < 1280px    one column: hero, overview, shortcuts, activity */

#welcomeScreen {
  --h-side-w: 380px;
  --h-max: 1680px; /* Home's max width; centred beyond this */
  /* Home's cards sit over the photo, so they're more solid than the
     defaults in shell.css; the photo should read as a backdrop. */
  --h-tile: rgba(13, 38, 35, 0.86);
  --h-tile-hover: rgba(19, 50, 46, 0.94);
  position: relative; isolation: isolate;
  overflow-x: hidden;
  /* Always at least a full window tall, so the photo behind it can be too. */
  min-height: 100vh; min-height: 100dvh;
}

/* The photo sits behind the hero and ends under the right-hand column, so
   the stethoscope lands between the greeting and the panels. It runs the
   full height of Home and scales with it, so big screens get a bigger
   photo, and fades fully into the background on its right and bottom
   edges so there's never a visible seam. */
.home-hero-bg {
  position: absolute; z-index: -1;
  top: 0; left: 0;
  /* Ends under the right-hand column, wherever the centred grid puts it. */
  right: calc(max(0px, (100% - var(--h-max)) / 2) + var(--h-side-w) - 40px);
  bottom: 0;
  background: url('../assets/img/welcome-hero.webp') 88% 40% / cover no-repeat;
}
.home-hero-bg::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(90deg, var(--h-bg) 0%, rgba(7, 24, 23, 0.72) 24%, rgba(7, 24, 23, 0.1) 52%, rgba(7, 24, 23, 0) 72%, var(--h-bg) 100%),
    linear-gradient(180deg, rgba(7, 24, 23, 0.25) 0%, rgba(7, 24, 23, 0) 22%, rgba(7, 24, 23, 0.3) 40%, rgba(7, 24, 23, 0.5) 65%, var(--h-bg) 100%);
}

/* ---------- Grid ---------- */
.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--h-side-w);
  grid-template-rows: auto 1fr auto auto;
  grid-template-areas:
    "hero    side"
    ".       side"
    "actions side"
    "footer  footer";
  column-gap: 40px;
  max-width: var(--h-max); margin-inline: auto;
  padding: 92px 32px 28px 56px;
}
.home-hero { grid-area: hero; padding-top: 44px; padding-bottom: 40px; }
.home-side { grid-area: side; display: flex; flex-direction: column; gap: 20px; }
.home-actions { grid-area: actions; container: actions / inline-size; }
.home-footer { grid-area: footer; }

/* ---------- Hero ---------- */
.home-hero h1 {
  margin: 0; max-width: 14em;
  font-family: var(--h-font-display); font-weight: 600;
  font-size: 3.25rem; line-height: 1.06; letter-spacing: -0.025em;
  text-wrap: balance;
}
.home-place { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin-top: 14px; }
.home-clinic { font-size: 19px; color: var(--h-text-soft); }
.home-lead { margin: 24px 0 0; max-width: 28em; font-size: 17px; line-height: 1.6; color: var(--h-text-soft); }

/* ---------- Panels ---------- */
.home-panel {
  background: var(--h-panel);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid var(--h-line);
  border-radius: 16px;
  padding: 20px 22px;
}
.home-panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.home-panel h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.home-panel-meta { font-size: 14px; color: var(--h-text-soft); }
.home-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--h-teal); font-size: 14px; font-weight: 500;
  transition: color 150ms ease;
}
.home-link svg { width: 16px; height: 16px; transition: transform 200ms var(--h-ease-out); }
@media (hover: hover) and (pointer: fine) {
  .home-link:hover { color: var(--h-teal-bright); }
  .home-link:hover svg { transform: translateX(3px); }
}

/* Today's overview */
.home-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.home-stat {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 18px 8px 16px;
  background: var(--h-tile); border: 1px solid var(--h-line); border-radius: 14px;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 160ms var(--h-ease-out);
}
.home-stat-icon { width: 26px; height: 26px; color: var(--h-teal-bright); }
.home-stat-num {
  display: block; min-width: 1ch; height: 34px; margin-top: 10px;
  font-size: 31px; font-weight: 600; line-height: 34px;
  font-variant-numeric: tabular-nums; color: var(--h-text);
}
.home-stat-label { margin-top: 6px; font-size: 13px; color: var(--h-text-soft); white-space: nowrap; }
.home-stat-note {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 18px; margin-top: 8px;
  font-size: 12.5px; font-weight: 500; color: var(--h-text-muted);
}
.home-stat-note svg { display: none; width: 13px; height: 13px; stroke-width: 2.25; }
.home-stat[data-tone="up"] .home-stat-note { color: var(--h-teal-bright); }
.home-stat[data-tone="up"] .home-stat-note svg { display: block; }
.home-stat[data-tone="ok"] .home-stat-note { color: var(--h-teal); }
.home-stat[data-tone="warning"] { background: var(--h-amber-wash); border-color: var(--h-amber-line); }
.home-stat[data-tone="warning"] .home-stat-icon,
.home-stat[data-tone="warning"] .home-stat-note { color: var(--h-amber); }
.home-stat[data-tone="critical"] { background: var(--h-coral-wash); border-color: var(--h-coral-line); }
.home-stat[data-tone="critical"] .home-stat-icon,
.home-stat[data-tone="critical"] .home-stat-note { color: var(--h-coral); }
.home-stat:active { transform: scale(0.98); }
.home-stat.is-loading .home-stat-num {
  width: 34px; border-radius: 8px; background: rgba(238, 246, 245, 0.07);
  animation: homePulse 1.4s ease-in-out infinite;
}
@media (hover: hover) and (pointer: fine) {
  .home-stat:hover { border-color: var(--h-line-strong); background: var(--h-tile-hover); }
  .home-stat[data-tone="warning"]:hover { border-color: var(--h-amber); background: rgba(232, 185, 104, 0.15); }
  .home-stat[data-tone="critical"]:hover { border-color: var(--h-coral); background: rgba(242, 147, 139, 0.15); }
}

/* Recent activity */
.home-activity { display: flex; flex-direction: column; }
.home-activity-list { list-style: none; margin: 10px 0 0; padding: 0; }
.home-activity-row {
  display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 12px 0;
}
.home-activity-row + .home-activity-row { border-top: 1px solid var(--h-line); }
.home-activity-icon {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 999px;
  background: var(--h-teal-wash); color: var(--h-teal-bright);
}
.home-activity-icon svg { width: 18px; height: 18px; }
.home-activity-row[data-kind="alert"] .home-activity-icon { background: var(--h-coral-wash); color: var(--h-coral); }
.home-activity-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.home-activity-title {
  font-size: 14.5px; font-weight: 600; color: var(--h-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.home-activity-actor { font-weight: 400; color: var(--h-text-muted); }
.home-activity-detail {
  font-size: 13px; line-height: 1.45; color: var(--h-text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.home-activity-item { color: var(--h-text-soft); }
.home-activity-time {
  align-self: start; padding-top: 2px;
  font-size: 12.5px; color: var(--h-text-muted); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.home-activity-row.is-skeleton .home-activity-icon { background: rgba(238, 246, 245, 0.06); }
.home-activity-row.is-skeleton .sk {
  display: block; height: 11px; border-radius: 6px; background: rgba(238, 246, 245, 0.07);
  animation: homePulse 1.4s ease-in-out infinite;
}
.home-activity-row.is-skeleton .sk-title { width: 42%; }
.home-activity-row.is-skeleton .sk-detail { width: 72%; margin-top: 4px; }
.home-activity-empty { padding: 26px 2px 8px; }
.home-activity-empty p { margin: 0; font-size: 13.5px; line-height: 1.55; color: var(--h-text-muted); max-width: 34ch; }
.home-activity-empty .home-activity-empty-title { margin-bottom: 4px; font-size: 15px; font-weight: 600; color: var(--h-text); }
.home-activity-empty .home-link { margin-top: 14px; }

/* ---------- Shortcuts ---------- */
.home-actions-grid {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 14px;
}
.home-action {
  display: grid; grid-template-rows: auto auto 1fr auto; justify-items: start;
  min-height: 212px; padding: 20px 18px 18px;
  background: var(--h-tile); border: 1px solid var(--h-line); border-radius: 14px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  text-align: left; cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 160ms var(--h-ease-out);
}
.home-action-icon {
  display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 999px;
  background: var(--h-teal-wash); color: var(--h-teal-bright);
}
.home-action-icon svg { width: 22px; height: 22px; }
.home-action-title { margin-top: 18px; font-size: 15.5px; font-weight: 600; color: var(--h-text); }
.home-action-desc { margin-top: 6px; font-size: 13px; line-height: 1.5; color: var(--h-text-muted); }
.home-action-arrow {
  width: 20px; height: 20px; margin-top: 16px; color: var(--h-text-soft);
  transition: transform 200ms var(--h-ease-out), color 150ms ease;
}
.home-action:active { transform: scale(0.98); }
@media (hover: hover) and (pointer: fine) {
  .home-action:hover { border-color: var(--h-line-strong); background: var(--h-tile-hover); }
  .home-action:hover .home-action-arrow { transform: translateX(4px); color: var(--h-teal-bright); }
}
.home-device-only { display: none; }
#welcomeScreen.is-device .home-device-only { display: grid; }

/* Too narrow for five tiles: switch to compact rows */
@container actions (max-width: 700px) {
  .home-actions-grid { grid-auto-flow: row; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .home-action {
    grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: auto auto;
    column-gap: 14px; align-items: center;
    min-height: 0; padding: 14px 16px;
  }
  .home-action-icon { grid-row: 1 / 3; width: 40px; height: 40px; }
  .home-action-icon svg { width: 19px; height: 19px; }
  .home-action-title { grid-column: 2; margin-top: 0; }
  .home-action-desc { grid-column: 2; margin-top: 2px; }
  .home-action-arrow { grid-column: 3; grid-row: 1 / 3; margin-top: 0; }
}

/* ---------- Footer ---------- */
.home-footer {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin: 28px 0 0; font-size: 13px; color: var(--h-text-muted);
}
.home-footer svg { width: 17px; height: 17px; color: var(--h-teal); margin-right: 4px; }
.home-footer span + span::before { content: "·"; margin-right: 6px; }

/* ---------- Motion ---------- */
@keyframes homeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes homePulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
/* First visit per sign-in only (see playHomeIntro in home.js). */
.home-intro .home-hero,
.home-intro .home-overview,
.home-intro .home-activity,
.home-intro .home-actions { animation: homeIn 480ms var(--h-ease-out) both; }
.home-intro .home-overview { animation-delay: 60ms; }
.home-intro .home-activity,
.home-intro .home-actions { animation-delay: 120ms; }

@media (prefers-reduced-transparency: reduce) {
  #welcomeScreen { --h-tile: #0d2623; --h-tile-hover: #13322e; --h-panel: #0a1f1d; }
  .home-panel, .home-action { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  #welcomeScreen *, #welcomeScreen *::before, #welcomeScreen *::after {
    animation: none !important; transition-duration: 0.01ms !important;
  }
}

/* ---------- Responsive ---------- */

/* Icon-rail widths: a little less room for the right-hand column */
@media (max-width: 1499px) {
  #welcomeScreen { --h-side-w: 372px; }
  .home-stat { padding-left: 4px; padding-right: 4px; }
  .home-stat-label { font-size: 12.5px; }
  .home-grid { padding-left: 44px; padding-right: 28px; }
}

/* One column: hero, overview, shortcuts, activity */
@media (max-width: 1279px) {
  .home-hero-bg { right: 0; bottom: auto; height: 560px; background-position: 82% 45%; }
  .home-hero-bg::after {
    background:
      linear-gradient(90deg, var(--h-bg) 0%, rgba(7, 24, 23, 0.78) 34%, rgba(7, 24, 23, 0.15) 75%, rgba(7, 24, 23, 0.3) 100%),
      linear-gradient(180deg, rgba(7, 24, 23, 0) 40%, var(--h-bg) 100%);
  }
  .home-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "hero" "overview" "actions" "activity" "footer";
    row-gap: 20px;
    padding-top: 76px;
  }
  .home-side { display: contents; }
  .home-overview { grid-area: overview; }
  .home-activity { grid-area: activity; }
  .home-hero { padding-top: 24px; padding-bottom: 16px; }
  .home-footer { margin-top: 8px; }
}

/* Phone */
@media (max-width: 767px) {
  .home-hero-bg { height: 420px; background-image: url('../assets/img/welcome-hero-960.webp'); background-position: 78% 50%; }
  .home-grid { padding: 8px 16px 24px; row-gap: 16px; }
  .home-hero { padding-top: 28px; padding-bottom: 12px; }
  .home-hero h1 { font-size: 2.25rem; }
  .home-clinic { font-size: 16.5px; }
  .home-lead { margin-top: 16px; font-size: 15.5px; }
  .home-panel { padding: 16px; }
  .home-stats { gap: 8px; margin-top: 14px; }
  .home-stat { padding: 14px 4px 12px; }
  .home-stat-icon { width: 22px; height: 22px; }
  .home-stat-num { font-size: 25px; height: 30px; line-height: 30px; margin-top: 8px; }
  .home-stat-label { font-size: 12px; }
  .home-stat-note { font-size: 11.5px; }
  .home-footer { justify-content: center; }
}

/* Expiring soon: same rows as Recent activity, red for expired or within a
   month, amber within two months. */
.home-expiring[hidden] { display: none; }
.home-expiring-lead { margin: 6px 0 0; font-size: 13px; color: var(--h-text-soft); }
.home-expiring-row .home-activity-icon { background: var(--h-amber-wash); color: var(--h-amber); }
.home-expiring-row[data-tone="soon"] .home-activity-icon,
.home-expiring-row[data-tone="expired"] .home-activity-icon { background: var(--h-coral-wash); color: var(--h-coral); }
.home-expiring-row[data-tone="soon"] .home-activity-time,
.home-expiring-row[data-tone="expired"] .home-activity-time { color: var(--h-coral); }
.home-expiring-more { padding: 8px 0 0; }
