/* =========================================================
   Currency Calculator Shortcode — calculator.css
   Plugin: zsh-currency-history
   Theme: Navy & Gold (matched to reference design)
   ========================================================= */

/* ── Custom Properties ─────────────────────────────────── */
.ch-calculator {
    /* Light theme (default) */
    --ch-bg:           #ffffff;
    --ch-bg-alt:       #f8f8fb;
    --ch-bg-card:      #ffffff;
    --ch-border:       #ececf3;
    --ch-primary:      #171a54;
    --ch-primary-h:    #0f1140;
    --ch-primary-15:   rgba(23, 26, 84, 0.08);
    --ch-accent:       #f0c419;
    --ch-accent-h:     #dcae0a;
    --ch-accent-15:    rgba(240, 196, 25, 0.16);
    --ch-text:         #17182c;
    --ch-text-sec:     #6b6d80;
    --ch-text-muted:   #9799ab;
    --ch-success:      #1a9c6b;
    --ch-danger:       #e5484d;
    --ch-shadow-sm:    0 1px 3px rgba(23,26,84,.06), 0 1px 2px rgba(23,26,84,.04);
    --ch-shadow-md:    0 10px 30px rgba(23,26,84,.09);
    --ch-shadow-lg:    0 14px 40px rgba(240,196,25,.18);
    --ch-radius:       18px;
    --ch-radius-sm:    12px;
    --ch-radius-xs:    8px;
    --ch-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, "IRANSans", "Vazirmatn", sans-serif;
    --ch-transition:   all .22s cubic-bezier(.4,0,.2,1);
}

/* Dark theme */
.ch-calculator.ch-theme-dark {
    --ch-bg:           #12143f;
    --ch-bg-alt:       #191c53;
    --ch-bg-card:      #191c53;
    --ch-border:       #2b2e6b;
    --ch-primary:      #f0c419;
    --ch-primary-h:    #f7d552;
    --ch-primary-15:   rgba(240, 196, 25, 0.16);
    --ch-accent:       #f0c419;
    --ch-text:         #f5f6ff;
    --ch-text-sec:     #a6a8d6;
    --ch-text-muted:   #7477ab;
    --ch-shadow-md:    0 10px 30px rgba(0,0,0,.35);
    --ch-shadow-lg:    0 14px 40px rgba(240,196,25,.20);
}

.ch-calculator.ch-theme-dark .ch-calc__header {
    background: linear-gradient(135deg, #0f1140 0%, #171a54 100%);
}

.ch-calculator.ch-theme-dark .ch-calc__pair-btn.is-active,
.ch-calculator.ch-theme-dark .ch-calc__swap:hover {
    color: var(--ch-primary-h);
}

/* ── Base ───────────────────────────────────────────────── */
.ch-calculator *,
.ch-calculator *::before,
.ch-calculator *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.ch-calculator {
    font-family: 'iranyekan';
    direction: rtl;
    background: var(--ch-bg);
    border: 1px solid var(--ch-border);
    border-radius: var(--ch-radius);
    box-shadow: var(--ch-shadow-md);
    overflow: hidden;
    max-width: 720px;
    margin: 0 auto 2rem;
    transition: var(--ch-transition);
}

/* ── Header ─────────────────────────────────────────────── */
.ch-calc__header {
    background: linear-gradient(135deg, var(--ch-primary) 0%, #23285f 100%);
    padding: 1.6rem 1.75rem 1.35rem;
    color: #fff;
    position: relative;
    overflow: hidden;
}

.ch-calc__header::after {
    content: '';
    position: absolute;
    top: -40%;
    left: -10%;
    width: 220px;
    height: 220px;
    background: radial-gradient(circle, rgba(240,196,25,.18) 0%, rgba(240,196,25,0) 70%);
    pointer-events: none;
}

.ch-calc__header-inner {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-wrap: wrap;
    position: relative;
}

.ch-calc__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 50%;
    background: var(--ch-accent-15);
    color: var(--ch-accent);
    flex-shrink: 0;
}

.ch-calc__title {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -.01em;
    flex: 1;
    min-width: 0;
    color: #fff;
}

.ch-calc__live-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    background: rgba(240,196,25,.14);
    border: 1px solid rgba(240,196,25,.35);
    border-radius: 100px;
    padding: .18rem .65rem;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
    color: var(--ch-accent);
    backdrop-filter: blur(4px);
}

