/**
 * GCC Typography — Mobile Modal  v2.3.0
 *
 * Bỏ FAB. Chọn vùng → modal hiện luôn.
 *
 * v2.3.0 — Migrated to GCC Design Tokens system.
 *   • Tất cả màu sắc → var(--gcc-*) tokens.
 *   • Phụ thuộc gcc-tokens.css load TRƯỚC (qua wp_enqueue dependency).
 *   • Đổi tone toàn site = sửa gcc-tokens.css, không động đến file này.
 */

/* ============================================================================
   MOBILE ≤900px — ẨN toolbar core + preset wrap, hiện modal riêng
   ============================================================================ */
@media (max-width: 900px) {
    /* Ẩn toolbar desktop — modal mobile thay thế hoàn toàn.
       Dùng display:none thay -9999px để tránh inline style từ positionToolbar() thắng.
       MutationObserver vẫn bắt class change khi display:none. */
    .gcc-typo-toolbar,
    .gcc-typo-toolbar.gcc-tb-visible {
        display: none !important;
        pointer-events: none !important;
    }

    /* Preset đã có trong modal → ẩn nút "Bộ cài sẵn" ngoài panel trên mobile */
    .gcc-typo-preset-wrap {
        display: none !important;
    }
    .gcct-mob-overlay { display: flex; }

    /* Preset menu trên mobile: 1 row, các nút co dãn đều */
    .gcc-typo-preset-wrap {
        padding: 0 12px;
    }
    .gcc-typo-preset-wrap .gcc-typo-preset-menu {
        flex-wrap: nowrap !important;
        flex-direction: row !important;
        width: 100% !important;
        max-width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        transform: none !important;
        gap: 5px !important;
        padding: 7px 10px !important;
        box-sizing: border-box !important;
    }
    .gcc-typo-preset-wrap .gcc-typo-preset-menu .gcc-typo-pm-btn {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        padding: 0 6px !important;
        font-size: 11px !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
}
@media (min-width: 901px) {
    .gcct-mob-overlay { display: none !important; }
}

/* ============================================================================
   OVERLAY — backdrop
   ============================================================================ */
.gcct-mob-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.45);
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.gcct-mob-overlay[hidden] { display: none !important; }
.gcct-mob-overlay.gcct-mob-overlay-show {
    opacity: 1;
    pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
    .gcct-mob-overlay { transition: none; }
}

/* ============================================================================
   MODAL
   ============================================================================ */
.gcct-mob-modal {
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    background: var(--gcc-surface);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.28), 0 4px 12px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    transform: translateY(16px) scale(0.96);
    transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    color: var(--gcc-ink);
    -webkit-font-smoothing: antialiased;
}
.gcct-mob-overlay.gcct-mob-overlay-show .gcct-mob-modal {
    transform: translateY(0) scale(1);
}
@media (prefers-reduced-motion: reduce) {
    .gcct-mob-modal { transition: none; }
}

/* Header */
.gcct-mob-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--gcc-line-faint);
    background: var(--gcc-surface);
}
.gcct-mob-head-icon {
    flex: 0 0 auto;
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
}
.gcct-mob-head-icon svg { width: 20px; height: 20px; fill: var(--gcc-ink); }
.gcct-mob-title {
    flex: 1 1 auto;
    font-size: 15px; font-weight: 600; color: var(--gcc-ink);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gcct-mob-close {
    flex: 0 0 auto;
    width: 32px; height: 32px;
    border-radius: 8px; border: none; background: transparent;
    color: var(--gcc-ink-muted); font-size: 18px; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s;
}
.gcct-mob-close:hover  { background: var(--gcc-surface-2); }
.gcct-mob-close:active { background: var(--gcc-line-light); }

/* Body */
.gcct-mob-body {
    flex: 1 1 auto;
    overflow-y: auto; overflow-x: hidden;
    padding: 4px 16px 12px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Section */
.gcct-mob-sec {
    padding: 14px 0;
    border-bottom: 1px solid var(--gcc-line-faint);
}
.gcct-mob-sec:last-child { border-bottom: none; }

.gcct-mob-sec-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 500; color: var(--gcc-ink);
    margin-bottom: 10px;
}
.gcct-mob-sec-label-icon { color: var(--gcc-ink-muted); font-size: 14px; line-height: 1; }

/* Slider section header */
.gcct-mob-sec-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; margin-bottom: 10px;
}
.gcct-mob-sec-header .gcct-mob-sec-label { margin-bottom: 0; }
.gcct-mob-sec-value {
    flex: 0 0 auto;
    font-size: 13px; color: var(--gcc-ink-muted);
    font-variant-numeric: tabular-nums; font-weight: 500;
    min-width: 44px; text-align: right;
}

