/* ============================================================
   KBC FAQ管理 — スタイルシート
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --primary      : #3A6B50;
  --primary-dark : #2C5340;
  --primary-light: #E8F2EC;
  --bg           : #F3F1EC;
  --surface      : #FFFFFF;
  --border       : #C8C2B5;
  --text         : #2A3A2B;
  --text-muted   : #6B7A6B;
  --error        : #B03A2E;
  --danger       : #C0392B;
  --danger-light : #FDECEA;
  --radius       : 6px;
  --shadow       : 0 2px 10px rgba(0,0,0,0.10);
  --font         : 'Hiragino Kaku Gothic ProN','Hiragino Sans','Yu Gothic','Meiryo',sans-serif;
}

html, body {
  font-family: var(--font);
  font-size  : 14px;
  color      : var(--text);
  background : var(--bg);
  height     : 100vh;
  overflow   : hidden;
}

/* ── ログイン ──────────────────────────────────────────────── */
body.login-body { display: flex; align-items: center; justify-content: center; }
#auth-screen { display: flex; align-items: center; justify-content: center; width: 100%; }

.auth-box {
  background: var(--surface); border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  padding: 48px 52px 44px; text-align: center; width: 380px;
}
.auth-logo    { max-width: 200px; height: auto; margin-bottom: 16px; }
.auth-subtitle { color: var(--text-muted); font-size: 12px; margin-bottom: 24px; }
.auth-form    { display: flex; flex-direction: column; gap: 10px; }
.auth-error   { color: var(--error); font-size: 12px; margin-top: 10px; }

/* ── ヘッダー ──────────────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px;
  background: var(--primary); color: #fff;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  flex-shrink: 0;
}
.header-left  { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-logo  { height: 34px; width: auto; filter: brightness(0) invert(1); opacity: .9; }
.header-title { font-size: 16px; font-weight: 700; color: #fff; }


.save-indicator {
  font-size: 12px; font-weight: 700; color: #fff;
  background: rgba(255,255,255,.2); padding: 3px 10px; border-radius: 12px;
}

/* ── 二ペインレイアウト ────────────────────────────────────── */
.page-body {
  display: flex;
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ── サイドバー ────────────────────────────────────────────── */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 2px solid var(--border);
  overflow: hidden;
}

