/* ============================================================
   Notice Page 특정 스타일 (pages/notice.css)
   ============================================================ */

:root {
    /* 카테고리 컬러 */
    --c-plan: #1a3a5c;
    --c-plan-bg: #eef3f9;
    --c-account: #1e7e34;
    --c-account-bg: #eafaf1;
    --c-service: #8e44ad;
    --c-service-bg: #f5eef8;
    --c-event: #d35400;
    --c-event-bg: #fef5ec;
    --c-pub: #2471a3;
    --c-pub-bg: #eaf4fb;
    --c-general: #616a6b;
    --c-general-bg: #f4f6f7;
}

/* 다크모드 대응 카테고리 컬러 */
html[data-theme="dark"] :root {
    --c-plan: #7eb1ff;
    --c-plan-bg: #1a2a3a;
    --c-account: #2ecc71;
    --c-account-bg: #143a20;
    --c-service: #bb86fc;
    --c-service-bg: #2d1a3a;
    --c-event: #ffb74d;
    --c-event-bg: #3a2a14;
    --c-pub: #64b5f6;
    --c-pub-bg: #1a2f3a;
    --c-general: #b0bec5;
    --c-general-bg: #263238;
}


/* ── 카테고리 필터 ── */
.cat-tabs {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    padding: 12px 16px 0;
    gap: 8px 6px;
}

.cat-tab {
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.cat-tab:hover {
    background: var(--bg);
    color: var(--text);
}

.cat-tab.active {
    color: #fff;
    background: var(--accent);
    border-color: transparent;
    font-weight: 600;
}

.cat-tab-count {
    font-size: clamp(10px, 3.2vmin, 12px);
    font-weight: 700;
    color: var(--text-muted);
    font-family: var(--font-mono);
    opacity: 0.7;
    transition: all .15s;
}

.cat-tab.active .cat-tab-count {
    color: #fff;
    opacity: 1;
}

.cat-tab-new {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--red);
    flex-shrink: 0;
}



/* ── 검색 ── */
.search-wrap {
    padding: 12px 12px 0;
    position: relative;
}

.search-icon {
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    cursor: pointer;
    z-index: 1;
}

.search-input {
    width: 100%;
    height: 38px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 0 80px 0 14px;
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    outline: none;
    color: var(--text);
    transition: border-color .15s;
}

.search-input:focus {
    border-color: var(--accent);
}

/* ── 핀 공지 ── */
.pinned-section {
    margin: 12px 12px 0;
}

.pinned-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 0 2px;
    margin-bottom: 6px;
    display: block;
}

.pinned-card {
    background: var(--accent);
    border-radius: 12px;
    padding: 14px 16px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .15s;
}

.pinned-card:active {
    opacity: 0.85;
}

.pinned-icon {
    width: 42px;
    height: 42px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 20px;
}

.pinned-content {
    flex: 1;
}

.pinned-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 3px;
}

.pinned-sub {
    font-size: 12px;
    opacity: 0.75;
}

.pinned-arrow {
    font-size: 18px;
    opacity: 0.7;
}

