/* Kaamko shared utility layer. Lines separate real controls and data groups. */
.page-tools .twrap--prose {
  width: min(1020px, 100% - 2rem);
}

.tbar__wordmark b {
  letter-spacing: -.035em;
}

.tbar__wordmark span {
  color: var(--ice-color-text-muted);
  font-size: .62rem;
  font-weight: 750;
  letter-spacing: .035em;
}

.page-tools .tool-panel,
.page-tools .tool-unitgroup,
.page-tools .tool-scroll,
.page-tools .tool-copybar,
.page-tools .tool-mode-note,
.page-tools .tool-preeti-preview {
  border-color: var(--ice-color-on-surface);
}

.page-tools .tool-panel__head {
  border-bottom: 2px solid var(--ice-color-on-surface);
}

.page-tools .tool-panel__body:has(> form + .tool-result) {
  display: grid;
  grid-template-columns: minmax(250px, .82fr) minmax(0, 1.18fr);
  padding: 0;
}

.page-tools .tool-panel__body:has(> form + .tool-result) > form {
  min-width: 0;
  padding: .85rem;
  border-right: 2px solid var(--ice-color-on-surface);
  background: var(--ice-color-surface-muted);
}

.page-tools .tool-panel__body:has(> form + .tool-result) > .tool-result {
  min-width: 0;
  margin: 0;
  padding: .85rem;
  border-top: 0;
}

.page-tools .tool-panel__body:has(> form + .tool-result) > .tool-note {
  grid-column: 1 / -1;
  margin: 0;
  border-top: 2px solid var(--ice-color-on-surface);
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
}

/* Interchangeable converters are one compound control, so their input row
   keeps the full panel width and the complete result grid follows below. */
.page-tools .tool-panel__body:has(> form .tool-converter) {
  grid-template-columns: 1fr;
}

.page-tools .tool-panel__body:has(> form .tool-converter) > form {
  border-right: 0;
  border-bottom: 2px solid var(--ice-color-on-surface);
}

/* A long amortisation schedule needs the panel width. Keeping it beside the
   loan form makes every currency column wrap and leaves no stable scroll head. */
.page-tools .tool-panel__body:has(#schedule) {
  grid-template-columns: 1fr;
}

.page-tools .tool-panel__body:has(#schedule) > form {
  border-right: 0;
  border-bottom: 2px solid var(--ice-color-on-surface);
}

/* Preeti modes are three distinct tools. The active cell must read as state,
   not as a slightly different label inside a pale container. */
.page-tools .tool-panel__head:has(.tool-modes--three) {
  display: grid;
  grid-template-columns: minmax(180px, .48fr) minmax(0, 1.52fr);
  align-items: stretch;
  padding: 0;
}

.page-tools .tool-panel__head:has(.tool-modes--three) .tool-panel__title {
  display: flex;
  align-items: center;
  padding: .7rem .85rem;
  border-right: 2px solid var(--ice-color-on-surface);
}

.page-tools .tool-modes--three {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
  gap: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--ice-color-surface);
}

.page-tools .tool-modes--three button {
  min-width: 0;
  min-height: 56px;
  padding: .55rem .65rem;
  border-left: 2px solid var(--ice-color-on-surface);
  border-radius: 0;
  background: var(--ice-color-surface);
  color: var(--ice-color-on-surface-muted);
  line-height: 1.25;
}

.page-tools .tool-modes--three button:first-child {
  border-left: 0;
}

.page-tools .tool-modes--three button:hover:not([aria-pressed='true']) {
  background: var(--ice-color-surface-muted);
  color: var(--ice-color-on-surface);
}

.page-tools .tool-modes--three button[aria-pressed='true'] {
  background: var(--ice-color-on-surface);
  color: var(--ice-color-surface);
  box-shadow: inset 0 -4px 0 var(--ice-color-text-action);
}
.page-tools .tool-fieldset {
  padding: .7rem;
  border: 2px solid var(--ice-color-border-strong);
  background: var(--ice-color-surface);
}

.page-tools .tool-fieldset + .tool-fieldset {
  margin-top: .65rem;
}

