/* =============================================
   Tỷ Giá Pro v2 – Frontend CSS
   ============================================= */

/* ---- Base containers ---- */
.tgp-cc-converter,
.tgp-cc-table-wrapper {
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 16px;
    margin: 16px 0;
    background: #ffffff;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .06);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.tgp-cc-table-wrapper {
    max-width: 960px;
    margin: 24px auto;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

/* ---- Header ---- */
.tgp-cc-header {
    margin-bottom: 12px;
    padding-bottom: 4px;
    border-bottom: 1px solid #e5e7eb;
}

.tgp-cc-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 4px;
    color: #111827;
}

/* ---- Updated time (SEO) ---- */
.tgp-cc-updated {
    display: block;
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 4px;
    font-style: normal;
}

/* ---- Converter body ---- */
.tgp-cc-body {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 12px;
}

.tgp-cc-column {
    flex: 1 1 0;
    min-width: 0;
}

.tgp-cc-swap-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.tgp-cc-swap-button {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
}

.tgp-cc-swap-button:hover {
    background: #eef2ff;
    box-shadow: 0 0 0 1px #4f46e5;
}

.tgp-cc-swap-button:active {
    transform: scale(.96);
}

/* ---- Label & currency code badge ---- */
.tgp-cc-label {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: .9rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 6px;
}

.tgp-cc-currency-code {
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    background: #eef2ff;
    color: #3730a3;
    padding: 2px 6px;
    border-radius: 999px;
}

/* ---- Input ---- */
.tgp-cc-input {
    min-height: 44px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    padding: 10px 14px;
    font-size: 1rem;
    line-height: 1.4;
    outline: none;
    word-break: break-word;
    width: 100%;
    box-sizing: border-box;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.tgp-cc-input:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, .2);
}

.tgp-cc-input-readonly {
    background: #f9fafb;
    cursor: default;
}

/* ---- Sub-text ---- */
.tgp-cc-number-small {
    margin-top: 4px;
    font-size: .8rem;
    color: #6b7280;
    word-break: break-all;
    min-height: 1.2em;
}

.tgp-cc-words {
    margin-top: 4px;
    font-size: .8rem;
    font-style: italic;
    color: #4b5563;
    word-break: break-word;
    min-height: 1.2em;
}

/* ---- Footer ---- */
.tgp-cc-footer {
    margin-top: 12px;
    font-size: .8rem;
    color: #6b7280;
}

.tgp-cc-footer small {
    display: block;
}

.tgp-cc-error {
    color: #b91c1c;
}

/* ---- Placeholder (block editor) ---- */
.tgp-cc-placeholder {
    font-size: .9rem;
    color: #6b7280;
}

/* ---- Rate table layout ---- */
.tgp-cc-table-pair {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
}

.tgp-cc-table-panel {
    flex: 1 1 260px;
    background: #ffffff;
    border-radius: 12px;
    padding: 12px 0;
}

.tgp-cc-subtitle {
    font-size: .95rem;
    font-weight: 600;
    margin: 0 0 8px;
    color: #111827;
}

.tgp-cc-table-scroll {
    width: 100%;
    overflow-x: auto;
}

.tgp-cc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

.tgp-cc-table th,
.tgp-cc-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
}

.tgp-cc-table th {
    text-align: left;
    font-weight: 600;
    background: #f3f4f6;
    white-space: nowrap;
}

.tgp-cc-table td:first-child {
    color: #2563eb;
    font-weight: 500;
}

.tgp-cc-table-from,
.tgp-cc-table-to {
    font-variant-numeric: tabular-nums;
}

.tgp-cc-table-words {
    font-size: .8rem;
    font-style: italic;
    color: #4b5563;
}

/* ---- Toolbar ---- */
.tgp-cc-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin: 8px 0 4px;
}

.tgp-cc-print-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid #2563eb;
    background: #2563eb;
    color: #ffffff;
    font-size: .8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s ease, transform .08s ease;
}

.tgp-cc-print-btn::before {
    content: "🖨";
    font-size: .9rem;
}

.tgp-cc-print-btn:hover { background: #1d4ed8; border-color: #1d4ed8; }
.tgp-cc-print-btn:active { transform: scale(.97); }

/* ---- Hide words when disabled ---- */
.tgp-cc-hide-words .tgp-cc-words,
.tgp-cc-hide-words .tgp-cc-table-words {
    display: none;
}

/* ---- Chart ---- */
.tgp-cc-chart-wrapper,
.tgp-cc-history-wrapper {
    margin: 1em 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.tgp-cc-chart {
    width: 100%;
    height: 220px;
    margin-top: 6px;
}

.tgp-cc-chart-canvas {
    width: 100%;
    height: 220px;
    display: block;
}

.tgp-cc-chart-latest {
    margin-bottom: .5em;
    font-size: .9em;
    opacity: .85;
}

.tgp-cc-chart-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
    font-size: .85rem;
}

.tgp-cc-chart-range-btn {
    border: 1px solid #d1d5db;
    background: #f9fafb;
    border-radius: 999px;
    padding: 3px 10px;
    cursor: pointer;
    transition: background .1s ease, color .1s ease;
}

.tgp-cc-chart-range-btn.is-active {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}

/* ---- History table ---- */
.tgp-cc-history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9em;
    margin-top: .5rem;
}

.tgp-cc-history-table th,
.tgp-cc-history-table td {
    border: 1px solid #e2e2e2;
    padding: 6px 8px;
}

.tgp-cc-history-table th {
    background: #f8f8f8;
    text-align: left;
    font-weight: 600;
}

.tgp-cc-history-table time {
    font-variant-numeric: tabular-nums;
}

/* ---- History stats ---- */
.tgp-cc-history-stats {
    width: 100%;
    border-collapse: collapse;
    margin: .75rem 0 1rem;
    font-size: .9rem;
}

.tgp-cc-history-stats th,
.tgp-cc-history-stats td {
    border: 1px solid #e2e2e2;
    padding: 6px 8px;
    text-align: right;
}

.tgp-cc-history-stats th:first-child,
.tgp-cc-history-stats td:first-child {
    text-align: left;
}

.tgp-cc-history-note {
    margin: 0 0 .75rem;
    font-size: .85rem;
    color: #4b5563;
}

/* ================================================================
   HISTORY v2 – giao diện mới với chart + KPI cards
   ================================================================ */

.tgp-cc-history-v2 {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #1a1a2e;
}

/* ---- Header ---- */
.tgp-hv2-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-bottom: 16px;
}

.tgp-hv2-current {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.tgp-hv2-rate-value {
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: #111827;
    font-variant-numeric: tabular-nums;
}

.tgp-hv2-rate-pair {
    font-size: .85rem;
    color: #6b7280;
    font-weight: 500;
    letter-spacing: .04em;
}

.tgp-hv2-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 600;
}

.tgp-hv2-up {
    background: #dcfce7;
    color: #15803d;
}

.tgp-hv2-down {
    background: #fee2e2;
    color: #b91c1c;
}

.tgp-hv2-change-icon {
    font-size: .75rem;
}

.tgp-hv2-change-label {
    font-weight: 400;
    opacity: .75;
}

/* ---- Chart section ---- */
.tgp-hv2-chart-section {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.tgp-hv2-range-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.tgp-hv2-range-btn {
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 6px;
    padding: 4px 14px;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    color: #374151;
    transition: background .15s, border-color .15s, color .15s;
    letter-spacing: .02em;
}

.tgp-hv2-range-btn:hover {
    background: #f0f4ff;
    border-color: #2563eb;
    color: #2563eb;
}

.tgp-hv2-range-btn.is-active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.tgp-hv2-chart {
    width: 100%;
    height: 200px;
    position: relative;
}

.tgp-hv2-canvas {
    width: 100% !important;
    height: 200px !important;
    display: block;
}

/* ---- KPI grid ---- */
.tgp-hv2-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.tgp-hv2-kpi-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    transition: box-shadow .15s;
}

.tgp-hv2-kpi-card:hover {
    box-shadow: 0 3px 10px rgba(0,0,0,.09);
}

.tgp-hv2-kpi-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 700;
    flex-shrink: 0;
}

.tgp-hv2-kpi-high  { background: #dcfce7; color: #15803d; }
.tgp-hv2-kpi-low   { background: #fee2e2; color: #b91c1c; }
.tgp-hv2-kpi-avg   { background: #dbeafe; color: #1d4ed8; }
.tgp-hv2-kpi-vol   { background: #fef9c3; color: #92400e; }

.tgp-hv2-kpi-body {
    min-width: 0;
}

.tgp-hv2-kpi-label {
    font-size: .72rem;
    color: #6b7280;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 2px;
    white-space: nowrap;
}

.tgp-hv2-kpi-value {
    font-size: .95rem;
    font-weight: 700;
    color: #111827;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- History table section ---- */
.tgp-hv2-table-section {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.tgp-hv2-table-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}

.tgp-hv2-table-title {
    font-size: .85rem;
    font-weight: 600;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.tgp-hv2-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.tgp-hv2-table thead th {
    background: #f9fafb;
    padding: 8px 16px;
    text-align: left;
    font-size: .78rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid #e5e7eb;
}

.tgp-hv2-table tbody td {
    padding: 9px 16px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    font-variant-numeric: tabular-nums;
}

.tgp-hv2-table tbody tr:last-child td {
    border-bottom: none;
}

.tgp-hv2-table tbody tr:hover td {
    background: #f9fafb;
}

.tgp-hv2-td-rate {
    font-weight: 600;
    color: #111827 !important;
}

.tgp-hv2-td-change.tgp-hv2-up {
    color: #15803d !important;
    font-weight: 500;
    background: none;
    padding-left: 16px !important;
}

.tgp-hv2-td-change.tgp-hv2-down {
    color: #b91c1c !important;
    font-weight: 500;
    background: none;
    padding-left: 16px !important;
}

.tgp-hv2-row-hidden {
    display: none;
}

.tgp-hv2-show-more {
    display: block;
    width: 100%;
    padding: 11px;
    background: #f9fafb;
    border: none;
    border-top: 1px solid #e5e7eb;
    color: #2563eb;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    text-align: center;
}

.tgp-hv2-show-more:hover {
    background: #eff6ff;
}

/* ---- Accessibility: screen reader only ---- */
.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    width: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    word-wrap: normal !important;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .tgp-cc-body {
        flex-wrap: wrap;
    }

    .tgp-cc-swap-wrap {
        order: 3;
        width: 100%;
        margin-top: 8px;
    }

    .tgp-cc-swap-button {
        width: 40px;
        height: 40px;
    }

    .tgp-cc-converter,
    .tgp-cc-table-wrapper {
        padding: 12px;
        border-radius: 12px;
    }

    .tgp-cc-table-wrapper {
        margin: 16px 0;
    }

    .tgp-cc-table-panel {
        flex-basis: 100%;
    }

    /* Ngăn iOS Safari tự zoom khi focus vào input (cần >= 16px) */
    .tgp-cc-input {
        font-size: 16px !important;
    }

    /* Bảng lịch sử: scroll ngang thay vì tràn layout */
    .tgp-cc-history-table,
    .tgp-cc-history-stats {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* History v2 mobile */
    .tgp-hv2-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .tgp-hv2-rate-value {
        font-size: 1.5rem;
    }

    .tgp-hv2-chart-section {
        padding: 12px;
    }

    .tgp-hv2-table thead th,
    .tgp-hv2-table tbody td {
        padding: 8px 12px;
    }

    .tgp-hv2-kpi-card {
        padding: 10px 12px;
    }

    .tgp-hv2-kpi-icon {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }

    .tgp-hv2-kpi-value {
        font-size: .88rem;
    }
}

@media (max-width: 420px) {
    .tgp-hv2-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .tgp-hv2-table thead th:last-child,
    .tgp-hv2-table tbody td:last-child {
        display: none; /* Ẩn cột Thay đổi trên màn hình rất nhỏ */
    }
}
