/* 색상은 여기 값만 바꾸면 사이트 전체에 적용됩니다 */
:root {
  --bg: #0f1626;
  --panel: #172036;
  --panel-2: #1e2a45;
  --line: #2a3857;
  --text: #e8edf7;
  --sub: #8e9bb8;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --mine: #2b5fd0;
  --danger: #e25555;
  --ok: #5fd39a;
  --wait: #f0b455;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; overscroll-behavior: none; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3, p { margin: 0; }

/* 버튼 / 입력 */
button, input, textarea, select { font: inherit; color: inherit; }
button, .btn { cursor: pointer; border: 0; border-radius: 8px; padding: 9px 14px; text-decoration: none; display: inline-block; line-height: 1.3; white-space: nowrap; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.outline { background: transparent; color: var(--text); border: 1px solid var(--line); }
.outline:hover { background: var(--panel-2); }
.danger { background: var(--danger); color: #fff; font-weight: 600; }
.ghost { background: transparent; color: var(--sub); padding: 6px 10px; }
.ghost:hover { background: var(--panel-2); color: var(--text); }
.small { padding: 5px 10px; font-size: 13px; }
.wide { width: 100%; }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; color: var(--text);
}
textarea.input { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--sub); }
.field > .input, .field > div { font-size: 15px; color: var(--text); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; white-space: nowrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--sub); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.hint { font-size: 13px; color: var(--sub); }
.hint.center { text-align: center; margin-top: 12px; }
.error { min-height: 20px; color: #ff8a8a; font-size: 13px; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--panel-2); color: var(--sub); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.wait { color: var(--wait); border-color: var(--wait); }
.badge.bad { color: #ff8a8a; border-color: var(--danger); }
.mark { font-size: 11px; color: var(--sub); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-left: 6px; vertical-align: 1px; }

/* 전체 틀 */
.app { height: 100dvh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }

/* 왼쪽 메뉴 */
.side { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { display: block; padding: 20px 18px 14px; font-size: 20px; font-weight: 800; color: var(--text); text-decoration: none; }
.menu { padding: 4px 8px; display: flex; flex-direction: column; gap: 2px; }
#menu { flex: 1; overflow-y: auto; }
.admin-menu { border-top: 1px solid var(--line); padding-top: 8px; padding-bottom: 8px; }
.menu-label { font-size: 12px; color: var(--sub); padding: 2px 10px 4px; }
.item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; color: var(--sub); text-decoration: none; }
.item:hover { background: var(--panel-2); color: var(--text); }
.item.on { background: var(--panel-2); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-icon { width: 20px; text-align: center; font-size: 14px; }
.item-tag { font-size: 11px; color: var(--sub); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.item-count { font-size: 12px; background: var(--danger); color: #fff; border-radius: 20px; padding: 0 7px; font-weight: 600; }
.me { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.me-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-buttons { display: flex; gap: 6px; }
.me-buttons button { flex: 1; }
.shade { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 9; }

/* 본문 */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); min-height: 58px; }
.head h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12px; color: var(--sub); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub.ok { color: var(--ok); }
.actions { display: flex; gap: 6px; }
.menu-btn { display: none; font-size: 18px; }
.view { flex: 1; min-height: 0; overflow-y: auto; }
.view.chat { display: flex; flex-direction: column; overflow: hidden; }
.empty { margin: auto; padding: 48px 16px; color: var(--sub); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* 채팅 */
.messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: min(78%, 560px); }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg-meta { font-size: 12px; color: var(--sub); margin-bottom: 2px; display: flex; gap: 6px; align-items: center; }
.msg-nick { color: var(--text); font-weight: 600; }
.msg-del { padding: 0 4px; font-size: 12px; opacity: 0; }
.msg:hover .msg-del, .msg-del:focus-visible { opacity: 1; }
.bubble { background: var(--panel-2); border-radius: 12px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.mine .bubble { background: var(--mine); }
.mine .bubble a { color: #fff; }
.msg-img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; cursor: zoom-in; background: var(--panel-2); margin-bottom: 4px; }
.preview { display: flex; align-items: center; gap: 10px; padding: 8px 18px; border-top: 1px solid var(--line); background: var(--panel); }
.preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.preview span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--sub); }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.composer.notice { justify-content: center; color: var(--sub); font-size: 14px; }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 140px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.attach { font-size: 18px; padding: 8px 12px; }
.view.drag .messages { outline: 2px dashed var(--accent); outline-offset: -8px; }

/* 게시판 */
.board, .post, .write { padding: 18px; max-width: 960px; }
.posts { width: 100%; border-collapse: collapse; }
.posts th { font-size: 13px; font-weight: 600; color: var(--sub); text-align: left; padding: 9px 10px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--panel); white-space: nowrap; }
.posts td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.posts tbody tr:hover { background: var(--panel); }
.c-no { width: 64px; text-align: center !important; color: var(--sub); }
.c-author { width: 130px; color: var(--sub); white-space: nowrap; }
.c-date { width: 110px; color: var(--sub); white-space: nowrap; }
.c-title { overflow-wrap: anywhere; }
.c-meta-mobile { display: none; font-size: 12px; color: var(--sub); margin-top: 2px; }
.post-link { color: var(--text); text-decoration: none; }
a.post-link:hover { text-decoration: underline; }
.locked .post-link { color: var(--sub); }
.cmt-count { color: var(--accent); font-size: 13px; margin-left: 6px; }
.none { text-align: center; color: var(--sub); padding: 48px 10px !important; }
.pager { display: flex; justify-content: center; gap: 4px; margin-top: 16px; }
.page { min-width: 34px; text-align: center; padding: 6px 8px; border-radius: 8px; color: var(--sub); text-decoration: none; }
.page:hover { background: var(--panel-2); }
.page.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.post-title { font-size: 20px; overflow-wrap: anywhere; }
.post-meta { display: flex; gap: 10px; font-size: 13px; color: var(--sub); padding: 8px 0 14px; border-bottom: 1px solid var(--line); }
.post-meta b { color: var(--text); }
.post-body { padding: 18px 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.post-images { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 0; }
.post-images img { max-width: 100%; max-height: 640px; border-radius: 10px; cursor: zoom-in; background: var(--panel); }
.file { display: inline-flex; align-items: center; gap: 10px; max-width: 100%; margin: 10px 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); text-decoration: none; }
a.file:hover { border-color: var(--accent); }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-size { color: var(--sub); font-size: 13px; white-space: nowrap; }
.post-buttons { padding: 14px 0; border-bottom: 1px solid var(--line); }
.comments { padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.comments h3 { font-size: 15px; }
.comment { background: var(--panel); border-radius: 10px; padding: 10px 12px; }
.comment-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--sub); }
.comment-meta b { color: var(--text); font-size: 14px; }
.comment-meta .mark { margin-left: 0; }
.comment-meta button { margin-left: auto; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; }
.comment-form textarea { flex: 1; min-width: 0; resize: vertical; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }

.write { display: flex; flex-direction: column; gap: 16px; }
.write .body { min-height: 240px; line-height: 1.7; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; }
.thumb img { width: 88px; height: 88px; object-fit: cover; border-radius: 8px; display: block; background: var(--panel); }
.thumb-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; padding: 0; border-radius: 50%; background: rgba(0, 0, 0, .7); color: #fff; font-size: 11px; }

/* 운영자 화면 */
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.tabs.inline { display: inline-flex; margin-bottom: 14px; flex-wrap: wrap; }
.tab { background: transparent; color: var(--sub); padding: 7px 14px; }
.tab.on { background: var(--panel-2); color: var(--text); font-weight: 600; }
.users td { font-size: 14px; overflow-wrap: anywhere; }
.board h3 { font-size: 15px; margin: 22px 0 10px; }
.room-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.room-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.room-row > .input { flex: 1 1 140px; width: auto; min-width: 120px; }
.room-row .field.inline .input { width: auto; }
.room-row .check { min-width: 124px; }
.room-row.add { margin-bottom: 10px; }
.room-move { display: flex; flex-direction: column; }
.room-move button { padding: 0 6px; line-height: 1.2; }

.search { display: flex; gap: 8px; margin-bottom: 14px; }
.search .input { flex: 1; min-width: 0; }
button.page { background: transparent; }
.act { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.act h3 { font-size: 14px; }
.act .input { width: auto; }
.act > .input { width: 100%; }
.temp-pw { display: block; text-align: center; font: 600 24px/1.4 ui-monospace, Consolas, monospace; letter-spacing: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px; user-select: all; }

/* 창 */
.dialog { max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: calc(100% - 32px); max-width: 380px; }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlg { position: relative; padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { font-size: 18px; }
.dlg-x { position: absolute; top: 10px; right: 10px; font-size: 20px; line-height: 1; }
.dlg .tabs { margin-right: 36px; }
.dlg-msg { line-height: 1.6; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.info dt { color: var(--sub); font-size: 13px; }
.info dd { margin: 0; overflow-wrap: anywhere; }

.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); display: grid; place-items: center; cursor: zoom-out; z-index: 40; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: #000; color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 13px; z-index: 50; max-width: calc(100% - 32px); }

/* 모바일 */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: block; }
  .side { position: fixed; inset: 0 auto 0 0; width: 264px; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .head { padding: 10px 12px; }
  .board, .post, .write { padding: 14px 16px; }
  .messages, .composer, .preview { padding-left: 16px; padding-right: 16px; }
  .msg { max-width: 88%; }
  .msg-del { opacity: 1; }
  /* 아이폰은 글자 크기가 16px 보다 작은 입력칸을 누르면 화면을 확대하므로 16px 로 맞춤 */
  input, textarea, select, .input, .field > .input { font-size: 16px; }
  /* 손가락으로 누르기 쉽게 */
  .item { padding: 12px 10px; }
  .small { padding: 8px 12px; }
  .posts td { padding: 12px 10px; }
  .head { padding-top: calc(10px + env(safe-area-inset-top)); }
  .view:not(.chat) { padding-bottom: env(safe-area-inset-bottom); }
  .room-row > .input { flex-basis: 100%; }
  .comment-form { flex-direction: column; align-items: stretch; }
  .posts .c-no, .posts .c-author, .posts .c-date { display: none; }
  .c-meta-mobile { display: block; }
  .users { display: block; overflow-x: auto; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }
