/* ===== モバイルファーストのレスポンシブCSS ===== */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1f2733;
  --muted: #6b7684;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

/* ===== ダークモード（data-theme=dark） ===== */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141a;
  --surface: #1a222c;
  --border: #2c3a47;
  --text: #e6edf3;
  --muted: #8b99a7;
  --primary: #4f8ef7;
  --primary-dark: #69a1ff;
  --danger: #f87171;
}
html[data-theme="dark"] .site-header { background: #131a22; }
html[data-theme="dark"] .bm-title a { color: var(--text); }
html[data-theme="dark"] .bm-notes { color: #c4ced8; }
html[data-theme="dark"] .bm-thumb { background: #16202b; }
html[data-theme="dark"] .tag-chip { background: #1d2a3a; color: #9ec1ff; border-color: #2b3b50; }
html[data-theme="dark"] .tag-chip.mini { background: #223040; color: #9fb0c0; border-color: var(--border); }
html[data-theme="dark"] .search-form input[type=search],
html[data-theme="dark"] .form input,
html[data-theme="dark"] .form textarea,
html[data-theme="dark"] .form select { background: #111820; border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .pager-btn { background: var(--surface); border-color: var(--border); }
html[data-theme="dark"] .progress { background: #223040; }


body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: 900px; margin: 0 auto; padding: 0 14px; }

/* ===== ヘッダー ===== */
.site-header {
  background: var(--text);
  color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.header-inner { display: flex; align-items: center; padding: 10px 14px; }
.brand { color: #fff; font-weight: 700; font-size: 18px; margin-right: auto; }
.theme-toggle {
  background: transparent; border: 1px solid rgba(255,255,255,.25);
  color: #fff; width: 34px; height: 34px; border-radius: 8px;
  cursor: pointer; font-size: 14px; margin-left: 8px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle .tt-sun { display: none; }
html[data-theme="dark"] .theme-toggle .tt-moon { display: none; }
html[data-theme="dark"] .theme-toggle .tt-sun { display: inline; }
.main-nav { display: flex; gap: 14px; align-items: center; font-size: 14px; }
.main-nav a { color: #cfd6e0; padding: 4px 2px; }
.main-nav a.active { color: #fff; font-weight: 600; border-bottom: 2px solid var(--primary); }
.main-nav a.logout-link { color: #fca5a5; }
.nav-toggle { display: none; }

/* ===== メイン ===== */
.main { padding-top: 20px; padding-bottom: 60px; }

/* ===== カード ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 16px 0;
}
.card h1 { margin: 0 0 10px; font-size: 20px; }

/* ===== フォーム ===== */
.form label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form input,
.form textarea,
.form select {
  display: block; width: 100%;
  padding: 11px 12px; margin-top: 4px;
  font-size: 15px; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff;
  font-family: inherit;
}
.form input:focus, .form textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ===== ボタン ===== */
.btn {
  display: inline-block; padding: 10px 18px;
  border: none; border-radius: 8px; cursor: pointer;
  font-size: 15px; font-weight: 600; text-align: center;
  text-decoration: none !important;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 6px 12px; font-size: 13px; margin: -8px 0 14px; display: inline-block; }
.btn-danger { background: var(--danger); color: #fff; }
.linklike { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }

/* ===== ツールバー / 検索 ===== */
.toolbar { margin: 8px 0 14px; }
.search-form { display: flex; gap: 8px; }
.search-form input[type=search] {
  flex: 1; padding: 11px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 8px;
}
.search-form .btn { white-space: nowrap; }

/* ===== タグクラウド ===== */
.tagcloud { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag-chip {
  display: inline-block; padding: 3px 9px; font-size: 13px;
  background: #eef2ff; color: var(--primary); border-radius: 999px;
  border: 1px solid #dbe3ff;
}
.tag-chip.on { background: var(--primary); color: #fff; }
.tag-chip.mini { padding: 1px 7px; font-size: 12px; background: #f1f5f9; color: var(--muted); border-color: var(--border); }

.result-count { font-size: 13px; color: var(--muted); margin: 6px 0; }

/* ===== ツールバー2段目（総数・ソート） ===== */
.toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 10px; }
.total-label { font-size: 13px; color: var(--muted); }
.total-label strong { color: var(--primary); font-size: 15px; }
.sort-nav { display: flex; flex-wrap: wrap; gap: 4px; }
.sort-link {
  padding: 4px 10px; font-size: 12px; border-radius: 999px;
  color: var(--muted); border: 1px solid var(--border);
}
.sort-link.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== 重複チェック ===== */
.dup-group { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.dup-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; word-break: break-all; }
.dup-count { color: var(--danger); font-weight: 700; white-space: nowrap; }
.dup-items { list-style: none; margin: 0; padding: 0; }
.dup-items li { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 4px 0; border-top: 1px dashed var(--border); }
.dup-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== ログ ===== */
.nowrap { white-space: nowrap; }
.log-type { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 11px; background: #eef1f5; color: var(--muted); }
.log-login { background: #e6f7ea; color: #1b7a2e; }
.log-login_fail { background: #fdecec; color: #b91c1c; }
.log-delete, .log-auto_backup_fail { background: #fdecec; color: #b91c1c; }
.log-backup, .log-auto_backup, .log-import { background: #e6f0ff; color: #1d4ed8; }
html[data-theme="dark"] .log-type { background: #223040; color: #9fb0c0; }
html[data-theme="dark"] .log-login { background: #16331e; color: #6fce8c; }
html[data-theme="dark"] .log-login_fail, html[data-theme="dark"] .log-delete, html[data-theme="dark"] .log-auto_backup_fail { background: #3a1a1a; color: #f48b8b; }
html[data-theme="dark"] .log-backup, html[data-theme="dark"] .log-auto_backup, html[data-theme="dark"] .log-import { background: #15283f; color: #8ab8ff; }

.stats-row { display: flex; gap: 20px; margin: 14px 0; }
.stat { text-align: center; }
.stat-num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); }
.bulk-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.progress-wrap { margin-top: 14px; }
.progress { height: 14px; background: #eef1f5; border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.progress-bar { width: 0; height: 100%; background: var(--primary); transition: width .2s; }
.progress-log { font-size: 12px; color: var(--muted); margin-top: 8px; max-height: 180px; overflow-y: auto; }

/* ===== ページネーション ===== */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin: 20px 0 6px; }
.pager-btn, .pager-num {
  min-width: 36px; text-align: center; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--primary); font-size: 14px; font-weight: 600;
}
.pager-btn:hover, .pager-num:hover { background: #eef2ff; text-decoration: none; }
.pager-num.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager-btn.disabled { color: var(--muted); pointer-events: none; opacity: .5; }
.pager-ellipsis { color: var(--muted); padding: 0 2px; }
.pager-jump { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 4px 0 20px; }
.pager-jump input[type=number] { width: 70px; padding: 7px 8px; font-size: 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.pager-total { color: var(--muted); }
html[data-theme="dark"] .pager-btn, html[data-theme="dark"] .pager-num { background: var(--surface); border-color: var(--border); }
html[data-theme="dark"] .pager-btn:hover, html[data-theme="dark"] .pager-num:hover { background: #223040; }
html[data-theme="dark"] .pager-jump input[type=number] { background: #111820; color: var(--text); }

/* ===== ブックマークリスト ===== */
.bm-list { list-style: none; margin: 0; padding: 0; }
.bm-card {
  display: flex;
  gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.bm-thumb {
  flex: 0 0 auto;
  width: 120px; height: 80px;
  border-radius: 8px; overflow: hidden;
  background: #eef1f5; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.bm-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bm-main { flex: 1; min-width: 0; }
.bm-title { margin: 0 0 2px; font-size: 16px; line-height: 1.4; }
.bm-title a { color: var(--text); }
.bm-title a:hover { color: var(--primary); }
.bm-url { font-size: 12px; color: var(--muted); word-break: break-all; margin-bottom: 6px; }
.bm-notes { font-size: 14px; color: #3a4552; margin: 4px 0 8px; white-space: pre-wrap; word-break: break-word; }
.bm-comment { font-size: 13px; color: var(--text); margin: 4px 0 8px; padding: 8px 10px; background: #f7f9fb; border-radius: 8px; border: 1px solid var(--border); }

/* ===== サイト詳細（公開ページ） ===== */
.site-detail { display: flex; gap: 18px; }
.site-detail-thumb { flex: 0 0 auto; width: 200px; height: 140px; border-radius: 10px; overflow: hidden; background: #eef1f5; border: 1px solid var(--border); }
.site-detail-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.site-detail-main { flex: 1; min-width: 0; }
.site-detail-title { margin: 0 0 4px; font-size: 22px; line-height: 1.35; }
.site-detail-title a { color: var(--text); }
.site-detail-tags { margin: 8px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.site-detail-notes { color: #3a4552; margin: 8px 0; }
html[data-theme="dark"] .site-detail-notes { color: #c4ced8; }
.site-detail .bm-url { margin-bottom: 8px; }

/* ===== AI 感想 ===== */
.ai-imp { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
.ai-imp-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.ai-model { color: var(--primary); font-weight: 600; }
.ai-imp-body { font-size: 14px; line-height: 1.7; white-space: pre-wrap; }
.ai-gen { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ai-gen select { padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }

/* ===== フォーム内チェック ===== */
.check-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 400; color: var(--muted); margin: 0; cursor: pointer; }
.check-inline input { width: auto; margin: 0; }


html[data-theme="dark"] .bm-comment { background: #141b24; }
.bm-comment p { margin: 0 0 6px; }
.bm-comment ul, .bm-comment ol { margin: 0 0 6px; padding-left: 20px; }
.bm-comment blockquote { margin: 0 0 6px; padding-left: 10px; border-left: 3px solid var(--primary); }

/* ===== リッチエディタ ===== */
.label-group { margin-bottom: 14px; }
.group-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.rich-editor { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.rich-editor:focus-within { outline: 2px solid var(--primary); }
.rich-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 6px; background: #f6f8fa; border-bottom: 1px solid var(--border); }
html[data-theme="dark"] .rich-toolbar { background: #141b24; }
.rich-toolbar button { min-width: 30px; height: 30px; border: none; background: transparent; border-radius: 6px; font-size: 14px; cursor: pointer; color: var(--text); display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.rich-toolbar button:hover { background: #e4e9ef; }
html[data-theme="dark"] .rich-toolbar button:hover { background: #2a3a4a; }
.rich-spacer { flex: 1; }
.rich-content { min-height: 120px; padding: 12px; outline: none; line-height: 1.7; font-size: 14px; color: var(--text); }
.rich-content:empty::before { content: attr(data-placeholder); color: var(--muted); }
.rich-content p { margin: 0 0 8px; }
.rich-content ul, .rich-content ol { margin: 0 0 8px; padding-left: 22px; }
.rich-content blockquote { margin: 0 0 8px; padding-left: 12px; border-left: 3px solid var(--primary); opacity: .9; }
.emoji-palette { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; background: var(--surface); border-top: 1px solid var(--border); max-height: 160px; overflow-y: auto; }
.emoji-palette[hidden] { display: none; }
.emoji-item { text-align: center; font-size: 18px; padding: 4px 0; cursor: pointer; border-radius: 6px; }
.emoji-item:hover { background: #eef2ff; }
.bm-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px; }
.bm-tags { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.bm-date { color: var(--muted); margin-left: auto; }
.bm-actions { display: inline-flex; gap: 10px; }
.bm-actions .danger { color: var(--danger); }
.muted { color: var(--muted); }

/* ===== フラッシュ ===== */
.flash { padding: 10px 14px; border-radius: 8px; margin: 8px 0; font-size: 14px; }
.flash-success { background: #e6f7ea; color: #1b5e20; border: 1px solid #b7e3c0; }
.flash-error { background: #fdecec; color: #8b1e1e; border: 1px solid #f5c6c6; }
.warning { color: var(--danger); font-size: 13px; }

/* ===== 認証カード ===== */
.auth-card { max-width: 420px; margin: 30px auto; }
.auth-msg { color: var(--muted); margin-top: 0; }

/* ===== テーブル（バックアップ）===== */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); word-break: break-all; }
.table th { color: var(--muted); font-weight: 600; }
.backup-actions { margin: 10px 0; }

hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ===== フッター ===== */
.site-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-bottom: 8px; }
.footer-links a { color: var(--muted); }
.footer-links a:hover { color: var(--primary); }
.footer-copy { color: var(--muted); }

/* ===== サイトマップ ===== */
.map-list { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 24px; }
.map-list li { padding: 4px 0; }
.map-list a { color: var(--text); }
.map-list a:hover { color: var(--primary); }
@media (max-width: 640px) { .map-list { columns: 1; } }

/* ===== ポリシー・ページ（プライバシー等） ===== */
.policy h2 { font-size: 16px; margin: 22px 0 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.policy ol, .policy ul { padding-left: 22px; }
.policy li { margin-bottom: 4px; }
.policy p { line-height: 1.9; }
.policy-updated { color: var(--muted); font-size: 13px; }

/* ===== 受信箱 ===== */
.badge { display: inline-block; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 0 6px; min-width: 16px; text-align: center; }
.inbox-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.inbox-head h1 { margin: 0; }
.msg { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: var(--surface); }
.msg.unread { border-left: 4px solid var(--primary); }
.msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 6px; }
.msg-title { font-weight: 700; }
.msg-mail { color: var(--primary); word-break: break-all; }
.msg-head time { color: var(--muted); margin-left: auto; }
.msg-actions { display: inline-flex; gap: 10px; }
.msg-actions .danger { color: var(--danger); }
.msg-body { font-size: 14px; white-space: pre-wrap; word-break: break-word; color: var(--text); letter-spacing: .02em; }

/* ===== ブックマークレット小窓 ===== */
.bmlet-card { max-width: 520px; }
.bmlet-card .form label { font-weight: 500; }

/* ===== モバイル ===== */
@media (max-width: 640px) {
  .nav-toggle {
    display: inline-block; width: 34px; height: 34px; border: none;
    background: transparent; cursor: pointer; padding: 6px; margin-left: 8px;
  }
  .nav-toggle span { display: block; height: 2px; background: #fff; margin: 5px 0; border-radius: 2px; transition: .2s; }
  .main-nav {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--text); flex-direction: column; align-items: stretch;
    padding: 8px 14px; gap: 2px;
  }
  .main-nav.open { display: flex; }
  .main-nav a { padding: 12px 4px; border-bottom: 1px solid rgba(255,255,255,.08); }
  .search-form { flex-wrap: wrap; }
  .search-form input[type=search] { flex-basis: 100%; }
  .bm-meta { gap: 6px; }
  .bm-date { margin-left: 0; width: 100%; }
  .bm-thumb { width: 88px; height: 62px; }
}
