:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --danger: #d92d20;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- 공통 ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; transition: background .12s, border-color .12s;
}
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a5fd0; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef0f3; }
.btn.danger { color: var(--danger); border-color: #f3c9c5; background: #fff5f4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 120px; line-height: 1.6; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.badge {
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center; font-weight: 600;
}
.chip {
  display: inline-block; background: #eef1f5; color: var(--muted);
  border-radius: 999px; padding: 2px 9px; font-size: 12px;
}
.chip.warn { background: #fff4e5; color: #a35b00; margin-left: 4px; }

/* ---------- 로그인 ---------- */
.login-wrap {
  display: grid; place-items: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
  min-height: 100dvh;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- 레이아웃 ---------- */
/* 휴대폰 주소창이 나타났다 사라지면 100vh 가 실제 보이는 높이와 어긋나 하단이 잘린다.
   dvh 를 쓰면 실제 표시 영역에 맞춰지고, 지원하지 않는 구형 브라우저는 vh 로 동작한다. */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0;
  height: 100vh;
  height: 100dvh;
}
/* 홈 화면 앱(standalone)에서는 브라우저 막대가 없어 콘텐츠가 노치·홈 인디케이터
   영역까지 깔린다. 위아래 안전영역만큼 밀어준다. 데스크톱에서는 env() 가 0 이라 영향 없음. */
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  padding-top: calc(18px + env(safe-area-inset-top, 0px));
}
.brand .logo {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand b { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; }

.nav { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 10px 16px; }
.nav-head {
  display: flex; align-items: center; gap: 6px; padding: 12px 8px 6px;
  font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em;
}
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; background: transparent; border-radius: 8px;
  cursor: pointer; color: var(--text); font-size: 14px;
}
.nav-item:hover { background: #f2f4f7; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ic { width: 20px; text-align: center; }
.nav-item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .lock { font-size: 11px; opacity: .55; flex: none; }
/* 아이폰 홈 인디케이터에 가리지 않도록 하단 안전영역만큼 더 띄운다. */
.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  flex: none;
  background: var(--panel);
}
.brand { flex: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { margin: 0; font-size: 17px; }
.hamburger { display: none; }
.search { flex: 1; max-width: 320px; }
.icon-btn {
  position: relative; border: 0; background: transparent; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; font-size: 18px;
}
.icon-btn:hover { background: #f0f2f5; }
.icon-btn .badge { position: absolute; top: 2px; right: 2px; }
.content { padding: 20px; max-width: 900px; width: 100%; margin: 0 auto; }

/* ---------- 글 목록 ---------- */
.post-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 10px; cursor: pointer; box-shadow: var(--shadow);
}
.post-card:hover { border-color: #cfd6de; }
.post-card h3 { margin: 0 0 6px; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.post-card .excerpt { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none;
}
.pin { color: #e08600; }

/* ---------- 글 상세 ---------- */
.detail { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.detail h1 { margin: 0 0 12px; font-size: 21px; line-height: 1.4; }
.detail .body { white-space: pre-wrap; word-break: break-word; margin: 18px 0; }
.detail .body img { max-width: 100%; border-radius: 8px; }
.hr { height: 1px; background: var(--border); margin: 18px 0; }

.files { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.file {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: #f7f8fa; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.file .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.comment { display: flex; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border); }
.comment .c-body { flex: 1; min-width: 0; }
.comment .c-head { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 3px; }
.comment .c-text { white-space: pre-wrap; word-break: break-word; }
.comment-form { margin-top: 14px; }

.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.attach-pill { display: flex; align-items: center; gap: 6px; background: #eef1f5; border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 12px; }
.attach-pill button { border: 0; background: transparent; cursor: pointer; color: var(--muted); }

/* ---------- 알림 패널 ---------- */
.dropdown {
  position: absolute; right: 12px; top: 56px; width: min(360px, calc(100vw - 24px));
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16,24,40,.14); z-index: 60; overflow: hidden;
}
.dropdown .dd-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; }
.dropdown .dd-list { max-height: 60vh; overflow-y: auto; }
.noti { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid #f1f3f5; }
.noti:hover { background: #f7f8fa; }
.noti.unread { background: #f4f8ff; }
.noti .t { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.noti .b { font-size: 13px; color: var(--muted); }
.noti .d { font-size: 11px; color: #9aa2ae; margin-top: 3px; }

/* ---------- 모달 ---------- */
.overlay { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; padding: 16px; z-index: 100; }
.modal { background: var(--panel); border-radius: 14px; width: min(640px, 100%); max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------- 표 ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 14px; font-size: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { background: #f7f8fa; border-radius: 10px; padding: 14px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.bar { height: 8px; background: #eef1f5; border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* ---------- 토스트 ---------- */
#toast-root { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1b1f24; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }

/* ---------- 모바일 ---------- */
.backdrop { display: none; }
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 90; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.15);
    /* 화면 폭이 좁은 기기에서 사이드바가 화면을 다 덮지 않도록 */
    width: min(var(--sidebar-w), 84vw);
    flex-basis: min(var(--sidebar-w), 84vw);
  }
  .sidebar.open { transform: none; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; }
  .hamburger { display: grid; }
  .content { padding: 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .search { max-width: none; }
  .topbar h2 { font-size: 15px; }
  /* 주소창 아래로 토스트가 숨지 않게 */
  #toast-root { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
  /* 모달이 화면을 넘겨 버튼을 못 누르는 일이 없도록 */
  .modal { max-height: calc(100dvh - 32px); }
  .modal-actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 12px; }
}

/* 세로가 아주 짧은 기기(작은 폰 가로 보기 등)에서는 사이드바 항목을 촘촘하게 */
@media (max-height: 620px) {
  .brand { padding: 12px 18px 8px; }
  .nav-item { padding: 6px 10px; }
  .nav-head { padding: 8px 8px 4px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a; --panel: #1c2024; --border: #2b3138; --text: #e6e9ec;
    --muted: #9aa4b0; --accent: #549cff; --accent-soft: #1d2b42;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
  .btn:hover, .btn.ghost:hover, .icon-btn:hover, .nav-item:hover { background: #262c33; }
  .input, .file, .stat, table.tbl th { background: #23282e; }
  .attach-pill, .chip { background: #262c33; }
  .noti:hover { background: #23282e; }
  .noti.unread { background: #1d2b42; }
  .noti { border-bottom-color: #23282e; }
  .btn.danger { background: #2b1b1b; border-color: #5a2b2b; color: #ff8a80; }
  .chip.warn { background: #3a2a12; color: #ffbf6b; }
  .bar { background: #2b3138; }
}
