/**
 * Webdev_OTC — otc-modal.css
 *
 * Works on both Hyvä (Tailwind-based) and Luma (LESS-based) themes.
 * Uses CSS custom properties for easy merchant overrides.
 * Includes Alpine.js x-cloak and transition helper classes.
 */

/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
    --otc-overlay-bg         : rgba(0,0,0,.55);
    --otc-modal-bg           : #ffffff;
    --otc-modal-radius       : 10px;
    --otc-modal-shadow       : 0 12px 40px rgba(0,0,0,.2);
    --otc-modal-max-width    : 560px;
    --otc-header-bg          : #f7f7f7;
    --otc-header-border      : #e8e8e8;
    --otc-title-color        : #111827;
    --otc-text-color         : #374151;
    --otc-label-color        : #4b5563;
    --otc-input-border       : #d1d5db;
    --otc-input-focus        : #2563eb;
    --otc-input-radius       : 6px;
    --otc-error-bg           : #fef2f2;
    --otc-error-border       : #fca5a5;
    --otc-error-text         : #b91c1c;
    --otc-primary            : #1d4ed8;
    --otc-primary-hover      : #1e40af;
    --otc-secondary-bg       : #f3f4f6;
    --otc-secondary-text     : #374151;
    --otc-required           : #dc2626;
    --otc-z-index            : 9999;
}

/* ── [x-cloak]: hide Alpine elements before init ──────────────────────── */
[x-cloak] { display: none !important; }

/* ── Overlay ───────────────────────────────────────────────────────────── */
.otc-modal-overlay {
    position        : fixed;
    inset           : 0;
    z-index         : var(--otc-z-index);
    background      : var(--otc-overlay-bg);
    display         : flex;
    align-items     : center;
    justify-content : center;
    padding         : 1rem;
}

body.otc-modal-active { overflow: hidden; }

/* ── Alpine transition classes ─────────────────────────────────────────── */
.otc-transition-enter,
.otc-transition-leave       { transition: opacity .2s ease; }
.otc-transition-enter-start,
.otc-transition-leave-end   { opacity: 0; }
.otc-transition-enter-end,
.otc-transition-leave-start { opacity: 1; }

.otc-slide-enter,
.otc-slide-leave            { transition: opacity .22s ease, transform .22s ease; }
.otc-slide-enter-start,
.otc-slide-leave-end        { opacity: 0; transform: translateY(20px); }
.otc-slide-enter-end,
.otc-slide-leave-start      { opacity: 1; transform: translateY(0); }

/* ── Modal wrapper ─────────────────────────────────────────────────────── */
.otc-modal-wrapper {
    background    : var(--otc-modal-bg);
    border-radius : var(--otc-modal-radius);
    box-shadow    : var(--otc-modal-shadow);
    width         : 100%;
    max-width     : var(--otc-modal-max-width);
    max-height    : 90vh;
    overflow-y    : auto;
    display       : flex;
    flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.otc-modal-header {
    display         : flex;
    align-items     : center;
    justify-content : space-between;
    padding         : 1.1rem 1.4rem;
    background      : var(--otc-header-bg);
    border-bottom   : 1px solid var(--otc-header-border);
    border-radius   : var(--otc-modal-radius) var(--otc-modal-radius) 0 0;
    position        : sticky;
    top             : 0;
    z-index         : 1;
}

.otc-modal-title {
    margin      : 0;
    font-size   : 1.15rem;
    font-weight : 700;
    color       : var(--otc-title-color);
    line-height : 1.3;
}

.otc-modal-close {
    background    : none;
    border        : none;
    cursor        : pointer;
    font-size     : 1.6rem;
    line-height   : 1;
    color         : #9ca3af;
    padding       : .2rem .5rem;
    border-radius : 4px;
    transition    : color .15s, background .15s;
}
.otc-modal-close:hover { color: var(--otc-title-color); background: var(--otc-header-border); }
.otc-modal-close:focus-visible { outline: 2px solid var(--otc-input-focus); outline-offset: 2px; }

/* ── Intro ─────────────────────────────────────────────────────────────── */
.otc-modal-intro {
    padding    : 1rem 1.4rem .5rem;
    color      : var(--otc-text-color);
    font-size  : .875rem;
    line-height: 1.6;
}
.otc-modal-intro p { margin: 0; }

/* ── Error box ─────────────────────────────────────────────────────────── */
.otc-modal-errors {
    margin        : .5rem 1.4rem 0;
    padding       : .75rem 1rem;
    background    : var(--otc-error-bg);
    border        : 1px solid var(--otc-error-border);
    border-radius : 6px;
    color         : var(--otc-error-text);
    font-size     : .875rem;
}
.otc-modal-errors ul { margin:0; padding:0 0 0 1.25rem; }
.otc-modal-errors li + li { margin-top:.3rem; }

/* ── Form ──────────────────────────────────────────────────────────────── */
.otc-modal-form { padding: 1.1rem 1.4rem 1.4rem; }

.otc-field-row {
    margin-bottom : 1rem;
    display       : flex;
    flex-direction: column;
    gap           : .4rem;
}

/* Side-by-side weight/height */
.otc-field-row--inline {
    flex-direction: row;
    gap           : .75rem;
}
.otc-field-col {
    flex   : 1;
    display: flex;
    flex-direction: column;
    gap    : .4rem;
}

.otc-label {
    font-size  : .875rem;
    font-weight: 600;
    color      : var(--otc-label-color);
}
.otc-required { color: var(--otc-required); margin-left: 2px; }

/* ── Inputs ────────────────────────────────────────────────────────────── */
.otc-input {
    width        : 100%;
    padding      : .55rem .75rem;
    border       : 1px solid var(--otc-input-border);
    border-radius: var(--otc-input-radius);
    font-size    : .9rem;
    color        : var(--otc-text-color);
    background   : #fff;
    transition   : border-color .15s, box-shadow .15s;
    box-sizing   : border-box;
    appearance   : none;
    -webkit-appearance: none;
}
.otc-input:focus {
    outline     : none;
    border-color: var(--otc-input-focus);
    box-shadow  : 0 0 0 3px rgba(37,99,235,.18);
}
.otc-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .6rem center; background-size: 1.2em; padding-right: 2.2rem; }
.otc-textarea { resize: vertical; min-height: 80px; }

