﻿/* ═══════════════════════════════════════════════════════════════════════
   reference-data-lineitem.css
   Styles for the line-item HS Code + Country search-helper buttons and
   their modals. All classes prefixed "rdli-" to prevent collisions.

   Everything is scoped via the :has() selector so that when the
   SearchHelperEnabled flag is OFF (buttons not rendered), NO existing
   layout is affected — the file is a zero-op.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── The 🔍 / 🌍 icon buttons ────────────────────────────────────────── */

.rdli-icon-btn {
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji",
                 "Twemoji Mozilla", sans-serif !important;
    font-size: 13px !important;
    line-height: 1 !important;

    width: 26px !important;
    min-width: 26px !important;
    height: 26px !important;
    min-height: 26px !important;
    padding: 0 !important;
    box-sizing: border-box !important;

    border: 1px solid #d0d7de !important;
    background: #f8fafc !important;
    color: #1e2d45 !important;
    border-radius: 4px !important;
    cursor: pointer !important;

    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    vertical-align: middle !important;

    transition: background 0.12s ease, border-color 0.12s ease !important;
    text-overflow: clip !important;
    overflow: visible !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}

.rdli-icon-btn:hover {
    background: #e7f0ff !important;
    border-color: #0d6efd !important;
}

.rdli-icon-btn:active {
    background: #d6e4ff !important;
}

.rdli-icon-btn:focus-visible {
    outline: 2px solid #0d6efd !important;
    outline-offset: 1px !important;
}

/* ── MAIN GRID (Grid 2) — cells hosting rv-li-input + rdli-icon-btn ──── */

/* Cell hosts input + button (and optionally the CBSA ↗ tariff link) */
td:has(> .rdli-icon-btn) {
    white-space: nowrap !important;
    overflow: visible !important;
    padding-right: 4px !important;
}

/* HS Code input (no rv-li-input-sm class): room for button + tariff link (~68px) */
td:has(> .rdli-icon-btn) > .rv-li-input:not(.rv-li-input-sm) {
    display: inline-block !important;
    width: calc(100% - 68px) !important;
    min-width: 60px !important;
    vertical-align: middle !important;
    box-sizing: border-box !important;
}

/* Country input (has rv-li-input-sm class): leave room for button only */
td:has(> .rdli-icon-btn) > .rv-li-input.rv-li-input-sm {
    display: inline-block !important;
    width: calc(100% - 34px) !important;
    min-width: 40px !important;
    vertical-align: middle !important;
    box-sizing: border-box !important;
}

/* Icon button placed inline next to input */
td:has(> .rdli-icon-btn) > .rdli-icon-btn {
    margin-left: 4px !important;
    vertical-align: middle !important;
}

/* CBSA Tariff ↗ link (rv-hs-row-link) — sits AFTER the button on HS Code cell */
td:has(> .rdli-icon-btn) > .rv-hs-row-link {
    display: inline-block !important;
    margin-left: 4px !important;
    vertical-align: middle !important;
    font-size: 12px !important;
    line-height: 1 !important;
    text-decoration: none !important;
}

/* ── MULTI-INVOICE GRID (Grid 3) — cells hosting mi-li-input + rdli-icon-btn ── */

td:has(> .mi-li-input + .rdli-icon-btn) {
    white-space: nowrap !important;
    overflow: visible !important;
    padding-right: 4px !important;
}

td:has(> .mi-li-input + .rdli-icon-btn) > .mi-li-input {
    display: inline-block !important;
    width: calc(100% - 34px) !important;
    min-width: 60px !important;
    vertical-align: middle !important;
    box-sizing: border-box !important;
}

td:has(> .mi-li-input + .rdli-icon-btn) > .rdli-icon-btn {
    margin-left: 4px !important;
    vertical-align: middle !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   MODAL — 🔍 Find HS Code   and   🌍 Find Country Code
   ═══════════════════════════════════════════════════════════════════════ */

.rdli-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 9500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: rdli-fade-in 0.15s ease-out;
}

@keyframes rdli-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.rdli-modal {
    background: #fff;
    border-radius: 10px;
    width: 720px;
    max-width: 92vw;
    max-height: 82vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}

.rdli-modal-narrow {
    width: 560px;
}

.rdli-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
}

.rdli-modal-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #1e2d45;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji",
                 inherit;
}

.rdli-modal-search {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid #f3f4f6;
}

.rdli-search-input {
    flex: 1;
    padding: 7px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.rdli-search-input:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.rdli-checkbox {
    font-size: 13px;
    color: #475569;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.rdli-modal-body {
    overflow-y: auto;
    padding: 12px 20px;
    flex: 1;
    min-height: 220px;
}

.rdli-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
    text-align: right;
    background: #f8fafc;
}

/* Results table inside the modal */
.rdli-results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.rdli-results-table th {
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid #e5e7eb;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.03em;
    position: sticky;
    top: 0;
    background: #f8fafc;
}

.rdli-results-table td {
    padding: 7px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #1e2d45;
}

.rdli-results-table tr:hover td {
    background: #f0f7ff;
}