/* ── 공지 목록 ── */
.notice-list {
    margin: 12px 12px 0;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.notice-item {
    display: flex;
    align-items: flex-start;
    gap: 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .1s;
    text-decoration: none;
    color: inherit;
}

.notice-item:last-child {
    border-bottom: none;
}

.notice-item:active {
    background: var(--bg);
}

.notice-cat-bar {
    width: 4px;
    align-self: stretch;
    flex-shrink: 0;
}

.notice-body {
    flex: 1;
    padding: 13px 14px;
}

.notice-top {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 5px;
    flex-wrap: wrap;
}

.notice-badge {
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.notice-new {
    font-size: 10px;
    font-weight: 700;
    color: var(--red);
    background: var(--red-bg);
    padding: 2px 6px;
    border-radius: 4px;
}

.notice-title {
    font-size: clamp(13.5px, 4.2vmin, 16px);
    font-weight: 600;
    line-height: 1.45;
    margin-bottom: 4px;
}

.notice-title.unread {
    font-weight: 700;
}

.notice-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
    color: var(--text-muted);
}

.notice-date {
    font-family: var(--font-mono);
    font-size: 11px;
}

.notice-attach {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    color: var(--text-muted);
}

.notice-attach svg {
    width: 12px;
    height: 12px;
}

.notice-right {
    padding: 13px 12px;
    display: flex;
    align-items: center;
    color: var(--text-muted);
}

.notice-rel-date {
    font-size: 10.5px;
    color: var(--text-muted);
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 6px;
    font-weight: 500;
}

.notice-rel-date.today {
    color: var(--accent);
    background: var(--accent-bg);
}

.notice-rel-date.recent {
    color: var(--green);
    background: var(--green-bg);
}

/* ── 상세 페이지 스타일 (Page-style Detail View) ── */
.notice-detail-page {
    position: relative;
    background: var(--bg);
    min-height: calc(100vh - var(--header-h) - var(--tabbar-h));
    /* 하단 네비게이션이 탭바에 가려지지 않도록 충분한 여백 확보 */
    padding-bottom: calc(var(--tabbar-h) + 40px);
}

.detail-body {
    background: var(--surface);
    margin: 12px;
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 24px 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

html[data-theme="dark"] .detail-body {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}


.detail-cat-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 10px;
    margin-bottom: 12px;
}

.detail-title {
    font-size: clamp(18px, 5.5vmin, 24px);
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: -0.5px;
    margin-bottom: 14px;
    color: var(--text);
}

.detail-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 24px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

/* ── HTML 콘텐츠 렌더링 지원 ── */
/* ── HTML 콘텐츠 렌더링 및 에디터 공통 스타일 ── */
.detail-content,
.write-content-input {
    font-size: clamp(14.5px, 4.2vmin, 16.5px);
    line-height: 1.8;
    color: var(--text);
    word-break: break-word;
    overflow-wrap: break-word;
}

.detail-content a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* 개별 요소 스타일 (기본 Reset 복구 및 가독성 확보) */
.detail-content h1,
.write-content-input h1,
.detail-content h2,
.write-content-input h2,
.detail-content h3,
.write-content-input h3 {
    margin: 24px 0 12px;
    line-height: 1.3;
    font-weight: 700;
    color: var(--text);
}

.detail-content h1,
.write-content-input h1 {
    font-size: 1.6em;
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
}

.detail-content h2,
.write-content-input h2 {
    font-size: 1.4em;
}

.detail-content h3,
.write-content-input h3 {
    font-size: 1.2em;
}

.detail-content p,
.write-content-input p {
    margin-bottom: 16px;
}

.detail-content b,
.write-content-input b,
.detail-content strong,
.write-content-input strong {
    font-weight: 700;
}

.detail-content i,
.write-content-input i,
.detail-content em,
.write-content-input em {
    font-style: italic;
}

.detail-content u,
.write-content-input u {
    text-decoration: underline;
}

/* 리스트 스타일 (Reset 복구가 확실해야 하므로 !important 유지) */
.detail-content ul,
.write-content-input ul,
.detail-content ol,
.write-content-input ol {
    margin: 16px 0;
    padding-left: 24px;
    list-style: initial !important;
}

.detail-content li,
.write-content-input li {
    margin-bottom: 8px;
    display: list-item !important;
}

/* 인용구 */
.detail-content blockquote,
.write-content-input blockquote {
    border-left: 4px solid var(--accent);
    padding: 12px 16px;
    margin: 20px 0;
    background: var(--bg);
    border-radius: 0 8px 8px 0;
    color: var(--text-muted);
    font-style: italic;
}

/* 테이블 Styles */
/* 기본 표는 가로 100%를 차지하지만 사용자가 너비나 정렬을 지정하면 양보합니다 */
.detail-content table:not([style*="width"]):not([width]),
.write-content-input table:not([style*="width"]):not([width]) {
    width: 100%;
}

.detail-content table:not([style*="margin"]),
.write-content-input table:not([style*="margin"]) {
    margin: 20px 0;
}

/* 표 기본 속성 (무조건 적용) */
.detail-content table,
.write-content-input table {
    border-collapse: collapse;
    font-size: 0.9em;
    border: 1px solid var(--border);
    table-layout: auto;
}

/* TinyMCE 구식 달기 속성(align="center") 호환성 지원 */
.detail-content table[align="center"],
.write-content-input table[align="center"] {
    margin-left: auto !important;
    margin-right: auto !important;
}

.detail-content table[align="right"],
.write-content-input table[align="right"] {
    margin-left: auto !important;
    margin-right: 0 !important;
}

/* 테이블 컨테이너 가로 스크롤 허용 */
.detail-content {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background-color: #ffffff !important;
    color: #111111 !important;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border) !important;
}

html[data-theme="dark"] .detail-content {
    background-color: #ffffff !important;
    color: #111111 !important;
}

/* 종이 모드 내부에서는 기본적인 테이블, 텍스트 색상 등이 다크모드로 반전되지 않도록 초기화 */
html[data-theme="dark"] .detail-content table {
    background-color: #ffffff;
}

/* 사용자가 직접 테두리 색상/두께를 지정하지 않은 '기본 표'에만 자동으로 회색 테두리 적용 */
html[data-theme="dark"] .detail-content th:not([style*="border"]),
html[data-theme="dark"] .detail-content td:not([style*="border"]) {
    border: 1px solid #cccccc !important;
}

/* 인라인 스타일로 지정된 흰색 배경/검은 글씨 강제 보정 (이제 종이모드이므로 불필요하지만 유지) */
html[data-theme="dark"] .detail-content [style*="background-color: white"],
html[data-theme="dark"] .detail-content [style*="background-color: #fff"],
html[data-theme="dark"] .detail-content [style*="background-color: #ffffff"],
html[data-theme="dark"] .detail-content [style*="background-color: rgb(255, 255, 255)"],
html[data-theme="dark"] .detail-content [style*="background: white"],
html[data-theme="dark"] .detail-content [style*="background: #fff"] {
    background-color: transparent !important;
}

html[data-theme="dark"] .detail-content [style*="color: black"],
html[data-theme="dark"] .detail-content [style*="color: #000"],
html[data-theme="dark"] .detail-content [style*="color: rgb(0, 0, 0)"] {
    color: #111111 !important;
}

.detail-content th:not([style*="border"]),
.write-content-input th:not([style*="border"]),
.detail-content td:not([style*="border"]),
.write-content-input td:not([style*="border"]) {
    border: 1px solid var(--border);
}

.detail-content th,
.write-content-input th,
.detail-content td,
.write-content-input td {
    padding: 12px 10px;
    min-width: 80px;
    vertical-align: middle;
}

/* 에디터 내 표 편집 칸 강조 효과 */
.write-content-input td:focus,
.write-content-input th:focus {
    background: var(--accent-bg) !important;
    outline: 2px solid var(--accent) !important;
    outline-offset: -2px;
}

.detail-content th,
.write-content-input th {
    background: #f8f9fa;
    font-weight: 700;
    text-align: left;
}

/* 코드/구분선/이미지 */
.detail-content hr,
.write-content-input hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

.detail-content img,
.write-content-input img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    margin: 16px 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* ── 유틸리티 스타일 ── */
.itw-text-red {
    color: var(--red) !important;
}

.itw-text-blue {
    color: var(--blue) !important;
}

.itw-text-orange {
    color: var(--orange) !important;
}

.itw-text-green {
    color: var(--green) !important;
}

.itw-text-muted {
    color: var(--text-muted) !important;
}

.itw-bg-red {
    background: var(--red-bg) !important;
    padding: 2px 6px;
    border-radius: 4px;
}

.itw-bg-blue {
    background: var(--blue-bg) !important;
    padding: 2px 6px;
    border-radius: 4px;
}

.itw-bg-green {
    background: var(--green-bg) !important;
    padding: 2px 6px;
    border-radius: 4px;
}

.itw-align-center {
    text-align: center !important;
}

.itw-align-right {
    text-align: right !important;
}

.itw-box {
    padding: 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin: 16px 0;
}

/* ── 하단 네비게이션 ── */
.detail-nav {
    display: flex;
    gap: 8px;
    margin-top: 30px;
}

.detail-nav-btn {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 12px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    text-decoration: none;
    transition: all .2s;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    min-width: 0;
}

.detail-nav-btn:active:not(:disabled) {
    background: var(--bg);
    transform: scale(0.98);
}

.detail-nav-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.nav-icon-box {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--bg-faint);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    flex-shrink: 0;
}

