/* OmniTeQ — modern contact (customer/supplier) create & edit forms */

:root {
    --cfm-radius: 10px;
    --cfm-radius-sm: 8px;
    --cfm-border: #e2e8f0;
    --cfm-border-strong: #cbd5e1;
    --cfm-bg: #ffffff;
    --cfm-bg-muted: #f8fafc;
    --cfm-bg-section: #f1f5f9;
    --cfm-text: #0f172a;
    --cfm-text-muted: #64748b;
    --cfm-accent: #0066ff;
    --cfm-accent-soft: rgba(0, 102, 255, 0.08);
    --cfm-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    --cfm-gap: 10px;
}

/* Modal shell */
.contact_modal .modal-dialog.contact-form-modern-dialog,
.contact-form-page .box {
    max-width: min(960px, calc(100vw - 24px));
}

.contact_modal .modal-content:has(.contact-form-modern),
.contact-form-page .box {
    border-radius: 14px;
    border: 1px solid var(--cfm-border);
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
    overflow: hidden;
}

.contact-form-modern .modal-header,
.contact-form-page .box-header {
    background: linear-gradient(180deg, #ffffff 0%, var(--cfm-bg-muted) 100%);
    border-bottom: 1px solid var(--cfm-border);
    padding: 14px 18px;
}

.contact-form-modern .modal-title,
.contact-form-page .box-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--cfm-text);
    letter-spacing: -0.01em;
}

.contact-form-modern .modal-header .close {
    opacity: 0.55;
    margin-top: 2px;
}

