/* === 嵌入式 WYSIWYG Widget 樣式 === */

.wysiwyg-wrap {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

/* 工具列 */
.wysiwyg-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: #f3f4f6;
    border-bottom: 1px solid #d1d5db;
}

.wysiwyg-toolbar .wt-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.wysiwyg-toolbar .wt-sep {
    width: 1px;
    height: 22px;
    background: #d1d5db;
    margin: 0 5px;
}

.wysiwyg-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #374151;
    cursor: pointer;
    font-size: 0.82rem;
    transition: all .15s;
}

.wysiwyg-toolbar button:hover {
    background: #fff;
    border-color: #d1d5db;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.wysiwyg-toolbar button.active {
    background: #4f46e5;
    color: #fff;
    border-color: #4f46e5;
}

.wysiwyg-toolbar select {
    height: 30px;
    padding: 0 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    font-size: 0.8rem;
    color: #374151;
    cursor: pointer;
    outline: none;
}

.wysiwyg-toolbar select:hover {
    border-color: #9ca3af;
}

.wysiwyg-color-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.wysiwyg-color-toggle {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #374151;
    cursor: pointer;
    font-size: 0.82rem;
    padding: 2px;
    gap: 1px;
    transition: all .15s;
}

.wysiwyg-color-toggle:hover {
    background: #fff;
    border-color: #d1d5db;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.wysiwyg-color-bar {
    display: block;
    width: 16px;
    height: 3px;
    border-radius: 1px;
}

.wysiwyg-palette {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    width: 168px;
}

.wysiwyg-palette.open {
    display: block;
}

.wp-swatches {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}

.wp-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 3px;
    border: 1px solid #d1d5db;
    cursor: pointer;
    transition: transform .1s, box-shadow .1s;
}

.wp-swatch:hover {
    transform: scale(1.25);
    box-shadow: 0 0 0 2px #4f46e5;
    z-index: 1;
    position: relative;
}

.wp-custom {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #e5e7eb;
    font-size: 0.78rem;
    color: #6b7280;
    cursor: pointer;
}

