* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: #f4f6f8;
  color: #222;
}
.topbar {
  background: #2e7d32;
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 { font-size: 18px; margin: 0; }
.status { font-size: 13px; opacity: .95; }
.topbar .right { display: flex; align-items: center; gap: 12px; }
#who { font-size: 13px; opacity: .92; }

/* ===== 認証（ログイン画面） ===== */
.hidden { display: none !important; }
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #f4f6f8; }
.auth-card { background: #fff; padding: 28px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.1); width: 360px; max-width: 92vw; }
.auth-card h1 { font-size: 22px; text-align: center; margin: 0 0 18px; }
.auth-tabs { display: flex; margin-bottom: 16px; }
.atab { flex: 1; border: none; background: #eee; padding: 10px; cursor: pointer; font-size: 14px; }
.atab:first-child { border-radius: 6px 0 0 6px; }
.atab:last-child { border-radius: 0 6px 6px 0; }
.atab.active { background: #2e7d32; color: #fff; font-weight: bold; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; font-weight: bold; color: #444; }
.auth-form input { padding: 9px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; font-weight: normal; }
.err { color: #c62828; font-size: 13px; margin: 0; }

.tabs {
  display: flex;
  gap: 4px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  padding: 0 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab {
  border: none;
  background: none;
  padding: 14px 16px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  color: #555;
}
.tab.active { color: #2e7d32; border-bottom-color: #2e7d32; font-weight: bold; }

main { max-width: 900px; margin: 0 auto; padding: 20px; }
.panel { display: none; }
.panel.active { display: block; }

h2 { font-size: 18px; }
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; font-weight: bold; margin-bottom: 6px; color: #444; }
.req { color: #c62828; font-size: 11px; font-weight: normal; background: #ffebee; padding: 1px 6px; border-radius: 8px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

.cascader { display: flex; flex-wrap: wrap; gap: 6px; }
.cascader select { flex: 1; min-width: 130px; padding: 7px; border: 1px solid #ccc; border-radius: 6px; }
.path { font-size: 12px; color: #2e7d32; margin-top: 4px; font-style: italic; }

.form-head, .list-head { display: flex; align-items: center; justify-content: space-between; }
.form-actions { margin-top: 20px; display: flex; align-items: center; gap: 12px; }
.hint { font-size: 13px; color: #666; }

button.primary { background: #2e7d32; color: #fff; border: none; padding: 11px 28px; border-radius: 6px; font-size: 15px; cursor: pointer; }
button.primary:hover { background: #276b2a; }
button.ghost { background: #eee; border: none; padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }

.dropzone {
  border: 2px dashed #bbb;
  border-radius: 8px;
  padding: 26px;
  text-align: center;
  color: #888;
  cursor: pointer;
  background: #fafafa;
  font-size: 13px;
}
.dropzone.drag { border-color: #2e7d32; background: #edf7ed; color: #2e7d32; }

.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.thumb { position: relative; width: 92px; height: 92px; border-radius: 6px; overflow: hidden; border: 1px solid #ddd; background: #fff; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .del { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; font-size: 13px; line-height: 1; }
/* 写真の並べ替え（ドラッグ）*/
.thumb[draggable="true"] { cursor: grab; }
.thumb.dragging { opacity: .4; }
.thumb.ti-before { box-shadow: -4px 0 0 -1px #2e7d32; }
.thumb.ti-after { box-shadow: 4px 0 0 -1px #2e7d32; }
.thumb-main { position: absolute; top: 0; left: 0; background: #2e7d32; color: #fff; font-size: 10px; font-weight: bold; padding: 2px 6px; border-bottom-right-radius: 6px; z-index: 2; }

.count { font-size: 13px; color: #666; font-weight: normal; }
#list-search { padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 14px; }
.card { background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.card .ph { width: 100%; height: 150px; background: #f0f0f0; display: flex; align-items: center; justify-content: center; color: #aaa; font-size: 12px; }
.card .ph img { width: 100%; height: 100%; object-fit: cover; }
.card .body { padding: 10px; flex: 1; }
.card .nm { font-size: 13px; font-weight: bold; line-height: 1.4; max-height: 3.6em; overflow: hidden; }
.card .meta { font-size: 12px; color: #666; margin-top: 6px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 8px; margin-top: 6px; }
.badge.ok { background: #e8f5e9; color: #2e7d32; }
.badge.draft { background: #fff3e0; color: #ef6c00; }
.card .row { display: flex; border-top: 1px solid #eee; }
.card .row button { flex: 1; border: none; background: #fff; padding: 9px; cursor: pointer; font-size: 13px; }
.card .row button:hover { background: #f5f5f5; }
.card .row .del-card { color: #c62828; border-left: 1px solid #eee; }

.steps { font-size: 14px; line-height: 1.9; }
.steps a { color: #2e7d32; }

.htable { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
.htable th, .htable td { border-bottom: 1px solid #eee; padding: 8px 10px; text-align: left; }
.htable th { background: #f5f5f5; }
.ok-text { color: #2e7d32; }
.ng-text { color: #c62828; }

#toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; }
.toast { background: #333; color: #fff; padding: 11px 18px; border-radius: 8px; margin-top: 8px; font-size: 14px; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.toast.error { background: #c62828; }
.toast.success { background: #2e7d32; }

/* ===== フォルダ（グループ）グリッド ===== */
.tip { font-size: 13px; color: #2e7d32; background: #f1f8e9; padding: 8px 12px; border-radius: 8px; margin: 10px 0 4px; }
.icon-btn { border: none; background: #eee; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; font-size: 15px; vertical-align: middle; }
.icon-btn:hover { background: #ddd; }
.breadcrumb { margin: 12px 0; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.breadcrumb .back { border: none; background: #eee; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.breadcrumb .back:hover { background: #ddd; }

.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; margin-top: 14px; }
.folder-card {
  background: #fff;
  border: 1px solid #e3e6e8;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  transition: transform .08s, box-shadow .08s;
}
.folder-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.folder-thumb {
  width: 100%;
  height: 120px;
  border-radius: 10px;
  overflow: hidden;
  background: #fdf3da; /* カバー画像が無いときのクリーム色プレースホルダ */
}
.folder-thumb img { width: 100%; height: 100%; object-fit: cover; }
.folder-name { font-weight: bold; font-size: 14px; margin-top: 10px; line-height: 1.35; min-height: 2.7em; }
.folder-badge { display: inline-block; background: #2e7d32; color: #fff; border-radius: 12px; padding: 3px 14px; font-size: 12px; margin-top: 4px; }
.field small { font-weight: normal; color: #999; font-size: 11px; }

/* ===== 拡張機能ダウンロード ===== */
.dl-box { margin: 18px 0; text-align: center; }
.dl-btn { display: inline-block; text-decoration: none; padding: 14px 32px; font-size: 16px; border-radius: 8px; }
h3 { font-size: 15px; margin-top: 24px; }
code { background: #eef1f4; padding: 1px 6px; border-radius: 4px; font-size: 13px; }
.steps li { margin-bottom: 6px; }

/* ===== トークン表示 ===== */
.token-row { display: flex; gap: 8px; margin: 8px 0 4px; max-width: 600px; }
.token-row input { flex: 1; padding: 9px 10px; border: 1px solid #ccc; border-radius: 6px; font-family: monospace; font-size: 13px; background: #f9f9f9; }
.token-row button { white-space: nowrap; }

/* ===================== スマホ対応（管理システム） ===================== */
@media (max-width: 640px) {
  main { padding: 12px; }
  /* トップバー：折り返して縦に積む */
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 6px; }
  .topbar h1 { font-size: 15px; flex: 1 1 100%; line-height: 1.4; }
  .topbar .right { flex-wrap: wrap; gap: 8px; width: 100%; }
  .status, #who { font-size: 12px; }
  /* タブ：横スクロール（縦書き潰れを防止） */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 0; padding: 0 6px; }
  .tab { flex: 0 0 auto; white-space: nowrap; padding: 12px 12px; font-size: 13px; }
  /* iOSの自動ズーム防止 */
  input, select, textarea { font-size: 16px; }
  /* テーブルは横スクロール（はみ出し防止） */
  .htable, table.grid { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  /* フォルダ／カードは小さめ2〜3列で詰める */
  .folder-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}

/* ===== ドラッグ移動（並べ替え・統合・グループ移動）===== */
.folder-card[draggable="true"], .card[draggable="true"] { cursor: grab; }
.folder-card.dragging, .card.dragging { opacity: .4; }
.folder-thumb { position: relative; }
.folder-card.merge-target { outline: 3px solid #2e7d32; outline-offset: 1px; }
.folder-card.merge-target .folder-thumb::after { content: "＋ ここに統合"; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; background: rgba(46,125,50,.55);
  color: #fff; font-size: 13px; font-weight: bold; }
.folder-card.reorder-before { box-shadow: -5px 0 0 -1px #2e7d32; }
.folder-card.reorder-after { box-shadow: 5px 0 0 -1px #2e7d32; }
.breadcrumb { flex-direction: column; align-items: flex-start; }
.bc-row { display: flex; align-items: center; gap: 10px; }
.move-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%;
  margin-top: 4px; padding: 8px 10px; background: #f1f8f2; border: 1px dashed #b5d8bb; border-radius: 8px; box-sizing: border-box; }
.move-bar-label { font-size: 12px; color: #2e7d32; font-weight: bold; }
.move-chip { font-size: 13px; padding: 6px 12px; background: #fff; border: 1px solid #cfd8cf; border-radius: 16px; }
.move-chip.new { border-style: dashed; color: #2e7d32; }
.move-chip.drop-hot { background: #2e7d32; color: #fff; border-color: #2e7d32; transform: scale(1.05); }

/* ===== 「📁移動」ボタンのグループ選択モーダル ===== */
.mv-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.mv-box { background: #fff; border-radius: 12px; width: 340px; max-width: 92vw; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.mv-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; font-weight: bold; border-bottom: 1px solid #eee; }
.mv-x { border: none; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: #888; }
.mv-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.mv-item { text-align: left; padding: 11px 14px; border: 1px solid #ddd; border-radius: 8px; background: #fff; cursor: pointer; font-size: 14px; }
.mv-item:hover { background: #f1f8f2; border-color: #2e7d32; }
.mv-item.cur { background: #eee; color: #888; cursor: default; }
.mv-item.new { border-style: dashed; color: #2e7d32; }

/* ===== メルカリShops 連携（Phase 1） ===== */
.mc-status { padding: 12px 14px; border-radius: 8px; font-size: 14px; background: #f5f5f5; border: 1px solid #e0e0e0; }
.mc-status.ok { background: #e8f5e9; border-color: #a5d6a7; }
.mc-status.warn { background: #fff8e1; border-color: #ffe082; }
.mc-status.err { background: #fdecea; border-color: #f5c6cb; color: #c62828; }
.mc-status code { background: rgba(0,0,0,.06); padding: 1px 6px; border-radius: 4px; }
.mc-badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; background: #eee; color: #444; margin-left: 4px; }
.mc-badge.opened { background: #e8f5e9; color: #2e7d32; }
.mc-badge.unopened { background: #eceff1; color: #607d8b; }
.mc-badge.sandbox { background: #ede7f6; color: #5e35b1; }
.mc-search { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.mc-search input { flex: 1; min-width: 160px; padding: 9px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; }
.mc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.mc-card { background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; padding-bottom: 8px; }
.mc-card img { width: 100%; height: 150px; object-fit: cover; background: #f0f0f0; }
.mc-card .mc-noimg { width: 100%; height: 150px; background: #f0f0f0; display: flex; align-items: center; justify-content: center; color: #aaa; font-size: 12px; }
.mc-card .mc-name { font-size: 13px; font-weight: bold; line-height: 1.4; max-height: 2.8em; overflow: hidden; padding: 8px 8px 0; }
.mc-card .mc-meta { font-size: 12px; color: #666; padding: 4px 8px 0; }
.mc-card .mc-badge { margin: 6px 8px 0; }
.mc-more-wrap { text-align: center; margin: 16px 0; }
.err-text { color: #c62828; }

/* ===== メルカリShops カテゴリ検索 / CSV一括登録タブ ===== */
.mcat-search { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.mcat-search input { flex: 1; min-width: 180px; padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; }
.mcat-results { display: flex; flex-direction: column; gap: 4px; max-height: 230px; overflow-y: auto; }
.mcat-results:not(:empty) { border: 1px solid #e0e0e0; border-radius: 6px; padding: 6px; margin-bottom: 6px; }
.mcat-opt { text-align: left; padding: 7px 10px; border: 1px solid #e6e6e6; border-radius: 6px; background: #fff; cursor: pointer; font-size: 13px; line-height: 1.4; }
.mcat-opt:hover { background: #f1f8f2; border-color: #2e7d32; }
.dl-btn.disabled-link { pointer-events: none; opacity: .45; }

/* WooCommerce integration */
.wc-row { display: flex; gap: 4px; margin-top: 6px; }
.wc-toggle, .wc-stock { font-size: 11px; padding: 3px 8px; border-radius: 6px; border: 1px solid #ddd; cursor: pointer; white-space: nowrap; }
.wc-toggle.wc-on { background: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; }
.wc-toggle.wc-off { background: #ffebee; color: #c62828; border-color: #ef9a9a; }
.wc-stock.wc-instock { background: #fff; color: #666; border-color: #ddd; }
.wc-stock.wc-sold { background: #fff3e0; color: #e65100; border-color: #ffcc80; }
.wc-toggle:hover, .wc-stock:hover { filter: brightness(0.95); }
.wc-toggle:disabled, .wc-stock:disabled { opacity: 0.6; cursor: wait; }
.wc-sync-btn { font-size: 12px !important; padding: 2px 10px !important; margin-left: 6px; }
