/* =========================================
   CRM CONFIG PAGE — STYLES SPECIFIC TO THIS PAGE
   Relies on the variables defined in cardflow.css
========================================= */

:root {
    --danger: #ff8a9a;
    --danger-bg: rgba(255, 110, 130, 0.1);
    --warning: #ffd079;

    --header-h: 86px;
}

@media (max-width: 800px) {
    :root {
        --header-h: 74px;
    }
}

html {
    scroll-padding-top: 170px;
}

[hidden] {
    display: none !important;
}

code {
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.07);
    color: var(--purple-light);
    font-size: 0.92em;
}


/* =========================================
   TITLE
========================================= */

.page-top {
    padding: 150px 0 34px;
}

.page-title {
    max-width: 800px;
    font-family: var(--font-heading);
    font-size: clamp(36px, 5vw, 60px);
    font-weight: 600;
    line-height: 1.12;
    letter-spacing: -2.4px;
}

.page-intro {
    max-width: 640px;
    margin-top: 22px;

    color: var(--text-muted);
    font-size: 16px;
    line-height: 1.85;
}


/* =========================================
   ACTION BAR (sticky)
========================================= */

/* display: contents so the bar sticks inside <main>, not inside a bar-sized wrapper */
.action-wrap {
    display: contents;
}

.action-bar {
    width: min(var(--container), calc(100% - 48px));
    margin-inline: auto;

    position: sticky;
    top: calc(var(--header-h) + 8px);
    z-index: 900;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;

    padding: 12px 14px 12px 20px;

    border: 1px solid rgba(139, 124, 255, 0.3);
    border-radius: 18px;

    background: rgba(16, 23, 42, 0.92);

    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);

    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.action-status {
    display: flex;
    align-items: center;
    gap: 11px;

    min-width: 0;

    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
}

.status-light {
    width: 9px;
    height: 9px;
    flex-shrink: 0;

    border-radius: 50%;
    background: var(--text-soft);

    transition: background var(--transition), box-shadow var(--transition);
}

.action-bar[data-state="ready"] .status-light {
    background: var(--green);
    box-shadow: 0 0 14px rgba(100, 229, 173, 0.6);
}

.action-bar[data-state="stale"] .status-light {
    background: var(--warning);
    box-shadow: 0 0 14px rgba(255, 208, 121, 0.5);
}

.action-bar[data-state="error"] .status-light {
    background: var(--danger);
    box-shadow: 0 0 14px rgba(255, 138, 154, 0.5);
}

.action-bar[data-state="ready"] .action-status {
    color: var(--text);
}

.action-buttons {
    display: flex;
    flex-shrink: 0;
    gap: 10px;
}

.action-buttons .btn {
    min-height: 48px;
    padding: 11px 18px;
    font-size: 13px;
    white-space: nowrap;
}

.btn-strong {
    border-color: rgba(139, 124, 255, 0.55);
    background: rgba(139, 124, 255, 0.14);
}

.btn-strong:hover {
    background: rgba(139, 124, 255, 0.26);
}

.btn-small {
    min-height: 44px;
    padding: 10px 18px;
    font-size: 13px;
}

button.btn {
    cursor: pointer;
}

.btn:focus-visible,
.reveal-btn:focus-visible {
    outline: 2px solid var(--purple-light);
    outline-offset: 3px;
}


/* =========================================
   LAYOUT
========================================= */

.config-section {
    padding: 34px 0 110px;
}

.config-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start;
    gap: 34px;
}

.config-form {
    display: flex;
    flex-direction: column;
    gap: 22px;
}


/* =========================================
   CARDS
========================================= */

.config-card {
    padding: 30px;

    border: 1px solid var(--border);
    border-radius: var(--radius);

    background: rgba(19, 27, 48, 0.65);
}

.card-head {
    display: flex;
    align-items: flex-start;
    gap: 16px;

    margin-bottom: 26px;
}

.card-head h2 {
    font-family: var(--font-heading);
    font-size: 21px;
    letter-spacing: -0.5px;
}

.card-head p {
    margin-top: 3px;

    color: var(--text-muted);
    font-size: 13px;
}

.step-badge {
    display: grid;
    place-items: center;

    width: 39px;
    height: 39px;
    flex-shrink: 0;

    border: 1px solid rgba(139, 124, 255, 0.25);
    border-radius: 12px;

    background: rgba(139, 124, 255, 0.08);
    color: var(--purple-light);

    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
}