.sb-section    { flex-shrink: 0; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.sb-search     {}
.sb-cats       {}
.sb-add        { display: flex; flex-direction: column; gap: 6px; }

.sb-label-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.sb-label { font-size: 11px; font-weight: 700; color: var(--text-muted); }

.cat-filter-group { display: flex; flex-wrap: wrap; gap: 4px; }
.cat-filter-btn {
  padding: 3px 10px; font-size: 11px; font-weight: 600;
  border: 1.5px solid var(--border); border-radius: 20px;
  background: var(--bg); color: var(--text-muted);
  cursor: pointer; font-family: var(--font);
  transition: background .12s, color .12s, border-color .12s;
}
.cat-filter-btn:hover  { border-color: var(--primary); color: var(--primary); }
.cat-filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

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

/* 項目リスト */
.sidebar-list { flex: 1; overflow-y: auto; min-height: 0; }

.item-row {
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; align-items: flex-start;
  gap: 7px; transition: background .1s;
}
.item-row:hover            { background: var(--primary-light); }
.item-row.active           { background: var(--primary); }
.item-row.active .item-row-no,
.item-row.active .item-row-name { color: #fff; }

.item-row-no {
  font-size: 10px; font-weight: 700; color: var(--text-muted);
  white-space: nowrap; flex-shrink: 0; padding-top: 2px; min-width: 30px;
}
.item-row-name {
  font-size: 13px; font-weight: 600; line-height: 1.4;
  color: var(--text); word-break: break-all;
}
.item-row-new .item-row-name { color: var(--primary); font-style: italic; }

.items-empty {
  padding: 24px 16px; text-align: center;
  font-size: 12px; color: var(--text-muted); line-height: 1.8;
}

/* 分類管理セクション */
.cat-manage-section {
  border-top: 2px solid var(--primary);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: 260px;
}
.cat-manage-header {
  padding: 6px 12px; font-size: 11px; font-weight: 700;
  color: var(--primary-dark); background: var(--primary-light); flex-shrink: 0;
}
.cat-manage-list {
  overflow-y: auto; flex: 1; min-height: 0; padding: 2px 0;
}
.cat-manage-row {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-bottom: 1px dotted var(--border);
}
.cat-manage-row:last-child { border-bottom: none; }
.cat-manage-row input[type="text"] { flex: 1; padding: 4px 7px; font-size: 12px; }

.cat-add-row {
  display: flex; gap: 5px; padding: 6px 8px;
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.cat-add-row input { flex: 1; }

/* ── 編集パネル ────────────────────────────────────────────── */
.edit-panel { flex: 1; overflow-y: auto; background: var(--bg); min-width: 0; }

.edit-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%;
  color: var(--text-muted); text-align: center; gap: 14px;
}
.edit-empty p { font-size: 13px; line-height: 1.9; }

.edit-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 2px solid var(--primary);
  background: var(--primary-light);
  position: sticky; top: 0; z-index: 10;
}
.edit-header-left { display: flex; align-items: center; gap: 10px; }
.edit-no {
  font-size: 12px; font-weight: 700; color: var(--primary-dark);
  background: rgba(58,107,80,.15); padding: 3px 10px; border-radius: 4px;
}
.dirty-badge { font-size: 12px; font-weight: 700; color: var(--primary); }

.edit-fields {
  padding: 20px 28px; display: flex; flex-direction: column;
  gap: 20px; max-width: 820px;
}

.field-group   { display: flex; flex-direction: column; gap: 7px; }
.field-label   { font-size: 12px; font-weight: 700; color: var(--text-muted); letter-spacing: .04em; }
.field-hint    { font-size: 11px; color: var(--text-muted); }
.lbl-required::after { content: " ＊"; color: var(--error); }

/* ── フォーム共通 ─────────────────────────────────────────── */
input[type="text"], input[type="password"], textarea {
  font-family: var(--font); font-size: 13px; color: #111;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 7px 10px; background: #fff; outline: none;
  transition: border-color .2s;
}
input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus { border-color: var(--primary); }
.w-full   { width: 100%; }
.flex-1   { flex: 1; min-width: 0; }
textarea  { resize: vertical; line-height: 1.8; }

/* 分類チェック */
.cat-checks { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-check-label {
  display: flex; align-items: center; gap: 5px; cursor: pointer;
  font-size: 13px; padding: 5px 12px;
  border: 1.5px solid var(--border); border-radius: 20px;
  background: var(--bg); color: var(--text-muted);
  transition: background .12s, border-color .12s, color .12s;
}
.cat-check-label:hover { border-color: var(--primary); color: var(--primary); }
.cat-check-label input[type="checkbox"] { display: none; }
.cat-check-label.checked { background: var(--primary); border-color: var(--primary); color: #fff; }

/* リンク行 */
.link-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.link-row  { display: flex; align-items: center; gap: 6px; }
.link-row .link-label { flex: 1; }
.link-row .link-url   { flex: 2; }

/* 画像グリッド */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px; margin-bottom: 8px;
}
.image-thumb {
  position: relative; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--border); background: #f5f5f5;
}
.image-thumb img { width: 100%; height: 100px; object-fit: cover; display: block; }
.img-name {
  font-size: 10px; color: var(--text-muted); padding: 2px 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.img-del-btn {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(192,57,43,.85); color: #fff; border: none;
  font-size: 12px; font-weight: 700; display: flex;
  align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; transition: opacity .12s;
}
.image-thumb:hover .img-del-btn { opacity: 1; }
.img-del-btn:hover { background: rgba(192,57,43,1) !important; }
.image-thumb.pending::after {
  content: '未保存'; position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(58,107,80,.8); color: #fff;
  font-size: 10px; text-align: center; padding: 2px;
}

/* 解説リッチテキスト */
.edit-desc-rich {
  width: 100%; min-height: 160px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; background: #fff; outline: none;
  line-height: 1.85; font-size: 13px; font-family: var(--font);
  color: #111; transition: border-color .2s;
  word-break: break-all; white-space: pre-wrap;
}
.edit-desc-rich:focus { border-color: var(--primary); }
.edit-desc-rich:empty::before {
  content: attr(data-placeholder);
  color: #bbb; font-style: italic; pointer-events: none;
  white-space: pre-line;
}

/* エラー表示 */
.field-error {
  background: var(--danger-light); color: var(--danger);
  border: 1px solid rgba(192,57,43,.3); border-radius: var(--radius);
  padding: 8px 12px; font-size: 12px;
}

/* ── ボタン ───────────────────────────────────────────────── */
button { font-family: var(--font); cursor: pointer; transition: background .12s; }

.btn-primary {
  background: var(--primary); color: #fff; border: none;
  border-radius: var(--radius); padding: 9px 20px;
  font-size: 13px; font-weight: 700;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: #E4E0D8; color: var(--text); border: none;
  border-radius: var(--radius); padding: 9px 20px; font-size: 13px;
}
.btn-secondary:hover { background: #D8D4CC; }

.btn-ghost {
  background: transparent; border: 1.5px solid rgba(255,255,255,.4);
  color: #fff; border-radius: var(--radius);
  padding: 6px 14px; font-size: 12px;
}
.btn-ghost:hover { background: rgba(255,255,255,.15); }

.btn-danger {
  background: var(--danger); color: #fff; border: none;
  border-radius: var(--radius); padding: 9px 20px;
  font-size: 13px; font-weight: 700;
}
.btn-danger:hover { background: #922b21; }

.btn-icon {
  background: transparent; border: none; border-radius: 4px;
  padding: 4px 7px; font-size: 13px; color: var(--text-muted);
}
.btn-icon:hover     { background: #EEE; color: var(--text); }
.btn-icon-del:hover { background: var(--danger-light); color: var(--danger); }

.btn-link {
  background: none; border: none; color: var(--primary);
  font-size: 11px; font-family: var(--font); cursor: pointer; padding: 0;
  text-decoration: underline;
}

.btn-sm { padding: 4px 10px !important; font-size: 12px !important; }

.upload-label {
  display: inline-block; cursor: pointer; user-select: none;
  padding: 5px 12px; font-size: 12px; font-family: var(--font);
  background: #E4E0D8; border-radius: var(--radius); transition: background .12s;
}
.upload-label:hover { background: #D8D4CC; }

/* ── 画像ビューア ─────────────────────────────────────────── */
.img-viewer {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.img-viewer-bg { position: absolute; inset: 0; background: rgba(0,0,0,.82); }
.img-viewer-img {
  position: relative; max-width: 90vw; max-height: 90vh;
  object-fit: contain; border-radius: 6px;
  box-shadow: 0 4px 32px rgba(0,0,0,.6);
}
.img-viewer-close {
  position: absolute; top: 16px; right: 20px;
  background: rgba(255,255,255,.18); border: 2px solid rgba(255,255,255,.4);
  color: #fff; width: 36px; height: 36px; border-radius: 50%;
  font-size: 18px; display: flex; align-items: center;
  justify-content: center; cursor: pointer;
}
.img-viewer-close:hover { background: rgba(255,255,255,.32); }

/* ── サイドパネル導入モーダル ─────────────────────────────── */
.sp-modal-overlay {
  position       : fixed;
  inset          : 0;
  z-index        : 600;
  background     : rgba(0,0,0,.55);
  display        : flex;
  align-items    : center;
  justify-content: center;
  padding        : 16px;
}
.sp-modal-card {
  background    : #fff;
  border-radius : 10px;
  width         : 100%;
  max-width     : 560px;
  max-height    : 88vh;
  display       : flex;
  flex-direction: column;
  box-shadow    : 0 8px 40px rgba(0,0,0,.28);
  overflow      : hidden;
}
.sp-modal-header {
  display        : flex;
  align-items    : center;
  justify-content: space-between;
  padding        : 16px 20px;
  background     : var(--primary);
  color          : #fff;
  flex-shrink    : 0;
}
.sp-modal-title {
  font-size  : 15px;
  font-weight: 700;
  margin     : 0;
}
.sp-modal-close {
  background   : rgba(255,255,255,.2);
  border       : 1.5px solid rgba(255,255,255,.4);
  color        : #fff;
  width        : 28px;
  height       : 28px;
  border-radius: 50%;
  font-size    : 13px;
  cursor       : pointer;
  display      : flex;
  align-items  : center;
  justify-content: center;
  flex-shrink  : 0;
}
.sp-modal-close:hover { background: rgba(255,255,255,.35); }

.sp-modal-body {
  overflow-y : auto;
  padding    : 20px;
  flex       : 1;
}
.sp-modal-lead {
  font-size    : 13px;
  color        : #444;
  margin-bottom: 18px;
}

/* ステップリスト */
.sp-steps {
  list-style : none;
  display    : flex;
  flex-direction: column;
  gap        : 14px;
  margin-bottom: 18px;
}
.sp-step {
  display: flex;
  gap    : 12px;
  align-items: flex-start;
}
.sp-step-num {
  background   : var(--primary);
  color        : #fff;
  font-size    : 12px;
  font-weight  : 700;
  width        : 24px;
  height       : 24px;
  border-radius: 50%;
  display      : flex;
  align-items  : center;
  justify-content: center;
  flex-shrink  : 0;
  margin-top   : 1px;
}
.sp-step-body  { flex: 1; min-width: 0; }
.sp-step-title {
  font-size  : 13px;
  font-weight: 700;
  color      : var(--primary-dark);
  margin-bottom: 4px;
}
.sp-step-desc {
  font-size  : 12px;
  color      : #444;
  line-height: 1.75;
}
.sp-step-note {
  display    : block;
  margin-top : 4px;
  font-size  : 11px;
  color      : #888;
}
.sp-code-block {
  display      : block;
  margin-top   : 6px;
  padding      : 6px 10px;
  background   : #f0f0f0;
  border-radius: 4px;
  font-size    : 12px;
  font-family  : 'Consolas','Courier New',monospace;
  color        : #2a2a2a;
  word-break   : break-all;
  user-select  : all;
}
.sp-dl-btn {
  display    : inline-block;
  margin-top : 10px;
  text-decoration: none;
}

.sp-modal-note {
  font-size    : 11px;
  color        : #7a5800;
  background   : #fff8e6;
  border       : 1px solid #e8c84a;
  border-radius: 6px;
  padding      : 10px 12px;
  line-height  : 1.75;
}

/* ── スクロールバー ───────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #BEB9B0; border-radius: 3px; }
