/**
 * companion-fields.css
 * Minimal, frontend-safe stylesheet for FieldFactory field types.
 * Admin-only styles (color picker, media picker, gallery, knob JS) live in companion-admin.css.
 *
 * Version: 1.0.0
 * Last Modified: 2026-03-07
 */

/* ==========================================================================
   Field Wrap
   ========================================================================== */

.companion-field-wrap {
    margin-bottom: 1rem;
}

.companion-field-label {
    display: block;
    font-weight: 600;
    margin-bottom: .35rem;
}

.companion-field-required {
    color: #d63638;
}

/* ==========================================================================
   Text / URL / Email
   ========================================================================== */

.companion-text-input,
.companion-url-input,
.companion-email-input {
    width: 100%;
    max-width: 25rem;
}

/* ==========================================================================
   Textarea / Code
   ========================================================================== */

.companion-code-input {
    font-family: monospace;
    font-size: .875em;
    width: 100%;
    max-width: 40rem;
    background: #1e1e1e;
    color: #d4d4d4;
    border: 1px solid #3c3c3c;
    padding: .5rem;
    resize: vertical;
    tab-size: 4;
}

/* ==========================================================================
   Number / Range
   ========================================================================== */

.companion-number-wrap {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.companion-number-input {
    width: 6rem;
}

.companion-number-unit,
.companion-range-unit {
    color: #757575;
    font-size: .875em;
}

.companion-range-wrap {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.companion-range {
    flex: 1;
    max-width: 20rem;
}

.companion-range-value {
    min-width: 3rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Switch
   ========================================================================== */

.companion-switch-row {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.companion-switch {
    position: relative;
    display: inline-block;
    width: 2.5rem;
    height: 1.375rem;
    flex-shrink: 0;
}

.companion-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.companion-switch-slider {
    position: absolute;
    inset: 0;
    background: #c3c4c7;
    border-radius: 1.375rem;
    cursor: pointer;
    transition: background .2s;
}

.companion-switch-slider::before {
    content: '';
    position: absolute;
    width: 1rem;
    height: 1rem;
    left: .2rem;
    top: .2rem;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
}

.companion-switch input:checked + .companion-switch-slider {
    background: #2271b1;
}

.companion-switch input:checked + .companion-switch-slider::before {
    transform: translateX(1.125rem);
}

.companion-switch-label label {
    cursor: pointer;
}

/* ==========================================================================
   Checkbox
   ========================================================================== */

.companion-checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
}

.companion-checkbox-label label {
    cursor: pointer;
}

/* ==========================================================================
   Select
   ========================================================================== */

.companion-select-input {
    min-width: 10rem;
    max-width: 25rem;
}

/* ==========================================================================
   Radio / Toggle Group
   ========================================================================== */

.companion-radio-group {
    display: flex;
    flex-direction: column;
    gap: .375rem;
}

.companion-radio-option {
    display: flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
}

.companion-toggle-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    width: fit-content;
    overflow: hidden;
}

.companion-toggle-group-btn {
    padding: .375rem .875rem;
    cursor: pointer;
    border-right: 1px solid #c3c4c7;
    font-size: .875em;
    transition: background .15s, color .15s;
    user-select: none;
}

.companion-toggle-group-btn:last-child {
    border-right: none;
}

.companion-toggle-group-btn input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.companion-toggle-group-btn.is-active,
.companion-toggle-group-btn:has(input:checked) {
    background: #2271b1;
    color: #fff;
}

/* ==========================================================================
   Color Picker
   ========================================================================== */

.companion-color-picker-wrap {
    display: flex;
    align-items: center;
}

/* ==========================================================================
   Image Picker
   ========================================================================== */

.companion-image-picker {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    max-width: 12rem;
}

.companion-image-preview {
    width: 10rem;
    height: 7rem;
    border: 2px dashed #c3c4c7;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f6f7f7;
}

.companion-image-preview.has-image {
    border-style: solid;
    border-color: #c3c4c7;
    background: none;
}

.companion-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.companion-image-preview .dashicons {
    color: #c3c4c7;
    font-size: 2rem;
    width: 2rem;
    height: 2rem;
}

.companion-image-controls {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

/* ==========================================================================
   Media Select
   ========================================================================== */

.companion-media-select {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    max-width: 28rem;
}

.companion-media-preview {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    background: #f6f7f7;
    min-height: 3rem;
}

.companion-media-thumb {
    width: 2.5rem;
    height: 2.5rem;
    object-fit: cover;
    border-radius: 2px;
    flex-shrink: 0;
}

.companion-media-filename {
    font-size: .875em;
    color: #50575e;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.companion-media-controls {
    display: flex;
    gap: .5rem;
}

/* ==========================================================================
   Gallery
   ========================================================================== */

.companion-gallery {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.companion-gallery-grid {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.companion-gallery-thumb {
    position: relative;
    width: 5rem;
    height: 5rem;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #c3c4c7;
}

.companion-gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.companion-gallery-remove {
    position: absolute;
    top: .125rem;
    right: .125rem;
    width: 1.25rem;
    height: 1.25rem;
    background: rgba(0, 0, 0, .6);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: .75rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity .15s;
}

.companion-gallery-thumb:hover .companion-gallery-remove {
    opacity: 1;
}

/* ==========================================================================
   Knob
   ========================================================================== */

.companion-knob-wrap {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: .25rem;
    cursor: ns-resize;
    user-select: none;
    outline: none;
}

.companion-knob-wrap:focus-visible {
    outline: 2px solid #2271b1;
    border-radius: 4px;
}

.companion-knob-svg {
    width: 4rem;
    height: 4rem;
}

.companion-knob-track {
    stroke: #c3c4c7;
}

.companion-knob-fill {
    stroke: #2271b1;
    transition: stroke-dasharray .05s linear;
}

.companion-knob-dot {
    fill: #2271b1;
}

.companion-knob-display {
    display: flex;
    align-items: baseline;
    gap: .15rem;
    font-size: .8125rem;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.companion-knob-unit {
    font-size: .6875rem;
    color: #757575;
}

/* ==========================================================================
   Description / Message / Hint
   ========================================================================== */

.companion-field-description {
    margin: .375rem 0 0;
    font-size: .8125rem;
    color: #646970;
}

.companion-field-message {
    display: flex;
    align-items: center;
    gap: .375rem;
    margin-top: .375rem;
    font-size: .8125rem;
}

.companion-field-message--error   { color: #d63638; }
.companion-field-message--success { color: #00a32a; }
.companion-field-message--warn,
.companion-field-message--warning { color: #dba617; }

.companion-field-hint {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    margin-top: .5rem;
    padding: .5rem .75rem;
    border-left: 3px solid #2271b1;
    background: #f0f6fc;
    font-size: .8125rem;
    border-radius: 0 4px 4px 0;
}

.companion-field-hint--warn {
    border-left-color: #dba617;
    background: #fcf9e8;
}

.companion-field-hint--tip {
    border-left-color: #00a32a;
    background: #edfaef;
}

/* ==========================================================================
   Language Checkbox Group (intranet/src/Field/LanguageCheckboxField.php)
   ========================================================================== */

.intranet-language-checkboxes {
    display: flex;
    flex-direction: column;
}

.intranet-language-item {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: .25rem .5rem;
    border: 1px solid transparent;
    border-radius: 4px;
    transition: background .15s, border-color .15s;
}

.intranet-language-item:hover {
    background: #f0f6fc;
    border-color: #c3c4c7;
}

.intranet-language-item input[type="checkbox"] {
    margin: 0;
    flex-shrink: 0;
}

.intranet-language-item .whi-flag {
    flex-shrink: 0;
    margin-left: .5rem;
}

.intranet-language-label {
    font-size: .875em;
    margin-left: .4rem;
}

/* ==========================================================================
   Companion Button (frontend-safe subset)
   ========================================================================== */

.companion-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: var(--dorf-radius-sm, 4px);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    background: none;
}

.companion-btn--ghost {
    border-color: #c3c4c7;
    color: #50575e;
}

.companion-btn--ghost:hover,
.companion-btn--ghost:focus {
    border-color: #2271b1;
    color: #2271b1;
}

.companion-btn--sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8125rem;
}

/* ==========================================================================
   File Upload Field
   ========================================================================== */

.companion-upload-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.companion-upload-trigger {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 2px dashed #c3c4c7;
    border-radius: var(--dorf-radius-sm, 4px);
    cursor: pointer;
    transition: border-color 0.2s;
    background: #f6f7f7;
}

.companion-upload-trigger:hover {
    border-color: #2271b1;
}

.companion-upload-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    overflow: hidden;
}

.companion-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    flex-shrink: 0;
    background: #2271b1;
    color: #fff;
    border-radius: var(--dorf-radius-sm, 4px);
    font-size: 1.1rem;
    line-height: 1;
}

.companion-upload-hint {
    font-size: 0.8125rem;
    color: #646970;
    flex: 1;
}

.companion-upload-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.companion-upload-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.625rem;
    border: 1px solid #c3c4c7;
    border-radius: var(--dorf-radius-sm, 4px);
    font-size: 0.8125rem;
    background: #f6f7f7;
}

.companion-upload-item--loading {
    opacity: 0.6;
    font-style: italic;
}

.companion-upload-item__name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.companion-upload-item__view {
    flex-shrink: 0;
    color: #646970;
    text-decoration: none;
    font-size: 1rem;
    line-height: 1;
    padding: 0.1rem 0.2rem;
}

.companion-upload-item__view:hover { color: #2271b1; }

.companion-upload-item__remove {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: #646970;
    font-size: 0.875rem;
    line-height: 1;
    padding: 0.1rem 0.3rem;
    border-radius: 2px;
    transition: color 0.15s;
}

.companion-upload-item__remove:hover { color: #d63638; }

.companion-upload-error {
    color: #d63638;
    font-size: 0.8125rem;
    padding: 0.2rem 0;
}

/* ==========================================================================
   Media Links Field
   ========================================================================== */

.companion-media-links-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.companion-ml-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.companion-ml-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.companion-ml-type {
    flex-shrink: 0;
    min-width: 8rem;
    padding: 0.45rem 0.75rem;
    border: 1px solid #c3c4c7;
    border-radius: var(--dorf-radius-sm, 4px);
    background: #fff;
    color: #1d2327;
    font-size: 0.875rem;
    cursor: pointer;
}

.companion-ml-url {
    flex: 1;
    min-width: 0;
    padding: 0.45rem 0.75rem;
    border: 1px solid #c3c4c7;
    border-radius: var(--dorf-radius-sm, 4px);
    background: #fff;
    color: #1d2327;
    font-size: 0.875rem;
}

.companion-ml-url:focus,
.companion-ml-type:focus {
    outline: none;
    border-color: #2271b1;
}

.companion-ml-url::placeholder { color: #a0a5aa; }

.companion-ml-remove {
    flex-shrink: 0;
    background: none;
    border: 1px solid #c3c4c7;
    border-radius: var(--dorf-radius-sm, 4px);
    cursor: pointer;
    color: #646970;
    font-size: 0.875rem;
    line-height: 1;
    padding: 0.45rem 0.625rem;
    transition: color 0.15s, border-color 0.15s;
}

.companion-ml-remove:hover {
    color: #d63638;
    border-color: #d63638;
}

/* ==========================================================================
   State modifiers
   ========================================================================== */

.companion-field-wrap.is-error   > .companion-text-input,
.companion-field-wrap.is-error   > .companion-url-input,
.companion-field-wrap.is-error   > .companion-email-input,
.companion-field-wrap.is-error   > textarea {
    border-color: #d63638;
    box-shadow: 0 0 0 1px #d63638;
}

.companion-field-wrap.is-success > .companion-text-input,
.companion-field-wrap.is-success > .companion-url-input,
.companion-field-wrap.is-success > .companion-email-input,
.companion-field-wrap.is-success > textarea {
    border-color: #00a32a;
    box-shadow: 0 0 0 1px #00a32a;
}
