/* Default (Light Theme) */
:root,
:root[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  /* Semantic Text Colors */
  --text-main: #1f2328;
  --text-sub: #57606a;
  --text-disabled: #8c959f;
  --text: var(--text-main);
  --text-muted: var(--text-sub);

  --accent: #0969da;
  --accent-hover: #0550ae;
  --success: #1a7f37;
  --border: #d0d7de;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 8px rgba(0, 0, 0, 0.02);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08), 0 8px 16px rgba(0, 0, 0, 0.04);
  --font: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  /* Category Colors (Light) */
  --cat-sales: #fff8c5;
  --cat-sales-text: #7d4e00;
  --cat-design: #ffebe9;
  --cat-design-text: #a40e26;
  --cat-elec: #dafbe1;
  --cat-elec-text: #116329;
  --cat-manu: #ddf4ff;
  --cat-manu-text: #0969da;
  --cat-trouble: #fff0f7;
  --cat-trouble-text: #bf3989;
  --cat-minutes: #f0f1fa;
  --cat-minutes-text: #212529;
  --cat-memo: #f6f8fa;
  --cat-memo-text: #656d76;
  --cat-other: #f6f8fa;
  --cat-other-text: #656d76;
}

/* Dark Theme (via OS preference OR manual override) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-card: #161b22;
    --bg-input: #0d1117;
    --text-main: #c9d1d9;
    --text-sub: #8b949e;
    --text-disabled: #484f58;
    --text: var(--text-main);
    --text-muted: var(--text-sub);
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --success: #2ea043;
    --border: #30363d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.6);

    /* Category Colors (Dark) */
    --cat-sales: rgba(210, 153, 34, 0.15);
    --cat-sales-text: #e3b341;
    --cat-design: rgba(248, 81, 73, 0.1);
    --cat-design-text: #ff7b72;
    --cat-elec: rgba(46, 160, 67, 0.15);
    --cat-elec-text: #3fb950;
    --cat-manu: rgba(56, 139, 253, 0.1);
    --cat-manu-text: #79c0ff;
    --cat-trouble: rgba(191, 57, 137, 0.15);
    --cat-trouble-text: #ff80ab;
    --cat-minutes: rgba(110, 118, 129, 0.1);
    --cat-minutes-text: #8b949e;
    --cat-memo: rgba(110, 118, 129, 0.1);
    --cat-memo-text: #8b949e;
    --cat-other: rgba(110, 118, 129, 0.1);
    --cat-other-text: #8b949e;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-input: #0d1117;
  --text-main: #c9d1d9;
  --text-sub: #8b949e;
  --text-disabled: #484f58;
  --text: var(--text-main);
  --text-muted: var(--text-sub);
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --success: #2ea043;
  --border: #30363d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.6);

  /* Category Colors (Dark) */
  --cat-sales: rgba(210, 153, 34, 0.15);
  --cat-sales-text: #e3b341;
  --cat-design: rgba(248, 81, 73, 0.1);
  --cat-design-text: #ff7b72;
  --cat-elec: rgba(46, 160, 67, 0.15);
  --cat-elec-text: #3fb950;
  --cat-manu: rgba(56, 139, 253, 0.1);
  --cat-manu-text: #79c0ff;
  --cat-trouble: rgba(191, 57, 137, 0.15);
  --cat-trouble-text: #ff80ab;
  --cat-minutes: rgba(110, 118, 129, 0.1);
  --cat-minutes-text: #8b949e;
  --cat-memo: rgba(110, 118, 129, 0.1);
  --cat-memo-text: #8b949e;
  --cat-other: rgba(110, 118, 129, 0.1);
  --cat-other-text: #8b949e;
}

* {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

.header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1rem;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
  flex-wrap: wrap;
  box-sizing: border-box;
}


.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.sidebar-toggle:hover {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent);
}

.logo {
  font-size: 1.35rem;
  /* Increased size */
  font-weight: 800;
  /* Bolder for professional look */
  color: var(--text-main);
  text-decoration: none;
  letter-spacing: -0.02em;
  transition: color 0.2s;
}

.logo:hover {
  color: var(--accent);
}

.search-form {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  max-width: 500px;
}

.search-form input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.95rem;
  transition: all 0.2s;
}

.search-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--primary-muted);
  /* More subtle focus ring if primary-muted existed, using rgba for now */
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.1);
}

.search-form input::placeholder {
  color: var(--text-disabled);
}

.search-form button {
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  align-self: center;
  flex-shrink: 0;
}

.header nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-shrink: 0;
}

.header nav a:not(.btn),
.header nav .nav-link {
  color: var(--text-sub);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: color 0.2s;
}

.header nav a:hover,
.header nav .nav-link:hover {
  color: var(--accent);
}

.mobile-text {
  display: none;
}

.desktop-text {
  display: inline;
}

.mobile-nav {
  display: none;
}

.mobile-only-nav {
  display: none;
}

.theme-select {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.2s;
}

.theme-select:hover {
  border-color: var(--accent);
}

