/* ==========================================================================
   toolpage.css  —  Shared calculator-page kit
   Used by form-style calculator pages (BMI, Mortgage, GPA, Grade). Contains
   the page chrome (breadcrumb, sidebar, panels) + generic tool components:
   tabs, labelled inputs, dynamic rows, purple result display, stat tiles and
   calculation steps. Load order: common, header, toolpage, content, footer.
   ========================================================================== */

.calc-tool { padding-block: 22px; background: var(--section-bg); }

/* ------------------------------- Breadcrumb ------------------------------- */
.calc-breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: .84rem; color: var(--muted); margin-bottom: 16px; }
.calc-breadcrumb a { color: var(--muted); font-weight: 500; }
.calc-breadcrumb a:hover { color: var(--primary); }
.calc-breadcrumb .sep { width: 14px; height: 14px; opacity: .55; }
.calc-breadcrumb .current { color: var(--primary); font-weight: 600; }
[data-theme="dark"] .calc-breadcrumb { color: #C7C3DC; }
[data-theme="dark"] .calc-breadcrumb a { color: #BDB8D4; }
[data-theme="dark"] .calc-breadcrumb a:hover { color: var(--primary-light); }
[data-theme="dark"] .calc-breadcrumb .current { color: var(--primary-light); }

/* --------------------------------- Sidebar ------------------------------- */
.calc-side { position: sticky; top: calc(var(--header-h) + 22px); }
.side-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 18px; }
.side-card + .side-card { margin-top: 18px; }
.side-title { font-size: .74rem; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; padding-inline: 6px; }
.side-list { display: flex; flex-direction: column; gap: 2px; }
.side-list a { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 12px; font-size: .9rem; font-weight: 500; color: var(--text); transition: background var(--transition), color var(--transition); }
.side-list a:hover { background: var(--bg-soft); }
.side-list a.active { background: var(--tint-purple); color: var(--primary-dark); font-weight: 600; }
[data-theme="dark"] .side-list a.active { color: var(--primary-light); }
.side-list .icon-chip { width: 34px; height: 34px; border-radius: 9px; }
.side-list .icon-chip img { width: 18px; height: 18px; }

/* ============================ TOOL CARD ================================= */
.tool-calc {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-md); padding: clamp(16px, 2vh, 26px);
  display: flex; flex-direction: column; gap: clamp(14px, 2vh, 18px);
  min-height: calc(100dvh - var(--header-h) - 88px);
}
.tool-topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px 18px; flex-wrap: wrap; }
.tool-heading { display: flex; align-items: center; gap: 14px; }
.tool-heading .icon-chip { width: 48px; height: 48px; border-radius: 13px; }
.tool-heading .icon-chip img { width: 26px; height: 26px; }
.tool-heading h1 { font-size: clamp(1.1rem, 2.2vw, 1.4rem); font-weight: 700; line-height: 1.15; }
.tool-heading p { font-size: .84rem; color: var(--muted); }

/* Segmented tabs */
.tool-tabs { display: flex; flex-wrap: wrap; gap: 6px; background: var(--bg-soft); padding: 6px; border-radius: 14px; border: 1px solid var(--border); }
.tool-tab { flex: 1 1 auto; padding: 10px 12px; border-radius: 10px; font-size: .86rem; font-weight: 600; color: var(--muted); white-space: nowrap; transition: background var(--transition), color var(--transition), box-shadow var(--transition); }
.tool-tab:hover { color: var(--primary); }
.tool-tab.active { background: var(--primary-grad); color: #fff; box-shadow: var(--shadow-primary); }

.tool-panel { display: none; }
.tool-panel.active { display: block; animation: tool-fade .28s ease; }
@keyframes tool-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .tool-panel.active { animation: none; } }

/* Form area */
.tool-form { background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--r-md); padding: clamp(16px, 2.6vh, 26px); }
.tool-lead { font-size: .9rem; color: var(--muted); margin-bottom: 16px; }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.tool-field { display: flex; flex-direction: column; gap: 7px; }
.tool-field label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.tool-inwrap { position: relative; display: flex; align-items: center; }
.tool-in {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border-strong); border-radius: 12px;
  background: var(--card); color: var(--heading);
  font-family: inherit; font-size: 1.05rem; font-weight: 600;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.tool-in:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 92, 231, .16); }
.tool-in::placeholder { color: var(--muted); font-weight: 500; opacity: .75; }
.tool-in::-webkit-inner-spin-button, .tool-in::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.tool-in[type=number] { -moz-appearance: textfield; }
.tool-unit {
  position: absolute; right: 14px; font-size: .84rem; font-weight: 600; color: var(--muted); pointer-events: none;
}
.tool-inwrap .tool-in { padding-right: 52px; }