.contact-form-modern .modal-body,
.contact-form-page .box-body {
    padding: 16px 18px 12px;
    background: var(--cfm-bg-muted);
    max-height: min(72vh, 720px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.contact-form-modern .modal-footer,
.contact-form-page .box-footer {
    background: var(--cfm-bg);
    border-top: 1px solid var(--cfm-border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* Sections */
.contact-form-modern .cfm-section {
    background: var(--cfm-bg);
    border: 1px solid var(--cfm-border);
    border-radius: var(--cfm-radius);
    box-shadow: var(--cfm-shadow);
    padding: 16px 18px 8px;
    margin-bottom: 12px;
}

.contact-form-modern .cfm-section__title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--cfm-border);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--cfm-text-muted);
}

.contact-form-modern .cfm-section__title i {
    color: var(--cfm-accent);
    font-size: 0.85rem;
}

.contact-form-modern .cfm-section--nested {
    background: var(--cfm-bg-muted);
    border-style: dashed;
    padding: 14px 16px 6px;
    margin-top: 8px;
}

/* Compact grid */
.contact-form-modern .row {
    margin-left: -6px;
    margin-right: -6px;
}

.contact-form-modern .row > [class*="col-"] {
    padding-left: 6px;
    padding-right: 6px;
}

.contact-form-modern .form-group {
    margin-bottom: 10px;
}

.contact-form-modern label {
    font-size: 12px;
    font-weight: 600;
    color: var(--cfm-text);
    margin-bottom: 4px;
}

.contact-form-modern .help-block {
    font-size: 11px;
    color: var(--cfm-text-muted);
    margin-top: 3px;
    margin-bottom: 0;
}

/* Inputs */
.contact-form-modern .form-control {
    height: 36px;
    min-height: 36px;
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--cfm-border-strong);
    border-radius: var(--cfm-radius-sm);
    box-shadow: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.contact-form-modern textarea.form-control {
    height: auto;
    min-height: 72px;
}

.contact-form-modern .form-control:focus {
    border-color: var(--cfm-accent);
    box-shadow: 0 0 0 3px var(--cfm-accent-soft);
}

/* Seamless input groups — icon + field flush (match Assigned to / Select2) */
.contact-form-modern .input-group {
    display: flex !important;
    align-items: stretch !important;
    flex-wrap: nowrap !important;
    width: 100%;
    gap: 0 !important;
    border-spacing: 0;
    position: relative;
}

.contact-form-modern .input-group > .input-group-addon,
.contact-form-modern .input-group > .input-group-btn {
    flex: 0 0 auto;
    display: flex !important;
    align-items: center;
    justify-content: center;
    float: none !important;
    width: auto;
    min-width: 38px;
    height: auto;
    min-height: 36px;
    margin: 0 !important;
    padding: 0 10px;
    background: var(--cfm-bg-muted);
    border: 1px solid var(--cfm-border-strong);
    border-right-width: 0 !important;
    border-radius: var(--cfm-radius-sm) 0 0 var(--cfm-radius-sm) !important;
    color: var(--cfm-text-muted);
    z-index: 2;
}

.contact-form-modern .input-group > .form-control,
.contact-form-modern .input-group > input.form-control,
.contact-form-modern .input-group > select.form-control,
.contact-form-modern .input-group > textarea.form-control,
.contact-form-modern .input-group > input[type="text"],
.contact-form-modern .input-group > input[type="email"],
.contact-form-modern .input-group > input[type="number"],
.contact-form-modern .input-group > input[type="password"],
.contact-form-modern .input-group > input[type="tel"] {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: 1% !important;
    float: none !important;
    display: block !important;
    margin: 0 0 0 -1px !important;
    height: 36px;
    min-height: 36px;
    border: 1px solid var(--cfm-border-strong);
    border-radius: 0 var(--cfm-radius-sm) var(--cfm-radius-sm) 0 !important;
    box-shadow: none !important;
    position: relative;
    z-index: 1;
}

.contact-form-modern .input-group > select.form-control {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: var(--cfm-bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.contact-form-modern .input-group > .form-control:focus,
.contact-form-modern .input-group > select.form-control:focus {
    z-index: 4;
    border-color: var(--cfm-accent);
    box-shadow: 0 0 0 3px var(--cfm-accent-soft) !important;
}

.contact-form-modern .input-group:focus-within > .input-group-addon:first-child,
.contact-form-modern .input-group:focus-within > .input-group-btn:first-child {
    border-color: var(--cfm-accent);
    z-index: 3;
}

.contact-form-modern .input-group.secret-field-wrap .form-control {
    border-radius: 0 !important;
    margin-left: -1px !important;
}

.contact-form-modern .input-group.secret-field-wrap > .input-group-addon:first-child {
    border-radius: var(--cfm-radius-sm) 0 0 var(--cfm-radius-sm) !important;
}

.contact-form-modern .input-group.secret-field-wrap .input-group-btn .btn {
    height: 36px;
    min-height: 36px;
    margin: 0 !important;
    border: 1px solid var(--cfm-border-strong);
    border-left-width: 0;
    border-radius: 0 var(--cfm-radius-sm) var(--cfm-radius-sm) 0 !important;
}

/* Individual / Business toggle */
.contact-form-modern .cfm-type-toggle {
    display: flex;
    align-items: center;
    min-height: 36px;
    padding-top: 22px;
}

.contact-form-modern .cfm-type-toggle .radio-inline {
    margin: 0 6px 0 0;
    padding: 0;
}

.contact-form-modern .cfm-type-toggle .radio-inline input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.contact-form-modern .cfm-type-toggle .radio-inline {
    display: inline-flex;
}

.contact-form-modern .cfm-type-toggle .radio-inline span,
.contact-form-modern .cfm-type-toggle .radio-inline {
    font-size: 12px;
    font-weight: 600;
}

.contact-form-modern .cfm-type-toggle .radio-inline input + span,
.contact-form-modern .cfm-type-toggle label.radio-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid var(--cfm-border-strong);
    border-radius: 999px;
    background: var(--cfm-bg);
    color: var(--cfm-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    margin: 0 6px 0 0;
}

.contact-form-modern .cfm-type-toggle .radio-inline input:checked + span,
.contact-form-modern .cfm-type-toggle label.radio-inline:has(input:checked) {
    background: var(--cfm-accent-soft);
    border-color: var(--cfm-accent);
    color: var(--cfm-accent);
}

/* Fallback when :has unsupported — rely on checked state via adjacent if we wrap text */
.contact-form-modern .cfm-type-toggle .radio-inline input:checked ~ span {
    background: var(--cfm-accent-soft);
    border-color: var(--cfm-accent);
    color: var(--cfm-accent);
}

/* Expand / accordion buttons */
.contact-form-modern .cfm-expand-wrap {
    margin: 4px 0 12px;
}

.contact-form-modern .more_btn,
.contact-form-modern .cfm-expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px dashed var(--cfm-border-strong);
    border-radius: var(--cfm-radius);
    background: var(--cfm-bg);
    color: var(--cfm-text);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: none;
    box-shadow: none;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.contact-form-modern .more_btn:hover,
.contact-form-modern .more_btn:focus,
.contact-form-modern .cfm-expand-btn:hover,
.contact-form-modern .cfm-expand-btn:focus {
    background: var(--cfm-accent-soft);
    border-color: var(--cfm-accent);
    color: var(--cfm-accent);
    outline: none;
}

.contact-form-modern .more_btn i,
.contact-form-modern .cfm-expand-btn i {
    font-size: 11px;
    opacity: 0.75;
}

.contact-form-modern .cfm-expand-panel {
    margin-top: 0;
}

.contact-form-modern #more_div:not(.hide),
.contact-form-modern #contact_person_div:not(.hide) {
    animation: cfmReveal 0.2s ease;
}

@keyframes cfmReveal {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Dividers inside expandable areas */
.contact-form-modern .cfm-expand-panel hr,
.contact-form-modern #more_div hr,
.contact-form-modern #contact_person_div hr {
    border-color: var(--cfm-border);
    margin: 10px 0;
}

/* Pay term inline fields */
.contact-form-modern .multi-input .width-40,
.contact-form-modern .multi-input .width-60 {
    float: left;
}

.contact-form-modern .multi-input .width-40 {
    width: 38%;
    margin-right: 2%;
}

.contact-form-modern .multi-input .width-60 {
    width: 60%;
}

.contact-form-modern .multi-input .form-control {
    width: 100%;
}

/* Select2 inside input-group */
.contact-form-modern .input-group > select.select2-hidden-accessible {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.contact-form-modern .input-group > .select2-container {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: 1% !important;
    max-width: 100% !important;
    display: block !important;
    margin: 0 0 0 -1px !important;
    float: none !important;
}

.contact-form-modern .select2-container {
    width: 100% !important;
    display: block;
}

.contact-form-modern .select2-container--default .select2-selection--single,
.contact-form-modern .select2-container--default .select2-selection--multiple {
    min-height: 36px;
    height: 36px;
    border: 1px solid var(--cfm-border-strong) !important;
    border-radius: var(--cfm-radius-sm) !important;
    background: var(--cfm-bg) !important;
}

.contact-form-modern .input-group > .select2-container .select2-selection--single,
.contact-form-modern .input-group > .select2-container .select2-selection--multiple {
    height: 36px;
    min-height: 36px;
    border: 1px solid var(--cfm-border-strong) !important;
    border-left-width: 0 !important;
    border-radius: 0 var(--cfm-radius-sm) var(--cfm-radius-sm) 0 !important;
}

.contact-form-modern .input-group:focus-within > .select2-container .select2-selection--single,
.contact-form-modern .input-group:focus-within > .select2-container .select2-selection--multiple {
    border-color: var(--cfm-accent) !important;
}

.contact-form-modern .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 34px;
    padding-left: 10px;
    font-size: 13px;
}

.contact-form-modern .select2-container--default .select2-selection--multiple .select2-selection__rendered {
    padding: 2px 8px;
    min-height: 32px;
}

.contact-form-modern .select2-container--default .select2-selection--multiple .select2-selection__choice {
    font-size: 11px;
    border-radius: 999px;
    margin-top: 4px;
}

.contact-form-modern .input-group > .select2-container .select2-selection__arrow {
    height: 34px !important;
}

/* Contact persons block */
.contact-form-modern #contact_person_div .row > .col-md-12:first-child hr {
    display: none;
}

.contact-form-modern #contact_person_div > .row:first-child {
    margin-bottom: 0;
}