.link-button {
  background: transparent;
  border: none;
  color: var(--text-sub);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  padding: 0;
  transition: color 0.2s;
}

.link-button:hover {
  color: var(--accent);
}

.user-chip {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.8rem;
  color: var(--text-sub);
  font-size: 0.88rem;
  font-weight: 500;
}

.card-subcategory,
.badge-subcategory {
  display: inline-flex;
  align-items: center;
  background: rgba(9, 105, 218, 0.05);
  border: 1px solid rgba(9, 105, 218, 0.15);
  color: var(--accent);
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-weight: 600;
  vertical-align: middle;
  line-height: 1;
  box-sizing: border-box;
  height: 24px;
}

.card-subcategory {
  margin-left: 0.25rem;
}

.badge-subcategory {
  margin-left: 0.5rem;
}

/* card-link moved to components section */

.btn {
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.mobile-only-btn {
  display: none;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.btn:active {
  transform: translateY(0);
}

.layout-wrapper {
  display: flex;
  flex: 1;
  max-width: 3600px;
  margin: 0 auto;
  width: 100%;
  gap: 2rem;
  padding: 0 0.6px;
}

.main {
  flex: 1;
  padding: 1.5rem 0;
  max-width: 100%;
  margin: 0;
  width: 100%;
  min-width: 0;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  padding: 2rem 0;
  position: sticky;
  top: var(--header-h, 52px);
  height: calc(100vh - var(--header-h, 52px));
  overflow-y: auto;
  transition: transform 0.3s ease, visibility 0.3s;
}

/* Mobile Responsiveness */
/* --- Breakpoints for Space Efficiency --- */
@media (max-width: 1100px) {
  .layout-wrapper {
    gap: 1.5rem;
  }
}

/* 768px〜1024px の中間幅でヘッダーが崩れる問題を修正 */
@media (max-width: 1024px) and (min-width: 769px) {
  .header-inner {
    gap: 0.5rem;
    flex-wrap: nowrap;
    align-items: center;
  }

  /* 検索フォームを縮められるようにする（過剰伸縮を防止） */
  .search-form {
    flex: 0 1 180px;
    min-width: 0;
    max-width: 180px;
  }

  /* 検索ボタンの縦伸びを防止 */
  .search-form button {
    height: 36px;
    padding: 0 0.75rem;
    white-space: nowrap;
  }

  /* desktop-navが押しつぶされないよう保護 */
  .header nav.desktop-nav {
    flex-shrink: 0;
    gap: 0.5rem;
    overflow: visible;
  }

  .header nav a:not(.btn),
  .header nav .nav-link {
    font-size: 0.82rem;
  }

  /* 通知ラッパーのインラインスタイルを上書き */
  .notification-wrapper {
    margin-right: 0 !important;
  }

  /* ロゴの縮小 */
  .logo {
    font-size: 1.1rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* 記事作成ボタンを縮小 */
  .btn-new-article {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
}

/* デフォルトでアイコンのみ表示用を非表示 */
.nav-icon-only {
  display: none;
}

/* 900px以下でナビリンクのテキスト部分を省略して幅を節約（アイコンのみ表示） */
@media (max-width: 900px) and (min-width: 769px) {
  .search-form {
    flex: 0 1 180px;
    max-width: 180px;
  }

  /* ナビリンクのテキストを非表示にしてアイコンだけにする */
  .header nav .nav-text {
    display: none;
  }

  /* ログアウトのアイコン表示 */
  .nav-icon-only {
    display: inline;
  }

  /* ナビリンクの間隔を縮小 */
  .header nav.desktop-nav {
    gap: 0.3rem;
  }

  /* ユーザーチップを縮小 */
  .user-chip {
    padding: 0.15rem 0.5rem;
    font-size: 0.8rem;
  }
}


@media (max-width: 1024px) {
  .layout-wrapper {
    padding: 0 0.6px;
  }

  .main {
    padding: 1rem 0;
  }

  .wiki-page {
    padding: 1rem !important;
  }

  .thread-article-card {
    padding: 1rem !important;
  }

  .thread-card-header {
    margin-bottom: 0.6rem !important;
    padding-bottom: 0.6rem !important;
  }
}

@media (max-width: 768px) {

  /* ===== ヘッダー: コンパクトに ===== */
  .header-inner {
    padding: 0.2rem 0.4rem;
    gap: 0.3rem;
    flex-wrap: nowrap;
    /* Keep it in one row locally if possible, or wrap only search */
  }

  .logo {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    margin-right: auto;
  }

  .mobile-nav {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-left: 0.25rem;
  }

  .mobile-nav .nav-link {
    font-size: 1.1rem;
    text-decoration: none;
  }

  .notif-badge-mini {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #cf222e;
    color: white;
    border-radius: 50%;
    padding: 2px 4px;
    font-size: 0.65rem;
    line-height: 1;
    font-weight: bold;
    pointer-events: none;
  }

  .sidebar-toggle {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    background: var(--bg-card);
    z-index: 2000;
    padding: 2rem 1.5rem;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
    transform: translateX(-100%);
    visibility: hidden;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }

  body.sidebar-open::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1500;
    backdrop-filter: blur(2px);
  }

  /* ===== レイアウト: 左右余白を最小化 ===== */
  .layout-wrapper {
    padding: 0;
  }

  .main {
    padding: 0.5rem 0.25rem;
  }

  /* ===== ナビゲーション ===== */
  .desktop-nav {
    display: none !important;
  }

  .mobile-only-nav {
    display: block;
  }

  .btn-new-article {
    display: none !important;
  }

  .desktop-text {
    display: none;
  }

  .mobile-text {
    display: inline;
  }

  .mobile-only-btn {
    display: inline-flex;
  }

  .search-form {
    flex: 1;
    min-width: 0;
    margin-top: 0;
    max-width: none;
    order: 0;
    /* Put it between logo and settings */
  }

  .search-form input {
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
  }

  .search-form button {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
  }

  /* ===== ページ一覧: タイトル行 ===== */
  .page-list-header {
    gap: 0.5rem;
    margin-bottom: 0.25rem;
  }

  .page-list-header h1 {
    font-size: 1.2rem;
  }

  .btn-large {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }

  /* ===== カードグリッド: 枠なし・詰めてリスト風に ===== */
  .cards {
    gap: 0;
    margin-top: 0.75rem;
  }

  .card-link {
    gap: 0.75rem;
    padding: 0.7rem 0.25rem;
    min-height: auto;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
    background: transparent;
  }

  .card-link:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--border);
    background: var(--bg-card);
  }

  .card-thumb {
    width: 56px;
    height: 44px;
    border-radius: 6px;
  }

  .card-body {
    gap: 0.2rem;
  }

  .card-title {
    font-size: 0.9rem;
  }

  .card-tags {
    gap: 0.3rem;
    margin-bottom: 0;
  }

  .card-category,
  .badge-category {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    height: 20px;
  }

  .card-subcategory,
  .badge-subcategory {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    height: 18px;
  }

  .card-pin {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    height: 18px;
  }

  .card-preview {
    font-size: 0.8rem;
    -webkit-line-clamp: 1;
    line-clamp: 1;
  }

  .card-meta {
    font-size: 0.75rem;
  }

  /* ===== ウィキページ（記事閲覧）: フルブリード ===== */
  .wiki-page {
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  .page-actions h1 {
    font-size: 1.3rem;
  }

  .action-buttons {
    gap: 0.35rem;
  }

  .action-buttons .btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
  }

  .wiki-content {
    font-size: 0.95rem;
    padding: 0;
  }

  .wiki-content p,
  .wiki-content ul,
  .wiki-content ol {
    margin: 0.5em 0;
  }

  .wiki-content h1,
  .wiki-content h2,
  .wiki-content h3 {
    margin-top: 1em;
    margin-bottom: 0.4em;
  }

  .wiki-content pre {
    padding: 0.75rem;
    font-size: 0.85rem;
    border-radius: 6px;
  }

  .wiki-toc {
    padding: 0.75rem;
    margin-bottom: 1rem;
  }

  .wiki-meta {
    font-size: 0.8rem;
    margin-top: 1rem;
  }

  /* ===== リアクション ===== */
  .page-reactions {
    gap: 0.4rem;
    margin: 1rem 0;
  }

  .text-reaction-btn {
    padding: 0.2rem 0.6rem;
    font-size: 0.8rem;
  }

  /* ===== 添付・履歴・被リンク ===== */
  .attachments-section,
  .history-section,
  .backlinks-section {
    margin-top: 1rem;
    padding-top: 0.75rem;
  }

  .attachments-section h2,
  .history-section h2,
  .backlinks-section h2 {
    font-size: 0.95rem;
  }

  .history-list li {
    grid-template-columns: 1fr;
    gap: 0.2rem;
    padding: 0.4rem 0.5rem;
    font-size: 0.82rem;
  }

  .history-list li .history-time {
    font-size: 0.75rem;
  }

  /* ===== 編集ページ ===== */
  .edit-page h1 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
  }

  .edit-form .form-group {
    margin-bottom: 1rem;
  }

  .edit-form label {
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
  }

  .edit-form input[type="text"],
  .edit-form input[type="password"] {
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
  }

  .edit-form textarea {
    padding: 0.75rem;
    font-size: 0.9rem;
  }

  .edit-toolbar {
    gap: 0.25rem;
  }

  .edit-toolbar button {
    padding: 0.3rem 0.45rem;
    font-size: 0.78rem;
  }

  .hint {
    font-size: 0.78rem;
  }

  .form-actions {
    gap: 0.5rem;
    margin-top: 1rem;
  }

  .drop-zone {
    padding: 1rem;
    margin-top: 0.5rem;
  }

  .edit-form select {
    min-width: 0;
    width: 100%;
  }

  /* ===== 目次 ===== */
  .wiki-toc ul {
    padding-left: 0.75rem;
  }

  .wiki-toc a {
    font-size: 0.85rem;
  }

  /* ===== スレッドタイムライン ===== */
  .thread-timeline {
    margin-top: 1.5rem;
    padding-top: 1rem;
  }

  .thread-title {
    font-size: 1.1rem;
    margin-bottom: 1rem;
  }

  .timeline-item {
    gap: 0.5rem;
    padding-bottom: 1rem;
  }

  .timeline-content {
    padding: 0.6rem;
  }

  .timeline-meta {
    font-size: 0.75rem;
  }

  .timeline-title {
    font-size: 0.95rem;
  }

  .timeline-preview {
    font-size: 0.82rem;
  }

  /* ===== スレッド展開記事 ===== */
  .thread-expanded-articles {
    margin-top: 1.5rem;
  }

  .thread-article-card {
    padding: 0.5rem 0;
    margin-bottom: 0;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
    background: transparent;
  }

  .thread-article-card:hover {
    box-shadow: none;
  }

  .thread-article-card.current-article {
    border: none;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
    background: rgba(9, 105, 218, 0.03);
    padding: 0.5rem 0.25rem;
  }

  .thread-article-card.current-article::before {
    display: none;
  }

  /* ===== ユーザーチップ ===== */
  .user-chip {
    padding: 0.15rem 0.5rem;
    font-size: 0.8rem;
  }

  /* ===== ページカテゴリバッジ ===== */
  .page-category {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    height: 20px;
  }

  /* ===== フッター ===== */
  .footer {
    padding: 0.5rem;
    font-size: 0.8rem;
  }

  /* ===== エラーページ ===== */
  .error-page {
    padding: 2rem 0;
  }

  .error-page h1 {
    font-size: 3rem;
  }

  /* ===== 認証ページ ===== */
  .auth-card {
    padding: 1rem;
    border-radius: 8px;
  }

  /* ===== カテゴリタブ ===== */
  .category-tabs {
    margin: 0.5rem 0 1rem;
  }

  .category-tabs .tab {
    padding: 0.35rem 0.7rem;
    font-size: 0.82rem;
  }

  /* ===== 差分表示 ===== */
  .diff-container {
    gap: 0.5rem;
  }

  .diff-content {
    padding: 0.5rem;
    font-size: 0.8rem;
  }

  /* ===== ページアクション/ヘッダーの圧縮 ===== */
  .page-actions {
    margin-bottom: 0.5rem;
  }

  .page-actions h1 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
  }

  .page-meta-info {
    font-size: 0.75rem !important;
    gap: 0.4rem 0.75rem !important;
    margin-bottom: 0.5rem;
  }

  .page-badges {
    margin-bottom: 0.2rem !important;
    min-height: 20px !important;
  }

  /* ===== QRモーダル ===== */
  .qr-modal-inner {
    padding: 1rem;
    margin: 0 1rem;
  }

  /* ===== スレッド展開記事の詳細制御 (Mobile) ===== */
  .thread-section-header {
    margin-bottom: 0.75rem;
  }

  .btn-compact-mobile {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
  }

  .thread-card-header {
    margin-bottom: 0.4rem;
    padding-bottom: 0.4rem;
  }

  .thread-card-header h3 {
    font-size: 1.05rem;
    margin-bottom: 0.2rem;
  }

  .thread-card-meta {
    font-size: 0.72rem;
    gap: 0.5rem;
  }
}

