/* Cross-platform login controls and global table system */

.crm-native-select {
    position: absolute !important;
    inline-size: 1px !important;
    block-size: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
}

.crm-select {
    position: relative;
    width: 100%;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.crm-select__trigger {
    width: 100%;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    border: 1px solid rgba(37, 99, 235, 0.48);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(3, 28, 75, 0.98), rgba(2, 22, 61, 0.98));
    color: #f8fafc;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    outline: none;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 0 0 1px rgba(29,78,216,0.08);
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.crm-select__trigger:hover {
    border-color: rgba(59, 130, 246, 0.8);
    background: linear-gradient(180deg, rgba(4, 37, 96, 0.98), rgba(2, 26, 72, 0.98));
}

.crm-select__trigger:focus-visible,
.crm-select.is-open .crm-select__trigger {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.18), 0 12px 28px rgba(0,0,0,0.18);
}

.crm-select__trigger:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.crm-select__value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-select__value.is-placeholder {
    color: #94a3b8;
    font-weight: 500;
}

.crm-select__chevron {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    color: #93c5fd;
    transition: transform .16s ease;
}

.crm-select__chevron svg,
.crm-table-toolbar svg,
.crm-th-button svg,
.crm-filter-popover svg {
    width: 100%;
    height: 100%;
    display: block;
}

.crm-select.is-open .crm-select__chevron {
    transform: rotate(180deg);
}

