/* ===================================================================
   CEORater – style.css (safe-area hardened, no stretch on iOS)
   - Cards & auth respect safe areas (top/bottom/left/right)
   - No global utility overrides that inflate heights
   - Robust dvh/svh + -webkit-fill-available fallbacks
   - Firebase Auth buttons never sit behind the mic/home-indicator
   =================================================================== */

/* -------------------------------------------------
   Base / Reset
------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* Safe-area variables (env() is 0 when unsupported) */
:root {
  --sat: env(safe-area-inset-top);
  --sar: env(safe-area-inset-right);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);

  /* App chrome padding you can tweak globally */
  --app-gap: 16px;
}

html, body {
  margin: 0;
  padding: 0;
  /* Robust viewport sizing on iOS (dynamic toolbars) */
  min-height: 100svh;
  height: 100dvh;
  min-height: -webkit-fill-available; /* iOS fallback */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: #0f172a;            /* slate-900 */
  background: #f8fafc;       /* slate-50 */
}

/* -------------------------------------------------
   App Shell (apply safe area here, not on body)
------------------------------------------------- */
.app-shell {
  /* All primary screens live inside .app-shell */
  padding-top: calc(var(--sat, 0px) + var(--app-gap));
  padding-right: calc(var(--sar, 0px) + var(--app-gap));
  padding-bottom: calc(var(--sab, 0px) + var(--app-gap));
  padding-left: calc(var(--sal, 0px) + var(--app-gap));
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Optional header/footer that hug the edges add extra breathing room */
.site-header { margin-top: calc(var(--sat, 0px)); }
.site-footer { margin-bottom: calc(var(--sab, 0px)); }

/* Never globally add safe-area padding to body or utility classes. */


/* -------------------------------------------------
   Non-stretch Card Defaults
   (Prevents flex parents from making cards fill the column)
------------------------------------------------- */
.card,
.ceo-card,
.ceorater-stat-card,
.firebase-card {
  align-self: start;         /* do not stretch in flex parents */
  width: 100%;
  max-width: 1200px;         /* guardrail for widescreens */
  height: auto;              /* content-driven height */
}

/* If a grid/flex container uses align-stretch, normalize children */
.no-stretch > * { align-self: start; }

/* Ensure images/video don’t force card growth unexpectedly */
img, svg, video, canvas, audio, iframe, embed, object {
  display: block;
  max-width: 100%;
  height: auto;
}


/* -------------------------------------------------
   FirebaseUI – Safe, Non-stretch, Touch-friendly
------------------------------------------------- */
.firebaseui-container,
.firebaseui-auth-container,
.firebaseui-card-content {
  /* Respect left/right safe areas; add comfortable inner gaps */
  padding-inline: calc(var(--sal, 0px) + 12px) calc(var(--sar, 0px) + 12px);
  display: block;
  max-width: 600px;
  margin: 0 auto;
}

/* Critical: bottom padding so buttons never sit behind mic/home-indicator */
.firebaseui-auth-container,
.firebaseui-card-content {
  padding-bottom: calc(var(--sab, 0px) + 24px);
}

/* Top spacing under the dynamic notch/status area */
.firebaseui-container { padding-top: calc(var(--sat, 0px) + 12px); }

/* Buttons: no fixed heights; keep minimum touch target */
.firebaseui-idp-button,
.firebaseui-idp-list .mdl-button {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;                 /* accessible target */
  padding: 10px 16px;
  line-height: 1.2;
  font-size: 16px;                  /* avoids iOS zoom-on-focus */
  border-radius: 10px;
  box-sizing: border-box;
  height: auto;                     /* let content define */
  max-width: 100%;
}

/* Ensure container items expand naturally, not a fixed row height */
.firebaseui-list-item {
  display: block;
  margin: 6px 0;
  height: auto;
}

/* Text inside buttons aligns properly */
.firebaseui-idp-text {
  display: inline-flex;
  align-items: center;
  line-height: 1.2;
}

/* Inputs: comfortable padding, no fixed heights */
.mdl-textfield__input,
.firebaseui-textfield,
.firebaseui-input {
  -webkit-appearance: none;
  appearance: none;
  font-size: 16px;
  line-height: 1.3;
  padding: 10px 12px;
  height: auto;
  border-radius: 8px;
  box-sizing: border-box;
  width: 100%;
}

/* If you have a fixed bottom bar within auth screens, pad for safe area */
.auth-bottom-bar,
.fixed-cta {
  position: sticky;                 /* or fixed if desired */
  bottom: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--sab, 0px));
  background: #ffffffcc;
  backdrop-filter: blur(6px);
  border-top: 1px solid #e5e7eb;
  z-index: 20;
}


/* -------------------------------------------------
   CEO Detail + Summary Cards (safe edges, no stretch)
------------------------------------------------- */
.ceo-detail,
.ceo-detail .content {
  width: 100%;
  max-width: 1100px;
  margin-inline: auto;
  padding-inline: calc(var(--sal, 0px) + 12px) calc(var(--sar, 0px) + 12px);
}

