/* ==========================================================================
   behtarinforex — tools (calculators, currency converter, economic calendar)
   Loaded only on the "Tools hub" and "Tool" page templates (inc/tools.php).
   Built on the global tokens (--bg --surface --ink --line --brand --gold …);
   everything here works in light and html.dark. RTL-first: logical props only.
   ========================================================================== */

:root {
  --bft-danger: #b91c1c;        /* text on light tints */
  --bft-danger-solid: #dc2626;  /* fills / dots */
  --bft-sticky-top: 96px;       /* clears the sticky site header */
  --bft-mono: "JetBrains Mono", Vazirmatn, ui-monospace, monospace;
}
html.dark {
  --bft-danger: #f87171;
  --bft-danger-solid: #ef4444;
}

/* ---- Page layout ------------------------------------------------------- */

.bft-wrap {
  padding-top: 40px;
  padding-bottom: 56px;
}

.bft-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.bft-content {
  min-width: 0;
  container: bft-content / inline-size;
}

@media (min-width: 1024px) {
  .bft-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 32px;
  }
  /* Sidebar sits in the first (right-hand, RTL) column; in the DOM it comes
     after the tool so it stacks below it on mobile. */
  .bft-side {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: var(--bft-sticky-top);
  }
  .bft-content {
    grid-column: 2;
    grid-row: 1;
  }
}

.bft-prose {
  margin-top: 40px;
}

/* ---- Sidebar (ToolsSidebar) ------------------------------------------- */

.bft-side {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.bft-side-title {
  padding: 0 8px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-3);
}

.bft-side-nav {
  display: grid;
  gap: 4px;
}

.bft-side-link {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  transition: background-color .15s, color .15s;
}
.bft-side-link:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.bft-side-link.is-active {
  background: var(--brand-50);
  color: var(--brand-700);
}

.bft-side-ico {
  display: inline-flex;
  flex-shrink: 0;
  margin-top: 4px;
  color: var(--ink-3);
}
.bft-side-ico svg {
  width: 18px;
  height: 18px;
}
.bft-side-link.is-active .bft-side-ico {
  color: var(--brand);
}

.bft-side-text {
  display: grid;
  min-width: 0;
}
.bft-side-label {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.6;
}
.bft-side-sub {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.6;
  opacity: .75;
}

/* ---- Hub grid --------------------------------------------------------- */

.bft-hub-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
@media (min-width: 640px) {
  .bft-hub-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .bft-hub-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.bft-hub-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  color: var(--ink);
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.bft-hub-card:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.bft-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--brand-50);
  color: var(--brand);
}
.bft-badge svg {
  width: 24px;
  height: 24px;
}

.bft-hub-title {
  margin: 16px 0 0;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.5;
  transition: color .2s;
}
.bft-hub-card:hover .bft-hub-title {
  color: var(--brand);
}
.bft-hub-sub {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink-2);
}

/* ---- Calculator layout (CalcLayout) ----------------------------------- */

.bft-calc {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@container bft-content (min-width: 680px) {
  .bft-calc {
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 24px;
  }
  .bft-aside {
    position: sticky;
    top: var(--bft-sticky-top);
  }
}

.bft-form {
  container: bft-form / inline-size;
  display: grid;
  gap: 18px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}

.bft-field {
  display: block;
  min-width: 0;
  margin: 0;
}

.bft-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.6;
  color: var(--ink);
}

.bft-input {
  display: block;
  width: 100%;
  min-height: 46px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* ≥16px stops iOS zooming into the field */
  line-height: 1.5;
  color-scheme: light;
  transition: border-color .15s, box-shadow .15s;
}
html.dark .bft-input {
  color-scheme: dark;
}
.bft-input:hover {
  border-color: var(--line-2);
}
.bft-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--brand) 22%, transparent);
}
.bft-input[type="number"] {
  direction: ltr;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
select.bft-input {
  cursor: pointer;
}

.bft-hint {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink-3);
}

/* From / To pair in the converter */
.bft-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}
@container bft-form (min-width: 440px) {
  .bft-pair {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
}

.bft-swap {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--brand);
  font-size: 14px;
  font-weight: 700;
}
.bft-swap:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Buy / sell toggle */
.bft-dir {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.bft-dir-btn {
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
  transition: background-color .15s, border-color .15s, color .15s;
}
.bft-dir-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.bft-dir-btn.is-buy[aria-pressed="true"] {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
html.dark .bft-dir-btn.is-buy[aria-pressed="true"] {
  color: #0b0f0c;
}
.bft-dir-btn.is-sell[aria-pressed="true"] {
  background: var(--bft-danger-solid);
  border-color: var(--bft-danger-solid);
  color: #fff;
}

/* ---- Result panel ----------------------------------------------------- */

.bft-aside {
  min-width: 0;
}

.bft-result {
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.bft-result[hidden] {
  display: none !important;
}

.bft-result-label {
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
  color: var(--ink-3);
}

.bft-result-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--brand);
  overflow-wrap: anywhere;
}
.bft-result-unit {
  margin-inline-start: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-3);
}
.bft-result-note {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--ink-3);
}

