/* CardPulse, Apex Ledger theme custom layer.
   Tailwind (Play CDN) handles utilities; this file holds tokens,
   base resets and a few component classes used across pages. */

:root {
  --surface: #131313;
  --surface-lowest: #0e0e0e;
  --surface-low: #1c1b1b;
  --surface-container: #201f1f;
  --surface-high: #2a2a2a;
  --surface-highest: #353534;
  --on-surface: #e5e2e1;
  --on-variant: #c2c6d8;
  --outline: #8c90a1;
  --outline-variant: #424655;
  --primary: #b3c5ff;
  --primary-container: #5e8bff;
  --secondary: #4edea3;
  --tertiary: #ffb95f;
  --danger: #ffb4ab;
  --danger-container: #93000a;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--on-surface);
  font-family: "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1;
}

/* Mono / tabular numerals for all financial data */
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
.label-caps {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--on-variant);
}

/* Surface tiers + hairline borders (depth via tone, not shadow) */
.panel {
  background: var(--surface-low);
  border: 1px solid #262626;
  border-radius: 0.5rem;
}
.panel-2 { background: var(--surface-container); border: 1px solid var(--outline-variant); }

/* Card visual (synthetic plastic, no image assets needed) */
.cc-visual {
  aspect-ratio: 1.586 / 1;
  border-radius: 0.6rem;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.cc-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 120% at 80% -10%, rgba(255, 255, 255, 0.18), transparent 55%);
  pointer-events: none;
}
.cc-chip {
  width: 30px;
  height: 22px;
  border-radius: 4px;
  background: linear-gradient(135deg, #f5d68a, #b78c2e);
  opacity: 0.9;
}
.accent-amazon { background: linear-gradient(135deg, #232f3e, #ff9900 230%); }
.accent-flipkart { background: linear-gradient(135deg, #1a2b66, #2874f0); }
.accent-cashback { background: linear-gradient(135deg, #00321f, #00a572); }
.accent-rewards { background: linear-gradient(135deg, #1a1740, #5e8bff); }
.accent-premium { background: linear-gradient(135deg, #2b2b2b, #6b6b6b); }

/* Chips / badges */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--outline-variant);
  color: var(--on-variant);
  background: transparent;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: all 0.12s ease;
}
.chip:hover { border-color: var(--outline); color: var(--on-surface); }
.chip.active {
  background: rgba(179, 197, 255, 0.12);
  border-color: var(--primary);
  color: var(--primary);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-warn { background: rgba(255, 185, 95, 0.12); color: var(--tertiary); border: 1px solid rgba(255, 185, 95, 0.3); }
.badge-good { background: rgba(78, 222, 163, 0.12); color: var(--secondary); border: 1px solid rgba(78, 222, 163, 0.3); }
.badge-info { background: rgba(179, 197, 255, 0.12); color: var(--primary); border: 1px solid rgba(179, 197, 255, 0.3); }
.badge-neutral { background: var(--surface-high); color: var(--on-variant); border: 1px solid var(--outline-variant); }
.badge-nice { background: rgba(255, 185, 95, 0.14); color: var(--tertiary); border: 1px solid rgba(255, 185, 95, 0.35); }

/* Status dot */
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
.dot-good { background: var(--secondary); box-shadow: 0 0 8px rgba(78, 222, 163, 0.6); }
.dot-warn { background: var(--tertiary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 0.375rem;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter 0.12s ease, background 0.12s ease;
  text-decoration: none;
}
.btn-primary { background: var(--primary-container); color: #fff; }
.btn-primary:hover { filter: brightness(1.12); }
.btn-ghost { background: transparent; border-color: var(--outline-variant); color: var(--on-surface); }
.btn-ghost:hover { border-color: var(--outline); background: var(--surface-high); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Inputs */
.field {
  width: 100%;
  background: var(--surface-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: 0.375rem;
  color: var(--on-surface);
  padding: 11px 12px;
  font-size: 14px;
  font-family: inherit;
}
.field:focus { outline: none; border-color: var(--primary-container); }
select.field { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238c90a1' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }

/* Data rows */
.data-row { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid #1c1c1c; }
.data-row:last-child { border-bottom: none; }
.data-row .k { color: var(--on-variant); font-size: 13px; }
.data-row .v { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13px; text-align: right; }

/* Sticky header: the wrapper div must be the sticky element so it pins within
   <body> (a tall scroll context). Making only the inner <header> sticky fails
   because its parent box is exactly header-height, so it has no room to stick. */
#app-header { position: sticky; top: 0; z-index: 40; }

/* Nav active link */
.nav-link { color: var(--on-variant); font-size: 14px; font-weight: 500; text-decoration: none; padding: 6px 2px; border-bottom: 2px solid transparent; }
.nav-link:hover { color: var(--on-surface); }
.nav-link.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Bottom mobile nav */
.tabbar-link { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--on-variant); text-decoration: none; padding: 6px 12px; }
.tabbar-link.active { color: var(--primary); }

/* Comparison highlight cells */
.cmp-best { background: rgba(78, 222, 163, 0.10); }
.cmp-worst { background: rgba(255, 180, 171, 0.08); }

/* Comparison: desktop table vs phone stacked layout */
.cmp-mobile { display: none; }

.cmp-m-cards {
  display: grid;
  gap: 8px;
  position: sticky;
  top: 64px;
  z-index: 5;
  background: var(--surface);
  padding: 10px 0;
  margin-bottom: 6px;
  border-bottom: 1px solid #1c1c1c;
}
.cmp-m-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-container);
  border: 1px solid var(--outline-variant);
  border-radius: 0.5rem;
  padding: 8px 9px;
  position: relative;
}
.cmp-m-swatch { width: 6px; align-self: stretch; border-radius: 3px; flex: none; }
.cmp-m-cardname { font-size: 12.5px; font-weight: 600; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; }
.cmp-m-issuer { font-size: 10.5px; color: var(--on-variant); margin-top: 1px; }
.cmp-m-x {
  position: absolute; top: 4px; right: 6px;
  background: none; border: none; color: var(--on-variant);
  font-size: 17px; line-height: 1; cursor: pointer; padding: 2px;
}
.cmp-m-x:hover { color: var(--danger); }

.cmp-m-row {
  background: var(--surface-low);
  border: 1px solid #262626;
  border-radius: 0.6rem;
  padding: 12px;
  margin-bottom: 10px;
}
.cmp-m-label { display: block; margin-bottom: 8px; }
.cmp-m-cell {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; flex-wrap: wrap;
  padding: 8px 10px; border-radius: 0.4rem;
  border-left: 3px solid transparent;
}
.cmp-m-cell + .cmp-m-cell { margin-top: 6px; }
.cmp-m-cell.cmp-best { background: rgba(78, 222, 163, 0.10); border-left-color: var(--secondary); }
.cmp-m-cell.cmp-worst { background: rgba(255, 180, 171, 0.06); }
.cmp-m-tag { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 600; color: var(--on-variant); flex: none; }
.cmp-m-dot { width: 9px; height: 9px; border-radius: 999px; flex: none; }
.cmp-m-val { font-size: 13px; line-height: 1.45; text-align: right; flex: 1; min-width: 120px; }

@media (max-width: 680px) {
  .cmp-desktop { display: none; }
  .cmp-mobile { display: block; }
}

.fade-in { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Gallery tiles: subtle lift + accent on hover (pointer devices only) */
@media (hover: hover) {
  #grid > article { transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease; }
  #grid > article:hover {
    border-color: var(--outline-variant);
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

/* Consistent keyboard focus ring for accessibility */
a:focus-visible,
button:focus-visible,
.chip:focus-visible,
.btn:focus-visible,
.field:focus-visible,
select:focus-visible {
  outline: 2px solid var(--primary-container);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Hide scrollbars on horizontal chip rows but keep scroll */
.scroll-x { overflow-x: auto; -ms-overflow-style: none; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* ---- Responsive ---- */
.mobile-tabbar { display: none; }

@media (max-width: 860px) {
  .detail-head { grid-template-columns: 1fr !important; }
  .detail-head > div:first-child { position: static !important; }
  .three-col { grid-template-columns: 1fr 1fr !important; }
}

@media (max-width: 680px) {
  .desktop-nav { display: none !important; }
  .mobile-tabbar { display: flex !important; }
  .two-col { grid-template-columns: 1fr !important; }
  .three-col { grid-template-columns: 1fr !important; }
  .cmp-scroll { overflow-x: auto; }
  .rec-grid { grid-template-columns: 1fr !important; }
  #opt-form { position: static !important; }
}

@media (max-width: 520px) {
  .rec-grid .cc-visual { max-width: 280px; }
}

/* Give pages room above the fixed bottom tab bar on mobile */
@media (max-width: 680px) {
  body { padding-bottom: 64px; }
}

/* Prevent any accidental horizontal scrollbar ("slider") on small screens */
html, body { max-width: 100%; overflow-x: hidden; }

/* ---- Compact gallery tiles on mobile so a card fits in roughly one screen ---- */
@media (max-width: 680px) {
  #grid { gap: 10px !important; }
  #grid > article { padding: 12px !important; gap: 8px !important; }
  /* Shorter synthetic card image so the tile is not so tall */
  #grid .cc-visual { aspect-ratio: 2.4 / 1; }
  #grid .cc-visual .cc-chip { display: none; }
  /* Tighten the data rows */
  #grid .data-row { padding: 6px 0; }
  #grid .data-row .k, #grid .data-row .v { font-size: 12px; }
  /* Smaller headline rate */
  #grid .rate-big { font-size: 20px !important; }
}
