/* ══════════════════════════════════════════════════════════════
   APPS SHOWCASE  (homepage "Our Applications" section)
   Loaded after index.css and reuses its design tokens
   (--green-deep, --gold, --ivory, --font-display, etc.).
   Every selector is prefixed .apps- / .app- so nothing here can
   collide with existing page styles.
   ══════════════════════════════════════════════════════════════ */

.apps-section {
  background: var(--ivory, #f5f0e8);
  padding: 7rem 3rem;
  position: relative;
  scroll-margin-top: var(--nav-h, 72px);
}

.apps-inner {
  max-width: 1160px;
  margin: 0 auto;
}

/* ── Header ───────────────────────────────────────────────── */
.apps-header {
  max-width: 720px;
  margin-bottom: 3.2rem;
}

.apps-header h2 {
  font-family: var(--font-display, Georgia, serif);
  font-size: clamp(2.2rem, 4vw, 3.5rem);
  font-weight: 700;
  color: var(--green-deep, #0a3d2e);
  line-height: 1.1;
  margin-bottom: 1.2rem;
}

.apps-header h2 em {
  font-style: italic;
  color: var(--green-light, #2d7a58);
}

.apps-lead {
  font-size: 1.02rem;
  line-height: 1.8;
  color: #55665a;
}

/* ── Application cards ────────────────────────────────────── */
.apps-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.app-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--white, #ffffff);
  border: 1px solid rgba(10, 61, 46, 0.1);
  border-radius: 4px;
  padding: 2.5rem;
  overflow: hidden;
  transition: transform 0.4s ease, box-shadow 0.4s ease, border-color 0.4s ease;
}

/* Gold accent line along the top edge */
.app-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold, #c9a84c), var(--gold-light, #e8c97b));
}

.app-card:hover {
  transform: translateY(-4px);
  border-color: rgba(201, 168, 76, 0.55);
  box-shadow: 0 18px 40px rgba(10, 61, 46, 0.12);
}

.app-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.app-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--green-deep, #0a3d2e);
  font-size: 1.6rem;
  line-height: 1;
}

.app-badge {
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7a5f14;
  background: rgba(201, 168, 76, 0.16);
  border: 1px solid rgba(201, 168, 76, 0.4);
  border-radius: 2px;
  padding: 0.32rem 0.7rem;
  white-space: nowrap;
}

.app-card h3 {
  font-family: var(--font-display, Georgia, serif);
  font-size: clamp(1.3rem, 2.5vw, 1.7rem);
  font-weight: 700;
  color: var(--green-deep, #0a3d2e);
  line-height: 1.2;
  margin: 1.6rem 0 0.9rem;
}

.app-card p {
  font-size: 0.92rem;
  line-height: 1.75;
  color: #55665a;
  margin-bottom: 1.4rem;
}

.app-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1.8rem;
}

.app-tag {
  font-size: 0.66rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--green-mid, #1a5c42);
  border: 1px solid rgba(10, 61, 46, 0.2);
  border-radius: 2px;
  padding: 0.28rem 0.65rem;
}

/* Buttons sit at the bottom of the card so both cards line up */
.app-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: auto;
}

.app-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.8rem 1.6rem;
  border: 2px solid var(--gold, #c9a84c);
  border-radius: 2px;
  font-family: var(--font-body, sans-serif);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s ease;
}