.contact-form-modern #contact_person_div .more_btn {
    margin-bottom: 6px;
}

.contact-form-modern .cfm-person-panel {
    margin-bottom: 8px;
}

/* Procurement / supplier module fields */
.contact-form-modern .procurement-supplier-fields {
    background: var(--cfm-bg);
    border: 1px solid var(--cfm-border);
    border-radius: var(--cfm-radius);
    box-shadow: var(--cfm-shadow);
    padding: 12px 12px 4px;
    margin: 12px 0;
}

.contact-form-modern .procurement-supplier-fields .cfm-section__title,
.contact-form-modern .procurement-supplier-fields > .row > .col-md-12 strong {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--cfm-text-muted);
    margin-bottom: 8px;
}

.contact-form-modern .procurement-supplier-fields > .row > .col-md-12 > strong {
    padding-top: 4px;
}

.contact-form-modern .procurement-supplier-fields > .row > .col-md-12 > .help-block {
    margin-top: -4px;
    margin-bottom: 8px;
}

/* POPIA consent */
.contact-form-modern .cfm-consent {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--cfm-radius);
    padding: 10px 12px;
    margin-top: 4px;
}

.contact-form-modern .cfm-consent label {
    font-weight: 500;
    font-size: 12px;
    line-height: 1.45;
    margin: 0;
}