.ch-calc__live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ch-accent);
    box-shadow: 0 0 0 0 rgba(240,196,25,.6);
    animation: ch-pulse 1.8s ease-in-out infinite;
}

@keyframes ch-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(240,196,25,.6); }
    60%  { box-shadow: 0 0 0 6px rgba(240,196,25,.0); }
    100% { box-shadow: 0 0 0 0   rgba(240,196,25,.0); }
}

.ch-calc__subtitle {
    margin-top: .4rem;
    font-size: .8rem;
    opacity: .7;
    padding-right: .1rem;
    position: relative;
}

/* ── Pairs Nav ──────────────────────────────────────────── */
.ch-calc__pairs {
    display: flex;
    gap: .4rem;
    overflow-x: auto;
    padding: .9rem 1.25rem;
    background: var(--ch-bg-alt);
    border-bottom: 1px solid var(--ch-border);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--ch-border) transparent;
    flex-wrap: nowrap;
}

.ch-calc__pairs::-webkit-scrollbar { display: none; }

.ch-calc__pair-btn {
    flex-shrink: 0;
    background: var(--ch-bg);
    border: 1.5px solid var(--ch-border);
    border-radius: 100px;
    color: var(--ch-text-sec);
    cursor: pointer;
    font-family: 'iranyekan';
    font-size: .78rem;
    font-weight: 500;
    padding: .35rem .85rem;
    transition: var(--ch-transition);
    white-space: nowrap;
    line-height: 1.4;
}

.ch-calc__pair-btn:hover {
    border-color: var(--ch-accent);
    color: var(--ch-primary);
    background: var(--ch-accent-15);
}

.ch-calc__pair-btn.is-active {
    background: var(--ch-primary);
    border-color: var(--ch-primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(23,26,84,.25);
}

/* ── Body ───────────────────────────────────────────────── */
.ch-calc__body {
    padding: 1.5rem 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* ── Input Row ──────────────────────────────────────────── */
.ch-calc__row--input {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: .75rem;
    align-items: end;
}

.ch-calc__label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--ch-text-sec);
    margin-bottom: .4rem;
    letter-spacing: .01em;
}

.ch-calc__input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.ch-calc__input,
.ch-calc__output {
    width: 100%;
    background: var(--ch-bg-alt);
    border-radius: var(--ch-radius-sm) !important;
    border: unset !important;
    color: var(--ch-text);
    height: 47px !important;
    font-family: 'iranyekan';
    font-size: 1.15rem;
    font-weight: 700;
    padding: .75rem 1rem .75rem 5.5rem;
    transition: var(--ch-transition);
    direction: ltr;
    text-align: right;
}

.ch-calc__input:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--ch-accent-15);
    background: var(--ch-bg);
}

.ch-calc__input::-webkit-inner-spin-button,
.ch-calc__input::-webkit-outer-spin-button { -webkit-appearance: none; }
.ch-calc__input { -moz-appearance: textfield; }

.ch-calc__input,
.ch-calc__output {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    cursor: default;
    background: var(--ch-bg-alt);
    border: 1.5px solid var(--ch-border) !important;
    min-height: 3.1rem;
}

.ch-calc__output {
    background: linear-gradient(135deg, var(--ch-accent-15), var(--ch-bg-alt));
    border-color: rgba(240,196,25,.35) !important;
    color: var(--ch-primary);
}

.ch-calc__currency-badge {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    padding: 0 .7rem;
    background: var(--ch-bg-card);
    border-radius: 0 var(--ch-radius-sm) var(--ch-radius-sm) 0;
    font-size: .72rem;
    font-weight: 700;
    color: var(--ch-primary);
    letter-spacing: .02em;
    white-space: nowrap;
    min-width: 4.5rem;
    justify-content: center;
}

.ch-calc__currency-badge--to {
    color: var(--ch-accent-h);
    border: 1px solid;
}

.ch-calc__currency-badge--from {
    color: var(--ch-accent-h);
    border: 1px solid;
}

/* ── Swap Button ────────────────────────────────────────── */
.ch-calc__swap {
    align-self: end;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.6rem;
    height: 2.6rem;
    margin-bottom: .15rem;
    background: var(--ch-primary);
    border: 1.5px solid var(--ch-primary);
    border-radius: 50%;
    color: var(--ch-accent);
    cursor: pointer;
    transition: var(--ch-transition);
    flex-shrink: 0;
}