.page-tools .tool-fieldset > legend {
  width: auto;
  padding: 0 .35rem;
  color: var(--ice-color-on-surface);
  background: var(--ice-color-surface);
  font-size: .7rem;
  font-weight: 800;
}

.page-tools .tool-headline {
  font-size: clamp(1.35rem, 1.2rem + .75vw, 1.8rem);
}

.page-tools .tool-headline__sub {
  margin-top: .35rem;
  font-size: .78rem;
  line-height: 1.4;
}

.page-tools .tool-units {
  gap: 0;
  border-top: 2px solid var(--ice-color-on-surface);
  border-left: 2px solid var(--ice-color-on-surface);
}

.page-tools .tool-unitgroup {
  padding: .65rem;
  border-width: 0 2px 2px 0;
  border-radius: 0;
}

.page-tools .tool-unitgroup h3 {
  margin-bottom: .4rem;
}

.page-tools .tool-readout th,
.page-tools .tool-readout td {
  padding-block: .46rem;
  border-bottom: 2px solid var(--ice-color-border-strong);
  font-size: .82rem;
}

.page-tools .tool-readout td {
  border-left: 2px solid var(--ice-color-border-strong);
  padding-left: .55rem;
}

.page-tools .tool-readout tr:last-child th,
.page-tools .tool-readout tr:last-child td {
  border-bottom: 0;
}

.page-tools .tool-scroll {
  border-width: 2px;
  border-radius: 0;
}

/* EMI result and schedule */
.page-tools #emi-form + .tool-result .tool-unitgroup {
  display: grid;
  grid-template-rows: auto 1fr;
}

.page-tools #emi-form + .tool-result .tool-unitgroup h3 {
  min-height: 2.35em;
}

.page-tools #emi-form + .tool-result .tool-unitgroup .tool-readout td,
.page-tools #schedule th,
.page-tools #schedule td {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.page-tools #schedule {
  max-height: 380px;
  overflow: auto;
  border-color: var(--ice-color-on-surface);
  background: var(--ice-color-surface);
  scrollbar-gutter: stable;
}

.page-tools #schedule .tool-readout {
  width: 100%;
  min-width: 680px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.page-tools #schedule thead th {
  position: sticky;
  z-index: 3;
  top: 0;
  height: 42px;
  padding: .6rem .75rem;
  border-bottom: 2px solid var(--ice-color-on-surface);
  background: var(--ice-color-surface-muted);
  box-shadow: 0 2px 0 var(--ice-color-on-surface);
}

.page-tools #schedule thead th:first-child {
  width: 72px;
}

.page-tools #schedule tbody th,
.page-tools #schedule tbody td {
  padding: .52rem .75rem;
}

.page-tools #schedule tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--ice-color-surface-muted) 58%, transparent);
}

.page-tools #schedule tbody tr:hover {
  background: var(--ice-color-surface-muted);
}

/* Unit results are one conversion matrix, not two unrelated half-tables. */
.page-tools .unit-matrix {
  display: block;
  margin-top: 0;
}

.page-tools .unit-matrix caption {
  display: block;
  width: 100%;
  padding: .65rem .75rem;
  border: 2px solid var(--ice-color-on-surface);
  border-bottom: 0;
  background: var(--ice-color-surface-muted);
  color: var(--ice-color-on-surface-muted);
}

.page-tools .unit-matrix tbody {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  border-top: 2px solid var(--ice-color-on-surface);
  border-left: 2px solid var(--ice-color-on-surface);
}

.page-tools .unit-matrix tr {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(118px, .58fr);
  align-items: stretch;
  border-right: 2px solid var(--ice-color-on-surface);
  border-bottom: 2px solid var(--ice-color-on-surface);
  background: var(--ice-color-surface);
}

.page-tools .unit-matrix th,
.page-tools .unit-matrix td {
  display: flex;
  align-items: center;
  min-width: 0;
  width: auto;
  min-height: 46px;
  padding: .58rem .75rem;
  border-bottom: 0;
}

.page-tools .unit-matrix th {
  color: var(--ice-color-on-surface-muted);
  font-weight: 650;
}