.nav-btn-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: left;
    overflow: hidden;
}

.nav-label {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 헤더용 내비게이션 스타일 */
.hd-nav-arrow {
    background: var(--surface) !important;
    border-radius: 8px !important;
    border: 1px solid var(--border) !important;
}

.hd-nav-arrow:disabled {
    opacity: 0.2 !important;
}

.hd-nav-arrow:active:not(:disabled) {
    background: var(--bg-faint) !important;
}

/* ── 첨부파일 섹션 (상세 페이지용) ── */
.detail-attach-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px dashed var(--border);
}

.detail-attach-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.detail-attach-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    margin-bottom: 8px;
}

.detail-attach-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-attach-size {
    font-size: 11px;
    color: var(--text-muted);
}

.detail-attach-actions {
    display: flex;
    gap: 6px;
}

.attach-btn {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    font-family: inherit;
    color: var(--text);
    white-space: nowrap;
    transition: all .15s;
}

.attach-btn.preview {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-bg);
}

.attach-btn.download {
    color: var(--green);
    border-color: #b7e4c7;
    background: var(--green-bg);
}

/* ── 파일 미리보기 오버레이 ── */
.preview-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 5500;
    /* 헤더/탭바보다 높게 */
    background: rgba(0, 0, 0, 0.9);
    flex-direction: column;
}