.ch-calc__swap:hover {
    background: var(--ch-accent);
    border-color: var(--ch-accent);
    color: var(--ch-primary);
    box-shadow: 0 4px 14px rgba(240,196,25,.4);
    transform: rotate(180deg);
}

/* ── Rate Bar ───────────────────────────────────────────── */

.ch-calc__rate-text {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.ch-calc__rate-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ch-calc__refresh {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--ch-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: .2rem;
    border-radius: var(--ch-radius-xs);
    transition: var(--ch-transition);
}

.ch-calc__refresh:hover {
    background: var(--ch-accent-15);
    color: var(--ch-accent-h);
    transform: rotate(-180deg);
}

.ch-calc__refresh.is-loading {
    animation: ch-spin 1s linear infinite;
}

@keyframes ch-spin {
    to { transform: rotate(-360deg); }
}

/* ── Price Breakdown (gold / silver) ───────────────────── */
.ch-calc__breakdown {
    background: var(--ch-bg-alt);
    border: 1.5px solid var(--ch-border);
    border-radius: var(--ch-radius-sm);
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: .55rem;
}

.ch-calc__breakdown[hidden] { display: none; }

.ch-calc__breakdown-title {
    font-size: .82rem;
    font-weight: 700;
    color: var(--ch-text);
    margin-bottom: .15rem;
}

.ch-calc__breakdown-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding-bottom: .55rem;
    border-bottom: 1px dashed var(--ch-border);
}

.ch-calc__breakdown-info {
    display: flex;
    flex-direction: column;
    gap: .1rem;
    min-width: 0;
}

.ch-calc__breakdown-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--ch-text);
}

.ch-calc__breakdown-formula {
    font-size: .68rem;
    color: var(--ch-text-muted);
    direction: rtl;
}

.ch-calc__breakdown-value {
    font-size: .82rem;
    font-weight: 700;
    color: var(--ch-text-sec);
    white-space: nowrap;
    direction: ltr;
}

.ch-calc__breakdown-row--total {
    border-bottom: none;
    padding-top: .1rem;
    padding-bottom: 0;
}

.ch-calc__breakdown-row--total .ch-calc__breakdown-label {
    font-size: .88rem;
    font-weight: 800;
    color: var(--ch-primary);
}

.ch-calc__breakdown-row--total .ch-calc__breakdown-value {
    font-size: 1rem;
    font-weight: 800;
    color: var(--ch-accent-h);
}

/* ── Zarrin Shamsh world-price comparison ──────────────── */
.ch-calc__zarrin {
    position: relative;
    background: linear-gradient(135deg, rgba(26,156,107,.08), rgba(26,156,107,.02));
    border: 1.5px solid rgba(26,156,107,.30);
    border-radius: var(--ch-radius-sm);
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.ch-calc__zarrin[hidden] { display: none; }

.ch-calc__zarrin-badge {
    align-self: flex-start;
    background: var(--ch-success);
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    padding: .2rem .6rem;
    border-radius: 100px;
    letter-spacing: .01em;
}

.ch-calc__zarrin-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.ch-calc__zarrin-row .ch-calc__breakdown-value {
    color: var(--ch-success);
    font-size: 1rem;
}

.ch-calc__zarrin-save {
    font-size: .78rem;
    font-weight: 700;
    color: var(--ch-success);
}

.ch-calc__zarrin-save[hidden] { display: none; }

/* ── Rate Cards ─────────────────────────────────────────── */
.ch-calc__cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .65rem;
}

.ch-calc__card {
    background: var(--ch-bg-card);
    border: 1.5px solid var(--ch-border);
    border-radius: var(--ch-radius-sm);
    padding: .95rem .75rem;
    text-align: center;
    transition: var(--ch-transition);
    cursor: default;
    position: relative;
    overflow: hidden;
}

.ch-calc__card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 60%, var(--ch-accent-15));
    opacity: 0;
    transition: var(--ch-transition);
}

.ch-calc__card:hover {
    border-color: var(--ch-accent);
    box-shadow: var(--ch-shadow-sm);
}

.ch-calc__card:hover::before { opacity: 1; }

