/*
 * Global form styling for Select2 + jQuery Validate + SweetAlert2
 * (see assets/js/app-forms.js). Based on profitniti's custom rules.
 */

/* --- Validation errors --- */
form label.error {
    display: block;
    color: var(--danger-600, #dc2626);
    font-size: 0.8125rem;
    font-weight: 500;
    margin-top: 4px;
    margin-bottom: 0;
}

form input.error,
form textarea.error,
form select.error {
    border-color: var(--danger-600, #dc2626) !important;
}

form select.error + .select2-container .select2-selection {
    border-color: var(--danger-600, #dc2626) !important;
}

/* --- Select2, matched to the theme's .form-control / .form-select --- */
.select2-container span.selection {
    width: 100%;
}

body .select2-container--default .select2-selection--single {
    height: 38px;
    border: 1px solid var(--input-form-light, #d1d5db);
    border-radius: 8px;
    background-color: var(--white, #fff);
}

body .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px;
    padding-left: 12px;
    padding-right: 36px;
    color: var(--text-primary-light, #111827);
}

body .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-secondary-light, #6b7280);
}

body .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
    right: 8px;
}

body .select2-container--default .select2-selection--single .select2-selection__clear {
    height: 36px;
    margin-right: 22px;
}

body .select2-container--default.select2-container--focus .select2-selection--single,
body .select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--primary-600, #487fff);
}

body .select2-container--default.select2-container--disabled .select2-selection--single {
    background-color: var(--neutral-100, #f3f4f6);
    cursor: not-allowed;
}

/* Multi-selects: the single select's height and border when empty; selected
   values are pill tags that wrap onto more lines as they are added. */
/* Select2 boxes are inline-blocks; a multi-select's baseline is its search
   text, which pushed it below the single selects in the same row. */
.select2-container {
    vertical-align: top;
}

body .select2-container--default .select2-selection--multiple {
    min-height: 38px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 3px 32px 3px 8px;
    border: 1px solid var(--input-form-light, #d1d5db);
    border-radius: 8px;
    background-color: var(--white, #fff);
    cursor: text;
    position: relative;
}

/* The same chevron as the single selects, so both read as dropdowns. */
body .select2-container--default .select2-selection--multiple::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 14px;
    margin-top: -2px;
    border-style: solid;
    border-width: 5px 4px 0;
    border-color: #888 transparent transparent;
    pointer-events: none;
}

body .select2-container--default .select2-selection--multiple .select2-selection__rendered {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* No tags yet: the empty list takes no room, so the placeholder starts at the left. */
body .select2-container--default .select2-selection--multiple .select2-selection__rendered:empty {
    display: none;
}

body .select2-container--default .select2-selection--multiple .select2-selection__choice {
    position: relative;
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    margin: 0;
    padding: 2px 8px 2px 22px;
    font-size: 12px;
    line-height: 18px;
    border-radius: 999px;
    color: var(--primary-600, #487fff);
    background-color: var(--primary-50, #eef3ff);
    border: 1px solid var(--primary-100, #dbe6ff);
}

body .select2-container--default .select2-selection--multiple .select2-selection__choice__display {
    padding: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 6px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font-size: 14px;
    line-height: 1;
}

body .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    background: none;
    color: var(--danger-600, #dc2626);
}

body .select2-container--default .select2-selection--multiple .select2-selection__clear {
    margin: 0 18px 0 0;
    height: auto;
}

/* The inline search box doubles as the placeholder ("All clients"): it fills
   the rest of the line, left-aligned, whatever width Select2 sets inline. */
body .select2-container .select2-search--inline {
    display: flex;
    flex: 1 1 60px;
    min-width: 60px;
}

body .select2-container .select2-search--inline .select2-search__field {
    width: 100% !important;
    height: 24px;
    margin: 0;
    padding: 0 4px;
    text-align: left;
    font-size: inherit;
    font-family: inherit;
    line-height: 24px;
    vertical-align: middle;
}

body .select2-container .select2-search--inline .select2-search__field::placeholder {
    color: var(--text-secondary-light, #6b7280);
    opacity: 1;
}

body .select2-container--default.select2-container--focus .select2-selection--multiple,
body .select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: var(--primary-600, #487fff);
}

[data-theme="dark"] body .select2-selection--multiple {
    background-color: var(--neutral-50, #1b2431);
    color: var(--text-primary-light, #fff);
}

body .select2-dropdown {
    border-color: var(--input-form-light, #d1d5db);
    border-radius: 8px;
    overflow: hidden;
    z-index: 1060;
}

body .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: var(--primary-600, #487fff);
}

body .select2-container--default .select2-search--dropdown .select2-search__field {
    border-radius: 6px;
}

[data-theme="dark"] body .select2-selection--single,
[data-theme="dark"] body .select2-dropdown,
[data-theme="dark"] body .select2-search__field {
    background-color: var(--neutral-50, #1b2431);
    color: var(--text-primary-light, #fff);
}

/* --- Inline button spinners (profitniti's hg-spinner-border) --- */
.hg-spinner-border {
    display: none;
    width: 20px;
    height: 20px;
}

.active-loader .hg-spinner-border {
    display: inline-block;
}

/* --- List tables: keep wide DataTables inside their card --- */
div.dt-container div.dt-layout-row.dt-layout-table div.dt-layout-cell {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.bordered-table th,
.bordered-table td.text-end,
.bordered-table .badge {
    white-space: nowrap;
}

/* --- Laravel pagination: match the DataTables paging buttons --- */
nav .pagination {
    gap: 0.625rem;
    margin-bottom: 0;
}

nav .pagination .page-link {
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 4px !important;
    background: var(--neutral-200);
    color: var(--text-secondary-light);
    font-weight: 500;
    box-shadow: none;
}

nav .pagination .page-item.active .page-link,
nav .pagination .page-link:hover {
    background: var(--primary-600);
    color: #fff;
}

nav .pagination .page-item.disabled .page-link {
    background: transparent;
    color: var(--text-secondary-light);
    opacity: 0.6;
}

nav:has(> .d-sm-flex > div > .pagination) p.small {
    margin-bottom: 0;
    color: var(--text-secondary-light) !important;
    font-size: 1rem !important;
}

/* --- Detail pages: info tiles, inline "Add …" panels, table notes --- */
.stat-tile {
    height: 100%;
    padding: 1rem;
    border: 1px solid var(--neutral-200);
    border-radius: 8px;
    background: var(--white);
}

.add-panel {
    margin: 0 0 1rem;
    padding: 1rem 0.25rem 1.25rem;
    border: 1px dashed var(--primary-600);
    border-radius: 8px;
    background: var(--primary-50);
}

.table-note {
    display: flex;
    gap: 0.375rem;
    margin: 0.75rem 0 0;
    font-size: 0.75rem;
    color: var(--text-secondary-light);
}

.table-note iconify-icon {
    flex-shrink: 0;
    margin-top: 1px;
    font-size: 0.875rem;
}

/* --- Event page: underlined tab bar with counts --- */
.event-tabs {
    gap: 0.25rem;
    border: 0;
    scrollbar-width: thin;
}

.event-tabs .nav-link {
    padding: 0.625rem 1rem 0.875rem;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary-light);
    font-weight: 600;
}

.event-tabs .nav-link:hover {
    color: var(--primary-600);
}

.event-tabs .nav-link.active {
    border-bottom-color: var(--primary-600);
    background: transparent;
    color: var(--primary-600);
}

.event-tab-count {
    min-width: 1.375rem;
    padding: 0 0.375rem;
    border-radius: 999px;
    background: var(--neutral-200);
    color: var(--text-secondary-light);
    font-size: 0.75rem;
    line-height: 1.375rem;
    text-align: center;
}

.event-tabs .nav-link.active .event-tab-count {
    background: var(--primary-600);
    color: #fff;
}

.lifecycle-step {
    transition: background-color 0.15s;
}

.lifecycle-step.lifecycle-step-link:hover {
    background: var(--neutral-50);
}

/* --- Detail pages: sectioned label / value profile lists --- */
.info-section-title {
    margin: 1.5rem 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary-light);
}

.info-section-title:first-child {
    margin-top: 0;
}

.info-list .info-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--neutral-200);
    font-size: 0.875rem;
}

.info-list .info-row:last-child {
    border-bottom: 0;
}

.info-list .info-row > span:first-child {
    flex-shrink: 0;
    color: var(--text-secondary-light);
}

.info-list .info-row > span:last-child {
    text-align: end;
    color: var(--text-primary-light);
    font-weight: 500;
}

/* --- Client page: communication timeline --- */
.comm-timeline .comm-item {
    position: relative;
    display: flex;
    gap: 0.875rem;
    padding-bottom: 1.25rem;
}

.comm-timeline .comm-item:last-child {
    padding-bottom: 0;
}

/* The line joining one entry's icon to the next. */
.comm-timeline .comm-item:not(:last-child)::before {
    content: "";
    position: absolute;
    top: 2.25rem;
    bottom: 0.25rem;
    left: 1.125rem;
    width: 1px;
    background: var(--neutral-200);
}

.comm-timeline .comm-icon {
    width: 2.25rem;
    height: 2.25rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--primary-50);
    color: var(--primary-600);
    font-size: 1.125rem;
}

/* Lookup pickers' "+ Create new …" item (app-forms.js): theme blue, white
   on the highlighted row so it stays readable. */
.select2-create-option {
    font-weight: 600;
    color: var(--primary-600, #487fff);
}

.select2-results__option--highlighted .select2-create-option {
    color: #fff;
}

/* "+" after a lookup field's label: opens its create page in a new tab. */
.lookup-create-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 4px;
    border-radius: 50%;
    vertical-align: middle;
    font-size: 14px;
    color: var(--primary-600, #487fff);
    background-color: var(--primary-50, #e4f1ff);
}

.lookup-create-link:hover {
    color: #fff;
    background-color: var(--primary-600, #487fff);
}