.page-tools .unit-matrix td {
  justify-content: flex-end;
  border-left: 2px solid var(--ice-color-on-surface);
  background: color-mix(in srgb, var(--ice-color-surface-muted) 56%, transparent);
  font-weight: 800;
  white-space: nowrap;
}

.page-tools .unit-matrix + .tool-actions {
  display: flex;
  align-items: center;
  min-height: 58px;
  margin-top: 0;
  padding: .55rem .65rem;
  border: 2px solid var(--ice-color-on-surface);
  border-top: 0;
  background: var(--ice-color-surface-muted);
}

.page-tools .unit-matrix + .tool-actions .tool-status {
  margin: 0 0 0 auto;
  font-size: .78rem;
}

/* Explanatory copy becomes a compact editorial grid instead of a long column. */
.page-tools .tool-explainer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-block: 1.4rem .7rem;
}

.page-tools .tool-explainer > * {
  min-width: 0;
  margin: 0 !important;
  padding: .8rem;
  border-right: 2px solid var(--ice-color-on-surface);
  border-bottom: 2px solid var(--ice-color-on-surface);
}

.page-tools .tool-explainer > :first-child {
  border-top: 2px solid var(--ice-color-on-surface);
}

.page-tools .tool-explainer > h2 {
  grid-column: 1 / -1;
  border-left: 2px solid var(--ice-color-on-surface);
  background: var(--ice-color-surface);
  font-size: clamp(1.2rem, 1.05rem + .65vw, 1.55rem);
}

.page-tools .tool-explainer > :nth-child(even) {
  border-left: 2px solid var(--ice-color-on-surface);
}

.page-tools .tool-explainer > h3 {
  color: var(--ice-color-on-surface-muted);
  background: var(--ice-color-surface-muted);
  font-size: .82rem;
  line-height: 1.35;
}

/* A topic heading and its answer must never be split into unrelated columns. */
.page-tools .tool-explainer > h3,
.page-tools .tool-explainer > h3 ~ *,
.page-tools .tool-explainer > h2 + p:has(+ h3) {
  grid-column: 1 / -1;
  border-left: 2px solid var(--ice-color-on-surface);
}
.page-tools .tool-explainer > p,
.page-tools .tool-explainer > ul,
.page-tools .tool-explainer > ol {
  font-size: .82rem;
  line-height: 1.5;
}

.page-tools .tool-explainer > .tool-facts {
  max-width: none;
  font-size: .84rem;
  line-height: 1.35;
  letter-spacing: 0;
}

.page-tools .tool-related {
  padding-block: .7rem 1.5rem;
  border-top: 2px solid var(--ice-color-on-canvas);
}

.page-tools .tool-related h2 {
  margin-bottom: .55rem;
}

.calendar-selected,
.calendar-facts,
.calendar-copy {
  padding: .72rem .8rem;
}

.calendar-selected strong {
  margin-top: .3rem;
  font-size: 1.02rem;
}

.calendar-selected p {
  margin-top: .25rem;
  font-size: .72rem;
}

.calendar-facts {
  align-content: center;
  gap: .5rem;
  background: var(--ice-color-surface-muted);
}

.page-tools .calendar-facts > div {
  align-items: center;
  min-height: 42px;
  padding: .5rem .58rem;
  border: 2px solid var(--ice-color-on-surface);
  background: var(--ice-color-surface);
}

/* The leading calendar is a mode, not a preference hint. Match the converter
   tabs so the active system is obvious before the user reads the month. */
.page-tools .calendar-controls .tool-modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  padding: 0;
  border: 2px solid var(--ice-color-on-surface);
  border-radius: 3px;
  overflow: hidden;
  background: var(--ice-color-surface);
}

.page-tools .calendar-controls .tool-modes button {
  min-width: 74px;
  border-left: 2px solid var(--ice-color-on-surface);
  border-radius: 0;
  background: var(--ice-color-surface);
  color: var(--ice-color-on-surface-muted);
}

.page-tools .calendar-controls .tool-modes button:first-child {
  border-left: 0;
}

.page-tools .calendar-controls .tool-modes button[aria-pressed='true'] {
  background: var(--ice-color-on-surface);
  color: var(--ice-color-surface);
  box-shadow: inset 0 -4px 0 var(--ice-color-text-action);
}