.preview-overlay.open {
    display: flex;
}

.preview-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.5);
}

.preview-filename {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-dl-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.preview-dl-btn svg {
    width: 15px;
    height: 15px;
}

.preview-close {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.preview-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

.preview-body img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.preview-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
    background: #fff;
}

.preview-unsupported {
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    line-height: 2;
}

.preview-unsupported .file-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

/* ── 글쓰기 모달 ── */
.write-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3100;
    background: rgba(0, 0, 0, 0.45);
}

.write-overlay.open {
    display: flex;
    flex-direction: column;
}

.write-modal {
    background: var(--surface);
    flex: 1;
    display: flex;
    flex-direction: column;
    animation: slideUp .22s ease;
    overflow: hidden;
    /* 전체 화면 확장 */
    position: fixed;
    inset: 0;
    z-index: 3101;
    height: 100vh;
    height: 100dvh;
    /* 가용 가능한 최대 높이 사용 */
}

.write-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    height: 56px;
}

.write-close-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
    transition: opacity .2s;
}

.write-close-icon:active {
    opacity: 0.6;
}

.write-topbar-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.write-submit {
    /* itw-hd-btn 클래스로 대체 */
    z-index: 2;
}

.itw-action-btn:hover {
    background: var(--bg);
}

.write-submit:active {
    opacity: 0.8;
}

.write-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* 바디 자체의 스크롤을 막고 에디터에게 공간을 위임 */
    background: var(--surface);
}

.write-field {
    margin: 12px 16px 0 16px;
    flex-shrink: 0;
    /* 제목/카테고리 칸이 줄어들지 않도록 함 */
}

/* 연속된 필드 사이의 간격을 줄임 */
.write-field+.write-field {
    margin-top: 8px;
}

.write-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 6px;
    display: block;
}

.write-cat-select {
    width: 100%;
    height: 40px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 0 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a7872' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.write-cat-select:focus {
    border-color: var(--accent);
}

