/* ==========================================================================
   calculator.css — the currency calculator (templates/exchange/_calculator.html)
   Loaded on the home and rates pages, after base.css and components.css.
   ========================================================================== */

.calc-section {
  padding-block: var(--space-7);
}

/* The open currency list overhangs the card. Sections after this one carry
   scroll-reveal transforms, which make their own stacking contexts and would
   otherwise paint over it. */
.calc-section,
.rates-calc {
  position: relative;
  z-index: 2;
}

.calc {
  background: var(--color-surface-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
  max-width: 880px;
  margin-inline: auto;
}

@media (min-width: 768px) {
  .calc { padding: var(--space-6); }
}

.calc__head { margin-bottom: var(--space-5); }

.calc__title {
  font-size: var(--text-xl);
  margin-bottom: var(--space-2);
}

.calc__lead {
  color: var(--color-text-muted);
  margin: 0;
}

/* --- transaction type ------------------------------------------------------ */

.calc__modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  padding: var(--space-1);
  background: var(--color-bg-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
}

.calc__mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: calc(var(--radius-md) - 2px);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-weight: 700;
  font-size: var(--text-sm);
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.calc__mode-sub {
  font-weight: 500;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.calc__mode[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-text-invert);
  box-shadow: var(--shadow-sm);
}

.calc__mode[aria-pressed="true"] .calc__mode-sub {
  color: rgba(255, 255, 255, 0.82);
}

@media (hover: hover) {
  .calc__mode[aria-pressed="false"]:hover {
    background: var(--color-primary-tint);
  }
}

/* --- fields ---------------------------------------------------------------- */

.calc__body {
  display: grid;
  gap: var(--space-4);
}

.calc__field {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.calc__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
}

.calc__input-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 52px;
  padding-inline: var(--space-3);
  background: var(--white);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

.calc__input-wrap:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-tint);
}

.calc__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-md);
  font-weight: 600;
  padding-block: var(--space-2);
}

.calc__input:focus {
  outline: none;
}

.calc__input {
  font-variant-numeric: tabular-nums;
}

.calc__unit {
  flex: none;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-primary-strong);
  background: var(--color-primary-tint);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-2);
}

.calc__unit--lead {
  background: transparent;
  padding: 0;
  color: var(--color-text-muted);
}

/* The IDR side carries the brand yellow — it is the number the customer came
   to find out. */
.calc__input-wrap--result {
  background: var(--yellow-100);
  border-color: var(--yellow-600);
}

/* --- the pair: foreign <-> IDR, with the swap between ---------------------- */

.calc__pair {
  display: grid;
  gap: var(--space-3);
  align-items: end;
}

.calc__swap {
  justify-self: center;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  background: var(--color-surface-card);
  color: var(--color-primary);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-base, 200ms) var(--ease-out);
}

.calc__swap:hover,
.calc__swap:focus-visible {
  background: var(--color-primary);
  color: var(--color-text-invert);
}

.calc[data-mode="buy"] .calc__swap svg { transform: rotate(180deg); }

/* "I want foreign cash" reads IDR first: what you pay, then what you get. */
.calc[data-mode="buy"] .calc__field--idr     { order: 1; }
.calc[data-mode="buy"] .calc__swap           { order: 2; }
.calc[data-mode="buy"] .calc__field--foreign { order: 3; }

@media (min-width: 720px) {
  .calc__pair {
    grid-template-columns: 1fr auto 1fr;
  }
  .calc__swap {
    margin-bottom: 4px;
  }
  .calc__swap svg { transform: rotate(90deg); }
  .calc[data-mode="buy"] .calc__swap svg { transform: rotate(-90deg); }
}

.calc__rate {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary-strong);
  font-variant-numeric: tabular-nums;
}

.calc__note {
  margin: var(--space-5) 0 0;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
}

.calc__updated {
  display: block;
  margin-top: var(--space-1);
  font-weight: 600;
}

/* On the rates page the calculator sits above the board, inside its column. */
.rates-calc {
  margin-top: var(--space-6);
}

/* --- currency picker (built by calculator.js) ------------------------------ */

.ccy-select {
  position: relative;
}

/* No-JS fallback: the native select, dressed like the other fields. Hidden
   (via the `hidden` attribute) once the custom picker takes over. */
.calc__select {
  width: 100%;
  min-height: 52px;
  padding: 0 var(--space-3);
  background: var(--white);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-md);
  font-weight: 600;
}

.ccy-select__button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 56px;
  padding: var(--space-2) var(--space-3);
  background: var(--white);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .ccy-select__button:hover { border-color: var(--color-primary); }
}

.ccy-select__button:focus-visible,
.ccy-select.is-open .ccy-select__button {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-tint);
}

.ccy-select__value {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
}

.ccy-select__chevron {
  flex: none;
  width: 10px;
  height: 10px;
  margin-right: var(--space-1);
  border-right: 2px solid var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
  transform: translateY(-3px) rotate(45deg);
  transition: transform var(--dur-fast) var(--ease-out);
}

.ccy-select.is-open .ccy-select__chevron {
  transform: translateY(2px) rotate(-135deg);
}

/* --- option content, shared by the button and the list --- */

.ccy-select__flag {
  flex: none;
  width: 28px;
  height: 21px;
  border-radius: 3px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(20, 21, 43, 0.12);
}

.ccy-select__flag--blank {
  background: var(--color-bg-subtle);
}

.ccy-select__text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.ccy-select__top {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  min-width: 0;
}

.ccy-select__code {
  flex: none;
  font-weight: 800;
  font-size: var(--text-md);
  color: var(--color-primary-strong);
  letter-spacing: 0.02em;
}

.ccy-select__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.ccy-select__denom {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-accent-text);
}

.ccy-select__rate {
  flex: none;
  margin-left: auto;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

/* --- popup --- */

.ccy-select__popup {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  max-height: min(380px, 70vh);
  background: var(--color-surface-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(10, 27, 61, 0.18), 0 2px 6px rgba(10, 27, 61, 0.08);
  overflow: hidden;
  animation: ccy-pop var(--dur-fast) var(--ease-out);
  transform-origin: top center;
}

.ccy-select.is-up .ccy-select__popup {
  top: auto;
  bottom: calc(100% + 6px);
  transform-origin: bottom center;
}

@keyframes ccy-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ccy-select__popup { animation: none; }
}

.ccy-select__popup[hidden] { display: none; }

.ccy-select__search {
  flex: none;
  margin: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-2) 36px;
  min-height: 40px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--white)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235C5E77' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E")
    no-repeat 11px center / 16px 16px;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-base);
}

.ccy-select__search:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-tint);
}

.ccy-select__list {
  flex: 1;
  margin: 0;
  padding: 0 var(--space-2) var(--space-2);
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ccy-select__option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.ccy-select__option.is-active {
  background: var(--color-primary-tint);
}

.ccy-select__option[aria-selected="true"] {
  background: var(--yellow-100);
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.ccy-select__option[aria-selected="true"].is-active {
  background: #FCEFA0;
}

.ccy-select__empty {
  margin: 0;
  padding: var(--space-4) var(--space-3) var(--space-5);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Narrow phones: the name gives way before the code and the rate do. */
@media (max-width: 380px) {
  .ccy-select__option .ccy-select__name { display: none; }
}