/* custom scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.sidebar-section {
  margin-bottom: 2rem;
}

.sidebar-section h3 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding: 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 0.45rem 0.65rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-size: 0.93rem;
  margin-bottom: 0.15rem;
  border: 1px solid transparent;
}

.sidebar-link:hover {
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.sidebar-link.active {
  background: var(--accent-light);
  color: var(--accent);
  border-left: 3px solid var(--accent);
  font-weight: 600;
}

.sidebar-accordion {
  list-style: none;
}

.sidebar-accordion summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-accordion summary::-webkit-details-marker {
  display: none;
}

.sidebar-accordion summary:focus {
  outline: none;
}

.sidebar-accordion .chevron {
  transition: transform 0.2s ease;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sidebar-accordion[open] .chevron {
  transform: rotate(180deg);
}

.sidebar-submenu {
  list-style: none;
  padding: 0.25rem 0 0.5rem 1.25rem;
  margin: 0;
}

.sidebar-sublink {
  display: block;
  padding: 0.35rem 0.65rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.sidebar-sublink:hover {
  background: var(--bg);
  color: var(--accent);
  padding-left: 0.85rem;
}

.sidebar-sublink.active {
  color: var(--accent);
  font-weight: 600;
  background: var(--bg-card);
}

.sidebar-empty {
  padding: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.wiki-page {
  margin-top: 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.page-list h1,
.search-results h1,
.edit-page h1 {
  margin-top: 0;
}

.page-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.page-list-header h1 {
  margin: 0;
}

.category-tabs {
  display: flex;
  gap: 0.25rem;
  margin: 1rem 0 1.5rem;
  flex-wrap: wrap;
}

.category-tabs .tab {
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.category-tabs .tab:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(9, 105, 218, 0.04);
}

.category-tabs .tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.cards {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 600px), 1fr));
  align-items: stretch;
}

.cards li {
  margin: 0;
}

.card-link {
  display: flex;
  gap: 1.25rem;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-main);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow);
  min-height: 110px;
  height: 100%;
}

.card-link:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
  transform: translateY(-3px);
}

.card-thumb {
  flex-shrink: 0;
  width: 120px;
  height: 85px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.card-thumb.placeholder::after {
  content: attr(data-letter);
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  opacity: 0.8;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.card-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.1rem;
}

.card-category,
.badge-category {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  background: var(--bg);
  border-radius: 4px;
  color: var(--text-sub);
  line-height: 1.2;
  box-sizing: border-box;
  height: 24px;
}

.page-category {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  margin-right: 0.25rem;
  line-height: 1;
  box-sizing: border-box;
  height: 24px;
  font-weight: 600;
  vertical-align: middle;
}

.cat-sales {
  background: var(--cat-sales);
  color: var(--cat-sales-text);
  font-weight: 500;
  border: 1px solid rgba(210, 153, 34, 0.3);
}

.cat-design {
  background: var(--cat-design);
  color: var(--cat-design-text);
  font-weight: 500;
  border: 1px solid rgba(248, 81, 73, 0.3);
}

.cat-elec {
  background: var(--cat-elec);
  color: var(--cat-elec-text);
  font-weight: 500;
  border: 1px solid rgba(46, 160, 67, 0.3);
}

.cat-manu {
  background: var(--cat-manu);
  color: var(--cat-manu-text);
  font-weight: 500;
  border: 1px solid rgba(56, 139, 253, 0.3);
}

.cat-trouble {
  background: var(--cat-trouble);
  color: var(--cat-trouble-text);
  font-weight: 500;
  border: 1px solid rgba(191, 57, 137, 0.3);
}

.cat-minutes {
  background: var(--cat-minutes);
  color: var(--cat-minutes-text);
  font-weight: 500;
  border: 1px solid rgba(110, 118, 129, 0.3);
}

.cat-memo {
  background: var(--cat-memo);
  color: var(--cat-memo-text);
  font-weight: 500;
  border: 1px solid rgba(110, 118, 129, 0.3);
}

.cat-other {
  background: var(--cat-other);
  color: var(--cat-other-text);
  font-weight: 500;
  border: 1px solid rgba(110, 118, 129, 0.3);
}






.card-pin {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  background: rgba(9, 105, 218, 0.1);
  border: 1px solid rgba(9, 105, 218, 0.15);
  border-radius: 4px;
  color: var(--accent);
  font-weight: 600;
  line-height: 1;
  box-sizing: border-box;
  height: 24px;
  vertical-align: middle;
}

.card-title {
  font-weight: 600;
  display: block;
  font-size: 1rem;
  word-break: break-word;
  overflow-wrap: break-word;
}

.card-preview {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.new-link {
  margin-top: 1.5rem;
}

.new-link a {
  color: var(--accent);
}


.empty {
  color: var(--text-muted);
  margin: 1.5rem 0;
}

.empty a {
  color: var(--accent);
}

.page-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.page-actions h1 {
  margin: 0;
  word-break: break-word;
  overflow-wrap: break-word;
}

.action-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.btn-mini {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  height: auto;
  min-height: 0;
}

.inline-form {
  margin: 0;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  display: inline-block;
}

.btn-edit {
  background: var(--accent);
  color: #fff;
}

.btn-edit:hover {
  background: var(--accent-hover);
}

.btn-pin {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-pin:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: var(--success);
  color: #ffffff !important;
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 0 3px rgba(46, 160, 67, 0.2);
}

.btn-cancel {
  background: var(--bg-input);
  color: var(--text-muted);
}

.btn-cancel:hover {
  color: var(--text);
}

.btn-danger {
  background: #da3633;
  color: #fff;
}

.btn-danger:hover {
  filter: brightness(1.1);
}

.btn-large {
  padding: 0.6rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.text-reaction-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.text-reaction-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface-hover);
}

.text-reaction-btn.reacted {
  background: rgba(9, 105, 218, 0.1);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: bold;
}

.wiki-content {
  padding: 1rem 0;
  font-size: 1rem;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.wiki-content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.wiki-content th,
.wiki-content td {
  border: 1px solid var(--border);
  padding: 0.5rem;
}

.wiki-content h1,
.wiki-content h2,
.wiki-content h3 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.wiki-content h1 {
  font-size: 1.5rem;
}

.wiki-content h2 {
  font-size: 1.25rem;
}

.wiki-content p {
  margin: 0.75em 0;
}

.wiki-content ul,
.wiki-content ol {
  margin: 0.75em 0;
  padding-left: 1.5em;
}

.wiki-content code {
  background: rgba(0, 0, 0, 0.06);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.wiki-content pre {
  background: rgba(0, 0, 0, 0.04);
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  border: 1px solid var(--border);
}

.wiki-content pre code {
  padding: 0;
  background: none;
}

.wiki-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.wiki-content a {
  color: var(--accent);
  text-decoration: none;
}

.wiki-content a:hover {
  text-decoration: underline;
}

.wiki-content a[href^="file:"]::after {
  content: " 📁";
  font-size: 0.85em;
}

.wiki-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2rem;
}

.attachments-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.attachments-section h2 {
  margin: 0 0 0.8rem;
  font-size: 1.05rem;
}

.attach-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.attachment-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.attachment-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  box-shadow: var(--shadow);
}

.attachment-list a {
  color: var(--accent);
  text-decoration: none;
}

.attachment-list a:hover {
  text-decoration: underline;
}

.history-section {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.history-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
  padding: 0.75rem 1rem;
  background: var(--surface-subtle, #f6f8fa);
  border-radius: 6px;
  transition: background 0.2s ease;
  user-select: none;
}

.history-summary:hover {
  background: var(--surface-hover, #eaeef2);
}

[data-theme="dark"] .history-summary {
  background: var(--surface-subtle, #161b22);
}

[data-theme="dark"] .history-summary:hover {
  background: var(--surface-hover, #21262d);
}

.history-summary::-webkit-details-marker {
  display: none;
}

.history-summary h2 {
  margin: 0;
  font-size: 1.05rem;
}

.history-summary .chevron {
  transition: transform 0.2s ease;
  font-size: 0.8rem;
  color: var(--text-muted);
}

details[open] .history-summary .chevron {
  transform: rotate(180deg);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0 0 0;
  display: grid;
  gap: 0.5rem;
}

.history-list li {
  display: grid;
  grid-template-columns: 180px 56px 80px 1fr auto;
  gap: 0.6rem;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
}

.history-time {
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.history-user {
  color: var(--accent);
  font-size: 0.85rem;
}

.history-action {
  display: inline-block;
  text-align: center;
  background: var(--bg);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
}

.history-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-category {
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
}

.edit-form .form-group {
  margin-bottom: 1.5rem;
}

.edit-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.edit-form select {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
  min-width: 160px;
}

.template-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25em 0.6em;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.category-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.category-chip.selected {
  background: var(--chip-color, var(--accent));
  border-color: var(--chip-color, var(--accent));
  color: var(--chip-text-color, #fff);
}

.category-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.edit-form input[type="text"],
.edit-form input[type="password"] {
  width: 100%;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
}

.edit-form input:focus,
.edit-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(9, 105, 218, 0.12);
}

.edit-form textarea {
  width: 100%;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  resize: vertical;
}

.edit-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.edit-toolbar button {
  padding: 0.4rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.edit-toolbar button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(9, 105, 218, 0.06);
}

.hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.hint code {
  font-size: 0.9em;
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

.drop-zone {
  margin-top: 1rem;
  padding: 1.5rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-muted);
  transition: border-color 0.2s, background 0.2s;
  background: var(--bg);
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(9, 105, 218, 0.06);
}

.error-page {
  text-align: center;
  padding: 3rem 0;
}

.error-page h1 {
  font-size: 4rem;
  margin: 0;
  color: var(--text-muted);
}

.error-page p {
  margin: 1rem 0 1.5rem;
}

.seed-page {
  max-width: 520px;
}

.seed-page h1 {
  margin-top: 0;
}

.seed-desc {
  color: var(--text-muted);
  margin: 1rem 0;
}

.seed-preview {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.seed-info {
  margin: 1rem 0;
}

.seed-form {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

.seed-success {
  background: rgba(26, 127, 55, 0.1);
  border: 1px solid rgba(26, 127, 55, 0.3);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  color: var(--success);
}

.delete-confirm {
  max-width: 480px;
}

.delete-confirm h1 {
  margin-top: 0;
}

.delete-target {
  margin: 1rem 0;
  color: var(--text-muted);
}

.delete-form {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

.wiki-toc {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.wiki-toc h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.wiki-toc ul {
  margin: 0;
  padding-left: 1.25rem;
  list-style: none;
}

.wiki-toc li {
  margin: 0.25rem 0;
}

.wiki-toc li.toc-h3 {
  padding-left: 1rem;
}

.wiki-toc a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.wiki-toc a:hover {
  text-decoration: underline;
}

.edit-content-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.edit-content-row textarea {
  flex: 1;
  min-width: 280px;
}

.preview-pane {
  flex: 1;
  min-width: 280px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: 1rem;
  max-height: 500px;
  overflow-y: auto;
}

.preview-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.preview-content {
  padding: 0;
}

.diff-page {
  max-width: 1200px;
}

.diff-meta {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.diff-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
  .diff-container {
    grid-template-columns: 1fr;
  }
}

.diff-col h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.diff-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
}

.recent-dropdown {
  position: relative;
}

.recent-dropdown .nav-link {
  background: none;
  border: none;
  cursor: pointer;
  font-size: inherit;
  color: inherit;
  padding: 0;
}

.recent-dropdown .nav-link:hover {
  color: var(--accent);
}

.recent-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin: 0.25rem 0 0;
  padding: 0.5rem 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  list-style: none;
  z-index: 100;
}

.recent-list.open {
  display: block;
}

.recent-list li {
  margin: 0;
}

.recent-list a {
  display: block;
  padding: 0.4rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

.recent-list a:hover {
  background: var(--bg);
  color: var(--accent);
}

.recent-list .empty {
  padding: 0.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.qr-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.qr-modal-inner {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow-hover);
}

.qr-modal-inner h3 {
  margin: 0 0 1rem;
}

.qr-modal-inner img {
  display: block;
  margin: 0 auto 1rem;
}

.qr-modal-inner p {
  font-size: 0.85rem;
  word-break: break-all;
  margin-bottom: 1rem;
}

.backlinks-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.backlinks-section h2 {
  margin: 0 0 0.8rem;
  font-size: 1.05rem;
}

.backlinks-list {
  margin: 0;
  padding-left: 1.25rem;
}

.backlinks-list a {
  color: var(--accent);
}

.history-diff-link {
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.wiki-content mark {
  background: #fff3cd;
  padding: 0 0.15em;
  border-radius: 2px;
}

@media print {

  .header,
  .sidebar,
  .action-buttons,
  .page-top-actions,
  .page-reactions,
  .reaction-details,
  .attachments-section,
  .upload-section,
  .history-section,
  .backlinks-section,
  .wiki-toc,
  .thread-timeline,
  .footer,
  .btn,
  .recent-dropdown {
    display: none !important;
  }

  /* Reset layout constraints for full page printing */
  body,
  .layout-wrapper,
  .main,
  .wiki-page {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    border: none !important;
  }

  /* Ensure content expands cleanly */
  .wiki-content {
    page-break-inside: auto;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    page-break-after: avoid;
  }

  table {
    page-break-inside: auto;
  }

  tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  /* Images shouldn't break across pages if possible */
  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }

  /* hide the placeholder of details (history) */
  details {
    display: none !important;
  }
}

