/* ===========================================================================
   Finocis — calculators and the tools hub.

   Everything here is built on the design tokens the theme layer prints into
   :root (--brand, --ink, --surface, --rule, --radius and the rest), so a
   palette change in Settings -> Branding reaches these screens too, and dark
   mode works without a second set of rules.
   =========================================================================== */

/* ------------------------------------------------------------------ hub */
.pagehead--hub { padding-bottom: 8px; }

.pagehead__lede {
  max-width: 64ch;
  font-size: 1.05rem;
  color: var(--ink-soft);
}

.pagehead__kicker {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .72rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--brand);
  margin: 0 0 6px;
}

.pagehead__badges { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 0; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  font-size: .78rem;
  color: var(--ink-soft);
}
.pill--ok { border-color: color-mix(in srgb, var(--brand) 35%, transparent); color: var(--brand); }
.pill--ok::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand);
}

.toolsearch { margin: 26px 0 6px; max-width: 520px; }

.toolsearch__input {
  width: 100%;
  padding: 14px 18px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--btn-radius, 10px);
  box-shadow: 0 1px 2px rgba(11, 27, 43, .04);
}
.toolsearch__input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.toolsearch__count { margin: 8px 0 0; font-size: .82rem; color: var(--muted); min-height: 1.2em; }

.toolnav { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 4px; }
.toolnav__link {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: .85rem;
  text-decoration: none;
  transition: border-color .15s ease, color .15s ease;
}
.toolnav__link:hover { border-color: var(--brand); color: var(--brand); }
.toolnav__link span {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .72rem;
  color: var(--muted);
}

.toolhub { padding-top: 40px; padding-bottom: 64px; }
.toolgroup { margin-bottom: 48px; scroll-margin-top: 110px; }
.toolgroup[hidden] { display: none; }

.toolgroup__head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px;
  padding-bottom: 14px; margin-bottom: 22px;
  border-bottom: 1px solid var(--rule);
}
.toolgroup__head h2 { margin: 0; font-size: 1.35rem; }
.toolgroup__head p { margin: 0; color: var(--muted); font-size: .92rem; }

.toolcard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 22px 20px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius, 12px);
  color: inherit;
  text-decoration: none;
  position: relative;
  overflow: hidden;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.toolcard[hidden] { display: none; }
.toolcard::before {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--brand);
  transform: scaleY(0); transform-origin: top;
  transition: transform .2s ease;
}
.toolcard:hover {
  border-color: color-mix(in srgb, var(--brand) 40%, var(--rule));
  box-shadow: 0 10px 24px -14px rgba(11, 27, 43, .35);
  transform: translateY(-2px);
}
.toolcard:hover::before { transform: scaleY(1); }
.toolcard:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }

.toolcard__title { margin: 0; font-size: 1.02rem; line-height: 1.35; }
.toolcard__desc { margin: 0; font-size: .88rem; color: var(--muted); line-height: 1.55; }
.toolcard__go {
  margin-top: auto; padding-top: 10px;
  font-size: .78rem; font-weight: 600; color: var(--brand);
}
.toolcard__go::after { content: " \2192"; }

.toolhub__empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ------------------------------------------------------- calculator shell */
.calcwrap { padding-top: 36px; padding-bottom: 8px; }

.calc {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  grid-template-rows: auto auto;
  gap: 28px;
  align-items: start;
}
.calc__form { grid-column: 1; grid-row: 1; }
.calc__panel { grid-column: 2; grid-row: 1 / span 2; }
@media (max-width: 900px) {
  .calc__form, .calc__panel { grid-column: auto; grid-row: auto; }
}

.calc__form {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius, 12px);
  padding: 26px;
}

.calcform__intro { margin: 0 0 18px; color: var(--muted); font-size: .9rem; }

.calcform__grid { display: grid; gap: 18px; }
@media (min-width: 720px) {
  .calcform__grid { grid-template-columns: 1fr 1fr; }
  .calcf--full, .calcf--text { grid-column: 1 / -1; }
}

/* ------------------------------------------------------------- the fields */
.calcf { display: flex; flex-direction: column; gap: 7px; min-width: 0; }

/* A field that does not apply to the mode in use. `display: flex` above would
   otherwise win over the [hidden] attribute and the field would stay on screen. */
.calcf[hidden] { display: none; }


.calcf__label { font-size: .85rem; font-weight: 600; color: var(--ink); }

.calcf__input {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm, 8px);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.calcf__input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}
select.calcf__input { cursor: pointer; }

