:root {
    --ink: #17201d;
    --muted: #65736f;
    --subtle: #eef2f0;
    --line: #dce4e0;
    --paper: #ffffff;
    --canvas: #f5f7f6;
    --green: #0f6a4c;
    --green-dark: #084c37;
    --green-soft: #e5f4ee;
    --blue: #1d5f99;
    --blue-soft: #e7f0f8;
    --violet: #7040a2;
    --violet-soft: #f1eaf8;
    --amber: #9a5a00;
    --amber-soft: #fff3d9;
    --red: #b42318;
    --red-soft: #fde7e5;
    --radius: 8px;
    --shadow: 0 10px 30px rgba(16, 24, 20, 0.12);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    background: var(--canvas);
}

body {
    min-height: 100vh;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body.modal-open {
    overflow: hidden;
}

button,
input {
    font: inherit;
}

button {
    touch-action: manipulation;
}

.dog-ear-button {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 35;
    width: 62px;
    height: 62px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: transparent;
    cursor: pointer;
}

.dog-ear-button::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-top: 62px solid #f3c469;
    border-left: 62px solid transparent;
    filter: drop-shadow(-4px 5px 8px rgba(16, 24, 20, 0.2));
}

.dog-ear-button::before {
    content: "?";
    position: absolute;
    top: 9px;
    right: 11px;
    z-index: 1;
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: var(--green-dark);
    font-size: 13px;
    font-weight: 900;
}

.dog-ear-button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.dog-ear-button:focus-visible {
    outline: 3px solid var(--blue);
    outline-offset: -7px;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--canvas);
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.header-brand {
    min-width: 0;
}

.app-kicker,
.section-label {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    line-height: 1.2;
    text-transform: uppercase;
}

.app-title {
    margin-top: 2px;
    color: var(--green-dark);
    font-size: 24px;
    font-weight: 850;
    line-height: 1;
    letter-spacing: 0;
}

.help-toggle {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--paper);
    color: var(--green-dark);
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
}

.help-toggle.active {
    background: var(--green-dark);
    border-color: var(--green-dark);
    color: #fff;
}

.workspace {
    width: 100%;
    max-width: 940px;
    margin: 0 auto;
    display: grid;
    gap: 10px;
    padding: 10px;
    flex: 1;
}

.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
}

.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-title {
    margin-top: 2px;
    color: var(--ink);
    font-size: 18px;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: 0;
}

.help-panel {
    display: none;
    background: #fffdf4;
    border-bottom: 1px solid #f0dfaa;
    padding: 12px 14px;
}

.help-panel.open {
    display: block;
}

.help-heading {
    margin-bottom: 10px;
    color: #6f4c10;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.help-grid {
    display: grid;
    gap: 8px;
}

.help-item {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 1px solid #f0dfaa;
    border-radius: var(--radius);
    background: #fffaf0;
}

.help-item p {
    color: #573f15;
    font-size: 13px;
    line-height: 1.45;
}

.help-item code {
    display: inline-block;
    margin-top: 3px;
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(111, 76, 16, 0.1);
    color: #49340f;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
}

.tag,
.badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 22px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.tag-send { background: var(--blue-soft); color: var(--blue); }
.tag-receive { background: var(--violet-soft); color: var(--violet); }
.tag-recv-ghs { background: var(--green-soft); color: var(--green-dark); }
.tag-recv-ngn { background: var(--amber-soft); color: var(--amber); }
.badge-v1 { background: var(--subtle); color: var(--muted); border: 1px solid var(--line); }

.field-group {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.field-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 750;
    line-height: 1.25;
}

.info-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.rates-row,
.quote-grid {
    display: grid;
    gap: 10px;
}

.input-pill-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
}

.input-tag {
    border-radius: 6px;
    padding-inline: 7px;
}

input[type="number"] {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    font-size: 16px;
    font-weight: 650;
    outline: none;
    appearance: textfield;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

input[type="number"]::placeholder {
    color: #a8b2ae;
}

input[type="number"]:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(15, 106, 76, 0.12);
    background: #fcfffd;
}

.amount-input-wrap {
    position: relative;
}

.currency-sym {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 16px;
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
}

.amount-input-wrap input {
    padding-left: 34px;
    font-size: 18px;
}

.spread-bar {
    margin-top: 10px;
    min-height: 0;
    padding: 9px 10px;
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
}

.spread-bar:empty {
    display: none;
}

.sync-status {
    margin-top: 8px;
    min-height: 16px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.35;
}

.sync-status:empty {
    display: none;
}

.customer-facing .rates-panel {
    display: none;
}

.spread-ok { background: var(--green-soft); color: var(--green-dark); }
.spread-warn { background: var(--amber-soft); color: var(--amber); }
.spread-error { background: var(--red-soft); color: var(--red); }

.calc-panel {
    display: grid;
    gap: 12px;
}

.tx-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tx-btn {
    min-height: 60px;
    display: grid;
    align-content: center;
    gap: 3px;
    padding: 11px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    text-align: center;
    cursor: pointer;
}