.ceo-card {
  position: relative; /* required for corner actions */
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}

.ceo-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

/* Prevent inner flex columns from stretching children vertically */
.ceo-card .col,
.ceo-card [class*="flex"],
.ceo-card [class*="grid"] > * { align-self: start; }

/* Borders that shouldn’t be overridden */
.ceo-card.border-l-4 { border-left-width: 4px; }
.ceo-card.border-green-500, .ceo-card.border-green-600 { border-left-color: #16a34a; }
.ceo-card.border-blue-500,  .ceo-card.border-blue-600  { border-left-color: #2563eb; }
.ceo-card.border-gray-600                            { border-left-color: #4b5563; }
.ceo-card.border-red-500,   .ceo-card.border-red-600   { border-left-color: #dc2626; }

/* Corner actions: ensure no overlap */
.ceo-card .compare-btn {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  z-index: 2;
}
.ceo-card a.details-link,
.ceo-card .view-details-link {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-weight: 600;
  font-size: .875rem;
  text-decoration: none;
  border-radius: .5rem;
  padding: .375rem .6rem;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(6px);
  border: 1px solid #e5e7eb;
  transition: transform .15s ease, box-shadow .15s ease;
  z-index: 2;
}
.ceo-card a.details-link:hover,
.ceo-card .view-details-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0,0,0,.08);
}
/* Ensure content doesn't hide behind the fixed-corner actions */
.ceo-card .card-body,
.ceo-card .content,
.ceo-card .card-content {
  padding-bottom: 3rem; /* space for the two corner buttons */
}


/* -------------------------------------------------
   CEO Comparison – grid that never forces row height
------------------------------------------------- */
.comparison-wrap {
  width: 100%;
  padding-inline: calc(var(--sal, 0px) + 12px) calc(var(--sar, 0px) + 12px);
  margin-inline: auto;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  align-items: start;          /* don’t stretch rows */
}

.comparison-card {
  grid-column: span 6;
  align-self: start;
  height: auto;
}

@media (max-width: 1024px) {
  .comparison-card { grid-column: span 12; }
}

.comparison-ceorater-highlight {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  border-left: 4px solid #475569;
}


/* -------------------------------------------------
   CEORaterScore – hero & stat cards
------------------------------------------------- */
.font-orbitron { font-family: 'Orbitron', sans-serif; }

.ceorater-hero {
  background: linear-gradient(135deg, #1e293b 0%, #334155 50%, #475569 100%);
  border-radius: 16px;
  box-shadow: 0 8px 25px rgba(30, 41, 59, 0.3);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.ceorater-hero:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 35px rgba(30, 41, 59, 0.4);
}

.score-weight-bar {
  background: linear-gradient(to right, #3b82f6 0%, #3b82f6 60%, #8b5cf6 60%, #8b5cf6 100%);
  height: 6px;
  border-radius: 3px;
  transition: height 0.3s ease, width 0.8s ease-in-out;
}
.score-weight-bar:hover { height: 8px; }

.score-progress { transition: width 0.8s ease-in-out; }

.ceorater-stat-card {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border: 3px solid #475569;
  transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
  position: relative;
  overflow: hidden;
  border-radius: 14px;
}
.ceorater-stat-card::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
  animation: shimmer 4s infinite;
  opacity: 0.5;
}
.ceorater-stat-card:hover {
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
  transform: scale(1.02);
  box-shadow: 0 20px 40px rgba(71, 85, 105, 0.2);
}
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

.modal-ceorater-section {
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}
.modal-ceorater-section.score-badge-excellent { background: linear-gradient(135deg, #10b981 0%, #059669 100%); color: #fff; border: none; }
.modal-ceorater-section.score-badge-good      { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); color: #fff; border: none; }
.modal-ceorater-section.score-badge-average   { background: linear-gradient(135deg, #1e293b 0%, #334155 100%); color: #fff; border: none; }
.modal-ceorater-section.score-badge-poor      { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); color: #fff; border: none; }
.modal-ceorater-section::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
  animation: shimmer 3s infinite;
}

/* Default modal section if no score tag */
.modal-ceorater-section:not(.score-badge-excellent):not(.score-badge-good):not(.score-badge-average):not(.score-badge-poor) {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border: 2px solid #475569;
  color: #334155;
}


/* -------------------------------------------------
   SCORE BADGES (GLOBAL) – summary + detail cards
------------------------------------------------- */

/* Base badge appearance */
.score-badge {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .25rem .5rem;
  border-radius: .5rem;
  font-weight: 600;
  font-size: .75rem;
  line-height: 1;
  color: #fff !important; /* readable text on gradients */
}

/* Force our gradients to win over any Tailwind bg-* utilities */
.score-badge-excellent { 
  background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
  border: none !important;
}
.score-badge-good { 
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%) !important;
  border: none !important;
}
.score-badge-average { 
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%) !important;
  border: none !important;
}
.score-badge-poor { 
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
  border: none !important;
}


/* -------------------------------------------------
   Tooltips (desktop only activation below)
------------------------------------------------- */
.weight-tooltip {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
  position: absolute;
  left: 50%;
  top: 100%;
  margin-top: 8px;
  background-color: #1f2937;
  color: #ffffff;
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  text-align: center;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
.weight-indicator { position: relative; }

.weight-tooltip::before {
  content: '';
  position: absolute;
  bottom: 100%; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid #1f2937;
}

.alpha-score-tooltip,
.comp-score-tooltip {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
  position: absolute;
  left: 50%;
  bottom: 100%;
  margin-bottom: 8px;
  background-color: #1f2937;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-width: 180px;
  text-align: center;
  z-index: 50;
}

/* -------------------------------------------------
   Utilities & Small Components
------------------------------------------------- */
#loading-spinner{
  border:4px solid rgba(0,0,0,.1);
  width:36px; height:36px; border-radius:50%;
  border-left-color:#09f;
  animation:spin 1s linear infinite
}
@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}

.modal { backdrop-filter: blur(4px); }

.watchlist-tab { transition: all 0.3s ease; }
.watchlist-tab.active { background-color: #3b82f6; color: #fff; }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Bottom tray that respects the home indicator */
#comparisonTray {
  transition: transform 0.3s ease-in-out;
  padding-bottom: calc(var(--sab, 0px) + 8px);
}

/* Subtle hovers */
.compare-btn, .watchlist-star { transition: transform 0.3s ease; }
.compare-btn:hover { transform: scale(1.1); }
.watchlist-star:hover { transform: scale(1.2) rotate(5deg); }

/* Secondary stat cards – subtle hover */
#statCardContainer .grid .bg-white {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#statCardContainer .grid .bg-white:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

/* Loading shimmer */
.ceorater-loading {
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: loading-shimmer 1.5s infinite;
}
@keyframes loading-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }


/* -------------------------------------------------
   Modal Layout with Safe-Area Awareness
------------------------------------------------- */
.modal-header, #modalHeader {
  padding-top: calc(1.5rem + var(--sat, 0px));
}
.modal-body, #modalBody {
  /* dvh avoids 100vh overshoot under dynamic bars */
  max-height: calc(100dvh - var(--sat, 0px) - var(--sab, 0px) - 8rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}


/* -------------------------------------------------
   Responsive Tweaks
------------------------------------------------- */
@media (max-width: 768px) {
  .ceorater-hero { padding: 1rem; }
  .ceorater-hero .font-orbitron { font-size: 2.5rem; }
  .score-weight-bar { height: 4px; }

  .ceorater-stat-card { padding: 1.5rem; }
  .ceorater-stat-card .text-5xl { font-size: 3rem; }

  /* Hide tooltips on touch */
  .weight-tooltip,
  .alpha-score-tooltip,
  .comp-score-tooltip {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
}

@media (max-width: 1024px) {
  /* When Tailwind sets .lg:grid-cols-5 we can override to 2 columns at <=1024px */
  #statCardContainer.grid.lg\:grid-cols-5 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .ceorater-stat-card { grid-column: 1 / -1; }
}


/* -------------------------------------------------
   Desktop-only Tooltip Activation
------------------------------------------------- */
@media (min-width: 769px) {
  .weight-indicator:hover .weight-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
  }

  .bg-blue-50:hover .alpha-score-tooltip,
  .bg-purple-50:hover .comp-score-tooltip {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto !important;
  }
}

/* ===== Safe-area patch: sticky header + modal close buttons ===== */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

/* Keep sticky header content out of the Dynamic Island / notch.
   Make sure your <header> has id="appHeader" in index.html */
#appHeader {
  padding-top: max(8px, var(--sat));
  padding-left: var(--sal);
  padding-right: var(--sar);
  background: #fff;
}

/* Add safe insets to the header’s inner Tailwind container */
#appHeader > .container {
  padding-left: calc(1rem + var(--sal)) !important;
  padding-right: calc(1rem + var(--sar)) !important;
}

/* Modal close buttons respect safe-area insets */
#closeDetailModal,
#closeComparisonModalBtn,
#closeLoginModalBtn {
  position: absolute;
  top: calc(var(--sat) + 0.75rem) !important;
  right: calc(var(--sar) + 0.75rem) !important;
  touch-action: manipulation;
}

/* Keep modal content below the notch and away from edges */
#ceoDetailModal .bg-white,
#loginModal .bg-white,
#comparisonModal .bg-white {
  padding-top: max(1rem, var(--sat));
  padding-left: max(1rem, var(--sal));
  padding-right: max(1rem, var(--sar));
}

/* Optional: tiny cushion inside header so scroll bounce looks nice */
#appHeader .container > .flex {
  padding-bottom: 4px;
}