/* ── Radio groups ──────────────────────────────────────────────────────── */
.otc-radio-group {
    display : flex;
    gap     : 1.25rem;
    flex-wrap: wrap;
}
.otc-radio-label {
    display    : flex;
    align-items: center;
    gap        : .4rem;
    cursor     : pointer;
    font-size  : .9rem;
    color      : var(--otc-text-color);
    user-select: none;
}
.otc-radio {
    accent-color: var(--otc-primary);
    width       : 16px;
    height      : 16px;
    cursor      : pointer;
    flex-shrink : 0;
}

/* ── Conditional fields ────────────────────────────────────────────────── */
.otc-conditional-field {
    padding       : .85rem;
    background    : #f9fafb;
    border        : 1px solid var(--otc-header-border);
    border-radius : 6px;
    margin-top    : -.25rem;
}

/* ── Actions ───────────────────────────────────────────────────────────── */
.otc-modal-actions {
    display        : flex;
    justify-content: flex-end;
    gap            : .75rem;
    margin-top     : 1.25rem;
    padding-top    : 1rem;
    border-top     : 1px solid var(--otc-header-border);
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
.otc-btn {
    padding      : .6rem 1.5rem;
    border       : none;
    border-radius: 6px;
    font-size    : .9rem;
    font-weight  : 600;
    cursor       : pointer;
    transition   : background .15s, opacity .15s, transform .1s;
    line-height  : 1.5;
    display      : inline-flex;
    align-items  : center;
    gap          : .4rem;
}
.otc-btn:focus-visible { outline: 2px solid var(--otc-input-focus); outline-offset: 2px; }
.otc-btn:active { transform: scale(.98); }

.otc-btn--primary { background: var(--otc-primary); color: #fff; }
.otc-btn--primary:hover:not(:disabled) { background: var(--otc-primary-hover); }
.otc-btn--primary:disabled,
.otc-btn--loading { opacity: .65; cursor: not-allowed; }

.otc-btn--secondary { background: var(--otc-secondary-bg); color: var(--otc-secondary-text); }
.otc-btn--secondary:hover { background: #e5e7eb; }

/* ── Spinner ───────────────────────────────────────────────────────────── */
.otc-spinner {
    display       : inline-block;
    width         : 1em;
    height        : 1em;
    border        : 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius : 50%;
    animation     : otc-spin .6s linear infinite;
}
@keyframes otc-spin { to { transform: rotate(360deg); } }

/* Screen-reader only utility */
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .otc-field-row--inline { flex-direction: column; }
    .otc-modal-actions     { flex-direction: column-reverse; }
    .otc-btn               { width: 100%; justify-content: center; }
}

/* ── Per-field inline validation errors ────────────────────────────────── */
.otc-field-error .otc-input,
.otc-field-error .otc-select,
.otc-field-error .otc-textarea {
    border-color: var(--otc-required);
    box-shadow  : 0 0 0 2px rgba(220,38,38,.15);
}

.otc-field-msg {
    display   : none;
    font-size : .8rem;
    color     : var(--otc-required);
    margin-top: .15rem;
}

/* Checkbox label layout */
.otc-label--checkbox {
    display    : block;
    line-height: 1.5;
}
