/**
 * Cell Editor Styles
 * 엑셀 스타일 셀 입력 에디터 스타일
 * KAICE Material 플러그인용
 */

/* ===========================================
   셀 에디터 컨테이너
   =========================================== */
.kaice-cell-editor {
    width: 100%;
    border: 1px solid var(--theme-item-border);
    border-radius: var(--theme-input-radius);
    background: #fff;
    overflow: visible;
    min-height: 500px;
    display: flex;
    flex-direction: column;
}

.kaice-cell-editor-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    /* 스크롤바 항상 표시 */
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

/* Webkit 브라우저 스크롤바 스타일 */
.kaice-cell-editor-wrapper::-webkit-scrollbar {
    height: 10px;
}

.kaice-cell-editor-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 5px;
}

.kaice-cell-editor-wrapper::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 5px;
}

.kaice-cell-editor-wrapper::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* ===========================================
   테이블 기본 스타일
   =========================================== */
.kaice-cell-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    overflow: visible;
}

/* tbody가 나머지 공간을 채우도록 */
.kaice-cell-table tbody {
    display: table-row-group;
}

/* 빈 tbody용 pseudo element로 최소 높이 확보 */
.kaice-cell-table tbody:empty::after {
    content: '';
    display: table-row;
    height: 100%;
}

.kaice-cell-table th,
.kaice-cell-table td {
    border: 1px solid #e8e8e8;
    padding: 0;
    vertical-align: middle;
    font-family: var(--theme-font-normal);
    font-size: var(--theme-font-size-body);
    overflow: visible;
}

/* ===========================================
   헤더 스타일
   =========================================== */
.kaice-cell-table thead th {
    background: var(--theme-table-bg);
    font-family: var(--theme-font-bold);
    font-weight: normal;
    text-align: center;
    padding: 12px 8px;
    color: var(--theme-text-color);
    border-bottom: 2px solid #ddd;
    position: relative;
    white-space: nowrap;
}

.kaice-cell-table thead th.col-order {
    width: 60px;
    min-width: 60px;
}

.kaice-cell-table thead th.col-title {
    min-width: 200px;
}

.kaice-cell-table thead th.col-public {
    width: 80px;
    min-width: 80px;
}

.kaice-cell-table thead th.col-author {
    width: 100px;
    min-width: 100px;
}

.kaice-cell-table thead th.col-category {
    width: 120px;
    min-width: 120px;
}

.kaice-cell-table thead th.col-objectives {
    min-width: 200px;
}

/* ===========================================
   셀 스타일
   =========================================== */
.kaice-cell-table tbody td {
    background: #fff;
    height: 48px;
    transition: background-color 0.15s ease;
}

.kaice-cell-table tbody tr:hover td {
    background: #fafafa;
}

.kaice-cell-table tbody tr.dragging td {
    background: var(--theme-info-bg);
    opacity: 0.8;
}

.kaice-cell-table tbody tr.drag-over td {
    border-top: 2px solid var(--theme-main-color);
}

/* 순서 셀 (드래그 핸들) */
.kaice-cell-order {
    text-align: center;
    cursor: grab;
    color: var(--theme-hint-text-color);
    font-size: var(--theme-font-size-body);
    user-select: none;
}

.kaice-cell-order:active {
    cursor: grabbing;
}

.kaice-cell-order .drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.kaice-cell-order .drag-handle::before {
    content: '\2630';
    font-size: 14px;
    color: #bbb;
    margin-right: 4px;
}

.kaice-cell-order .order-number {
    font-family: var(--theme-font-bold);
    color: var(--theme-text-color);
}

/* 제목 셀 */
.kaice-cell-title {
    position: relative;
}

.kaice-cell-title-wrapper {
    display: flex;
    align-items: center;
    padding: 0 8px;
}

.kaice-cell-title input[type="text"] {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 0;
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    outline: none;
    min-width: 0;
}

.kaice-cell-title input[type="text"]:focus {
    background: var(--theme-info-bg);
    margin: 0 0 0 -8px;
    padding: 12px 8px;
    border-radius: 0;
}