.bft-rows {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.bft-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.bft-row-k {
  color: var(--ink-3);
}
.bft-row-v {
  color: var(--ink);
  text-align: end;
  overflow-wrap: anywhere;
}

.bft-num {
  font-family: var(--bft-mono);
  font-variant-numeric: tabular-nums;
}

.bft-result-value.is-pos,
.bft-row-v.is-pos {
  color: var(--brand);
}
.bft-result-value.is-neg,
.bft-row-v.is-neg {
  color: var(--bft-danger);
}

.bft-empty {
  margin: 0;
  font-size: 14px;
  color: var(--ink-3);
}

/* ---- Economic calendar ------------------------------------------------ */

.bft-cal-body {
  display: grid;
  gap: 40px;
}

.bft-cal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.bft-cal-mark {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand);
}
.bft-cal-h {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.5;
  color: var(--ink);
}
.bft-cal-h.is-muted {
  margin-bottom: 16px;
  color: var(--ink-2);
}

.bft-cal-days {
  display: grid;
  gap: 20px;
}

.bft-cal-day {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.bft-cal-day.is-today {
  border-color: color-mix(in oklab, var(--brand) 40%, var(--line));
  background: color-mix(in oklab, var(--brand) 6%, var(--surface));
}
.bft-cal-day.is-past {
  opacity: .7;
}

.bft-cal-dayhead {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
}

.bft-cal-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.bft-cal-list > li + li {
  border-top: 1px solid var(--line);
}

.bft-ev {
  padding: 12px;
}
.bft-ev.is-past {
  opacity: .55;
}

.bft-ev-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bft-ev-time {
  flex-shrink: 0;
  width: 48px;
  font-family: var(--bft-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.bft-ev-ccy {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  width: 64px;
}
.bft-flag {
  display: block;
  width: 20px;
  height: 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  object-fit: cover;
}
.bft-globe {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  color: var(--ink-3);
}
.bft-globe svg {
  width: 14px;
  height: 14px;
}
.bft-ev-code {
  font-family: var(--bft-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
}

.bft-ev-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.bft-ev-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.bft-ev-pill {
  display: none;
  flex-shrink: 0;
  padding: 1px 8px;
  border: 1px solid;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}

.bft-ev-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 6px;
  padding-inline-start: 60px; /* time column + gap */
  font-size: 12px;
  color: var(--ink-2);
}
.bft-ev-meta b {
  font-weight: 700;
  color: var(--ink);
}

/* Impact colours (dot + pill) */
.bft-ev-dot.bft-imp-high    { background: var(--bft-danger-solid); }
.bft-ev-dot.bft-imp-medium  { background: var(--gold); }
.bft-ev-dot.bft-imp-low     { background: var(--ink-3); }
.bft-ev-dot.bft-imp-holiday { background: var(--brand); }

.bft-ev-pill.bft-imp-high {
  background: var(--danger-bg);
  border-color: color-mix(in oklab, var(--bft-danger-solid) 40%, transparent);
  color: var(--bft-danger);
}
.bft-ev-pill.bft-imp-medium {
  background: var(--gold-soft);
  border-color: color-mix(in oklab, var(--gold) 40%, transparent);
  color: var(--gold-3);
}
html.dark .bft-ev-pill.bft-imp-medium {
  color: var(--gold);
}
.bft-ev-pill.bft-imp-low {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink-2);
}
.bft-ev-pill.bft-imp-holiday {
  background: var(--brand-50);
  border-color: color-mix(in oklab, var(--brand) 40%, transparent);
  color: var(--brand-700);
}

.bft-cal-note {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
  text-align: center;
  color: var(--ink-2);
}
.bft-cal-empty {
  padding: 40px 20px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  color: var(--ink-2);
}

@media (min-width: 640px) {
  .bft-ev {
    padding: 12px 16px;
  }
  .bft-ev-pill {
    display: inline-block;
  }
}

/* ---- Small screens (down to 360px) ------------------------------------ */

@media (max-width: 640px) {
  .bft-wrap {
    padding-top: 28px;
    padding-bottom: 40px;
  }
}

@media (max-width: 480px) {
  .bft-form {
    padding: 18px;
    gap: 16px;
  }
  .bft-result {
    padding: 18px;
  }
  .bft-result-value {
    font-size: 26px;
  }
  .bft-hub-card {
    padding: 18px;
  }
  .bft-cal-dayhead {
    padding: 10px 12px;
  }
  .bft-ev-main {
    gap: 10px;
  }
  .bft-ev-ccy {
    width: 58px;
  }
  .bft-ev-meta {
    padding-inline-start: 58px;
  }
}