.write-editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-top: 0;
    /* 여백 제거로 공간 확보 */
    border-top: 1.5px solid var(--border);
    background: #fff;
}

/* ── [SECURITY] 시스템 다크 모드 강제 고대비 스타일 ── */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #121212 !important;
        --surface: #1e1e1e !important;
        --bg-faint: #252525 !important;
        --border: #333333 !important;
        --text: #ffffff !important;
        --text-muted: #aaaaaa !important;
    }

    :root:not([data-theme="light"]) body.itw-mobile,
    :root:not([data-theme="light"]) .notice-detail-page {
        background-color: #121212 !important;
        color: #ffffff !important;
    }

    :root:not([data-theme="light"]) .notice-list,
    :root:not([data-theme="light"]) .cat-tabs,
    :root:not([data-theme="light"]) .detail-body,
    :root:not([data-theme="light"]) .detail-nav-btn,
    :root:not([data-theme="light"]) .detail-attach-file,
    :root:not([data-theme="light"]) .write-modal,
    :root:not([data-theme="light"]) .preview-topbar {
        background-color: #1e1e1e !important;
        border-color: #333333 !important;
    }

    :root:not([data-theme="light"]) .notice-item:active,
    :root:not([data-theme="light"]) .cat-tab:hover,
    :root:not([data-theme="light"]) .detail-nav-btn:active {
        background-color: #252525 !important;
    }

    :root:not([data-theme="light"]) .notice-title,
    :root:not([data-theme="light"]) .detail-title,
    :root:not([data-theme="light"]) .nav-title,
    :root:not([data-theme="light"]) .write-topbar-title,
    :root:not([data-theme="light"]) .preview-filename {
        color: #ffffff !important;
    }

    :root:not([data-theme="light"]) .search-input {
        background-color: #252525 !important;
        border-color: #444 !important;
        color: #ffffff !important;
    }

    :root:not([data-theme="light"]) .cat-tab {
        background-color: #1e1e1e !important;
        border-color: #444 !important;
        color: #aaaaaa !important;
    }

    :root:not([data-theme="light"]) .cat-tab.active {
        background-color: var(--accent) !important;
        color: #ffffff !important;
    }

    .notice-rel-date {
        background-color: #252525 !important;
        color: #aaaaaa !important;
    }

    /* 게시글 본문 (종이모드는 유지하되 눈부심 방지를 위해 약간 톤다운된 흰색 사용 가능) */
    /* 유저가 완전한 다크모드를 원할 경우 아래 주석을 해제할 수 있으나, 현재는 호환성을 위해 유지 */
    .itw-skeleton {
        background: linear-gradient(90deg, #252525 25%, #333 50%, #252525 75%) !important;
        background-size: 200% 100% !important;
    }

    /* 상세 네비게이션 버튼 */
    .detail-nav-btn {
        background-color: #1e1e1e !important;
        border-color: #444 !important;
    }

    /* 파일 미리보기 오버레이 */
    .preview-overlay {
        background-color: rgba(0, 0, 0, 0.95) !important;
    }
}

.write-title-input {
    width: 100%;
    height: 44px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 0 12px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    outline: none;
}

.write-title-input:focus {
    border-color: var(--accent);
}

.write-content-input {
    flex: 1;
    /* 남은 공간 모두 차지 */
    min-height: 200px;
    padding: 16px;
    margin: 16px;
    /* body 패딩 대신 margin 적용 */
    border: 1.5px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    outline: none;
    transition: all 0.2s;
    overflow: auto;
    /* 세로/가로 스크롤 허용 */
    -webkit-overflow-scrolling: touch;
}

.write-content-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