.kaice-cell-title input[type="text"]::placeholder {
    color: var(--theme-hint-text-color);
}

/* 편집/삭제 버튼은 button-styles.css의 btn-edit, btn-danger 사용 */

/* 공개 셀 */
.kaice-cell-public {
    text-align: center;
}

/* 토글 스위치 스타일은 toggle-styles.css의 .toggle-switch 클래스를 사용합니다. */

/* 저자 셀 */
.kaice-cell-author {
    padding: 4px 8px;
    position: relative;
}

.kaice-cell-author .author-field-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.kaice-cell-author .author-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.kaice-cell-author .author-tags:not(:empty) {
    padding: 5px;
}

/* 태그 스타일은 tag-styles.css의 .tag-item 클래스를 사용합니다. */

.kaice-cell-author .author-search-wrapper {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 30px;
    position: relative;
}

.kaice-cell-author .author-search-icon {
    color: var(--theme-hint-text-color);
    font-size: 12px;
    padding: 0 5px 0 10px;
    flex-shrink: 0;
}

.kaice-cell-author .author-search-input {
    flex: 1;
    width: 100%;
    min-width: 0;
    border: none;
    background: transparent;
    padding: 5px 5px 5px 0;
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    outline: none;
}

.kaice-cell-author .author-search-input:focus {
    background: var(--theme-info-bg);
    border-radius: 0;
}

.kaice-cell-author .author-suggestions {
    display: none;
    position: fixed;
    background: #fff;
    border: 1px solid var(--theme-item-border);
    border-radius: var(--theme-card-radius);
    box-shadow: var(--theme-box-shadow);
    z-index: 9999;
    max-height: 200px;
    overflow-y: auto;
    min-width: 200px;
}

.kaice-cell-author .author-suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: var(--theme-font-size-body);
    color: var(--theme-text-color);
    transition: background-color 0.15s ease;
}

.kaice-cell-author .author-suggestion-item:hover {
    background: var(--theme-info-bg);
    color: var(--theme-main-color);
}

.kaice-cell-author .author-loading,
.kaice-cell-author .author-no-results,
.kaice-cell-author .author-error {
    padding: 8px 12px;
    font-size: var(--theme-font-size-small);
    color: var(--theme-hint-text-color);
    text-align: center;
}

/* 분류 셀 */
.kaice-cell-category input[type="text"] {
    width: 100%;
    border: none;
    background: transparent;
    padding: 12px 8px;
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    outline: none;
}

.kaice-cell-category input[type="text"]:focus {
    background: var(--theme-info-bg);
    border-radius: 0;
}

/* 교육 목표 셀 (리스트 타입) */
.kaice-cell-objectives textarea {
    width: 100%;
    border: none;
    background: transparent;
    padding: 8px;
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    outline: none;
    resize: vertical;
    min-height: 48px;
    line-height: 1.5;
}

.kaice-cell-objectives textarea:focus {
    background: var(--theme-info-bg);
    border-radius: 0;
}


/* ===========================================
   툴바
   =========================================== */
.kaice-cell-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e8e8e8;
    background: var(--theme-tab-default-bg);
}

.kaice-cell-toolbar .toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.kaice-cell-toolbar .toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-add-column,
.toolbar-csv {
    position: relative;
}

.toolbar-history {
    display: flex;
    gap: 4px;
}

/* 툴바 버튼 - btn-normal 기반 커스터마이징 */
.kaice-cell-toolbar .btn-normal {
    padding: 8px 14px;
    font-family: var(--theme-font-normal);
}

.kaice-cell-toolbar .btn-normal i {
    font-size: var(--theme-font-size-icon-small);
}

.kaice-cell-toolbar .btn-normal:disabled {
    opacity: 0.4;
}

/* 되돌리기/다시실행 버튼 (아이콘만) */
.toolbar-history .btn-normal {
    padding: 8px 10px;
}

/* CSV 드롭다운 */
.csv-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--theme-item-border);
    border-radius: var(--theme-card-radius);
    box-shadow: var(--theme-box-shadow);
    z-index: 1000;
    min-width: 120px;
    padding: 8px 0;
}