.calendar-copy output {
  min-height: 1.5em;
}

/* Today is a quiet filled state. Selection remains a separate dark focus
   treatment for any other day. */
.page-tools .calendar-grid td.is-today,
.page-tools .calendar-grid td.is-today .calendar-day,
.page-tools .calendar-grid td.is-today .calendar-day[aria-pressed='true'] {
  background: color-mix(in srgb, var(--ice-color-text-accent) 14%, var(--ice-color-surface));
  box-shadow: none;
}

.page-tools .calendar-grid td.is-today .calendar-day::after {
  padding: 0;
  border: 0;
  background: transparent;
}

/* Keep selected facts compact, then give every copy format the full width. */
.page-tools .calendar-inspector {
  grid-template-columns: minmax(0, 1.2fr) minmax(230px, .8fr);
}

.page-tools .calendar-copy {
  display: block;
  grid-column: 1 / -1;
  padding: .72rem;
  border-top: 2px solid var(--ice-color-on-surface);
  background: var(--ice-color-surface-muted);
}

.calendar-copy__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .65rem;
  padding: .55rem .7rem .55rem .85rem;
  border: 2px solid var(--ice-color-on-surface);
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--ice-color-text-action) 16%, var(--ice-color-surface)) 0%,
    var(--ice-color-surface) 72%
  );
  box-shadow: inset 5px 0 0 var(--ice-color-text-action);
}

.calendar-copy__head span {
  color: var(--ice-color-on-surface-muted);
  font-size: .68rem;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.calendar-copy__head small {
  color: var(--ice-color-text-muted);
  font-size: .68rem;
}

.calendar-copy-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .58rem;
}