.auth-main {
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-hover);
}

.auth-card h1 {
  margin-top: 0;
}

.auth-error {
  color: #cf222e;
  background: rgba(207, 34, 46, 0.08);
  border: 1px solid rgba(207, 34, 46, 0.2);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
}

.footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* Quick Search */
.search-form {
  position: relative;
}

.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-hover);
  margin-top: 0.5rem;
  overflow: hidden;
  display: none;
  z-index: 1000;
}

.suggestion-item {
  display: block;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover {
  background: var(--bg);
}

.suggestion-item .title {
  font-weight: 500;
  display: block;
}



/* Reactions */
.page-reactions {
  display: flex;
  gap: 0.75rem;
  margin: 2rem 0;
  flex-wrap: wrap;
}

/* タイムライン (スレッド表示) */
.thread-timeline {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px dashed var(--border);
}

.thread-title {
  margin-bottom: 1.5rem;
  font-size: 1.4rem;
  color: var(--text-main);
}

.timeline-container {
  display: flex;
  flex-direction: column;
}

.timeline-item {
  display: flex;
  gap: 1rem;
  position: relative;
  padding-bottom: 2rem;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 20px;
}

.timeline-dot {
  width: 14px;
  height: 14px;
  background-color: var(--bg-card);
  border: 3px solid var(--accent);
  border-radius: 50%;
  z-index: 2;
  margin-top: 5px;
}

.timeline-line {
  flex-grow: 1;
  width: 2px;
  background-color: var(--border);
  margin-top: 5px;
}

.timeline-item.current .timeline-dot {
  background-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.2);
}