.wp-custom input[type="color"] {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

/* 編輯器內容區 */
.wysiwyg-editor {
    min-height: 200px;
    max-height: 500px;
    overflow-y: auto;
    padding: 16px 20px;
    outline: none;
    font-size: 0.95rem;
    line-height: 1.7;
    color: #1f2937;
}

.wysiwyg-editor:focus {
    box-shadow: inset 0 0 0 2px rgba(79, 70, 229, .12);
}

/* 編輯器內容樣式 */
.wysiwyg-editor h1 { font-size: 1.8rem; margin: 0.6em 0 0.3em; font-weight: 700; }
.wysiwyg-editor h2 { font-size: 1.5rem; margin: 0.5em 0 0.25em; font-weight: 600; }
.wysiwyg-editor h3 { font-size: 1.25rem; margin: 0.4em 0 0.2em; font-weight: 600; }
.wysiwyg-editor p { margin: 0.4em 0; }
.wysiwyg-editor ul, .wysiwyg-editor ol { margin: 0.5em 0; padding-left: 1.8em; }
.wysiwyg-editor blockquote {
    border-left: 4px solid #4f46e5;
    padding: 8px 14px;
    margin: 0.8em 0;
    background: #f0f0ff;
    color: #6b7280;
}
.wysiwyg-editor img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    cursor: pointer;
}
.wysiwyg-editor img:hover {
    outline: 2px solid #4f46e5;
}
.wysiwyg-editor img.wysiwyg-selected {
    outline: 3px solid #4f46e5;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(79,70,229,.12);
}
.wysiwyg-editor table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.8em 0;
}
.wysiwyg-editor th, .wysiwyg-editor td {
    border: 1px solid #d1d5db;
    padding: 6px 10px;
}
.wysiwyg-editor th {
    background: #f3f4f6;
    font-weight: 600;
}
.wysiwyg-editor a { color: #4f46e5; text-decoration: underline; }

/* 原始碼區 */
.wysiwyg-source-area {
    display: none;
    width: 100%;
    min-height: 200px;
    max-height: 500px;
    padding: 12px 16px;
    border: none;
    outline: none;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #e2e8f0;
    background: #1e293b;
    resize: vertical;
    box-sizing: border-box;
}

/* 隱藏 file input */
.wysiwyg-file-input {
    display: none;
}

/* 響應式 */
/* 表格編輯按鈕 */
.wysiwyg-table-group button {
    width: auto !important;
    padding: 0 7px;
    gap: 2px;
    font-size: 0.72rem;
}

/* 表格欄寬拖曳 */
.wysiwyg-editor table {
    position: relative;
}
.wysiwyg-editor td, .wysiwyg-editor th {
    position: relative;
}
.wysiwyg-col-resize-handle {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
    background: transparent;
}
.wysiwyg-col-resize-handle:hover,
.wysiwyg-col-resize-handle.active {
    background: rgba(79, 70, 229, 0.3);
}
.wysiwyg-row-resize-handle {
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 100%;
    height: 6px;
    cursor: row-resize;
    z-index: 10;
    background: transparent;
}
.wysiwyg-row-resize-handle:hover,
.wysiwyg-row-resize-handle.active {
    background: rgba(79, 70, 229, 0.3);
}

/* 表格屬性面板 */
.wysiwyg-tbl-props-panel {
    display: none;
    position: absolute;
    z-index: 1000;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    width: 320px;
    padding: 0;
    font-size: 0.82rem;
}
.wysiwyg-tbl-props-panel.open {
    display: block;
}
.wysiwyg-tbl-props-panel .tp-head {
    padding: 10px 14px;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    border-radius: 10px 10px 0 0;
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wysiwyg-tbl-props-panel .tp-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: #6b7280;
    line-height: 1;
}
.wysiwyg-tbl-props-panel .tp-body {
    padding: 12px 14px;
}
.wysiwyg-tbl-props-panel .tp-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.wysiwyg-tbl-props-panel .tp-label {
    min-width: 80px;
    font-weight: 500;
    color: #374151;
    font-size: 0.8rem;
}
.wysiwyg-tbl-props-panel .tp-ctrl {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
}
.wysiwyg-tbl-props-panel .tp-ctrl input[type="range"] {
    flex: 1;
    height: 6px;
    accent-color: #4f46e5;
}
.wysiwyg-tbl-props-panel .tp-ctrl .tp-val {
    min-width: 45px;
    text-align: center;
    font-size: 0.78rem;
    color: #6b7280;
    font-family: monospace;
}
.wysiwyg-tbl-props-panel .tp-ctrl select {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.8rem;
}
.wysiwyg-tbl-props-panel .tp-ctrl input[type="number"] {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.8rem;
    text-align: center;
}
.wysiwyg-tbl-props-panel .tp-sep {
    height: 1px;
    background: #e5e7eb;
    margin: 8px 0;
}
.wysiwyg-tbl-props-panel .tp-btn-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.wysiwyg-tbl-props-panel .tp-btn {
    padding: 4px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.78rem;
    transition: all .15s;
}
.wysiwyg-tbl-props-panel .tp-btn:hover {
    border-color: #4f46e5;
    color: #4f46e5;
    background: #f0f0ff;
}

@media (max-width: 600px) {
    .wysiwyg-toolbar {
        padding: 4px;
        gap: 1px;
    }
    .wysiwyg-toolbar button {
        width: 26px;
        height: 26px;
        font-size: 0.75rem;
    }
    .wysiwyg-toolbar select {
        height: 26px;
        font-size: 0.72rem;
        max-width: 70px;
    }
    .wysiwyg-editor {
        min-height: 150px;
        padding: 10px 12px;
    }
}
