/* ============================================================
   kdp-cover.css  — KDP Cover Generator Modal
   Prefix: kcm-*  (không conflict với bpp-*, aireq-*, gen-*)
   Load trong App.razor: <link rel="stylesheet" href="css/kdp-cover.css" />
   ============================================================ */

/* ══════════════════════════════════════════════════════════
   OVERLAY + PANEL
══════════════════════════════════════════════════════════ */

.kcm-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.kcm-panel {
    position: relative;
    background: var(--color-background-primary, #ffffff);
    border-radius: 14px;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    width: min(1100px, 98vw);
    height: min(820px, 94vh);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
    overflow: hidden;
}

/* ══════════════════════════════════════════════════════════
   HEADER
══════════════════════════════════════════════════════════ */

.kcm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--color-border-primary, #e5e7eb);
    background: var(--color-background-secondary, #f9fafb);
    flex-shrink: 0;
}

.kcm-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

    .kcm-header-left > i {
        font-size: 22px;
        color: #639922;
    }

.kcm-header-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text-primary, #111827);
    line-height: 1.2;
}

.kcm-header-sub {
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
    margin-top: 1px;
}

.kcm-close {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    background: transparent;
    color: var(--color-text-secondary, #6b7280);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: background .12s;
}

    .kcm-close:hover:not(:disabled) {
        background: var(--color-background-tertiary, #f3f4f6);
    }

/* ══════════════════════════════════════════════════════════
   BODY — 2-panel grid
══════════════════════════════════════════════════════════ */

.kcm-body {
    display: grid;
    grid-template-columns: 320px 1fr;
    flex: 1;
    overflow: hidden;
}

/* ══════════════════════════════════════════════════════════
   LEFT PANEL
══════════════════════════════════════════════════════════ */

.kcm-left {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--color-border-primary, #e5e7eb);
    overflow: hidden;
}

/* ── Tabs ── */
.kcm-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border-primary, #e5e7eb);
    background: var(--color-background-secondary, #f9fafb);
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

    .kcm-tabs::-webkit-scrollbar {
        display: none;
    }

.kcm-tab {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 11px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary, #6b7280);
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color .12s, border-color .12s;
}

    .kcm-tab i {
        font-size: 13px;
    }

    .kcm-tab:hover {
        color: var(--color-text-primary, #111827);
    }

    .kcm-tab.active {
        color: #639922;
        border-bottom-color: #639922;
        background: var(--color-background-primary, #fff);
    }

/* ── Section content ── */
.kcm-section {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

    .kcm-section::-webkit-scrollbar {
        width: 4px;
    }

    .kcm-section::-webkit-scrollbar-thumb {
        background: var(--color-border-secondary, #d1d5db);
        border-radius: 2px;
    }

/* ── Form controls ── */
.kcm-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.kcm-label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--color-text-secondary, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.kcm-opt {
    font-size: 10px;
    font-weight: 400;
    color: var(--color-text-tertiary, #9ca3af);
    text-transform: none;
    letter-spacing: 0;
    margin-left: 4px;
}

.kcm-hint {
    font-size: 10px;
    color: var(--color-text-tertiary, #9ca3af);
    font-weight: 400;
    text-transform: none;
    margin-left: 4px;
}

.kcm-input,
.kcm-select,
.kcm-textarea {
    padding: 7px 10px;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-md, 6px);
    font-size: 13px;
    color: var(--color-text-primary, #111827);
    background: var(--color-background-primary, #fff);
    width: 100%;
    box-sizing: border-box;
    transition: border-color .15s;
    font-family: inherit;
}

    .kcm-input:focus,
    .kcm-select:focus,
    .kcm-textarea:focus {
        outline: none;
        border-color: #639922;
        box-shadow: 0 0 0 2px rgba(99, 153, 34, 0.15);
    }

.kcm-textarea {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}

/* ── Radio row ── */
.kcm-radio-row {
    display: flex;
    gap: 6px;
}

.kcm-radio {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-md, 6px);
    cursor: pointer;
    font-size: 12px;
    color: var(--color-text-secondary, #6b7280);
    background: var(--color-background-primary, #fff);
    flex: 1;
    transition: border-color .12s, background .12s;
}

    .kcm-radio input[type="radio"] {
        display: none;
    }

    .kcm-radio.on {
        border-color: #639922;
        background: #f3f9ea;
        color: #3B6D11;
        font-weight: 500;
    }

/* ── Segmented control ── */
.kcm-seg {
    display: flex;
    gap: 4px;
    background: var(--color-background-secondary, #f3f4f6);
    border-radius: var(--border-radius-md, 6px);
    padding: 3px;
}

.kcm-seg-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 6px 10px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--color-text-secondary, #6b7280);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background .12s, color .12s;
    white-space: nowrap;
}

    .kcm-seg-btn i {
        font-size: 13px;
    }

    .kcm-seg-btn.on {
        background: var(--color-background-primary, #fff);
        color: #639922;
        box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    }

/* ── Spine card ── */
.kcm-spine-card {
    padding: 10px 12px;
    border-radius: var(--border-radius-md, 6px);
    border: 1px solid;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
}

    .kcm-spine-card.ok {
        background: var(--color-background-success, #f0fdf4);
        border-color: #bbf7d0;
    }

    .kcm-spine-card.warn {
        background: var(--color-background-warning, #fffbeb);
        border-color: #fde68a;
    }

.kcm-spine-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kcm-spine-label {
    color: var(--color-text-secondary, #6b7280);
}

.kcm-spine-val {
    font-weight: 600;
    color: var(--color-text-primary, #111827);
}

    .kcm-spine-val.green {
        color: #166534;
    }

    .kcm-spine-val.amber {
        color: #92400e;
    }

/* ── Image grid ── */
.kcm-img-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.kcm-img-card {
    position: relative;
    border: 2px solid var(--color-border-primary, #e5e7eb);
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    aspect-ratio: 1;
    background: var(--color-background-secondary);
    padding: 0;
    transition: border-color .12s;
}

    .kcm-img-card:hover {
        border-color: #a3c56a;
    }

    .kcm-img-card.on {
        border-color: #639922;
        border-width: 2.5px;
    }

    .kcm-img-card img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }

.kcm-img-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 9px;
    padding: 2px 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kcm-img-check {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #639922;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}

.kcm-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 24px;
    color: var(--color-text-tertiary, #9ca3af);
    font-size: 12px;
}

    .kcm-empty i {
        font-size: 28px;
    }

/* ── Pager ── */
.kcm-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 4px;
}

.kcm-pager-btn {
    width: 26px;
    height: 26px;
    border-radius: 5px;
    border: 1px solid var(--color-border-primary);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: background .12s;
}

    .kcm-pager-btn:hover:not(:disabled) {
        background: var(--color-background-secondary);
    }

    .kcm-pager-btn:disabled {
        opacity: .4;
        cursor: not-allowed;
    }

/* ── Hint block ── */
.kcm-hint-block {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
    background: var(--color-background-secondary, #f3f4f6);
    border-radius: var(--border-radius-md, 6px);
    padding: 8px 10px;
    line-height: 1.5;
}

    .kcm-hint-block i {
        font-size: 13px;
        flex-shrink: 0;
        margin-top: 1px;
    }

/* ── Preset grid ── */
.kcm-preset-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 4px;
}

.kcm-preset-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 6px;
    border: 1.5px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-lg, 10px);
    background: var(--color-background-primary, #fff);
    cursor: pointer;
    font-size: 11.5px;
    font-weight: 500;
    color: var(--color-text-secondary, #6b7280);
    transition: border-color .12s, background .12s;
}

    .kcm-preset-card:hover {
        border-color: #a3c56a;
    }

    .kcm-preset-card.on {
        border-color: #639922;
        color: #3B6D11;
        background: #f3f9ea;
    }

/* Preset swatches */
.kcm-preset-swatch {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.08);
}

    .kcm-preset-swatch.elegant {
        background: linear-gradient(135deg, #1A1A2E 50%, #FDF6EC 50%);
    }

    .kcm-preset-swatch.modern {
        background: linear-gradient(135deg, #111111 50%, #f0f0f0 50%);
    }

    .kcm-preset-swatch.playful {
        background: linear-gradient(135deg, #FF6B35 50%, #FFF3E0 50%);
    }

/* ── Divider ── */
.kcm-divider {
    height: 1px;
    background: var(--color-border-primary, #e5e7eb);
    margin: 2px 0;
}

/* ── Color grid ── */
.kcm-color-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.kcm-color-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kcm-color-label {
    font-size: 10.5px;
    color: var(--color-text-secondary, #6b7280);
    font-weight: 500;
}

.kcm-color-input {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-md, 6px);
    padding: 4px 8px;
    background: var(--color-background-primary, #fff);
}

    .kcm-color-input input[type="color"] {
        width: 26px;
        height: 26px;
        border: none;
        padding: 0;
        border-radius: 4px;
        cursor: pointer;
        flex-shrink: 0;
    }

    .kcm-color-input span {
        font-size: 11px;
        color: var(--color-text-secondary, #6b7280);
        font-family: monospace;
    }

/* ── Info card (back cover) ── */
.kcm-info-card {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    background: var(--color-background-info, #eff6ff);
    border-radius: var(--border-radius-md, 6px);
    border: 1px solid #bfdbfe;
    font-size: 12px;
}

    .kcm-info-card > i {
        font-size: 18px;
        color: #1e40af;
        flex-shrink: 0;
        margin-top: 1px;
    }

    .kcm-info-card strong {
        display: block;
        color: var(--color-text-info, #1e40af);
        font-size: 12px;
        font-weight: 600;
        margin-bottom: 2px;
    }

    .kcm-info-card p {
        margin: 0;
        color: var(--color-text-secondary, #6b7280);
        line-height: 1.5;
    }

/* ── Feedback boxes ── */
.kcm-warn-box {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    padding: 9px 11px;
    background: var(--color-background-warning, #fffbeb);
    border: 1px solid #fde68a;
    border-radius: var(--border-radius-md, 6px);
    font-size: 11.5px;
    color: var(--color-text-warning, #92400e);
}

    .kcm-warn-box > i {
        flex-shrink: 0;
        margin-top: 1px;
    }

    .kcm-warn-box ul {
        margin: 4px 0 0 14px;
        padding: 0;
        line-height: 1.6;
    }

.kcm-err-box {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    padding: 9px 11px;
    background: var(--color-background-danger, #fef2f2);
    border: 1px solid #fca5a5;
    border-radius: var(--border-radius-md, 6px);
    font-size: 11.5px;
    color: var(--color-text-danger, #991b1b);
}

    .kcm-err-box > i {
        flex-shrink: 0;
        margin-top: 1px;
    }

/* ── Progress ── */
.kcm-progress-wrap {
    height: 4px;
    background: var(--color-border-primary, #e5e7eb);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.kcm-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #639922, #8bc34a);
    border-radius: 2px;
    transition: width .3s ease;
}

.kcm-progress-msg {
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
    text-align: center;
    margin-top: 3px;
}

/* ── Success ── */
.kcm-success-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--color-background-success, #f0fdf4);
    border: 1px solid #bbf7d0;
    border-radius: var(--border-radius-md, 6px);
}

    .kcm-success-box > i {
        font-size: 22px;
        color: #16a34a;
        flex-shrink: 0;
    }

    .kcm-success-box strong {
        font-size: 12.5px;
        color: var(--color-text-success, #166534);
        font-weight: 600;
    }

.kcm-success-meta {
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
    margin-top: 1px;
}

.kcm-dl-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: #16a34a;
    color: #fff;
    border-radius: var(--border-radius-md, 6px);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    margin-left: auto;
    flex-shrink: 0;
}

    .kcm-dl-btn:hover {
        background: #15803d;
    }

/* ── Spinner ── */
.kcm-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: kcm-spin .7s linear infinite;
    display: inline-block;
}

@keyframes kcm-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ══════════════════════════════════════════════════════════
   RIGHT PANEL — Preview
══════════════════════════════════════════════════════════ */

.kcm-right {
    display: flex;
    flex-direction: column;
    background: var(--color-background-tertiary, #f3f4f6);
    overflow: hidden;
    padding: 14px;
    gap: 10px;
}

.kcm-preview-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-shrink: 0;
}

.kcm-preview-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-primary, #111827);
}

.kcm-preview-sub {
    font-size: 10.5px;
    color: var(--color-text-tertiary, #9ca3af);
}

.kcm-canvas-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #e8e8e8;
    background-image: linear-gradient(45deg, #d0d0d0 25%, transparent 25%), linear-gradient(-45deg, #d0d0d0 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #d0d0d0 75%), linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

.kcm-canvas {
    display: block;
    max-width: calc(100% - 24px);
    max-height: calc(100% - 24px);
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
}

.kcm-dims-bar {
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
    text-align: center;
    flex-shrink: 0;
    font-family: monospace;
    padding: 4px 8px;
    background: var(--color-background-secondary, #f9fafb);
    border-radius: var(--border-radius-md, 6px);
    border: 1px solid var(--color-border-primary, #e5e7eb);
}

.kcm-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-shrink: 0;
}

.kcm-legend-item {
    font-size: 10.5px;
    color: var(--color-text-tertiary, #9ca3af);
    display: flex;
    align-items: center;
    gap: 4px;
}

    .kcm-legend-item::before {
        content: '';
        display: inline-block;
        width: 16px;
        height: 3px;
        border-radius: 1px;
    }

    .kcm-legend-item.bleed::before {
        background: rgba(255,100,100,0.6);
    }

    .kcm-legend-item.safe::before {
        background: rgba(99,153,34,0.5);
        border: 1px dashed #639922;
    }

    .kcm-legend-item.barcode::before {
        background: #fff;
        border: 1px solid #ccc;
    }

/* ══════════════════════════════════════════════════════════
   FOOTER
══════════════════════════════════════════════════════════ */

.kcm-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--color-border-primary, #e5e7eb);
    background: var(--color-background-secondary, #f9fafb);
    flex-shrink: 0;
    gap: 10px;
}

.kcm-footer-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.kcm-footer-info {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--color-text-secondary, #6b7280);
}

    .kcm-footer-info i {
        font-size: 13px;
    }

.kcm-warn-text {
    color: var(--color-text-warning, #92400e);
}

.kcm-footer-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ══════════════════════════════════════════════════════════
   DARK MODE
══════════════════════════════════════════════════════════ */

html[data-theme="dark"] .kcm-panel,
.adm-dark .kcm-panel {
    background: var(--color-background-primary);
    border-color: var(--color-border-primary);
}

html[data-theme="dark"] .kcm-header,
.adm-dark .kcm-header,
html[data-theme="dark"] .kcm-tabs,
.adm-dark .kcm-tabs,
html[data-theme="dark"] .kcm-footer,
.adm-dark .kcm-footer {
    background: var(--color-background-secondary);
    border-color: var(--color-border-primary);
}

html[data-theme="dark"] .kcm-tab.active,
.adm-dark .kcm-tab.active {
    background: var(--color-background-primary);
}

html[data-theme="dark"] .kcm-input,
html[data-theme="dark"] .kcm-select,
html[data-theme="dark"] .kcm-textarea,
.adm-dark .kcm-input,
.adm-dark .kcm-select,
.adm-dark .kcm-textarea {
    background: var(--color-background-secondary);
    border-color: var(--color-border-primary);
    color: var(--color-text-primary);
}

html[data-theme="dark"] .kcm-right,
.adm-dark .kcm-right {
    background: var(--color-background-tertiary);
}

html[data-theme="dark"] .kcm-canvas-wrap,
.adm-dark .kcm-canvas-wrap {
    background: #1a1a2e;
    background-image: linear-gradient(45deg, #222236 25%, transparent 25%), linear-gradient(-45deg, #222236 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #222236 75%), linear-gradient(-45deg, transparent 75%, #222236 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

html[data-theme="dark"] .kcm-radio,
.adm-dark .kcm-radio {
    background: var(--color-background-secondary);
    border-color: var(--color-border-primary);
    color: var(--color-text-secondary);
}

    html[data-theme="dark"] .kcm-radio.on,
    .adm-dark .kcm-radio.on {
        background: rgba(99,153,34,.15);
        border-color: #4d7a1a;
        color: #a3c56a;
    }

html[data-theme="dark"] .kcm-preset-card,
.adm-dark .kcm-preset-card {
    background: var(--color-background-secondary);
    border-color: var(--color-border-primary);
}

    html[data-theme="dark"] .kcm-preset-card.on,
    .adm-dark .kcm-preset-card.on {
        background: rgba(99,153,34,.12);
        border-color: #639922;
        color: #a3c56a;
    }

html[data-theme="dark"] .kcm-color-input,
.adm-dark .kcm-color-input {
    background: var(--color-background-secondary);
    border-color: var(--color-border-primary);
}

html[data-theme="dark"] .kcm-seg,
.adm-dark .kcm-seg {
    background: var(--color-background-tertiary);
}

html[data-theme="dark"] .kcm-seg-btn.on,
.adm-dark .kcm-seg-btn.on {
    background: var(--color-background-secondary);
}

html[data-theme="dark"] .kcm-spine-card.ok,
.adm-dark .kcm-spine-card.ok {
    background: var(--color-background-success);
    border-color: #166534;
}

html[data-theme="dark"] .kcm-spine-card.warn,
.adm-dark .kcm-spine-card.warn {
    background: var(--color-background-warning);
    border-color: #92400e;
}

html[data-theme="dark"] .kcm-info-card,
.adm-dark .kcm-info-card {
    background: var(--color-background-info);
    border-color: #1e3a8a;
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — collapse to single panel on narrow
══════════════════════════════════════════════════════════ */

@media (max-width: 720px) {
    .kcm-panel {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .kcm-body {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
    }

    .kcm-right {
        height: 220px;
        border-top: 1px solid var(--color-border-primary);
        border-right: none;
    }

    .kcm-left {
        border-right: none;
    }

    .kcm-img-grid {
        grid-template-columns: repeat(4, 1fr);
        max-height: 200px;
    }
}

/* ══════════════════════════════════════════════════════════
   HISTORY VIEW
══════════════════════════════════════════════════════════ */

.kcm-body-history {
    display: block; /* override grid khi ở history view */
    overflow-y: auto;
}

.kcm-history-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.kcm-history-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--color-border-primary, #e5e7eb);
    flex-shrink: 0;
}

.kcm-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-md, 6px);
    background: transparent;
    color: var(--color-text-secondary, #6b7280);
    font-size: 12px;
    cursor: pointer;
    transition: background .12s;
}

    .kcm-back-btn:hover {
        background: var(--color-background-secondary, #f3f4f6);
        color: var(--color-text-primary, #111827);
    }

    .kcm-back-btn i {
        font-size: 13px;
    }

.kcm-history-count {
    font-size: 12px;
    color: var(--color-text-secondary, #6b7280);
}

.kcm-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

    .kcm-history-list::-webkit-scrollbar {
        width: 4px;
    }

    .kcm-history-list::-webkit-scrollbar-thumb {
        background: var(--color-border-secondary, #d1d5db);
        border-radius: 2px;
    }

.kcm-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-lg, 10px);
    background: var(--color-background-primary, #fff);
    transition: border-color .12s;
}

    .kcm-history-item:hover {
        border-color: var(--color-border-secondary, #d1d5db);
    }

    .kcm-history-item.latest {
        border-color: #a3c56a;
        background: #f9fdf3;
    }

/* Thumbnail */
.kcm-history-thumb {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    gap: 3px;
    position: relative;
}

    .kcm-history-thumb > i {
        font-size: 22px;
        color: #16a34a;
    }

.kcm-latest-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    font-size: 9px;
    font-weight: 600;
    padding: 2px 5px;
    background: #639922;
    color: #fff;
    border-radius: 4px;
}

/* Info */
.kcm-history-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.kcm-history-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-primary, #111827);
    display: flex;
    align-items: center;
    gap: 6px;
}

.kcm-history-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
}

    .kcm-history-meta span {
        display: flex;
        align-items: center;
        gap: 3px;
    }

    .kcm-history-meta i {
        font-size: 11px;
    }

.kcm-history-date {
    font-size: 10.5px;
    color: var(--color-text-tertiary, #9ca3af);
    display: flex;
    align-items: center;
    gap: 3px;
}

.kcm-history-warn {
    font-size: 10.5px;
    color: var(--color-text-warning, #92400e);
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Actions */
.kcm-history-actions {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-shrink: 0;
}

/* ── Header history button ── */
.kcm-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.kcm-history-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-md, 6px);
    background: transparent;
    color: var(--color-text-secondary, #6b7280);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background .12s, border-color .12s;
}

    .kcm-history-btn:hover,
    .kcm-history-btn.active {
        background: #f3f9ea;
        border-color: #639922;
        color: #3B6D11;
    }

    .kcm-history-btn > span {
        min-width: 16px;
        height: 16px;
        background: #639922;
        color: #fff;
        border-radius: 8px;
        font-size: 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0 4px;
    }

/* ── Misc ── */
.kcm-empty-center {
    flex: 1;
    justify-content: center;
    align-items: center;
}

.kcm-char-count {
    font-size: 10.5px;
    color: var(--color-text-tertiary, #9ca3af);
    text-align: right;
    margin-top: -4px;
}

    .kcm-char-count.warn {
        color: var(--color-text-warning, #92400e);
    }

.kcm-muted {
    font-size: 10px;
    color: var(--color-text-tertiary, #9ca3af);
    font-weight: 400;
    text-transform: none;
    margin-left: 4px;
}

/* ── Success box multi-action ── */
.kcm-success-info {
    flex: 1;
}

.kcm-success-actions {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.kcm-dl-btn-outline {
    background: transparent !important;
    border: 1px solid #16a34a;
    color: #16a34a !important;
}

    .kcm-dl-btn-outline:hover {
        background: #f0fdf4 !important;
    }

.mx {
    margin-left: 14px;
    margin-right: 14px;
}

/* ── Canvas hover hint ── */
.kcm-canvas-wrap {
    position: relative;
    cursor: zoom-in;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.kcm-canvas-hint {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0,0,0,0.3);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    opacity: 0;
    transition: opacity .2s;
    pointer-events: none;
}

.kcm-canvas-wrap:hover .kcm-canvas-hint {
    opacity: 1;
}

/* ══════════════════════════════════════════════════════════
   LIGHTBOX (full-size preview)
══════════════════════════════════════════════════════════ */

.kcm-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1500;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.kcm-lightbox-inner {
    background: var(--color-background-primary, #fff);
    border-radius: 12px;
    overflow: hidden;
    width: 92vw;
    height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}

.kcm-lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border-primary, #e5e7eb);
    font-size: 12px;
    color: var(--color-text-secondary, #6b7280);
}

    .kcm-lightbox-header button {
        width: 28px;
        height: 28px;
        border: none;
        background: transparent;
        color: var(--color-text-secondary);
        cursor: pointer;
        border-radius: 6px;
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

        .kcm-lightbox-header button:hover {
            background: var(--color-background-secondary);
        }

.kcm-canvas-lg {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ══════════════════════════════════════════════════════════
   DARK MODE — History additions
══════════════════════════════════════════════════════════ */

html[data-theme="dark"] .kcm-history-item,
.adm-dark .kcm-history-item {
    background: var(--color-background-secondary);
    border-color: var(--color-border-primary);
}

    html[data-theme="dark"] .kcm-history-item.latest,
    .adm-dark .kcm-history-item.latest {
        background: rgba(99,153,34,.08);
        border-color: #4d7a1a;
    }

html[data-theme="dark"] .kcm-history-thumb,
.adm-dark .kcm-history-thumb {
    background: rgba(22,163,74,.1);
    border-color: #166534;
}

html[data-theme="dark"] .kcm-history-btn:hover,
html[data-theme="dark"] .kcm-history-btn.active,
.adm-dark .kcm-history-btn:hover,
.adm-dark .kcm-history-btn.active {
    background: rgba(99,153,34,.12);
    border-color: #639922;
    color: #a3c56a;
}

html[data-theme="dark"] .kcm-lightbox-inner,
.adm-dark .kcm-lightbox-inner {
    background: var(--color-background-primary);
}

/* ══════════════════════════════════════════════════════════
   PER-FIELD TEXT CONFIG
══════════════════════════════════════════════════════════ */

.kcm-text-field-group {
    border: 1px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-lg, 10px);
    overflow: hidden;
}

.kcm-text-field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--color-background-secondary, #f9fafb);
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid transparent;
    transition: background .12s;
}

    .kcm-text-field-header:hover {
        background: var(--color-background-tertiary, #f3f4f6);
    }

    .kcm-text-field-header.open {
        border-bottom-color: var(--color-border-primary, #e5e7eb);
    }

.kcm-text-field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-primary, #111827);
    display: flex;
    align-items: center;
    gap: 6px;
}

    .kcm-text-field-label i {
        font-size: 13px;
        color: #639922;
    }

.kcm-text-field-preview {
    font-size: 11px;
    color: var(--color-text-tertiary, #9ca3af);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kcm-text-field-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kcm-text-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

    .kcm-text-row .kcm-field {
        flex: 1;
        margin: 0;
    }

/* Font selector */
.kcm-font-select {
    font-size: 12px;
    padding: 5px 8px;
}

/* Size + margin inline */
.kcm-num-input {
    width: 64px;
    padding: 5px 6px;
    font-size: 12px;
    text-align: center;
    border: 1px solid var(--color-border-primary, #e5e7eb);
    border-radius: var(--border-radius-md, 6px);
    background: var(--color-background-primary);
    color: var(--color-text-primary);
}

/* ══════════════════════════════════════════════════════════
   GENERATED COVER IMAGES GRID (điểm 4 + 6)
══════════════════════════════════════════════════════════ */

.kcm-gen-covers {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kcm-gen-covers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
}

.kcm-gen-covers-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
}

    .kcm-gen-covers-grid::-webkit-scrollbar {
        width: 3px;
    }

    .kcm-gen-covers-grid::-webkit-scrollbar-thumb {
        background: var(--color-border-secondary);
        border-radius: 2px;
    }

.kcm-gen-cover-thumb {
    position: relative;
    aspect-ratio: 1;
    border: 2px solid var(--color-border-primary, #e5e7eb);
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    background: var(--color-background-secondary);
    padding: 0;
    transition: border-color .12s;
}

    .kcm-gen-cover-thumb:hover {
        border-color: #a3c56a;
    }

    .kcm-gen-cover-thumb.on {
        border-color: #639922;
        border-width: 2.5px;
    }

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

.kcm-gen-cover-check {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #639922;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}

.kcm-gen-cover-del {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .15s;
}

.kcm-gen-cover-thumb:hover .kcm-gen-cover-del {
    opacity: 1;
}

/* ── Divider with label ── */
.kcm-or-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--color-text-tertiary, #9ca3af);
    margin: 4px 0;
}

    .kcm-or-divider::before,
    .kcm-or-divider::after {
        content: '';
        flex: 1;
        height: 1px;
        background: var(--color-border-primary, #e5e7eb);
    }

/* ── Loading state for gen-covers ── */
.kcm-gen-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--color-text-secondary);
    padding: 8px;
}

/* Dark mode */
html[data-theme="dark"] .kcm-text-field-group,
.adm-dark .kcm-text-field-group {
    border-color: var(--color-border-primary);
}

html[data-theme="dark"] .kcm-text-field-header,
.adm-dark .kcm-text-field-header {
    background: var(--color-background-secondary);
}

html[data-theme="dark"] .kcm-num-input,
.adm-dark .kcm-num-input {
    background: var(--color-background-secondary);
    border-color: var(--color-border-primary);
    color: var(--color-text-primary);
}

/* ══════════════════════════════════════════════════════════
   BACK COVER THUMBNAIL UI
══════════════════════════════════════════════════════════ */

.kcm-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.kcm-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--color-background-secondary, #f3f4f6);
    color: var(--color-text-secondary, #6b7280);
    border: 1px solid var(--color-border-primary, #e5e7eb);
}

    .kcm-badge.full {
        background: #fef3c7;
        color: #92400e;
        border-color: #fde68a;
    }

/* img-card disabled state */
.kcm-img-card.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Order badge thay check */
.kcm-img-order {
    background: #639922;
    font-size: 12px;
    font-weight: 700;
}

/* Selected thumbs row */
.kcm-back-selected {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kcm-back-selected-grid {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.kcm-back-thumb {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 6px;
    overflow: visible;
    flex-shrink: 0;
}

    .kcm-back-thumb img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 6px;
        border: 2px solid #639922;
        display: block;
    }

.kcm-back-thumb-order {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #639922;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kcm-back-thumb-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

    .kcm-back-thumb-remove:hover {
        background: #dc2626;
    }

/* Dark mode */
html[data-theme="dark"] .kcm-badge,
.adm-dark .kcm-badge {
    background: var(--color-background-tertiary);
    border-color: var(--color-border-primary);
}

    html[data-theme="dark"] .kcm-badge.full,
    .adm-dark .kcm-badge.full {
        background: var(--color-background-warning);
        border-color: #92400e;
    }