.csv-dropdown.active {
    display: block;
}

/* 열 추가 드롭다운 */
.column-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--theme-item-border);
    border-radius: var(--theme-card-radius);
    box-shadow: var(--theme-box-shadow);
    z-index: 1000;
    min-width: 140px;
    padding: 8px 0;
}

.column-dropdown.active {
    display: block;
}

.column-dropdown .dropdown-item,
.csv-dropdown .dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    border: none;
    border-radius: 0;
    background: transparent;
    cursor: pointer;
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    transition: background-color 0.15s ease;
}

.column-dropdown .dropdown-item i,
.csv-dropdown .dropdown-item i {
    font-size: var(--theme-font-size-icon-small);
}

.column-dropdown .dropdown-item:hover,
.csv-dropdown .dropdown-item:hover {
    background: var(--theme-info-bg);
    color: var(--theme-main-color);
}

/* ===========================================
   행 추가 버튼
   =========================================== */
.kaice-cell-add-row {
    padding: 12px;
    text-align: center;
    border-top: 1px solid #e8e8e8;
}

/* ===========================================
   빈 상태
   =========================================== */
.kaice-cell-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--theme-hint-text-color);
}

.kaice-cell-empty .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.kaice-cell-empty .empty-text {
    font-size: var(--theme-font-size-body);
    margin-bottom: 16px;
}

/* ===========================================
   반응형 디자인
   =========================================== */
@media (max-width: 768px) {
    .kaice-cell-toolbar {
        padding: 10px 12px;
    }

    .toolbar-btn .btn-text {
        display: none;
    }

    .toolbar-btn {
        padding: 8px 10px;
    }

    .kaice-cell-table thead th {
        padding: 10px 4px;
        font-size: var(--theme-font-size-small);
    }

    .kaice-cell-table tbody td {
        height: 44px;
    }

    .kaice-cell-order .drag-handle::before {
        display: none;
    }
}

/* ===========================================
   선택 열 헤더 삭제 버튼
   =========================================== */
.kaice-cell-table thead th .remove-col-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: #bbb;
    cursor: pointer;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s ease;
    opacity: 0;
    padding: 10px;
}

.kaice-cell-table thead th:hover .remove-col-btn {
    opacity: 1;
}

.kaice-cell-table thead th .remove-col-btn:hover {
    background: #fee;
    color: var(--theme-danger-button-bg);
}

/* ===========================================
   드래그 앤 드롭 상태
   =========================================== */
.kaice-cell-table tbody tr.sortable-ghost {
    background: var(--theme-info-bg);
    opacity: 0.5;
}

.kaice-cell-table tbody tr.sortable-chosen {
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.kaice-cell-table tbody tr.sortable-drag {
    background: #fff;
}

/* ===========================================
   Title with Details 레이아웃
   =========================================== */
/* kaice-cell-title-wrapper: 세로 배치 */
.kaice-cell-title-wrapper {
    display: flex;
    flex-direction: column;
    padding: 0 8px;
}

/* title-row: input과 버튼 배치 (넘침 시 줄바꿈) */
.title-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    gap: 5px;
}

.title-row input[type="text"] {
    flex: 1;
    min-width: 200px;
}

/* ===========================================
   날짜 셀 스타일
   =========================================== */
.kaice-cell-date .kaice-date-field-wrapper {
    border: none;
    background: transparent;
}

.kaice-cell-date .kaice-date-input {
    border: none !important;
    background: transparent !important;
    padding: 12px 8px;
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    outline: none;
    width: 100%;
    box-sizing: border-box;
}

.kaice-cell-date .kaice-date-input:focus {
    background: var(--theme-info-bg) !important;
}

/* 캘린더 피커가 셀 에디터 영역을 벗어나도록 */
.kaice-cell-date {
    position: relative;
    overflow: visible;
}

.kaice-cell-date .kaice-field-picker-container {
    position: absolute;
    z-index: 99999;
    left: 0;
    top: 100%;
}