.calcf__affix {
  display: flex; align-items: stretch;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm, 8px);
  background: var(--paper);
  overflow: hidden;
}
.calcf__affix:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}
.calcf__affix .calcf__input {
  border: 0; border-radius: 0; background: transparent; box-shadow: none; flex: 1; min-width: 0;
}
.calcf__affix .calcf__input:focus { box-shadow: none; }
.calcf__unit {
  display: flex; align-items: center;
  padding: 0 12px;
  font-size: .85rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  white-space: nowrap;
}
.calcf__unit--pre { border-right: 1px solid var(--rule); }
.calcf__unit--post { border-left: 1px solid var(--rule); }

.calcf__range { width: 100%; accent-color: var(--brand); cursor: pointer; margin: 2px 0 0; }
.calcf__hint { margin: 0; font-size: .78rem; color: var(--muted); line-height: 1.5; }

/* ------------------------------------------------------------ result panel */
.calc__panel { position: sticky; top: 92px; }
@media (max-width: 900px) { .calc__panel { position: static; } }

.calc__result {
  /* Lets the rules above respond to the width of this card rather than the
     width of the window — the hero widget is narrow on a wide screen. */
  container-type: inline-size;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius, 12px);
  padding: 26px;
  box-shadow: 0 18px 40px -30px rgba(11, 27, 43, .55);
}

.calcresult__head { padding-bottom: 18px; border-bottom: 1px solid var(--rule); margin-bottom: 18px; }

.calcresult__eyebrow {
  margin: 0 0 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .7rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--muted);
}
.calcresult__lead {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.85rem, 1.2rem + 2vw, 2.5rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.02em;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.calcresult__sub { margin: 8px 0 0; font-size: .86rem; color: var(--muted); line-height: 1.5; }

.calcresult__subhead {
  margin: 22px 0 10px;
  font-size: .76rem; letter-spacing: .1em; text-transform: uppercase;
  font-weight: 700; color: var(--ink-soft);
}
.calcresult__group { border-top: 1px solid var(--rule-soft); margin-top: 6px; }

.calcrow {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule-soft);
  font-size: .92rem;
}
.calcrow:last-child { border-bottom: 0; }
.calcrow__label { color: var(--ink-soft); min-width: 0; }
.calcrow__value { font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }

/* A row whose value is a sentence rather than a figure. `flex: none` plus
   `nowrap` above is right for ₹12,50,000 and wrong for prose, which then runs
   straight out of the card on a phone. */
.calcrow__value--prose {
  white-space: normal;
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-weight: 600;
}
.calcrow--strong { font-weight: 700; }
.calcrow--strong .calcrow__label { color: var(--ink); }
.calcrow--strong .calcrow__value { color: var(--brand); }
.calcrow__hint { margin: -2px 0 8px; font-size: .78rem; color: var(--muted); line-height: 1.5; }

.calcresult__note {
  margin: 16px 0 0; padding-top: 14px;
  border-top: 1px solid var(--rule-soft);
  font-size: .78rem; color: var(--muted); line-height: 1.6;
}
.calcresult__note + .calcresult__note { border-top: 0; padding-top: 0; margin-top: 8px; }

.calcresult__error {
  margin: 0; padding: 14px 16px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-sm, 8px);
  color: var(--ink);
  font-size: .9rem; line-height: 1.55;
}

/* ----------------------------------------------------------------- charts */
.calcresult__chart { margin: 4px 0 14px; }

.calcchart--donut {
  display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 18px; align-items: center;
}
@media (max-width: 420px) { .calcchart--donut { grid-template-columns: 1fr; } }
.calcchart__svg { width: 112px; height: 112px; transform: rotate(-90deg); }

.calclegend { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; min-width: 0; }
.calclegend--inline { margin-top: 10px; grid-auto-flow: row; }

/* Grid rather than flex: with large rupee amounts (a crore-plus loan) a flex
   row has nothing it is allowed to shrink, so the value and the percentage
   push straight through the right-hand padding of the card. Here the label
   is the only flexible track and it truncates instead. */
