/* Rewrite Steps UI */
:root {
  --ink: #1c1f26;
  --muted: #6b7280;
  --line: #e3e5ea;
  --bg: #f6f7f9;
  --card: #ffffff;
  --accent: #2456c4;
  --accent-weak: #e8eefb;
  --danger: #b42318;
  --marker: #e2543a;
  --nav-bg: #20242e;
  --nav-ink: #c7ccd8;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.7;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

/* ---- レフトナビつきシェル ---- */
.shell-wrap { display: flex; min-height: 100vh; }
.sidenav {
  width: 220px; flex: 0 0 220px; background: var(--nav-bg); color: var(--nav-ink);
  display: flex; flex-direction: column; padding: 16px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidenav .brand { display: block; padding: 6px 16px 14px; }
.sidenav .brand img { display: block; width: 100%; max-width: 172px; height: auto; }
.nav-toggle { display: none; }
.sidenav-main { display: flex; flex-direction: column; }
.sidenav-main a {
  color: var(--nav-ink); padding: 7px 18px; font-size: 14px; border-left: 3px solid transparent;
  display: flex; align-items: center; gap: 9px;
}
.sidenav-main a:hover { color: #fff; background: rgba(255, 255, 255, 0.05); }
.sidenav-main a.active { color: #fff; border-left-color: var(--accent); background: rgba(255, 255, 255, 0.07); }
/* 長い項目名は改行せず省略記号に（変な折返し防止） */
.sidenav-main a > span:not(.cnt) {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidenav-main a .cnt { flex: none; margin-left: auto; font-size: 12px; opacity: 0.7; }
.nav-ico { width: 16px; height: 16px; flex: none; opacity: 0.85; }
.nav-head {
  font-size: 11px; letter-spacing: 0.08em; color: #8b91a0; margin: 16px 18px 4px; text-transform: none;
}
.nav-tags { padding: 2px 14px 4px; display: flex; flex-wrap: wrap; gap: 6px; }
.nav-tags .tag-chip { border-color: #3a4050; color: var(--nav-ink); }
.nav-tags .tag-chip:hover, .nav-tags .tag-chip.active { color: #fff; border-color: var(--accent); }
.sidenav-foot {
  margin-top: auto; padding: 14px 18px 4px; border-top: 1px solid #303646;
  display: flex; flex-direction: column; gap: 4px; font-size: 13px;
}
.sidenav-foot .nav-user { color: #fff; }
.sidenav-foot a { color: var(--nav-ink); }
.shell-main { flex: 1; min-width: 0; padding: 28px 32px 90px; max-width: 1160px; }

.container { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; white-space: nowrap; }
.page-head .btn { white-space: nowrap; }
h1 { font-size: 22px; margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

.btn {
  display: inline-block; padding: 7px 14px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: #c9cdd6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.icon-btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 5px;
  padding: 3px 8px; font-size: 12px; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { border-color: #c9cdd6; }
.icon-btn.danger { color: var(--danger); }
.icon-btn:disabled { opacity: 0.45; cursor: default; }

/* 認証画面 */
.auth-page { background: var(--bg); }
.auth-card {
  max-width: 400px; margin: 80px auto; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 32px;
}
.auth-card h1 { font-size: 24px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
.auth-card input {
  width: 100%; padding: 9px 10px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 6px;
}
.auth-card .btn { width: 100%; margin-top: 20px; padding: 10px; }
.error { color: var(--danger); font-size: 14px; }

/* 一覧 */
.guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.guide-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; color: var(--ink); display: block; position: relative;
}
.guide-card:hover { border-color: #b9c6e8; }
.guide-card .card-link { display: block; color: var(--ink); }
.pin-btn {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.92);
  color: #b6bcc8; font-size: 16px; cursor: pointer; line-height: 1;
}
.pin-btn.on { color: #e8a200; border-color: #e8c86a; }
.pin-btn.inline { position: static; width: 26px; height: 26px; font-size: 14px; flex: none; }
.card-actions { display: flex; gap: 8px; padding: 0 14px 12px; }
.card-actions .btn { margin-top: 0; }

/* 検索・ソートバー: 折返し単位を明確化（検索は伸びる、選択は固定基準幅、ボタンは折返さない） */
.list-toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.list-toolbar input[type="search"] {
  flex: 1 1 240px; min-width: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px;
}
.list-toolbar select {
  flex: 0 1 auto; min-width: 0; max-width: 220px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px; font-size: 13px; background: var(--card);
  text-overflow: ellipsis;
}
.list-toolbar .btn { white-space: nowrap; }

/* タグ一覧ページ */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 10px; }
.tag-big {
  display: inline-block; background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 16px; font-size: 14px; color: var(--ink);
}
.tag-big:hover { border-color: var(--accent); color: var(--accent); }
.tag-big .cnt { color: var(--muted); font-size: 12px; }

/* カテゴリDnD */
.drag-handle { cursor: grab; color: var(--muted); font-size: 16px; padding: 0 2px; user-select: none; }
.cat-row.dragging { opacity: 0.4; }
.badge-client {
  display: inline-block; background: #eef7ef; color: #106b39;
  border-radius: 4px; padding: 0 6px; font-size: 11px;
}
.guide-card .thumb { aspect-ratio: 16 / 9; background: #eceef2; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.guide-card .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.guide-card .card-body { padding: 12px 14px; }
.guide-card h2 { font-size: 15px; margin: 0 0 6px; line-height: 1.5; }
.guide-card .meta { font-size: 12px; color: var(--muted); margin: 0 0 3px; }
.card-tags { margin: 2px 0 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag-chip {
  display: inline-block; font-size: 11px; border: 1px solid var(--line); border-radius: 999px;
  padding: 0 8px; color: var(--muted);
}
.badge-share { color: #106b39; }
.badge-cat {
  display: inline-block; background: var(--accent-weak); color: var(--accent);
  border-radius: 4px; padding: 0 6px; font-size: 11px;
}
.badge-admin { font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 5px; }
.empty-state { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 40px; text-align: center; }
.empty-state h2 { font-size: 17px; }

/* 編集画面 */
.lock-banner {
  background: #fdf3e7; border: 1px solid #ecc994; color: #7a4d0b;
  border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}
.editor-head { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 24px; }
#guide-title {
  width: 100%; font-size: 22px; font-weight: 700; border: none; outline: none;
  padding: 4px 2px; color: var(--ink); background: transparent;
}
#guide-desc {
  width: 100%; border: 1px solid transparent; border-radius: 6px; padding: 6px;
  font-size: 14px; color: var(--muted); resize: vertical; min-height: 40px; background: transparent;
}
#guide-desc:focus { border-color: var(--line); background: #fff; color: var(--ink); outline: none; }

/* メタ行: ラベル上・入力下のフィールドを整然と折り返す */
.meta-row {
  display: flex; align-items: flex-end; gap: 14px 18px; flex-wrap: wrap;
  border-top: 1px solid var(--line); margin-top: 10px; padding-top: 12px; font-size: 13px;
}
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.field select, .field input {
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
  background: var(--card); max-width: 100%;
}
.field select { min-width: 140px; max-width: 220px; text-overflow: ellipsis; }
.field.grow { flex: 1 1 220px; }
.field.grow input { width: 100%; }
.field-switch .switch { font-size: 13px; color: var(--ink); white-space: nowrap; padding: 6px 0; margin: 0; }
.field-static .field-value { font-size: 13px; padding: 6px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }

.info-edit { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.info-edit > label { display: block; font-size: 12px; color: var(--muted); }
#guide-memo {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px;
  font-size: 13px; min-height: 44px; resize: vertical; margin-top: 3px;
}
.links-edit { margin-top: 10px; }
.links-head { font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.link-row { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.link-row .link-title { flex: 1 1 140px; min-width: 0; }
.link-row .link-url { flex: 2 1 220px; min-width: 0; }
.link-row .icon-btn { flex: none; }
.link-row input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }

.editor-toolbar { display: flex; align-items: center; gap: 8px 8px; margin-top: 12px; flex-wrap: wrap; font-size: 13px; border-top: 1px solid var(--line); padding-top: 12px; }
.editor-toolbar .btn { white-space: nowrap; }
.editor-toolbar > .muted { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.share-panel { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-bottom: 0; }
.share-panel .switch { margin-bottom: 10px; }
.share-row { display: flex; gap: 8px; align-items: end; margin-bottom: 8px; flex-wrap: wrap; }
.share-row .btn { white-space: nowrap; flex: none; }
.share-row input { flex: 1 1 200px; min-width: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.share-row label { font-size: 12px; color: var(--muted); flex: 1; }
.share-row label input { width: 100%; margin-top: 3px; }

/* メモ・関連リンク（閲覧表示） */
.info-block {
  display: flex; gap: 24px; flex-wrap: wrap; background: #f4f6fa;
  border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin: 12px 0;
}
.info-block h3 { font-size: 13px; margin: 0 0 4px; color: var(--muted); }
.info-block p, .info-block ul { margin: 0; font-size: 14px; }
.info-block ul { padding-left: 18px; }
.info-memo { flex: 1 1 300px; }
.info-links { flex: 1 1 260px; }

/* 手順 */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: stepno; }
.step {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 18px; counter-increment: stepno;
}
.step-head { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.step-head .step-no { flex: none; }
.step-no::before {
  content: counter(stepno);
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 700;
}
.step-title {
  flex: 1 1 220px; min-width: 0; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px;
  font-size: 16px; font-weight: 600; color: var(--ink); background: transparent;
}
.step-title:focus { border-color: var(--line); background: #fff; outline: none; }
.step-title-ro { flex: 1 1 220px; min-width: 0; font-size: 16px; margin: 0; overflow-wrap: anywhere; }
.step-actions { display: flex; gap: 5px; flex: none; margin-left: auto; opacity: 0.35; transition: opacity 0.15s; }
.step-actions .icon-btn { white-space: nowrap; }
.step:hover .step-actions { opacity: 1; }
.step-note {
  width: 100%; margin-top: 8px; border: 1px solid transparent; border-radius: 6px;
  padding: 6px 8px; font-size: 14px; color: var(--muted); resize: vertical; min-height: 34px; background: transparent;
}
.step-note:focus { border-color: var(--line); background: #fff; color: var(--ink); outline: none; }
.step-note-ro { color: #444a55; font-size: 14px; margin: 8px 0 0; }
.step-url { font-size: 12px; color: var(--muted); word-break: break-all; margin: 6px 0 0; }

.shot { position: relative; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.shot-inner { position: relative; transition: transform 0.9s cubic-bezier(0.22, 0.8, 0.3, 1); }
.shot img { display: block; width: 100%; height: auto; }
.shot .anno, .anno {
  position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
}
.click-marker {
  position: absolute; width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--marker); background: rgba(226, 84, 58, 0.15);
  transform: translate(-50%, -50%); pointer-events: none;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
}
/* クリック位置ズーム（共有ビュー）: 中央基準で拡大しつつ、クリック位置が中央に来るよう平行移動 */
.share-view .shot.zoomed .shot-inner { transform: translate(var(--zx, 0%), var(--zy, 0%)) scale(1.45); }
.editor-foot { text-align: center; margin-top: 6px; }

/* readonlyモード */
.editor.readonly .step-actions, .editor.readonly .editor-foot { display: none; }
.editor.readonly input:disabled, .editor.readonly textarea:disabled, .editor.readonly select:disabled { color: var(--ink); opacity: 0.8; }

/* モーダル共通 */
.modal {
  position: fixed; inset: 0; background: rgba(20, 22, 28, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box { background: var(--card); border-radius: 10px; padding: 18px; max-width: 900px; width: 100%; max-height: 92vh; overflow: auto; }
.modal-box.wide { max-width: 1040px; }
.stage { position: relative; user-select: none; }
.stage img { display: block; width: 100%; height: auto; pointer-events: none; }
.blur-stage { cursor: crosshair; }
#blur-rects { position: absolute; inset: 0; }
.blur-rect { position: absolute; border: 2px dashed var(--marker); background: rgba(226, 84, 58, 0.2); }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }

/* 図形エディタ */
.anno-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.anno-modes { display: flex; gap: 5px; }
.anno-modes .btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.anno-colors { display: flex; gap: 6px; align-items: center; }
.anno-color {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line);
}
.anno-color.on { box-shadow: 0 0 0 2px var(--ink); }
#anno-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.anno-stage { cursor: crosshair; }
.anno-stage.mode-select { cursor: default; }
#anno-svg .selectable { pointer-events: all; cursor: move; }
#anno-svg .handle { pointer-events: all; cursor: nwse-resize; }

/* 音声メモ */
.audio-block { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.audio-block audio { height: 36px; max-width: 340px; flex: 1 1 220px; min-width: 0; }
.audio-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.audio-status { font-size: 13px; }
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none;
  animation: rec-blink 1s infinite;
}
@keyframes rec-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* 共有ビューの完了チェック */
.check-box { display: inline-flex; align-items: center; flex: none; }
.check-box input {
  width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer;
}
.step.done .step-title-ro { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.step.done .shot { opacity: 0.75; }
.check-progress { display: flex; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.check-bar-track {
  flex: 1 1 200px; min-width: 0; height: 8px; background: #eceef2; border-radius: 999px; overflow: hidden;
}
.check-bar { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.check-text { font-size: 13px; color: var(--muted); white-space: nowrap; }
.check-progress .btn { white-space: nowrap; }

/* 共有ビュー */
.share-page { background: #fff; }
.share-view { max-width: 860px; }
.share-brand { font-weight: 700; color: var(--muted); font-size: 13px; letter-spacing: 0.06em; margin: 0 0 8px; }
.share-head h1 { font-size: 26px; }
.guide-desc { color: #444a55; }
.share-view .step { border: none; border-top: 1px solid var(--line); border-radius: 0; padding: 24px 0; margin: 0; }

/* 印刷 */
@media print {
  .sidenav, .no-print, .editor-toolbar, .step-actions { display: none !important; }
  body { background: #fff; }
  .container, .shell-main { padding: 0; max-width: none; }
  .step { page-break-inside: avoid; border: none; border-top: 1px solid #ccc; border-radius: 0; }
  .shot { border-color: #ccc; }
  .share-view .shot.zoomed .shot-inner { transform: none; }
}

/* トースト */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #23262e; color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 8px; z-index: 90;
  opacity: 0; transition: opacity 0.2s; max-width: 90vw;
}
.toast.show { opacity: 1; }

/* 設定ページのインストール手順 */
.guide-steps { margin: 8px 0; padding-left: 22px; font-size: 14px; }
.guide-steps li { margin-bottom: 6px; }
.guide-steps code {
  background: #f2f4f8; border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 6px; font-size: 13px; font-family: Consolas, Menlo, monospace;
}
.panel .btn.primary { color: #fff; }

/* 設定・管理ページ */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.panel h2 { font-size: 16px; margin: 0 0 10px; }
.panel label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.panel input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
.panel .btn { margin-top: 10px; }
.panel .share-row input { width: auto; }
.cat-row, .user-row { display: flex; align-items: center; gap: 8px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cat-row .cat-name { flex: 1 1 180px; min-width: 0; width: auto; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
.cat-row .btn, .user-row .btn { margin-top: 0; white-space: nowrap; flex: none; }
.cat-row > a, .user-row > .muted { white-space: nowrap; flex: none; }
.user-row .user-name { flex: 1 1 160px; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-add { display: flex; gap: 8px; flex-wrap: wrap; }
.user-add input { flex: 1 1 180px; min-width: 0; width: auto; }
.user-add .btn { margin-top: 0; white-space: nowrap; }

@media (max-width: 1100px) {
  .sidenav { width: 200px; flex-basis: 200px; }
  .shell-main { padding: 22px 20px 80px; }
}
@media (max-width: 860px) {
  .shell-wrap { flex-direction: column; }
  /* 狭幅ではコンパクトなトップバー+ハンバーガー。メニューは開いたときだけ表示 */
  .sidenav {
    width: 100%; flex: none; height: auto; position: static;
    flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 14px;
  }
  .sidenav .brand { padding: 0; flex: none; }
  .sidenav .brand img { max-width: 136px; }
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    margin-left: auto; width: 40px; height: 36px;
    background: none; border: 1px solid #3a4050; border-radius: 6px;
    color: var(--nav-ink); cursor: pointer;
  }
  .nav-toggle svg { width: 20px; height: 20px; }
  .sidenav .sidenav-main, .sidenav .sidenav-foot { display: none; }
  .sidenav.open .sidenav-main {
    display: flex; flex-direction: column; width: 100%;
    margin-top: 10px; border-top: 1px solid #303646; padding-top: 6px;
  }
  .sidenav.open .sidenav-foot {
    display: flex; width: 100%; margin-top: 0;
  }
  .shell-main { padding: 18px 14px 70px; }
  .step-actions { opacity: 1; margin-left: 0; }
  .field select { max-width: 100%; }
  .field-static .field-value { max-width: 100%; }
  .guide-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
@media (max-width: 560px) {
  .guide-grid { grid-template-columns: 1fr; }
  .list-toolbar input[type="search"] { flex-basis: 100%; }
  .list-toolbar select { flex: 1 1 45%; max-width: none; }
}