.calendar-copy-option {
  min-width: 0;
  min-height: 82px;
  padding: 0;
  border: 2px solid var(--ice-color-on-surface);
  border-radius: 3px;
  background: var(--ice-color-surface);
  color: var(--ice-color-on-surface);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

.calendar-copy-option > span {
  display: block;
  min-height: 34px;
  padding: .48rem .58rem;
  border-bottom: 2px solid var(--ice-color-on-surface);
  background: color-mix(in srgb, var(--ice-color-text-action) 7%, var(--ice-color-surface));
  color: var(--ice-color-on-surface-muted);
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: .035em;
  text-transform: uppercase;
}

.calendar-copy-option output {
  display: block;
  min-height: 0;
  padding: .58rem .62rem .65rem;
  color: var(--ice-color-on-surface);
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.calendar-copy-option:hover,
.calendar-copy-option:focus-visible,
.calendar-copy-option[data-copy-state='copied'] {
  background: color-mix(in srgb, var(--ice-color-text-action) 8%, var(--ice-color-surface));
}

.calendar-copy-option:hover {
  transform: translateY(-2px);
  box-shadow: 3px 3px 0 color-mix(in srgb, var(--ice-color-on-surface) 20%, transparent);
}

.calendar-copy-option:active {
  transform: translateY(1px);
  box-shadow: none;
}

.calendar-copy-option:focus-visible {
  outline: 3px solid var(--ice-color-text-action);
  outline-offset: -3px;
}

.calendar-copy-option[data-copy-state='copied'] {
  box-shadow: inset 0 -4px 0 var(--ice-color-text-action);
}

.page-tools .calendar-copy > .tool-status {
  min-height: 0;
  margin: .5rem 0 0;
  padding: 0 .1rem;
  font-size: .7rem;
}

.page-tools .tool-fields,
.page-tools .tool-textpair {
  gap: 0;
  border-top: 2px solid var(--ice-color-on-surface);
  border-left: 2px solid var(--ice-color-on-surface);
}

.page-tools .tool-fields > .tool-field,
.page-tools .tool-textpair > .tool-field {
  padding: .58rem;
  border-right: 2px solid var(--ice-color-on-surface);
  border-bottom: 2px solid var(--ice-color-on-surface);
  background: var(--ice-color-surface);
}

.page-tools .tool-textpair textarea {
  min-height: 180px;
}
/* Copy bars live inside narrow form columns on split result panels. Keep the
   preview on its own row so no result can collapse into vertical letters. */
.page-tools .tool-copybar {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .5rem;
  margin-top: .75rem;
  padding: .7rem;
}

.page-tools .tool-copybar label {
  grid-column: 1 / -1;
}

.page-tools .tool-copybar select {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
}

.page-tools .tool-copybar .tool-action {
  grid-column: 2;
  grid-row: 2;
}

.page-tools .tool-copybar output {
  grid-column: 1 / -1;
  grid-row: 3;
  width: 100%;
  min-width: 0;
  min-height: 2.2rem;
  padding: .45rem .5rem;
  border: 2px solid var(--ice-color-border-strong);
  background: var(--ice-color-surface);
  overflow-wrap: anywhere;
}
/* Result values announce their copy behavior only when approached. */
.tool-quickcopy {
  position: relative;
  cursor: copy;
  outline: 0;
  transition: background-color .12s ease, box-shadow .12s ease;
}

.tool-readout td.tool-quickcopy {
  padding-right: 3rem;
}

.tool-quickcopy::after {
  content: 'Copy';
  position: absolute;
  top: .25rem;
  right: .25rem;
  padding: .17rem .28rem;
  border: 1px solid currentColor;
  background: var(--ice-color-surface);
  color: var(--ice-color-text-action);
  font: 800 .56rem/1 var(--ice-font-primary);
  letter-spacing: .045em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
}

.tool-quickcopy:hover,
.tool-quickcopy:focus-visible {
  background: color-mix(in srgb, var(--ice-color-text-action) 8%, var(--ice-color-surface));
  box-shadow: inset 0 0 0 2px var(--ice-color-text-action);
}

.tool-quickcopy:hover::after,
.tool-quickcopy:focus-visible::after,
.tool-quickcopy[data-copy-state='copied']::after {
  opacity: 1;
}

.tool-quickcopy[data-copy-state='copied']::after {
  content: 'Copied';
  color: var(--ice-color-on-action);
  border-color: var(--ice-color-action);
  background: var(--ice-color-action);
}

.tool-copy-toast {
  position: fixed;
  right: .75rem;
  bottom: .75rem;
  z-index: 20;
  padding: .6rem .75rem;
  border: 2px solid var(--ice-color-on-surface);
  background: var(--ice-color-surface);
  color: var(--ice-color-on-surface);
  font-size: .75rem;
  font-weight: 800;
  opacity: 0;
  transform: translateY(.3rem);
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
}

.tool-copy-toast[data-visible='true'] {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .page-tools .tool-panel__body:has(> form + .tool-result) {
    grid-template-columns: 1fr;
  }

  .page-tools .tool-panel__body:has(> form + .tool-result) > form {
    padding: .7rem;
    border-right: 0;
    border-bottom: 2px solid var(--ice-color-on-surface);
  }

  .page-tools .tool-panel__body:has(> form + .tool-result) > .tool-result {
    padding: .7rem;
  }

  .page-tools .tool-panel__head:has(.tool-modes--three) {
    grid-template-columns: 1fr;
  }

  .page-tools .tool-panel__head:has(.tool-modes--three) .tool-panel__title {
    min-height: 42px;
    padding: .55rem .7rem;
    border-right: 0;
    border-bottom: 2px solid var(--ice-color-on-surface);
  }

  .page-tools .tool-modes--three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .page-tools .tool-modes--three button {
    min-height: 54px;
    padding: .45rem .35rem;
    font-size: .72rem;
  }

  .page-tools .tool-explainer {
    grid-template-columns: 1fr;
    padding-top: .9rem;
  }

  .page-tools .tool-explainer > * {
    grid-column: 1;
    border-left: 2px solid var(--ice-color-on-surface);
    padding: .68rem;
  }

  .page-tools .unit-matrix tbody {
    grid-template-columns: 1fr;
  }

  .page-tools .unit-matrix tr {
    grid-template-columns: minmax(0, 1fr) minmax(105px, .65fr);
  }

  .page-tools .calendar-inspector {
    grid-template-columns: 1fr;
  }

  .calendar-copy-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .calendar-selected,
  .calendar-facts,
  .calendar-copy {
    padding: .62rem .7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tool-quickcopy,
  .tool-copy-toast {
    transition: none;
  }
}