.timeline-content {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.timeline-item.current .timeline-content {
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
  background: rgba(9, 105, 218, 0.02);
}

.timeline-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.timeline-title {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-main);
  text-decoration: none;
  display: block;
}

.timeline-title:hover {
  text-decoration: underline;
  color: var(--accent);
}

.current-title {
  color: var(--accent);
}

.current-title:hover {
  text-decoration: none;
}

.timeline-preview {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.thread-actions {
  margin-top: 1.5rem;
  text-align: center;
}

.reaction-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  color: var(--text);
}

.reaction-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

.reaction-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.reaction-btn.active .emoji {
  transform: scale(1.2);
}

.reaction-btn .emoji {
  font-size: 1.1rem;
  transition: transform 0.2s;
}

.reaction-btn .count {
  font-size: 0.9rem;
  font-weight: 600;
}


/* --- スレッド展開UI向けスタイル (Desktop/Base) --- */
.thread-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

.thread-section-header h2 {
  font-size: 1.4rem;
}

.thread-expanded-articles {
  margin-top: 2rem;
}

.thread-article-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.thread-article-card:hover {
  box-shadow: var(--shadow-hover);
}

.thread-article-card.current-article {
  border: 2px solid var(--accent);
  box-shadow: 0 4px 12px rgba(9, 105, 218, 0.15);
}

