/**
 * Quill 에디터 확장 스타일
 *
 * 1. 링크 tooltip z-index 수정
 * 2. 테이블 Embed 스타일
 * 3. 테이블 삽입 UI (행/열 선택 패널)
 * 4. 우클릭 컨텍스트 메뉴
 * 5. 반응형
 */

/* ============================================
   1. Quill Tooltip z-index 수정
   ============================================ */
.ql-tooltip {
    z-index: 10001 !important;
}

.ql-tooltip.ql-editing {
    z-index: 10001 !important;
}

/* ============================================
   Quill Toolbar 상단 고정 (sticky)
   스크롤 시에도 툴바가 항상 보이도록 고정
   ============================================ */
.ql-toolbar.ql-snow {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
}

.ql-toolbar .ql-picker.ql-size {
    width: 76px;
}

.ql-snow .ql-picker.ql-size .ql-picker-label[data-value$="px"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value$="px"]::before {
    content: attr(data-value);
}

/* ============================================
   2. 테이블 Embed 스타일 (에디터 + 상세보기)
   ============================================ */

.ql-table-embed {
    margin: 16px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ql-table-embed table,
.notice-view-content table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #d1d5db;
    font-size: 14px;
    line-height: 1.6;
    table-layout: auto;
}

/* th, td 공통 - 모두 흰색 배경 */
.ql-table-embed th,
.ql-table-embed td,
.notice-view-content th,
.notice-view-content td {
    background: #ffffff;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    color: #374151;
    vertical-align: top;
}

/* 상세보기 행 호버 */
.notice-view-content tr:hover td {
    background: #f9fafb;
}

/* 빈 셀 최소 높이 */
.ql-table-embed td:empty::after,
.ql-table-embed th:empty::after {
    content: '\00a0';
}

/* 래퍼 상태 */
.ql-table-embed[contenteditable="false"] {
    cursor: default;
    position: relative;
}

/* 테이블 선택 시 외곽선 */
.ql-table-embed:focus,
.ql-table-embed:focus-within {
    outline: 2px solid rgba(134, 85, 231, 0.5);
    outline-offset: 2px;
    border-radius: 4px;
}

/* 삭제 버튼 - 항상 표시 */
.ql-table-embed .ql-table-delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    background: #ffffff;
    color: #9ca3af;
    border: 1px solid #d1d5db;
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.ql-table-embed .ql-table-delete-btn svg {
    stroke: #9ca3af;
    transition: stroke 0.2s ease;
}

.ql-table-embed .ql-table-delete-btn:hover {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.ql-table-embed .ql-table-delete-btn:hover svg {
    stroke: #ffffff;
}

/* ============================================
   3. 툴바 테이블 삽입 버튼
   ============================================ */

.ql-toolbar .ql-table-insert {
    width: 28px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    position: relative;
}

.ql-toolbar .ql-table-insert svg {
    width: 18px;
    height: 18px;
    stroke: #444;
    fill: none;
    stroke-width: 2;
}

.ql-toolbar .ql-table-insert:hover svg {
    stroke: #06c;
}

/* ============================================
   4. 테이블 삽입 패널
   ============================================ */

.ql-table-panel {
    position: fixed;
    z-index: 10002;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    min-width: 220px;
    display: none;
}

.ql-table-panel.active {
    display: block;
}

.ql-table-panel-title {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
    margin-bottom: 12px;
}

.ql-table-panel-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.ql-table-panel-label {
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    min-width: 24px;
}

.ql-table-panel-select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.ql-table-panel-select:focus {
    outline: none;
    border-color: #8655e7;
    box-shadow: 0 0 0 2px rgba(134, 85, 231, 0.15);
}

.ql-table-panel-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.ql-table-panel-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ql-table-panel-btn-cancel {
    background: #f3f4f6;
    color: #6b7280;
}

.ql-table-panel-btn-cancel:hover {
    background: #e5e7eb;
}

.ql-table-panel-btn-insert {
    background: #8655e7;
    color: white;
}

.ql-table-panel-btn-insert:hover {
    background: #6d3ec7;
}

/* ============================================
   5. 우클릭 컨텍스트 메뉴
   ============================================ */

.ql-table-ctx {
    position: fixed;
    z-index: 10003;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 4px 0;
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    display: none;
}

.ql-table-ctx.active {
    display: block;
}

.ql-table-ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s ease;
    position: relative;
}

.ql-table-ctx-item:hover {
    background: #f3f4f6;
}

.ql-table-ctx-danger {
    color: #ef4444;
}

.ql-table-ctx-danger:hover {
    background: #fef2f2;
}

.ql-table-ctx-sep {
    height: 1px;
    background: #e5e7eb;
    margin: 4px 0;
}

.ql-table-ctx-arrow {
    margin-left: auto;
    font-size: 10px;
    color: #9ca3af;
}

/* 셀 배경색 서브 메뉴 */
.ql-table-ctx-colors {
    display: none;
    position: absolute;
    left: 100%;
    top: -4px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    width: 168px;
    z-index: 10004;
}

.ql-table-ctx-colors.active {
    display: grid;
}

.ql-table-ctx-swatch {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ql-table-ctx-swatch:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* ============================================
   6. 반응형
   ============================================ */

@media (max-width: 768px) {
    .ql-table-embed {
        margin: 12px -8px;
        padding: 0 8px;
    }

    .ql-table-embed table {
        font-size: 12px;
    }

    .ql-table-embed th,
    .ql-table-embed td,
    .notice-view-content th,
    .notice-view-content td {
        padding: 8px 10px;
    }

    .ql-table-panel {
        min-width: 180px;
        padding: 12px;
    }

    .ql-table-ctx {
        min-width: 160px;
    }

    .ql-table-ctx-colors {
        left: auto;
        right: 0;
    }
}