/* =========================================
   FIELDS
========================================= */

.field {
    margin-bottom: 20px;
}

.field:last-child {
    margin-bottom: 0;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

@media (max-width: 560px) {
    .field-row {
        grid-template-columns: 1fr;
    }
}

.field label {
    display: block;
    margin-bottom: 8px;

    color: #d7ddef;
    font-size: 13px;
    font-weight: 600;
}

.field label em {
    color: var(--purple-light);
    font-style: normal;
}

.field label small {
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 500;
}

.field input,
.field select,
.header-row input {
    width: 100%;
    min-height: 50px;
    padding: 13px 16px;

    border: 1px solid var(--border);
    border-radius: 12px;

    background: rgba(255, 255, 255, 0.035);
    color: var(--text);

    font: inherit;
    font-size: 14px;

    transition:
        border-color var(--transition),
        background var(--transition),
        box-shadow var(--transition);
}

.field input::placeholder,
.header-row input::placeholder {
    color: var(--text-soft);
}

.field input:hover,
.field select:hover,
.header-row input:hover {
    border-color: rgba(139, 124, 255, 0.3);
}

.field input:focus,
.field select:focus,
.header-row input:focus {
    outline: none;

    border-color: var(--purple-light);
    background: rgba(139, 124, 255, 0.06);
    box-shadow: 0 0 0 4px rgba(139, 124, 255, 0.14);
}

.field select {
    padding-right: 44px;

    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;

    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9' fill='none'><path d='M1 1.5l6 6 6-6' stroke='%23b3a9ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 17px center;
}

.field select option {
    background: var(--surface);
    color: var(--text);
}

.field.has-error input,
.field.has-error select,
.header-row.has-error input {
    border-color: var(--danger);
    background: var(--danger-bg);
}

.field.has-error input:focus,
.header-row.has-error input:focus {
    box-shadow: 0 0 0 4px rgba(255, 110, 130, 0.16);
}

.field-hint {
    margin-top: 8px;

    color: var(--text-soft);
    font-size: 12px;
}

.field-error {
    margin-top: 8px;

    color: var(--danger);
    font-size: 12.5px;
    font-weight: 600;
}

.field-error:empty {
    display: none;
}

.input-group {
    position: relative;
}

.input-group input {
    padding-right: 78px;
}

.reveal-btn {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);

    padding: 8px 12px;

    border: 0;
    border-radius: 8px;

    background: rgba(139, 124, 255, 0.12);
    color: var(--purple-light);

    font-size: 12px;
    font-weight: 700;

    cursor: pointer;
    transition: background var(--transition);
}

.reveal-btn:hover {
    background: rgba(139, 124, 255, 0.24);
}


/* =========================================
   AUTHENTICATION PANELS
========================================= */

.auth-panel {
    margin-top: 6px;
    padding-top: 22px;

    border-top: 1px dashed rgba(139, 124, 255, 0.22);

    animation: panelIn 0.3s ease;
}