.contact-form-modern .cfm-consent .checkbox {
    margin: 0;
}

/* Shipping map */
.contact-form-modern .shipping_addr_div strong {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--cfm-text-muted);
    margin-bottom: 8px;
}

.contact-form-modern #map {
    border-radius: var(--cfm-radius-sm);
    border: 1px solid var(--cfm-border);
    min-height: 180px;
    margin-top: 8px;
}

/* Checkboxes / iCheck */
.contact-form-modern .checkbox label,
.contact-form-modern .form-check-label {
    font-size: 12px;
    font-weight: 500;
}

/* Validation */
.contact-form-modern label.error {
    color: #dc2626;
    font-size: 11px;
    font-weight: 600;
    margin-top: 3px;
}

.contact-form-modern .form-control.error {
    border-color: #dc2626;
}

/* Remove legacy top margin helper inside modern form */
.contact-form-modern .mt-15 {
    margin-top: 0 !important;
}

.contact-form-modern .mt-56 {
    margin-top: 0 !important;
}

/* Dark theme */
[data-theme="dark"] {
    --cfm-border: #334155;
    --cfm-border-strong: #475569;
    --cfm-bg: #0f172a;
    --cfm-bg-muted: #111827;
    --cfm-bg-section: #1e293b;
    --cfm-text: #f1f5f9;
    --cfm-text-muted: #94a3b8;
    --cfm-accent-soft: rgba(96, 165, 250, 0.15);
}

[data-theme="dark"] .contact-form-modern .modal-header,
[data-theme="dark"] .contact-form-page .box-header {
    background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
}

[data-theme="dark"] .contact-form-modern .cfm-consent {
    background: rgba(251, 191, 36, 0.08);
    border-color: rgba(251, 191, 36, 0.35);
}

[data-theme="dark"] .contact-form-modern .input-group-addon {
    background: #1e293b;
}

[data-theme="dark"] .contact-form-modern .input-group > select.form-control {
    background-color: var(--cfm-bg);
}

[data-theme="dark"] .contact-form-modern .input-group > .form-control,
[data-theme="dark"] .contact-form-modern .input-group > select.form-control {
    background-color: var(--cfm-bg);
}

@media (max-width: 767px) {
    .contact-form-modern .modal-body,
    .contact-form-page .box-body {
        max-height: none;
        padding: 10px;
    }

    .contact-form-modern .cfm-section {
        padding: 10px 8px 2px;
    }

    .contact-form-modern .cfm-type-toggle {
        padding-top: 0;
        margin-bottom: 6px;
    }
}