.rdli-mono {
    font-family: "SF Mono", Consolas, "Courier New", monospace;
    font-size: 12.5px;
}

.rdli-btn-select {
    padding: 4px 12px;
    border: 1px solid #0d6efd;
    background: #0d6efd;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.12s ease;
}

.rdli-btn-select:hover {
    background: #0b5ed7;
}

.rdli-btn-ghost {
    padding: 6px 14px;
    border: 1px solid #cbd5e1;
    background: transparent;
    color: #475569;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.rdli-btn-ghost:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.rdli-muted {
    color: #94a3b8;
    font-size: 13px;
    margin: 6px 0;
}

.rdli-warn {
    color: #b45309;
    background: #fef3c7;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    display: inline-block;
}

/* ═══════════════════════════════════════════════════════════════════════
   Column-width nudges to prevent icon-button overlap.

   Applied ONLY when the corresponding cell contains an .rdli-icon-btn,
   via :has() scope. When SearchHelperEnabled=false the buttons are
   absent, so these rules have zero effect.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Grid 2 (main line-items grid in Review.razor) ─────────────────────
   Widen the Country column when a 🌍 button is present, so it doesn't
   push into the trash-icon (delete) column next to it.
   ────────────────────────────────────────────────────────────────────── */

/* Country column header — widen when any Country cell in the same table
   contains an icon button */
table:has(td > .rv-li-input.rv-li-input-sm + .rdli-icon-btn) th.rv-lh-col-coo {
    min-width: 95px !important;
    width: 95px !important;
}

/* Country column body cell — force minimum width so [input] + [🌍]
   both fit without overlapping the next column */
table:has(td > .rv-li-input.rv-li-input-sm + .rdli-icon-btn)
    td:has(> .rv-li-input.rv-li-input-sm + .rdli-icon-btn) {
    min-width: 95px !important;
    width: 95px !important;
}

/* HS Code column body cell — also widen a bit to fit [input] + [🔍] + [↗] */
table:has(td > .rv-line-hs .rdli-icon-btn) td.rv-line-hs {
    min-width: 140px !important;
    width: 140px !important;
}

/* ── Grid 3 (Multi-Invoice — InvoiceLineItemsTable.razor) ───────────────
   Country column widening + UoM column sizing.
   ────────────────────────────────────────────────────────────────────── */

/* Country column body cell in Multi-Invoice grid — when 🌍 button present */
table:has(td > .mi-li-input.mi-li-input-mono + .rdli-icon-btn:not(:only-child))
    td:has(> .mi-li-input.mi-li-input-mono + .rdli-icon-btn) {
    min-width: 130px !important;
    width: 130px !important;
}

/* Multi-Invoice UoM column — small, centered, fixed width */
.mi-li-col-uom {
    min-width: 70px !important;
    width: 70px !important;
    text-align: center !important;
}

/* Multi-Invoice HS Code body cell — widen to fit [input] + [🔍] */
table:has(td > .mi-li-input.mi-li-input-mono + .rdli-icon-btn) td.mi-li-col-hs,
table:has(.mi-li-col-hs td > .rdli-icon-btn) .mi-li-col-hs {
    min-width: 160px !important;
    width: 160px !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   Multi-Invoice assigned grid — prevent visual overlap between the COO
   cell (containing 🌍 icon) and the ↩ unassign cell.

   The DOM order is correct (COO comes before Unassign). The overlap is
   purely visual because the COO column is narrow and the Unassign header
   has no min-width. These rules ensure both cells have enough breathing
   room.

   Scoped via table:has(td.mi-lh-actions) so it only applies to the
   Multi-Invoice assigned grid.
   ═══════════════════════════════════════════════════════════════════════ */

/* Give the COO cell + button a minimum width so the 🌍 icon sits inside
   its own column, well before the unassign column starts */
table:has(td.mi-lh-actions) td:has(> .mi-li-input.mi-li-input-mono + .rdli-icon-btn) {
    min-width: 140px !important;
    width: 140px !important;
    padding-right: 12px !important;
}

/* Give the Unassign column its own guaranteed width so the ↩ button never
   creeps left toward the COO cell */
table:has(td.mi-lh-actions) th.mi-lh-actions,
table:has(td.mi-lh-actions) td.mi-lh-actions {
    min-width: 56px !important;
    width: 56px !important;
    padding-left: 8px !important;
    text-align: center !important;
}

/* Ensure the COO <th> header has a matching minimum width so the header
   label doesn't get clipped to "C_OO" style truncation */
table:has(td.mi-lh-actions) thead th:nth-last-child(2) {
    min-width: 140px !important;
    width: 140px !important;
    padding-right: 12px !important;
}

/* Hide TOTAL $ column in Multi-Invoice assigned grid.
   Reversible: remove this rule. Data still bound in DOM. */
.mi-col-total { display: none !important; }

/* Ensure UOM column in the main grid never collapses to zero width.
   The rv-lh-col-uom class marks both the <th> and (via structural
   proximity) the corresponding <td>. Give a modest fixed width. */
.rv-lh-col-uom {
    min-width: 70px !important;
    width: 70px !important;
}