.auth-note {
    color: var(--text-soft);
    font-size: 13px;
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* =========================================
   CUSTOM HEADER ROWS
========================================= */

.header-rows {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header-rows:not(:empty) {
    margin-bottom: 16px;
}

.header-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 46px;
    align-items: start;
    gap: 10px;

    animation: panelIn 0.25s ease;
}

.header-row .row-error {
    grid-column: 1 / -1;

    color: var(--danger);
    font-size: 12.5px;
    font-weight: 600;
}

.header-row .row-error:empty {
    display: none;
}

.remove-row {
    display: grid;
    place-items: center;

    width: 46px;
    height: 50px;

    border: 1px solid var(--border);
    border-radius: 12px;

    background: rgba(255, 255, 255, 0.035);
    color: var(--text-muted);

    font-size: 20px;
    line-height: 1;

    cursor: pointer;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.remove-row:hover {
    border-color: var(--danger);
    background: var(--danger-bg);
    color: var(--danger);
}


/* =========================================
   SUBMIT AREA
========================================= */

.form-submit {
    display: flex;
    flex-wrap: wrap;
    gap: 13px;

    margin-top: 6px;
}

.form-submit .btn-primary {
    flex: 1 1 280px;
}

.form-submit .btn-secondary {
    flex: 0 0 auto;
}


/* =========================================
   PREVIEW COLUMN
========================================= */

.preview-col {
    position: sticky;
    top: calc(var(--header-h) + 96px);

    display: flex;
    flex-direction: column;
    gap: 18px;
}

.preview-card {
    padding: 24px;

    border: 1px solid rgba(139, 124, 255, 0.22);
    border-radius: var(--radius);

    background:
        radial-gradient(
            ellipse at 100% 0%,
            rgba(97, 232, 213, 0.06),
            transparent 55%
        ),
        linear-gradient(
            145deg,
            #19213a,
            #111830
        );

    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.28);
}

.preview-head {
    display: flex;
    align-items: center;
    gap: 14px;

    margin-bottom: 22px;
}

.preview-avatar {
    display: grid;
    place-items: center;

    width: 58px;
    height: 58px;
    flex-shrink: 0;

    border-radius: 16px;

    background: linear-gradient(135deg, var(--purple), #5bc7d6);
    box-shadow: 0 6px 24px rgba(139, 124, 255, 0.4);

    color: white;
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
}

.preview-titles {
    display: flex;
    flex-direction: column;
    gap: 2px;

    min-width: 0;
}

.preview-titles strong {
    overflow: hidden;

    font-family: var(--font-heading);
    font-size: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-titles span {
    overflow: hidden;

    color: var(--text-muted);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qr-frame {
    position: relative;

    display: grid;
    place-items: center;

    aspect-ratio: 1;
    padding: 14px;

    border-radius: 18px;
    background: white;
}

.qr-frame #qrImage {
    width: 100%;
    height: 100%;

    image-rendering: pixelated;
    object-fit: contain;
}

.qr-placeholder {
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 12px;

    padding: 20px;

    color: #8e98b3;
    font-size: 13px;
    text-align: center;
}

.qr-placeholder svg {
    width: 64px;
    color: #b9c0d6;
}

.qr-stale {
    position: absolute;
    inset: 0;

    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    gap: 4px;

    border-radius: 18px;

    background: rgba(11, 16, 32, 0.84);

    text-align: center;
}

.qr-stale span {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 600;
}

.qr-stale small {
    color: var(--text-muted);
    font-size: 12px;
}

.json-details {
    margin-top: 18px;

    border: 1px solid var(--border);
    border-radius: 12px;

    background: rgba(0, 0, 0, 0.16);
}

.json-details summary {
    padding: 12px 15px;

    color: var(--purple-light);
    font-size: 12.5px;
    font-weight: 600;

    cursor: pointer;
}

.json-details pre {
    max-height: 260px;
    overflow: auto;

    padding: 0 15px 15px;

    color: #c4ccdf;
    font-size: 11.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
}

.notice {
    display: flex;
    align-items: flex-start;
    gap: 13px;

    padding: 18px;

    border: 1px solid rgba(255, 208, 121, 0.22);
    border-radius: 16px;

    background: rgba(255, 208, 121, 0.05);

    color: var(--text-muted);
    font-size: 12.5px;
    line-height: 1.7;
}

.notice strong {
    color: var(--text);
}

.notice-icon {
    display: grid;
    place-items: center;

    width: 24px;
    height: 24px;
    flex-shrink: 0;

    border-radius: 50%;

    background: rgba(255, 208, 121, 0.16);
    color: var(--warning);

    font-size: 13px;
    font-weight: 800;
}


/* =========================================
   RESPONSIVE
========================================= */

@media (max-width: 1000px) {

    .config-grid {
        grid-template-columns: 1fr;
    }

    .preview-col {
        position: static;
    }

    .preview-card {
        max-width: 460px;
    }

}

@media (max-width: 480px) {

    .action-bar {
        width: calc(100% - 36px);
    }

}

@media (max-width: 800px) {

    .page-top {
        padding-top: 118px;
    }

    .action-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;

        padding: 12px;
    }

    .action-status {
        font-size: 12px;
    }

    .action-buttons .btn {
        flex: 1;
        padding-inline: 10px;
        font-size: 12px;
        white-space: normal;
        text-align: center;
    }

}

@media (max-width: 560px) {

    .config-card {
        padding: 22px 18px;
        border-radius: 20px;
    }

    .header-row {
        grid-template-columns: 1fr 46px;
    }

    .header-row input:nth-of-type(2) {
        grid-column: 1;
    }

    .action-buttons {
        flex-direction: column;
    }

    .form-submit .btn {
        width: 100%;
    }

}