.thread-card-header {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.thread-card-header h3 {
  margin-top: 0;
  margin-bottom: 0.4rem;
  font-size: 1.25rem;
}

.thread-card-header h3 a {
  color: var(--text);
  text-decoration: none;
}

.thread-card-header h3 a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.thread-card-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.thread-card-meta .current-label {
  color: var(--accent);
  font-weight: bold;
  margin-left: auto;
}

.thread-card-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
}

.thread-article-card.current-article::before {
  content: '';
  display: block;
  height: 4px;
  background: var(--accent);
  margin: -1rem -1rem 0.75rem -1rem;
  border-radius: 8px 8px 0 0;
}

/* ダークモード時のスレッド展開における微調整 */
[data-theme="dark"] .thread-article-card {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .thread-article-card.current-article {
  box-shadow: 0 4px 12px rgba(88, 166, 255, 0.2);
}

/* ==========================================
   カレンダーページ
   ========================================== */
.calendar-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.calendar-month-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
}

.calendar-legend {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.created {
  background: #2ea043;
}

.legend-dot.updated {
  background: #0969da;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 1.5rem;
}

.cal-header {
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.5rem 0;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.cal-header.sun {
  color: #cf222e;
}

.cal-header.sat {
  color: #0969da;
}

.cal-day {
  min-height: 60px;
  padding: 0.3rem;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cal-day:hover {
  background: var(--bg);
  border-color: var(--border);
}

.cal-day.active {
  border-color: var(--accent);
  background: rgba(9, 105, 218, 0.06);
  box-shadow: 0 0 0 2px rgba(9, 105, 218, 0.15);
}

.cal-day.holiday {
  background: rgba(248, 81, 73, 0.08);
  border-color: rgba(248, 81, 73, 0.2);
}

.cal-day.holiday .cal-day-num {
  color: var(--danger);
  font-weight: 700;
}

.cal-day.today .cal-day-num {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-day.sun .cal-day-num {
  color: #cf222e;
}

.cal-day.sat .cal-day-num {
  color: #0969da;
}

.cal-day.today .cal-day-num {
  color: #fff;
}

.cal-day.empty {
  cursor: default;
  min-height: 20px;
}

.cal-day-num {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.cal-dots {
  display: flex;
  gap: 3px;
  align-items: center;
  margin-top: auto;
}

.cal-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.cal-dot.created {
  background: #2ea043;
}

.cal-dot.updated {
  background: #0969da;
}

.cal-event-count {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 8px;
  padding: 0 4px;
  line-height: 1.4;
}

.cal-day.has-events {
  background: rgba(46, 160, 67, 0.04);
}

/* Detail Panel */
.calendar-detail {
  border-top: 2px solid var(--border);
  padding-top: 1rem;
}

.calendar-detail h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.cal-detail-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cal-event-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.15s ease;
  flex-wrap: wrap;
}

.cal-event-item:hover {
  border-color: var(--accent);
  background: var(--bg);
  transform: translateX(3px);
}

.cal-event-item.created {
  border-left: 3px solid #2ea043;
}

.cal-event-item.updated {
  border-left: 3px solid #0969da;
}

.cal-event-type {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.cal-event-title {
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-event-cat {
  font-size: 0.75rem;
  background: rgba(9, 105, 218, 0.08);
  border: 1px solid rgba(9, 105, 218, 0.15);
  color: var(--accent);
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
}

.cal-event-author {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Calendar Mobile */
@media (max-width: 768px) {
  .calendar-container {
    padding: 0.5rem;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .calendar-nav {
    gap: 0.5rem;
  }

  .calendar-nav .btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
  }

  .calendar-month-title {
    font-size: 1.1rem;
  }

  .cal-day {
    min-height: 44px;
    padding: 0.2rem;
  }

  .cal-day-num {
    font-size: 0.75rem;
  }

  .cal-event-item {
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
  }
}

/* --- Upload Progress UI --- */
.upload-progress-container {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.upload-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.8rem;
  background-color: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.upload-cancel-btn {
  background: none;
  border: none;
  color: var(--danger, #e74c3c);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.2rem;
}

.upload-cancel-btn:hover {
  text-shadow: 0 0 5px rgba(231, 76, 60, 0.5);
}

/* --- Image Lightbox --- */
.wiki-content img {
  max-width: 400px;
  width: 100%;
  height: auto;
  cursor: zoom-in;
  border-radius: var(--radius);
  transition: transform 0.2s;
}

.wiki-content img:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.wiki-lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
  opacity: 0;
  transition: opacity 0.3s;
}

.wiki-lightbox-overlay.active {
  opacity: 1;
}

.wiki-lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  cursor: default;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 30px;
  color: white;
  font-size: 2rem;
  font-weight: bold;
  cursor: pointer;
  user-select: none;
}