select.tool-in { appearance: none; cursor: pointer; padding-right: 34px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237A7690' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; }

/* Dynamic rows (GPA courses / grade assessments) */
.rows-head { display: grid; gap: 10px; font-size: .74rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); padding: 0 4px 6px; }
.tool-rows { display: flex; flex-direction: column; gap: 8px; }
.tool-row { display: grid; gap: 10px; align-items: center; }
.cols-3 { grid-template-columns: 1.4fr 1fr 1fr 40px; }
.cols-2 { grid-template-columns: 1.4fr 1fr 40px; }
.row-in { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border-strong); border-radius: 12px; background: var(--card); color: var(--heading); font-family: inherit; font-size: .98rem; font-weight: 600; }
.row-in:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 92, 231, .16); }
.row-in::placeholder { color: var(--muted); font-weight: 500; opacity: .7; }
.row-in::-webkit-inner-spin-button, .row-in::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
select.row-in { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237A7690' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 15px; padding-right: 30px; }
.row-del { width: 40px; height: 40px; border-radius: 10px; background: var(--tint-red); color: #E0415B; font-size: 1.2rem; font-weight: 700; line-height: 1; transition: background var(--transition); }
.row-del:hover { background: #F9D2D8; }
[data-theme="dark"] .row-del:hover { background: #4A2530; }
.row-add { margin-top: 12px; display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: var(--r-pill); background: var(--tint-purple); color: var(--primary-dark); font-size: .86rem; font-weight: 600; transition: background var(--transition), color var(--transition); }
[data-theme="dark"] .row-add { color: var(--primary-light); }
.row-add:hover { background: var(--primary); color: #fff; }

.tool-actions { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.tool-btn { padding: 12px 26px; border-radius: var(--r-pill); background: var(--primary-grad); color: #fff; font-weight: 600; font-size: .95rem; box-shadow: var(--shadow-primary); transition: transform var(--transition), box-shadow var(--transition); }
.tool-btn:hover { transform: translateY(-2px); box-shadow: 0 16px 32px rgba(92, 62, 232, .4); }
.tool-btn.ghost { background: var(--card); color: var(--heading); border: 1.5px solid var(--border-strong); box-shadow: none; }
.tool-btn.ghost:hover { border-color: var(--primary); color: var(--primary); transform: none; }

/* Result display */
.tool-display { margin-top: auto; background: linear-gradient(145deg, #4B3BA6 0%, #2E2568 100%); border-radius: var(--r-md); padding: clamp(16px, 2.6vh, 24px) clamp(20px, 3vw, 30px); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08); }
[data-theme="dark"] .tool-display { background: linear-gradient(145deg, #2E2568 0%, #1A1540 100%); border: 1px solid var(--border); }
.tool-display .t-label { font-size: .8rem; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: rgba(255, 255, 255, .55); margin-bottom: 4px; }
.tool-display .t-result { font-size: clamp(1.9rem, 6vh, 2.9rem); font-weight: 700; letter-spacing: .5px; line-height: 1.1; white-space: nowrap; overflow-x: auto; }
.tool-display .t-note { margin-top: 6px; font-size: .95rem; font-weight: 600; color: rgba(255, 255, 255, .72); min-height: 1.2em; }
.tool-display .t-note.good { color: #6EE7B7; }
.tool-display .t-note.warn { color: #FCD34D; }
.tool-display .t-note.bad  { color: #FDA4AF; }
.tool-display .t-note.info { color: #93C5FD; }

/* Stat tiles */
.tool-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat-tile { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px; padding: 12px 10px; text-align: center; }
.stat-tile .stat-label { display: block; font-size: .72rem; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.stat-tile .stat-val { font-size: 1.08rem; font-weight: 700; color: var(--heading); word-break: break-word; }

/* Calculation steps */
.tool-steps { background: var(--bg-soft); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 10px; padding: 12px 14px; font-size: .86rem; color: var(--text); line-height: 1.6; word-break: break-word; }
.tool-steps .st-title { display: block; font-size: .72rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }

/* ================== Formula · Examples · How-to panels ================== */
.calc-panels { padding-block: 26px; background: var(--bg); }
.panel-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 22px; height: 100%; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-head .p-ic { width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center; }
.panel-head .p-ic .micon { width: 22px; height: 22px; }
.p-ic.chip-purple { color: var(--primary); }
.p-ic.chip-green { color: var(--green-dark); }
.p-ic.chip-blue { color: #3B82F6; }
.p-ic.chip-red { color: #E0415B; }
.p-ic.chip-orange { color: #EA7A28; }
.panel-head h2 { font-size: 1.05rem; font-weight: 600; }
.panel-sub { font-size: .85rem; color: var(--muted); margin: -6px 0 14px; }

.formula-list { display: flex; flex-direction: column; gap: 10px; }
.formula-list li { padding: 12px 14px; border-radius: 12px; background: var(--bg-soft); }
.formula-list .f-name { display: block; font-size: .72rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.formula-list .f-eq { color: var(--heading); font-weight: 700; font-size: .96rem; }
.formula-list .f-eq b { color: var(--primary); }
[data-theme="dark"] .formula-list .f-eq b { color: var(--primary-light); }

.example-chips { display: flex; flex-wrap: wrap; gap: 9px; }
.ex-chip { padding: 9px 15px; border-radius: var(--r-pill); background: var(--tint-purple); color: var(--primary-dark); font-size: .86rem; font-weight: 600; border: 1px solid transparent; transition: background var(--transition), color var(--transition), transform var(--transition); }
[data-theme="dark"] .ex-chip { color: var(--primary-light); }
.ex-chip:hover { background: var(--primary); color: #fff; transform: translateY(-1px); }

.mini-steps { display: flex; flex-direction: column; }
.mini-steps li { position: relative; display: flex; gap: 14px; padding-bottom: 20px; }
.mini-steps li:last-child { padding-bottom: 0; }
.mini-steps li:not(:last-child)::before { content: ""; position: absolute; left: 13px; top: 30px; bottom: 0; width: 2px; background: var(--tint-purple); }
.mini-steps .s-num { position: relative; z-index: 1; flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--primary-grad); color: #fff; font-size: .8rem; font-weight: 700; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 10px rgba(92, 62, 232, .28); }
.mini-steps li span:not(.s-num) { padding-top: 4px; font-size: .9rem; color: var(--text); line-height: 1.55; }

/* Reference table (BMI categories, GPA scale, letter grades) */
.ref-table { width: 100%; border-collapse: collapse; margin: 20px 0 8px; font-size: .92rem; }
.ref-table th, .ref-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.ref-table th { font-size: .76rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.ref-table td { color: var(--text); font-weight: 500; }
.ref-table td:first-child { color: var(--heading); font-weight: 600; }
.ref-table tr:last-child td { border-bottom: none; }
.ref-badge { display: inline-block; padding: 3px 11px; border-radius: var(--r-pill); font-size: .8rem; font-weight: 600; }
.ref-badge.b-blue  { background: var(--tint-blue);  color: #2563EB; }
.ref-badge.b-green { background: var(--tint-green); color: var(--green-dark); }
.ref-badge.b-amber { background: var(--tint-amber); color: #B45309; }
.ref-badge.b-red   { background: var(--tint-red);   color: #DC2626; }

/* =============================== RESPONSIVE ============================= */
@media (max-width: 767.98px) {
  .calc-side { position: static; margin-top: 20px; }
  .tool-calc { min-height: 0; }
}
@media (max-width: 560px) {
  .tool-heading p { display: none; }
  .tool-heading .icon-chip { width: 42px; height: 42px; }
  .cols-3 { grid-template-columns: 1fr 1fr; }
  .cols-3 .row-name { grid-column: 1 / -1; }
  .cols-3 .row-del { position: absolute; }
  .tool-row.cols-3 { position: relative; padding-right: 48px; }
  .tool-row.cols-3 .row-del { right: 0; top: 50%; transform: translateY(-50%); }
  .rows-head { display: none; }
}

/* ==================== Collapsible breakdown table =====================
   Shared by the finance calculators (loan, investment, 401k, car payment,
   rent vs buy): a year-by-year schedule folded away under a summary so the
   answer stays above it, with the header row pinned while the body scrolls. */
.tool-tablewrap {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-soft);
  overflow: hidden;
}
.tool-tablewrap > summary {
  cursor: pointer;
  list-style: none;
  padding: 13px 16px;
  font-size: .86rem;
  font-weight: 600;
  color: var(--heading);
  display: flex;
  align-items: center;
  gap: 9px;
}
.tool-tablewrap > summary::-webkit-details-marker { display: none; }
.tool-tablewrap > summary::before {
  content: "";
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform var(--transition);
}
.tool-tablewrap[open] > summary::before { transform: rotate(45deg); }
.tool-tablewrap > summary:hover { color: var(--primary); }
.tool-tablewrap > summary .sum-note { margin-left: auto; font-weight: 500; color: var(--muted); font-size: .8rem; }

.tool-tablescroll { max-height: 340px; overflow: auto; border-top: 1px solid var(--border); }

.tool-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tool-table th, .tool-table td { padding: 9px 14px; text-align: right; white-space: nowrap; }
.tool-table th:first-child, .tool-table td:first-child { text-align: left; }
.tool-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-soft);
  box-shadow: inset 0 -1px 0 var(--border);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
}
.tool-table tbody td { border-bottom: 1px solid var(--border); color: var(--text); font-variant-numeric: tabular-nums; }
.tool-table tbody td:first-child { color: var(--heading); font-weight: 600; }
.tool-table tbody tr:last-child td { border-bottom: none; }
.tool-table tbody tr:hover td { background: var(--card); }

/* Multi-line data input (random picker list, statistics data set, …) */
.tool-area {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  padding: 12px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  background: var(--card);
  color: var(--heading);
  font-family: inherit;
  font-size: .95rem;
  font-weight: 500;
  line-height: 1.6;
}
.tool-area:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 92, 231, .16); }
.tool-area::placeholder { color: var(--muted); font-weight: 500; opacity: .75; }

/* Small explanatory line under a form block */
.tool-hint { margin-top: 10px; margin-bottom: 0; font-size: .82rem; color: var(--muted); line-height: 1.55; }
