/* =======================================================================
   Infinity Insights - UI system (mobile-first)
   Design goals
   - Clean, modern, trustworthy (fintech-like) but not distracting
   - Fast to scan (cards + clear hierarchy)
   - Accessible defaults (contrast, focus rings, target sizes)
   - Works without frameworks (self-hostable)
   ======================================================================= */

/* Theme tokens --------------------------------------------------------- */
:root{
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --maxw: 1120px;
  --radius: 16px;

  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;

  --text: #0f172a;
  --muted: #475569;

  --border: rgba(15, 23, 42, 0.12);
  --border-strong: rgba(15, 23, 42, 0.16);

  --primary: #0f766e;
  --primary-2: #115e59;

  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;

  --shadow: 0 10px 30px rgba(2, 6, 23, 0.10);
  --shadow-lg: 0 18px 60px rgba(2, 6, 23, 0.16);

  --focus: rgba(15, 118, 110, 0.26);

  --header-h: 72px;
}

/* System dark mode */
@media (prefers-color-scheme: dark){
  :root{
    --bg: #0b1220;
    --surface: #0f172a;
    --surface-2: #111c33;

    --text: #e2e8f0;
    --muted: #94a3b8;

    --border: rgba(226, 232, 240, 0.14);
    --border-strong: rgba(226, 232, 240, 0.22);

    --shadow: 0 18px 60px rgba(0,0,0,0.45);
    --shadow-lg: 0 26px 76px rgba(0,0,0,0.55);

    --focus: rgba(45, 212, 191, 0.22);
  }
}

/* Explicit theme overrides (via site.js) */
html[data-theme="light"]{
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;

  --text: #0f172a;
  --muted: #475569;

  --border: rgba(15, 23, 42, 0.12);
  --border-strong: rgba(15, 23, 42, 0.16);

  --shadow: 0 10px 30px rgba(2, 6, 23, 0.10);
  --shadow-lg: 0 18px 60px rgba(2, 6, 23, 0.16);

  --focus: rgba(15, 118, 110, 0.26);
}

html[data-theme="dark"]{
  --bg: #0b1220;
  --surface: #0f172a;
  --surface-2: #111c33;

  --text: #e2e8f0;
  --muted: #94a3b8;

  --border: rgba(226, 232, 240, 0.14);
  --border-strong: rgba(226, 232, 240, 0.22);

  --shadow: 0 18px 60px rgba(0,0,0,0.45);
  --shadow-lg: 0 26px 76px rgba(0,0,0,0.55);

  --focus: rgba(45, 212, 191, 0.22);
}

/* Base --------------------------------------------------------------- */
*{ box-sizing: border-box; }
html, body{ height: 100%; }
body{
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1000px 540px at 18% -8%, rgba(15, 118, 110, 0.14), transparent 65%),
    radial-gradient(900px 520px at 92% 0%, rgba(20, 184, 166, 0.12), transparent 62%),
    var(--bg);
  line-height: 1.45;
}

a{ color: inherit; text-underline-offset: 3px; }
a:hover{ text-decoration-thickness: 2px; }

.container{
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
}


.hide-sm{ display: inline; }
.show-sm{ display: none; }
@media (max-width: 520px){
  .hide-sm{ display: none; }
  .show-sm{ display: inline; }
}

.skip-link{
  position: absolute;
  left: -9999px;
  top: 10px;
  padding: 10px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 9999;
}
.skip-link:focus{
  left: 12px;
}

/* Header + nav ------------------------------------------------------- */
.site-header{
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--header-h);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 68%, transparent);
  backdrop-filter: blur(12px);
}