.app-btn-primary {
  background: var(--gold, #c9a84c);
  color: var(--green-deep, #0a3d2e);
}

.app-btn-primary:hover {
  background: var(--gold-light, #e8c97b);
  border-color: var(--gold-light, #e8c97b);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(201, 168, 76, 0.35);
}

.app-btn-secondary {
  background: transparent;
  border-color: var(--green-deep, #0a3d2e);
  color: var(--green-deep, #0a3d2e);
}

.app-btn-secondary:hover {
  background: var(--green-deep, #0a3d2e);
  color: var(--white, #ffffff);
}

.app-btn:focus-visible,
.app-preview-btn:focus-visible {
  outline: 3px solid var(--green-light, #2d7a58);
  outline-offset: 2px;
}

/* ── Live preview panel ───────────────────────────────────── */
.app-preview {
  margin-top: 2rem;
  background: var(--white, #ffffff);
  border: 1px solid rgba(10, 61, 46, 0.18);
  border-radius: 6px;
  box-shadow: 0 24px 60px rgba(10, 61, 46, 0.14);
  overflow: hidden;
  scroll-margin-top: calc(var(--nav-h, 72px) + 16px);
}

.app-preview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem 1rem;
  padding: 0.7rem 1rem;
  background: var(--green-deep, #0a3d2e);
  color: rgba(255, 255, 255, 0.85);
}

.app-preview-dots {
  display: inline-flex;
  gap: 0.4rem;
}

.app-preview-dots i {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
}

.app-preview-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.app-preview-btn {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0.45rem 0.85rem;
  background: transparent;
  border: 1px solid rgba(232, 201, 123, 0.5);
  border-radius: 2px;
  color: var(--gold-light, #e8c97b);
  font-family: var(--font-body, sans-serif);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.25s ease;
}

.app-preview-btn:hover {
  background: rgba(232, 201, 123, 0.14);
}

/*
  The frame has a fixed, viewport-relative height on purpose.
  CareHub uses fixed-position headers, drawers and modals; those
  need a viewport-sized frame to sit in the right place. Letting the
  frame grow to the full page height would push them off-screen.
  The app scrolls inside the frame, like any embedded app.
*/
.app-preview-frame {
  position: relative;
  height: clamp(560px, 85vh, 900px);
  background: var(--ivory, #f5f0e8);
}

@supports (height: 1svh) {
  .app-preview-frame {
    height: clamp(560px, 85svh, 900px);
  }
}

.app-preview-frame iframe {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--white, #ffffff);
}

/* Sits behind the iframe; visible only until CareHub paints */
.app-preview-loading {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-accent, Georgia, serif);
  font-size: 1.25rem;
  font-style: italic;
  color: var(--text-muted, #6b7c6e);
}

.app-preview-note {
  padding: 0.7rem 1rem;
  border-top: 1px solid rgba(10, 61, 46, 0.1);
  font-size: 0.78rem;
  color: #55665a;
}

.app-preview-note a {
  color: var(--green-mid, #1a5c42);
  font-weight: 600;
}

/* Friendly message shown instead of the browser's blank "sad page" icon
   if the preview frame is ever refused. */
.app-preview-fallback {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 2rem 1.2rem;
  text-align: center;
  background: var(--ivory, #f5f0e8);
}

.app-preview-fallback[hidden],
.app-preview-diag[hidden] {
  display: none;
}

.app-preview-fallback-title {
  font-family: var(--font-display, Georgia, serif);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--green-deep, #0a3d2e);
}

.app-preview-fallback-text {
  font-size: 0.92rem;
  color: #55665a;
  margin-bottom: 0.6rem;
}

/* Only appears when the page URL ends in #efa-diag (support use) */
.app-preview-diag {
  max-width: 100%;
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  background: #fff;
  border: 1px solid rgba(10, 61, 46, 0.18);
  border-radius: 4px;
  font-size: 0.72rem;
  line-height: 1.5;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
  color: #1c2b21;
  overflow: auto;
  max-height: 45%;
}

/* ── Tablet ───────────────────────────────────────────────── */
@media (max-width: 960px) {
  .apps-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 600px) {
  .apps-section {
    padding: 4.5rem 1.2rem;
  }

  .apps-header {
    margin-bottom: 2.4rem;
  }

  .app-card {
    padding: 1.8rem 1.5rem;
  }

  .app-actions .app-btn {
    flex: 1 1 100%;
  }

  .app-preview-dots {
    display: none;
  }

  .app-preview-title,
  .app-preview-actions {
    flex: 1 1 100%;
  }

  .app-preview-actions .app-preview-btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* Shorter on phones so there is always page margin to scroll with */
  .app-preview-frame {
    height: clamp(480px, 72vh, 680px);
  }

  @supports (height: 1svh) {
    .app-preview-frame {
      height: clamp(480px, 72svh, 680px);
    }
  }
}

@media (max-width: 380px) {
  .app-badge {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-card,
  .app-btn,
  .app-preview-btn {
    transition: none;
  }

  .app-card:hover,
  .app-btn-primary:hover {
    transform: none;
  }
}