.crm-select__panel {
    position: absolute;
    z-index: 10020;
    inset-inline: 0;
    top: calc(100% + 7px);
    overflow: hidden;
    border: 1px solid rgba(96, 165, 250, 0.42);
    border-radius: 14px;
    background: rgba(5, 22, 48, 0.985);
    color: #f8fafc;
    box-shadow: 0 24px 70px rgba(0,0,0,0.48), 0 0 0 1px rgba(255,255,255,0.035) inset;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.crm-select__search-wrap {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px;
    border-bottom: 1px solid rgba(148,163,184,0.14);
    background: rgba(15, 42, 83, 0.76);
}

.crm-select__search-wrap > span {
    width: 17px;
    height: 17px;
    color: #93c5fd;
    flex: 0 0 auto;
}

.crm-select__search {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid rgba(96,165,250,0.28);
    border-radius: 9px;
    outline: none;
    background: rgba(2, 17, 44, 0.9);
    color: #f8fafc;
    font: inherit;
    font-size: 13px;
}

.crm-select__search::placeholder { color: #64748b; }
.crm-select__search:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

.crm-select__list {
    max-height: min(48vh, 420px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 7px;
    scrollbar-width: thin;
    scrollbar-color: rgba(148,163,184,.55) transparent;
}

.crm-select__option {
    width: 100%;
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 10px 11px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #e2e8f0;
    text-align: left;
    font: inherit;
    font-size: 13px;
    line-height: 1.35;
    cursor: pointer;
}

.crm-select__option:hover,
.crm-select__option:focus-visible {
    outline: none;
    background: rgba(37, 99, 235, 0.28);
    color: #fff;
}

.crm-select__option[aria-selected="true"] {
    background: linear-gradient(90deg, rgba(37,99,235,.74), rgba(59,130,246,.55));
    color: #fff;
}

.crm-select__option:disabled { opacity: .45; cursor: not-allowed; }
.crm-select__check { color: #fff; font-weight: 900; text-align: center; }
.crm-select__empty { padding: 18px 12px; text-align: center; color: #94a3b8; font-size: 13px; }

.crm-table-shell {
    width: 100%;
    min-width: 0;
    overflow: visible;
    border: 1px solid var(--cc-border, rgba(15,23,42,.12));
    border-radius: 16px;
    background: var(--cc-card, #fff);
    box-shadow: 0 12px 32px rgba(15,23,42,.08);
}

.crm-table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--cc-border, rgba(15,23,42,.1));
    background: color-mix(in srgb, var(--cc-card, #fff) 92%, var(--cc-accent, #006aa6) 8%);
    border-radius: 16px 16px 0 0;
}

.crm-table-search {
    width: min(380px, 100%);
    min-width: 180px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 11px;
    border: 1px solid var(--cc-input-bd, rgba(15,23,42,.16));
    border-radius: 11px;
    background: var(--cc-input-bg, #fff);
    color: var(--cc-text-muted, #475569);
}

.crm-table-search > span { width: 17px; height: 17px; flex: 0 0 auto; }
.crm-table-search input {
    width: 100%;
    min-width: 0;
    padding: 9px 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--cc-text, #0f172a);
    font: inherit;
    font-size: 13px;
}
.crm-table-search input::placeholder { color: var(--cc-text-faint, #94a3b8); }
.crm-table-search:focus-within { border-color: var(--cc-accent, #006aa6); box-shadow: 0 0 0 3px rgba(20,104,168,.1); }

.crm-table-toolbar__right { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.crm-table-count { color: var(--cc-text-muted, #64748b); font-size: 11px; font-weight: 700; white-space: nowrap; }
.crm-table-clear {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border: 1px solid rgba(220,38,38,.18);
    border-radius: 9px;
    background: rgba(239,68,68,.08);
    color: #dc2626;
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}
.crm-table-clear[hidden] { display: none; }
.crm-table-clear svg { width: 14px; height: 14px; }
.crm-table-clear:hover { background: rgba(239,68,68,.14); }

.crm-table-scroll {
    width: 100%;
    overflow-x: auto;
    border-radius: 0 0 16px 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--cc-scrollbar, rgba(15,23,42,.2)) transparent;
}

.crm-smart-table {
    width: 100%;
    min-width: max-content;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--cc-text, #0f172a);
}

.crm-smart-table thead th,
.crm-smart-table tbody td,
.crm-smart-table tbody th {
    transition: background-color .14s ease, color .14s ease;
}

.crm-smart-table thead th {
    position: relative;
    padding-right: 66px !important;
    background: rgb(var(--crm-col-rgb, 37 99 235) / .105) !important;
    box-shadow: inset 0 -1px 0 var(--cc-border, rgba(15,23,42,.1));
    color: var(--cc-text, #0f172a) !important;
    white-space: nowrap;
}

.crm-smart-table tbody td,
.crm-smart-table tbody th {
    background: rgb(var(--crm-col-rgb, 37 99 235) / .035);
}

.crm-smart-table tbody tr:hover td,
.crm-smart-table tbody tr:hover th {
    background: rgb(var(--crm-col-rgb, 37 99 235) / .09) !important;
}

.crm-smart-table tr[hidden] { display: none !important; }

.crm-th-actions {
    position: absolute;
    top: 50%;
    right: 9px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.crm-th-button {
    width: 25px;
    height: 25px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--cc-text-muted, #64748b);
    cursor: pointer;
    transition: background .14s ease, color .14s ease, border-color .14s ease, transform .14s ease;
}
.crm-th-button:hover { background: rgb(var(--crm-col-rgb, 37 99 235) / .16); color: rgb(var(--crm-col-rgb, 37 99 235)); }
.crm-th-button.is-active { background: rgb(var(--crm-col-rgb, 37 99 235) / .19); color: rgb(var(--crm-col-rgb, 37 99 235)); border-color: rgb(var(--crm-col-rgb, 37 99 235) / .28); }
.crm-sort-button.is-desc { transform: rotate(180deg); }

.crm-filter-popover {
    position: fixed;
    z-index: 10040;
    max-height: min(520px, calc(100vh - 24px));
    overflow-y: auto;
    padding: 14px;
    border: 1px solid var(--cc-border-h, rgba(15,23,42,.16));
    border-radius: 14px;
    background: var(--cc-modal-bg, #fff);
    color: var(--cc-text, #0f172a);
    box-shadow: 0 22px 70px rgba(15,23,42,.28);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.crm-filter-popover__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 13px;
}
.crm-filter-popover__head strong { display: block; font-size: 13px; }
.crm-filter-popover__head span { display: block; margin-top: 3px; color: var(--cc-text-muted, #64748b); font-size: 10px; line-height: 1.35; }
.crm-filter-popover__head button { width: 28px; height: 28px; padding: 6px; border: 0; border-radius: 8px; background: var(--cc-border, rgba(15,23,42,.08)); color: var(--cc-text-muted, #64748b); cursor: pointer; }

.crm-filter-field,
.crm-filter-grid label {
    display: grid;
    gap: 6px;
    color: var(--cc-text-muted, #64748b);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.crm-filter-field input,
.crm-filter-grid input {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--cc-input-bd, rgba(15,23,42,.16));
    border-radius: 9px;
    outline: none;
    background: var(--cc-input-bg, #fff);
    color: var(--cc-text, #0f172a);
    font: inherit;
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0;
}
.crm-filter-field input:focus,
.crm-filter-grid input:focus { border-color: var(--cc-accent, #006aa6); box-shadow: 0 0 0 3px rgba(20,104,168,.1); }

.crm-filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.crm-filter-choices { display: grid; gap: 4px; max-height: 230px; overflow-y: auto; padding-right: 4px; }
.crm-filter-choices label { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; color: var(--cc-text, #0f172a); font-size: 12px; cursor: pointer; }
.crm-filter-choices label:hover { background: var(--cc-row-hover, rgba(15,23,42,.04)); }
.crm-filter-choices input { width: 15px; height: 15px; accent-color: var(--cc-accent, #006aa6); }
.crm-filter-choices span { overflow-wrap: anywhere; }

.crm-filter-popover__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--cc-border, rgba(15,23,42,.1));
}
.crm-filter-popover__actions button { padding: 8px 11px; border-radius: 9px; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }
.crm-filter-popover__actions [data-filter-reset] { border: 1px solid var(--cc-border, rgba(15,23,42,.1)); background: transparent; color: var(--cc-text-muted, #64748b); }
.crm-filter-popover__actions [data-filter-apply] { border: 1px solid var(--cc-accent, #006aa6); background: var(--cc-accent, #006aa6); color: #fff; }

html.dark .crm-table-shell { box-shadow: 0 16px 42px rgba(0,0,0,.22); }
html.dark .crm-smart-table thead th { background: rgb(var(--crm-col-rgb, 37 99 235) / .16) !important; }
html.dark .crm-smart-table tbody td,
html.dark .crm-smart-table tbody th { background: rgb(var(--crm-col-rgb, 37 99 235) / .055); }
html.dark .crm-smart-table tbody tr:hover td,
html.dark .crm-smart-table tbody tr:hover th { background: rgb(var(--crm-col-rgb, 37 99 235) / .12) !important; }

@media (max-width: 767px) {
    .crm-select__panel { position: fixed; left: 12px; right: 12px; top: 12vh; max-height: 76vh; }
    .crm-select__list { max-height: 58vh; }
    .crm-table-toolbar { align-items: stretch; flex-direction: column; }
    .crm-table-search { width: 100%; }
    .crm-table-toolbar__right { justify-content: space-between; }
    .crm-smart-table thead th { padding-right: 58px !important; }
    .crm-th-actions { right: 6px; }
    .crm-th-button { width: 23px; height: 23px; padding: 4px; }
    .crm-filter-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .crm-select__trigger,
    .crm-select__chevron,
    .crm-th-button,
    .crm-smart-table td,
    .crm-smart-table th { transition: none !important; }
}