.ch-calc__card.is-active {
    border-color: var(--ch-primary);
    box-shadow: 0 0 0 3px var(--ch-primary-15);
}

.ch-calc__card-flag {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.4rem;
    height: 2.4rem;
    margin: 0 auto .5rem;
    border-radius: 50%;
    background: var(--ch-accent-15);
    font-size: 1.2rem;
    line-height: 1;
}

.ch-calc__card-name {
    display: block;
    font-size: .7rem;
    color: var(--ch-text-muted);
    font-weight: 500;
    margin-bottom: .35rem;
}

.ch-calc__card-rate {
    display: block;
    font-size: .95rem;
    font-weight: 800;
    color: var(--ch-primary);
    letter-spacing: -.01em;
    direction: ltr;
}

.ch-calc__card-unit {
    display: block;
    font-size: .65rem;
    color: var(--ch-accent-h);
    font-weight: 700;
    margin-top: .15rem;
}

/* ── Footer ─────────────────────────────────────────────── */
.ch-calc__footer {
    padding: .75rem 1.75rem 1.25rem;
    border-top: 1px solid var(--ch-border);
    background: var(--ch-bg-alt);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}

.ch-calc__disclaimer,
.ch-calc__updated {
    font-size: .72rem;
    color: var(--ch-text-muted);
    display: flex;
    align-items: center;
    gap: .3rem;
    line-height: 1.5;
}

.ch-calc__updated {
    font-weight: 500;
    color: var(--ch-text-sec);
}

/* ── Loading skeleton ────────────────────────────────────── */
.ch-calc__skeleton {
    display: inline-block;
    height: 1em;
    width: 5rem;
    background: linear-gradient(90deg, var(--ch-border) 25%, var(--ch-bg) 50%, var(--ch-border) 75%);
    background-size: 200% 100%;
    border-radius: var(--ch-radius-xs);
    animation: ch-shimmer 1.4s infinite;
    vertical-align: middle;
}

@keyframes ch-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Error state ─────────────────────────────────────────── */
.ch-calc__error {
    background: rgba(229,72,77,.08);
    border: 1px solid rgba(229,72,77,.25);
    border-radius: var(--ch-radius-sm);
    color: var(--ch-danger);
    font-size: .82rem;
    padding: .6rem .9rem;
    text-align: center;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 600px) {
    .ch-calc__body { padding: 1.1rem 1rem; gap: 1rem; }
    .ch-calc__header { padding: 1.2rem 1rem 1rem; }
    .ch-calc__footer { padding: .65rem 1rem 1rem; flex-direction: column; align-items: flex-start; }
    .ch-calc__pairs { padding: .7rem .75rem; gap: .3rem; }

    .ch-calc__row--input {
        grid-template-columns: 1fr;
        gap: .6rem;
    }

    .ch-calc__swap {
        margin: 0 auto;
        transform: rotate(90deg);
    }

    .ch-calc__swap:hover {
        transform: rotate(90deg) rotate(180deg);
    }

    .ch-calc__title { font-size: 1rem; }

    .ch-calc__cards {
        grid-template-columns: repeat(3, 1fr);
        gap: .4rem;
    }

    .ch-calc__card { padding: .7rem .4rem; }
    .ch-calc__card-flag { width: 1.9rem; height: 1.9rem; font-size: 1rem; }
    .ch-calc__card-name { font-size: .62rem; }
    .ch-calc__card-rate { font-size: .82rem; }

    .ch-calc__input,
    .ch-calc__output { font-size: 1rem; padding: .7rem .85rem .7rem 4.8rem; }

    .ch-calc__breakdown { padding: .85rem .9rem; }
    .ch-calc__breakdown-row { flex-wrap: wrap; gap: .25rem .75rem; }
    .ch-calc__breakdown-value { margin-inline-start: auto; }

    .ch-calc__zarrin { padding: .85rem .9rem; }
    .ch-calc__zarrin-row { flex-wrap: wrap; gap: .25rem .75rem; }
}

@media (max-width: 400px) {
    .ch-calc__cards { grid-template-columns: repeat(3, 1fr); }
    .ch-calc__card-name { display: none; }
}

/* ── Print ──────────────────────────────────────────────── */
@media print {
    .ch-calc__pairs,
    .ch-calc__refresh,
    .ch-calc__swap { display: none; }
}