.calclegend__item {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto auto;
  align-items: baseline;
  gap: 8px;
  font-size: .84rem;
  min-width: 0;
}
.calclegend__dot { width: 9px; height: 9px; border-radius: 2px; align-self: center; }
.calclegend__label {
  min-width: 0;
  color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.calclegend__value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.calclegend__pct {
  min-width: 32px; text-align: right; color: var(--muted);
  font-size: .76rem; font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* The percentage is the first thing to go when the card itself is narrow —
   which happens at any viewport width, so this is a container query rather
   than a media query. The donut already shows the proportion. */
@container (max-width: 380px) {
  /* Side by side there is not enough room for "Principal  ₹5,00,00,000", and
     truncating to "P..." is worse than the overflow was. Stacking the donut
     above the legend gives every label the full width of the card.
     The selectors are deliberately specific: a container query adds no
     specificity of its own, so a plain .calcchart--donut here would lose to
     the .calc--mini override in home.css. */
  .calc__result .calcresult__chart .calcchart--donut {
    grid-template-columns: minmax(0, 1fr);
    justify-items: start;
    gap: 12px;
  }
  .calc__result .calcresult__chart .calcchart__svg { width: 72px; height: 72px; }
  .calc__result .calclegend { width: 100%; }
  .calc__result .calclegend__item { grid-template-columns: 9px minmax(0, 1fr) auto; }
  .calc__result .calclegend__label { overflow: visible; text-overflow: clip; }
  .calc__result .calclegend__pct { display: none; }
}
@media (max-width: 460px) {
  .calclegend__item { grid-template-columns: 9px minmax(0, 1fr) auto; }
  .calclegend__pct { display: none; }
}

.calcbar { display: grid; grid-template-columns: minmax(0, 30%) minmax(0, 1fr) auto; gap: 10px; align-items: center; margin-bottom: 9px; min-width: 0; }
.calcbar__label { font-size: .82rem; color: var(--ink-soft); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.calcbar__track { height: 9px; background: color-mix(in srgb, var(--ink) 7%, transparent); border-radius: 999px; overflow: hidden; }
.calcbar__fill { display: block; height: 100%; border-radius: 999px; }
.calcbar__value { font-size: .82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.calcstack { display: flex; height: 13px; border-radius: 999px; overflow: hidden; background: color-mix(in srgb, var(--ink) 7%, transparent); }
.calcstack__part { display: block; height: 100%; }

/* ----------------------------------------------------------------- tables */
.calctable {
  margin-top: 20px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm, 8px);
  overflow: hidden;
}
.calctable__summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: .86rem; font-weight: 600;
  background: var(--paper);
  list-style: none;
}
.calctable__summary::-webkit-details-marker { display: none; }
.calctable__summary::after { content: "\25BE"; color: var(--muted); transition: transform .18s ease; }
.calctable[open] .calctable__summary::after { transform: rotate(180deg); }
.calctable__count { font-weight: 400; color: var(--muted); font-size: .78rem; margin-left: auto; margin-right: 8px; }

.calctable__scroll { max-height: 340px; overflow: auto; }
.calctable__table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.calctable__table th,
.calctable__table td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--rule-soft); white-space: nowrap; }
.calctable__table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--rule);
}
.calctable__table td.is-num, .calctable__table th.is-num { text-align: right; font-variant-numeric: tabular-nums; }
.calctable__table tbody tr:last-child td { border-bottom: 0; }
.calctable__table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--ink) 2%, transparent); }
.calctable__note { margin: 0; padding: 12px 16px; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--rule-soft); line-height: 1.6; }

/* ---------------------------------------------------------------- toolbar */
.calctools {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px;
  /* Explicit placement: the toolbar is a third grid child, and without this it
     takes column 2 and pushes the result panel down a row. */
  grid-column: 1; grid-row: 2;
}
@media (max-width: 900px) { .calctools { grid-column: auto; grid-row: auto; } }
.calctools__btn {
  padding: 8px 15px;
  font: inherit; font-size: .83rem; font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--btn-radius, 8px);
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.calctools__btn:hover { border-color: var(--brand); color: var(--brand); }
.calctools__btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.calctools__btn--ghost { color: var(--muted); }

/* ------------------------------------------------------------------- rest */
.calcwrap__notes { padding-top: 36px; padding-bottom: 10px; }
.calcwrap__related { padding-top: 26px; padding-bottom: 64px; }
.calcwrap__all { margin-top: 24px; }

.u-visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

@media (max-width: 900px) {
  .calc { grid-template-columns: minmax(0, 1fr); }
}

/* Grid and flex children default to min-width:auto, which lets a wide table
   push its column past the viewport instead of scrolling within it. */
.calc > *,
.calc__panel > *,
.calcresult__chart,
.calctable { min-width: 0; max-width: 100%; }
.calctable__scroll { max-width: 100%; }

/* ------------------------------------------------------------------ print */
@media print {
  .masthead, .footer, .topbar, .calctools, .toolnav, .toolsearch,
  .calcwrap__related, .site-chrome, .back-to-top { display: none !important; }
  .calc { grid-template-columns: 1fr 1fr; gap: 16px; }
  .calc__form, .calc__result { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
  .calctable { break-inside: avoid; }
  .calctable__scroll { max-height: none; overflow: visible; }
  .calctable:not([open]) .calctable__scroll { display: block; }
  .calcresult__lead { color: #000; }
}