.site-header .container{
  /* Header should span the full viewport width (not the main content max width). */
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 0 24px;
}
.nav{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}
.header-actions{
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand{
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-name{
  font-weight: 950;
  font-size: 30px;
  letter-spacing: -0.02em;
  line-height: 1.15;
  padding-bottom: 1px;
  color: var(--text);
}
@supports (-webkit-background-clip: text) or (background-clip: text){
  .brand-name{
    background: linear-gradient(90deg, var(--text) 0%, var(--primary) 92%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}
@media (max-width: 520px){
  .site-header .container{ padding: 0 16px; }
  .brand-name{ font-size: 24px; }
}
.brand-badge{
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), #22c55e);
  box-shadow: 0 10px 22px rgba(37,99,235,0.22);
  font-size: 19px;
}

.nav-right{
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-actions{
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Header layout variant: centered brand + left menu + right profile */
.nav-grid{
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}
.nav-left{
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: start;
}
.nav-center{ justify-self: center; }
.nav-right{
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}

.brand-center{ justify-content: center; }

@media (max-width: 520px){
  .nav-grid{ grid-template-columns: auto 1fr auto; }
  .brand-name{ font-size: 22px; }
}

/* Home: secondary banner under the header (Menu left / Profile right) */
.home-header-inner{
  display: flex;
  align-items: center;
  justify-content: center;
}

.sub-header{
  position: sticky;
  top: var(--header-h);
  z-index: 999;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  backdrop-filter: blur(12px);
}

.sub-header-inner{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
}

.sub-header-left,
.sub-header-right{
  display: flex;
  align-items: center;
}

.tool-switch{
  display: flex;
  align-items: center;
  gap: 8px;
}
.tool-switch__label{
  font-weight: 700;
  color: var(--muted);
  font-size: 0.95rem;
}
.tool-select{
  min-width: 190px;
  max-width: 240px;
  padding-right: 34px;
}
@media (max-width: 520px){
  .tool-switch__label{ display: none; }
  .tool-select{ min-width: 0; max-width: 180px; }
}

/* Parent tools dropdown ------------------------------------------------ */
.tool-menu{ position: relative; }
.tool-menu-btn{ white-space: nowrap; }
.tool-menu-chev{ font-size: 0.9em; opacity: 0.75; }

.tool-menu-panel{
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  padding: 6px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 18px 45px rgba(0,0,0,0.18);
  display: none;
  z-index: 80;
}

/* Left-aligned menu panel (for the main Menu button) */
.menu-panel-left{
  left: 0;
  right: auto;
}

/* Nested menu (Parent tools) */
.menu-accordion{
  margin: 4px 0;
}
.menu-accordion summary{
  list-style: none;
  cursor: pointer;
}
.menu-accordion summary::-webkit-details-marker{ display: none; }

.menu-sub{
  padding: 0 6px 6px 6px;
  display: grid;
  gap: 6px;
}

.tool-menu-subitem{
  display: flex;
  align-items: center;
  padding: 10px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  font-weight: 650;
  border: 1px solid transparent;
  margin-left: 8px;
}

.tool-menu-subitem:hover{
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.tool-menu-subitem[aria-current="page"]{
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}

/* Small section label inside dropdown panels */
.menu-subheading{
  padding: 0 10px 8px 10px;
  color: var(--muted);
  font-weight: 850;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

@media (max-width: 520px){
  .tool-menu-panel{
    min-width: 0;
    width: calc(100vw - 32px);
  }
}


/* Dropdown menu helpers (Settings / Profile) */
.tool-menu-panel .menu-heading{
  padding: 10px 10px 6px 10px;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-size: 0.95rem;
}
.tool-menu-panel .menu-note{
  padding: 0 10px 10px 10px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}
.tool-menu-panel .menu-divider{
  height: 1px;
  background: var(--border);
  margin: 8px 6px;
}
.tool-menu-panel button.tool-menu-item{
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}
.tool-menu-panel button.tool-menu-item:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}
.tool-menu-item[aria-checked="true"]{
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--border));
}

.tool-menu.open .tool-menu-panel,
.tool-menu:focus-within .tool-menu-panel{
  display: block;
}

.tool-menu-item{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  font-weight: 650;
}

.tool-menu-item:hover{
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.tool-menu-item[aria-current="page"]{
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--border));
}

.icon-pill{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  color: var(--text);
  font-family: inherit;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
  cursor: pointer;
  font-weight: 650;
}
.icon-pill:hover{
  border-color: var(--border-strong);
}
.icon-pill:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}
.nav-toggle{ display: none; }

.nav-links{
  display: flex;
  align-items: center;
  gap: 10px;
}
.link{
  text-decoration: none;
  color: var(--text);
  font-weight: 650;
}

button.link{
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text);
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}
button.link:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.pill{
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.link.pill:hover{
  border-color: var(--border);
  background: color-mix(in srgb, var(--surface) 84%, transparent);
}
.link.pill.active{
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}

@media (max-width: 860px){
  .nav-toggle{ display: inline-flex; }
  .nav-links{
    display: none;
    position: absolute;
    z-index: 1200;
    top: calc(var(--header-h) + 10px);
    right: 12px;
    left: 12px;
    padding: 12px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  body.nav-open .nav-links{ display: flex; }
}

/* Layout sections ----------------------------------------------------- */
main{ padding: 22px 0 44px; }

.hero{
  padding: 12px 0 18px;
}
.hero-card{
  padding: 20px 18px;
  display: grid;
  gap: 10px;
}
.hero h1{
  margin: 0;
  font-size: clamp(24px, 3.4vw, 36px);
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.hero p{
  margin: 0;
  color: var(--muted);
  max-width: 68ch;
  font-size: 1.02rem;
}
.hero-actions{
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

/* Cards + surfaces ---------------------------------------------------- */
.card{
  border-radius: var(--radius);
  border: 1px solid var(--border);
  /* Fallback background for browsers without color-mix() support */
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
}
.card.pad{ padding: 18px; }
.card.soft{
  background: color-mix(in srgb, var(--surface-2) 72%, transparent);
}
.card h2, .card h3{ margin: 0; }
.card + .card{ margin-top: 14px; }

.badge{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border));
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  color: color-mix(in srgb, var(--text) 88%, var(--primary));
  font-weight: 650;
  width: fit-content;
}

/* Forms --------------------------------------------------------------- */
.section-title{
  margin-top: 16px;
  margin-bottom: 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
}
.form-grid{
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 720px){
  .form-grid{ grid-template-columns: 1fr; }
}
.span-2{ grid-column: 1 / -1; }

.field label{
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: 0.95rem;
}
.field input,
.field select,
.field textarea{
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
}
.field textarea{ min-height: 110px; resize: vertical; }

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible{
  outline: none;
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: 0 0 0 4px var(--focus);
}

.help{
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}
.small{ font-size: 0.9rem; color: var(--muted); }
.sep{
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

/* Buttons ------------------------------------------------------------- */
.btn-row{
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover{
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.btn:active{ transform: translateY(0); }
.btn:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}
.btn-primary{
  /* Fallback for browsers without color-mix() */
  background: var(--primary);
  border-color: var(--primary);
  color: white;

  /* Enhanced gradient when supported */
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 92%, white), var(--primary));
  border-color: color-mix(in srgb, var(--primary) 60%, var(--border));
}
.btn-primary:hover{
  /* Fallback */
  background: var(--primary-2);
  border-color: var(--primary-2);

  /* Enhanced gradient */
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary-2) 92%, white), var(--primary-2));
  border-color: color-mix(in srgb, var(--primary-2) 60%, var(--border));
}
.btn-ghost{
  background: transparent;
  border-style: dashed;
}
.btn-danger{
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

/* Notices ------------------------------------------------------------- */
.notice{
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 76%, transparent);
  color: color-mix(in srgb, var(--text) 92%, var(--muted));
}
.notice--error{
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}
.notice--info{
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}

/* Calculator layout --------------------------------------------------- */
.calc-layout{
  display: grid;
  gap: 14px;
  align-items: start;
}
@media (min-width: 980px){
  .calc-layout{ grid-template-columns: 1.05fr 0.95fr; }
  .sticky{ position: sticky; top: calc(var(--header-h) + 14px); }
}

/* Stats --------------------------------------------------------------- */
.stats{
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 560px){
  .stats{ grid-template-columns: 1fr; }
}
.stat{
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 12px;
}
.stat .label{ color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }
.stat .value{ font-weight: 900; font-size: 1.25rem; letter-spacing: -0.02em; }

.table{
  width: 100%;
  border-collapse: collapse;
  font-size: 0.98rem;
}
.table th, .table td{
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
}
.table th{ color: var(--muted); font-weight: 800; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* Footer -------------------------------------------------------------- */
.footer{
  border-top: 1px solid var(--border);
  padding: 26px 0 34px;
  color: var(--muted);
  font-size: 0.95rem;
}
.footer a{ color: inherit; }

/* Motion safety ------------------------------------------------------- */
@media (prefers-reduced-motion: reduce){
  *{ scroll-behavior: auto !important; }
  .btn:hover{ transform: none; }
}