.tx-btn strong {
    font-size: 14px;
    font-weight: 850;
    line-height: 1.15;
}

.tx-btn small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
}

.tx-btn.active {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-dark);
    box-shadow: inset 0 0 0 1px var(--green);
}

.tx-btn.active small {
    color: var(--green);
}

.amount-grid {
    display: grid;
    gap: 8px;
}

.equals-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 18px;
    color: var(--muted);
    font-size: 18px;
    font-weight: 850;
}

.result-card {
    display: grid;
    gap: 4px;
    min-height: 86px;
    align-content: center;
    padding: 14px;
    border-radius: var(--radius);
    background: var(--subtle);
    text-align: left;
}

.result-main {
    color: var(--muted);
    font-size: 18px;
    font-weight: 800;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.result-sub {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.result-active {
    background: var(--green-soft);
}

.result-active .result-main {
    color: var(--green-dark);
    font-size: 21px;
}

.result-warn {
    background: var(--amber-soft);
}

.result-warn .result-main {
    color: var(--amber);
    font-size: 16px;
}

.quote-card {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fbfcfc;
}

.quote-dir-label {
    display: flex;
    align-items: center;
}

.quote-result {
    min-height: 44px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: var(--radius);
    background: var(--subtle);
}

.quote-result.quote-has-value {
    background: var(--green-soft);
}

.quote-arrow {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.quote-amount {
    color: var(--ink);
    font-size: 16px;
    font-weight: 850;
    line-height: 1.2;
    text-align: right;
    overflow-wrap: anywhere;
}

.quote-rate-note {
    min-height: 14px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.3;
}

.hint-label {
    flex: 0 0 auto;
    color: var(--green);
    font-size: 12px;
    font-weight: 800;
}

.tooltip {
    position: absolute;
    z-index: 100;
    max-width: min(280px, calc(100vw - 28px));
    padding: 10px 12px;
    border-radius: var(--radius);
    background: #18211e;
    color: #fff;
    box-shadow: var(--shadow);
    font-size: 12px;
    line-height: 1.45;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.15s, transform 0.15s;
    white-space: pre-line;
}

.tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: end center;
    padding: 14px;
    background: rgba(16, 24, 20, 0.52);
}

.modal-backdrop[hidden] {
    display: none;
}

.dealer-modal {
    width: min(100%, 520px);
    max-height: min(86vh, 680px);
    overflow: auto;
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 12px 12px var(--radius) var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
}

.dealer-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.modal-close {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fff;
    color: var(--ink);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.dealer-controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.dealer-rate-wrap input {
    padding-left: 52px;
}

.dealer-rate-wrap .currency-sym {
    font-size: 13px;
}

.dealer-controls .amount-input-wrap:not(.dealer-rate-wrap) input {
    padding-left: 58px;
}

.dealer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.dealer-action-btn {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    font-size: 13px;
    font-weight: 850;
    cursor: pointer;
}

.dealer-action-btn.active {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-dark);
    box-shadow: inset 0 0 0 1px var(--green);
}

.dealer-summary {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.dealer-summary div {
    min-width: 0;
    display: grid;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fbfcfc;
}

.dealer-summary span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
}

.dealer-summary strong {
    color: var(--ink);
    font-size: 17px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.dealer-summary .positive {
    color: var(--green-dark);
}

.dealer-summary .negative {
    color: var(--red);
}

.dealer-note {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.45;
}

.app-footer {
    padding: 14px 10px calc(14px + env(safe-area-inset-bottom));
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
    text-align: center;
}

@media (min-width: 560px) {
    body {
        padding: 18px;
    }

    .app {
        min-height: calc(100vh - 36px);
        border: 1px solid var(--line);
        border-radius: 12px;
        box-shadow: var(--shadow);
        overflow: hidden;
    }

    .workspace {
        padding: 14px;
        gap: 12px;
    }

    .panel {
        padding: 16px;
    }

    .rates-row,
    .amount-grid {
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: end;
    }

    .rates-row {
        grid-template-columns: 1fr 1fr;
    }

    .equals-divider {
        min-width: 32px;
        min-height: 48px;
    }

    .quote-grid,
    .help-grid {
        grid-template-columns: 1fr 1fr;
    }

    .modal-backdrop {
        place-items: center;
        padding: 28px;
    }

    .dealer-modal {
        border-radius: 12px;
        padding: 20px;
    }

    .dealer-summary {
        grid-template-columns: 1fr 1fr;
    }

    .dealer-controls {
        grid-template-columns: 1fr 1fr;
    }

    .dealer-controls .field-group:first-child {
        grid-column: 1 / -1;
    }
}

@media (min-width: 900px) {
    body {
        display: flex;
        justify-content: center;
        padding: 24px;
    }

    .workspace {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .rates-panel,
    .quote-panel {
        grid-column: 1 / -1;
    }

    .app-header,
    .help-panel {
        padding-left: 18px;
        padding-right: 18px;
    }

    .quote-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