/* CKEditor 5 UI 확장 및 다크모드 대응 */
.ck.ck-editor {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ck.ck-editor__main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.ck-editor__editable_inline {
    flex: 1;
    overflow-y: auto;
}

html[data-theme="dark"] {
    --ck-color-base-background: var(--surface);
    --ck-color-base-text: var(--text);
    --ck-color-editor-base-text: var(--text);
    --ck-color-text: var(--text);
    --ck-color-base-border: var(--border);
    --ck-color-toolbar-background: var(--bg);
    --ck-color-toolbar-border: var(--border);
    --ck-color-button-default-hover-background: var(--surface);
    --ck-color-button-on-background: var(--accent-bg);
    --ck-color-button-on-color: var(--accent);
    --ck-color-dropdown-panel-background: var(--surface);
    --ck-color-dropdown-panel-border: var(--border);
    --ck-color-list-background: var(--surface);
    --ck-color-list-button-hover-background: var(--bg);
    --ck-color-panel-background: var(--surface);
    --ck-color-panel-border: var(--border);
}

.write-editor-toolbar {
    display: flex;
    gap: 8px;
    margin: 0 -16px 16px -16px;
    /* 상단 마진 제거, 좌우 패딩 상쇄 유지 */
    background: var(--bg);
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    align-items: center;
    overflow-x: auto;
    position: sticky;
    top: 0;
    /* 스크롤 시 바디 최상단에 고정 */
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    /* 고정 시 가독성을 위해 그림자 강화 */
}

.write-editor-toolbar::-webkit-scrollbar {
    display: none;
}

.write-editor-toolbar button {
    flex: none;
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}

.write-editor-toolbar button:hover {
    background: rgba(0, 0, 0, 0.05);
}

.write-editor-divider {
    flex: none;
    width: 1px;
    height: 16px;
    background: var(--border);
    margin: 0 4px;
}

.write-editor-select {
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
    padding: 0 4px;
    outline: none;
    cursor: pointer;
}

.write-editor-select:focus {
    border-color: var(--accent);
}

/* Redundant definition removed */

.write-html-preview {
    flex: 1;
    border-top: 2px solid var(--border);
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

.write-html-preview .preview-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 6px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
}

.write-html-preview .preview-content {
    flex: 1;
    padding: 16px;
    overflow: auto;
    /* 세로/가로 스크롤 기능 추가 */
    background: var(--surface);
}

.write-attach-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1.5px dashed var(--border);
    background: var(--bg);
    font-size: 13px;
    font-family: inherit;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.write-attach-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.write-attach-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.write-attach-list {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.write-attach-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: var(--surface);
}

.write-attach-item .ai-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.write-attach-item .ai-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.write-attach-item .ai-size {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.write-attach-item .ai-remove {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: var(--red-bg);
    color: var(--red);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
}

/* ──────────────── 모달 이전/다음 네비게이션 ──────────────── */
.modal-nav {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-nav-btn {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all .15s;
    text-align: left;
}

.modal-nav-btn:not(:disabled):hover {
    border-color: var(--accent);
    color: var(--accent);
}

.modal-nav-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.modal-nav-btn.next {
    flex-direction: row-reverse;
    text-align: right;
}

.modal-nav-title {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

/* TinyMCE Modal z-index bugfix: 실질적인 modal z-index(9999 이상)보다 높게 설정해야 메뉴가 보임 */
.tox-tinymce-aux {
    z-index: 11000 !important;
}

/* [UI Fix] 에디터 메뉴 색상 오류 보정 (4차 초강력 범용 오버라이드)
   글로벌 다크모드 하에서 TinyMCE 메뉴의 텍스트가 흰색으로 표시되는 현상을 방지하기 위해 
   'body' 셀렉터를 포함하여 우선순위를 극대화하고 모든 기본 태그의 색상을 강제합니다. */

/* 일반 상태: 메뉴 내 모든 텍스트 요소를 어둡게 고정 */
body .tox-tinymce-aux div,
body .tox-tinymce-aux span,
body .tox-tinymce-aux p,
body .tox-tinymce-aux label,
body .tox-tinymce-aux strong,
body .tox-tinymce-aux em,
body .tox-tinymce-aux h1,
body .tox-tinymce-aux h2,
body .tox-tinymce-aux h3,
body .tox-tinymce-aux h4,
body .tox-tinymce-aux h5,
body .tox-tinymce-aux h6 {
    color: #222222 !important;
}

/* TinyMCE 내부 변수 강제 고정 */
.tox-tinymce-aux,
.tox {
    --tox-collection-item-label-color: #222222 !important;
    --tox-mbtn-select-label-color: #222222 !important;
    --tox-listbox-select-label-color: #222222 !important;
    --tox-dialog-title-color: #222222 !important;
    --tox-label-color: #222222 !important;
}

/* [Active State] 선택된 항목의 배경과 글씨색 반전 유지 (매우 높은 우선순위) */
body .tox-tinymce-aux .tox-collection__item--active,
body .tox-tinymce-aux .tox-collection__item--active *,
body .tox-tinymce-aux .tox-collection__item--active div,
body .tox-tinymce-aux .tox-collection__item--active span {
    background-color: var(--accent) !important;
    color: #ffffff !important;
}

/* 아이콘 및 체크마크 색상 고정 */
body .tox-tinymce-aux svg,
body .tox-tinymce-aux svg path {
    fill: #222222 !important;
}

body .tox-tinymce-aux .tox-collection__item--active svg,
body .tox-tinymce-aux .tox-collection__item--active svg path {
    fill: #ffffff !important;
}

/* 대화상자 버튼 텍스트 예외 처리 (어두운 배경의 확인 버튼 등) */
body .tox-tinymce-aux .tox-button:not(.tox-button--secondary) {
    color: #ffffff !important;
}

/* TinyMCE wrapper size fix */
.tox-tinymce {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 200px !important;
    border: none !important;
    border-radius: 0 !important;
    max-width: none !important;
    background: #fff !important;
    transition: opacity .2s ease-in-out;
}

/* 내부 레이아웃 강제 확장: 툴바와 상태바 사이 공간을 꽉 채움 */
.tox-editor-container {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    height: 0 !important;
    /* Flex stretch를 위해 0으로 시작 */
    min-height: 100% !important;
}

.tox-sidebar-wrap {
    flex: 1 !important;
    display: flex !important;
    flex-direction: row !important;
    height: 100% !important;
}

.tox-edit-area {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
}

.tox-edit-area__iframe {
    flex: 1 !important;
    height: 100% !important;
    display: block !important;
}

/* 에디터 툴바를 화면 상단에 고정 */
.tox .tox-editor-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
    flex-shrink: 0 !important;
}

/* ── 데스크탑 환경 최적화 (Desktop Optimization) ──────────────── */
@media (min-width: 600px) {
    .write-modal {
        position: fixed !important;
        inset: 0 !important;
        /* 데스크탑도 이제 0으로 꽉 채움 */
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-width: none !important;
        max-height: none !important;
        margin: 0 !important;
        border-radius: 0 !important;
        z-index: 9999 !important;
    }
}

/* 다크모드 대응: 모달 내의 표가 무조건 흰 바탕에 검은 글씨를 갖도록 설정 (.detail-content는 위에서 이미 설정됨)
   TinyMCE의 iframe 내부 body가 .detail-content 클래스를 가지므로 자동 적용됩니다.
   단, UI 요소(툴바 등)는 TinyMCE 최신 버전이 브라우저 다크모드를 자체적으로 따라갈 수 있습니다. */

/* ══ [EDITOR] TinyMCE 내부 본문 전용 스타일 (테두리/마진 제거) ══ */
body#tinymce {
    margin: 0 !important;
    padding: 20px !important;
    border: none !important;
    background-color: #fff !important;
    box-shadow: none !important;
    height: auto !important;
    min-height: 100% !important;
    width: 100% !important;
    box-sizing: border-box;
}

/* 에디터 내부 폰트 최적화 */
body#tinymce.detail-content {
    font-size: 16px;
    line-height: 1.8;
    color: #222;
}

/* 다크모드 대응: 에디터 내부는 항상 밝은 테마 유지 (글쓰기 가독성) */
@media (prefers-color-scheme: dark) {
    body[id="tinymce"] {
        background-color: #fff !important;
        color: #111 !important;
    }
}