/* Presets 2×2 grid */
.gcct-mob-presets {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.gcct-mob-preset-btn {
    height: 42px; padding: 0 14px;
    font-size: 14px; font-weight: 500; line-height: 1;
    background: var(--gcc-surface); color: var(--gcc-ink);
    border: 1px solid var(--gcc-line); border-radius: 10px;
    cursor: pointer; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.gcct-mob-preset-btn:active { background: var(--gcc-surface-2); }
.gcct-mob-preset-btn.is-active {
    background: var(--gcc-ink); color: var(--gcc-surface);
    border-color: var(--gcc-ink); font-weight: 600;
}

/* Font select */
.gcct-mob-font-select {
    width: 100%; height: 44px; padding: 0 14px;
    font-size: 14px; color: var(--gcc-ink); background: var(--gcc-surface);
    border: 1px solid var(--gcc-line); border-radius: 10px;
    box-sizing: border-box;
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23525252' stroke-width='1.6'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px 8px;
    padding-right: 36px; cursor: pointer;
}
.gcct-mob-font-select:focus { outline: none; border-color: var(--gcc-ink); }

/* Range slider */
.gcct-mob-range {
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    width: 100%; height: 4px; border-radius: 2px;
    outline: none; margin: 6px 0; cursor: pointer;
    background: linear-gradient(
        to right,
        var(--gcc-ink) 0%,
        var(--gcc-ink) calc(var(--gcct-p, 0) * 100%),
        var(--gcc-line-light) calc(var(--gcct-p, 0) * 100%),
        var(--gcc-line-light) 100%
    );
}
.gcct-mob-range::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--gcc-ink); border: 2px solid var(--gcc-surface);
    box-shadow: 0 1px 4px rgba(0,0,0,0.22); cursor: pointer;
}
.gcct-mob-range::-moz-range-thumb {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--gcc-ink); border: 2px solid var(--gcc-surface);
    box-shadow: 0 1px 4px rgba(0,0,0,0.22); cursor: pointer;
}
.gcct-mob-range::-moz-range-track { height: 4px; background: transparent; }

/* Style toggles — 5 nút equal */
.gcct-mob-toggles {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}
.gcct-mob-toggle {
    height: 48px;
    border: 1px solid var(--gcc-line); border-radius: 10px;
    background: var(--gcc-surface); color: var(--gcc-ink);
    cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    padding: 0; font-size: 16px; font-weight: 500;
}
.gcct-mob-toggle:active { background: var(--gcc-surface-2); }
.gcct-mob-toggle.is-active {
    background: var(--gcc-ink); color: var(--gcc-surface); border-color: var(--gcc-ink);
}
.gcct-mob-toggle svg { width: 18px; height: 18px; fill: currentColor; pointer-events: none; }
.gcct-mob-toggle-italic { font-style: italic; font-family: Georgia, "Times New Roman", serif; }
.gcct-mob-toggle-bold   { font-weight: 700; }

/* Color */
.gcct-mob-color-row { display: flex; gap: 10px; align-items: center; }
.gcct-mob-color-swatch {
    flex: 0 0 auto;
    width: 48px; height: 44px;
    border: 1px solid var(--gcc-line); border-radius: 10px;
    overflow: hidden; position: relative; cursor: pointer;
}
.gcct-mob-color-swatch input[type="color"] {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    border: none; padding: 0; background: transparent; cursor: pointer;
}
.gcct-mob-color-reset-btn {
    flex: 1 1 auto; height: 44px; padding: 0 14px;
    font-size: 13px; color: var(--gcc-ink-muted); background: var(--gcc-surface);
    border: 1px solid var(--gcc-line); border-radius: 10px;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: background 0.12s, border-color 0.12s;
}
.gcct-mob-color-reset-btn:active { background: var(--gcc-surface-2); border-color: var(--gcc-line-strong-hover); }

/* Footer */
.gcct-mob-foot {
    flex: 0 0 auto;
    display: flex; gap: 10px; align-items: center;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--gcc-line-faint); background: var(--gcc-surface);
}
.gcct-mob-reset {
    flex: 0 0 auto; height: 46px; padding: 0 16px;
    border-radius: 12px; font-size: 13px; font-weight: 500;
    cursor: pointer; background: var(--gcc-surface); color: var(--gcc-ink);
    border: 1px solid var(--gcc-line);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s, border-color 0.12s;
}
.gcct-mob-reset:active { background: var(--gcc-surface-2); border-color: var(--gcc-ink); }
.gcct-mob-foot-spacer {
    flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
    color: var(--gcc-line);
}
.gcct-mob-foot-spacer svg { width: 18px; height: 18px; fill: currentColor; }
.gcct-mob-done {
    flex: 1 1 auto; height: 46px;
    border-radius: 12px; font-size: 14px; font-weight: 600;
    cursor: pointer; background: var(--gcc-ink); color: var(--gcc-surface);
    border: 1px solid var(--gcc-ink);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s; padding: 0 16px;
}
.gcct-mob-done:active { background: var(--gcc-ink-strong-hover); }