/* ===== CSS Variables & Theme ===== */
:root {
  --accent: #4f6ef7;
  --accent-soft: rgba(79, 110, 247, 0.15);
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-header: linear-gradient(180deg, #ffffff 0%, #f4f5f7 100%);
  --text: #1f2430;
  --text-sub: #6b7280;
  --border: #e4e6eb;
  --border-strong: #d1d5db;
  --status-active: #22c55e;
  --status-dev: #eab308;
  --status-plan: #9ca3af;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-hover: 0 6px 20px rgba(79, 110, 247, 0.12);
  --header-h: 60px;
  --sidebar-w: 260px;
}
[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #1a1d25;
  --surface-header: linear-gradient(180deg, #1a1d25 0%, #161920 100%);
  --text: #e5e7eb;
  --text-sub: #9ca3af;
  --border: #2a2e38;
  --border-strong: #3a3f4c;
  --shadow: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-hover: 0 6px 20px rgba(79, 110, 247, 0.25);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== Auth Overlay ===== */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: none;
  align-items: center; justify-content: center;
  z-index: 1000;
}
.auth-overlay.active { display: flex; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: min(92vw, 400px);
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
}
.auth-logo {
  display: flex; align-items: center; justify-content: center;
  gap: 14px;
  margin-bottom: 20px;
}
.auth-logo-img {
  width: 72px; height: 72px;
  object-fit: contain;
  flex-shrink: 0;
}
.auth-logo-text {
  display: flex; flex-direction: column; align-items: flex-start;
  line-height: 1.1;
}
.auth-logo-main {
  font-size: 32px; font-weight: 700; letter-spacing: 1px;
  color: var(--text);
}
.auth-logo-sub {
  font-size: 11px; font-weight: 500;
  color: var(--text-sub);
  letter-spacing: 0.3px;
  margin-top: 4px;
}
.auth-logo .ax { color: var(--accent); }
.auth-msg { color: var(--text-sub); margin-bottom: 24px; }
.auth-btn {
  background: var(--accent); color: white; border: none;
  padding: 12px 28px; border-radius: 8px; font-weight: 600;
  cursor: pointer; font-size: 14px;
  transition: opacity 0.15s;
}
.auth-btn:hover { opacity: 0.9; }
.auth-err { color: #ef4444; margin-top: 12px; font-size: 13px; min-height: 1em; }

/* ===== Header ===== */
.header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  background: var(--surface-header);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px;
  z-index: 100;
  gap: 16px;
}
.hamburger {
  background: none; border: none; cursor: pointer;
  padding: 8px; border-radius: 8px;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.hamburger:hover { background: var(--border); }
.hamburger svg { width: 22px; height: 22px; }
.logo {
  display: flex; align-items: center; gap: 10px;
  white-space: nowrap;
}
.logo-img {
  width: 44px; height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}
.logo-text {
  display: flex; flex-direction: row; align-items: baseline;
  gap: 8px;
}
.logo-main {
  font-size: 22px; font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text);
}
.logo-sub {
  font-size: 11px; font-weight: 500;
  color: var(--text-sub);
  letter-spacing: 0.3px;
}
.logo .ax { color: var(--accent); }
/* ===== ヘッダーマスコット（POKI 配下のメインツールロゴを並べる） =====
   2026-04-22: 検索ボックスを撤去し、POTATO-kun + MALASADA-chan を小さく配置。
   検索機能はポキちゃんチャット (home.js の onSearch) 経由に集約済み。
   id="searchInput" は hidden input で存続させ、chat→filter 連携を維持。 */
.header-mascots {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
  flex-shrink: 0;
}
.header-mascot {
  width: 38px; height: 38px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.10));
  transition: transform 0.18s ease-out, filter 0.18s ease-out;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
/* Nemo は元画像の余白でやや小さく見えるため +2px で視覚バランスを揃える */
#headerNemoLogo.header-mascot { width: 40px; height: 40px; }
/* iOS Safari は @media (hover: hover) で囲んでも :hover が sticky になる場合があり、
   「1タップ目で hover 発動 / 2タップ目で click 発火」というダブルタップ症状が
   実機で再現していた。:hover の transform/filter ルール自体を撤廃し、PC/スマホとも
   :active のみで押下フィードバックを与える形に統一する。
   cursor: pointer でクリック可能性は伝わるので実用上問題なし。 */
.header-mascot:active {
  transform: scale(0.95);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.18));
}
@media (max-width: 640px) {
  .header-mascot { width: 32px; height: 32px; }
  #headerNemoLogo.header-mascot { width: 34px; height: 34px; }
  .header-mascots { gap: 4px; }
}
@media (max-width: 420px) {
  /* 極小画面: logo-sub を既存CSSが隠すのと合わせ、マスコットも小さく */
  .header-mascot { width: 28px; height: 28px; }
  #headerNemoLogo.header-mascot { width: 30px; height: 30px; }
}
.header-right {
  display: flex; align-items: center; gap: 12px;
  margin-left: auto;
}
.theme-toggle {
  background: none; border: 1px solid var(--border);
  cursor: pointer; padding: 6px;
  border-radius: 999px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
  transition: border-color 0.15s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle .icon-dark,
.theme-toggle .icon-light { width: 16px; height: 16px; }
[data-theme="dark"] .theme-toggle .icon-light { display: none; }
[data-theme="light"] .theme-toggle .icon-dark,
:root:not([data-theme="dark"]) .theme-toggle .icon-dark { display: none; }
.user-email {
  font-size: 13px; color: var(--text-sub);
  white-space: nowrap;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}
.logout-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text); cursor: pointer;
  padding: 6px 12px; border-radius: 8px;
  font-size: 12px; font-family: inherit;
  transition: all 0.15s;
}
.logout-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed; top: var(--header-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface-header);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.25s ease;
  z-index: 50;
  padding: 16px 0;
}
.sidebar.closed { transform: translateX(-100%); }
.nav-group { padding: 0 14px; margin-bottom: 8px; }
.nav-label {
  font-size: 11px; font-weight: 600;
  color: var(--text-sub);
  padding: 10px 12px 6px;
  letter-spacing: 0.5px;
}
.nav-divider {
  height: 1px; background: var(--border);
  margin: 8px 14px;
}
.nav-item {
  display: flex; align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-weight: 500;
}
.nav-item:hover { background: var(--accent-soft); color: var(--accent); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.child {
  padding-left: 28px;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-sub);
}
.nav-item.child:hover { color: var(--accent); }
.nav-item.nav-parent {
  justify-content: space-between;
  font-weight: 600;
}
.nav-item.nav-parent .nav-arrow {
  font-size: 10px;
  color: var(--text-sub);
  transition: transform 0.2s ease;
  margin-left: 8px;
}
.nav-group.open .nav-item.nav-parent .nav-arrow { transform: rotate(90deg); }
.nav-item.nav-parent.active-parent {
  background: rgba(79, 110, 247, 0.07);
  color: var(--accent);
}
.nav-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}
.nav-group.open .nav-children { max-height: 500px; }

/* ===== Main ===== */
.main {
  margin-left: var(--sidebar-w);
  padding: calc(var(--header-h) + 28px) 28px 40px;
  transition: margin-left 0.25s ease;
  min-height: 100vh;
}
.main.expanded { margin-left: 0; }
.main-title {
  font-size: 22px; font-weight: 700;
  margin: 0 0 6px;
}
.main-sub { color: var(--text-sub); margin: 0 0 28px; font-size: 13px; }

.section { margin-bottom: 36px; }
.section-head {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-size: 15px; font-weight: 700;
  margin: 0;
}
.section-count {
  font-size: 12px; color: var(--text-sub);
}

/* ===== Card Sections ===== */
.cards-section {
  margin-bottom: 32px;
}
.cards-section.hidden { display: none; }
.cards-section:last-child { margin-bottom: 0; }
.section-header {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 14px;
  padding: 0 2px;
}
.section-title {
  font-size: 13px; font-weight: 700;
  color: var(--text-sub);
  margin: 0;
  letter-spacing: 0.04em;
}

/* ===== Cards ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  position: relative;
  display: flex; flex-direction: column;
  min-height: 120px;
}
.card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}
.card-title {
  font-size: 15px; font-weight: 600;
  margin: 0 0 6px;
  display: flex; align-items: center; gap: 8px;
}
.card-desc {
  font-size: 12.5px; color: var(--text-sub);
  margin: 0;
  flex: 1;
}
.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px;
}
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
}
.badge.active { background: rgba(34, 197, 94, 0.12); color: #16a34a; }
.badge.active::before { background: var(--status-active); }
.badge.dev { background: rgba(234, 179, 8, 0.15); color: #a16207; }
.badge.dev::before { background: var(--status-dev); }
.badge.plan { background: rgba(156, 163, 175, 0.2); color: var(--text-sub); }
.badge.plan::before { background: var(--status-plan); }
[data-theme="dark"] .badge.active { color: #4ade80; }
[data-theme="dark"] .badge.dev { color: #facc15; }

/* ===== Main Tool 強調 =====
   --card-accent は JSON 側 accentColor で上書き可能。未指定時はテーマの --accent を継承 */
.card.main-tool {
  --card-accent: var(--accent);
  border: 2px solid var(--card-accent);
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--card-accent) 15%, transparent) 0%,
      transparent 65%),
    var(--surface);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--card-accent) 22%, transparent);
  min-height: 160px;
  padding-top: 26px;
  padding-right: 112px;
}
.card.main-tool .card-logo {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 96px; height: 96px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.card.main-tool .card-logo img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
}
@media (max-width: 520px) {
  .card.main-tool { padding-right: 96px; }
  .card.main-tool .card-logo { width: 82px; height: 82px; right: 8px; bottom: 8px; }
}
.card.main-tool::before {
  content: "⭐ メインツール";
  position: absolute;
  top: -11px;
  left: 14px;
  background: var(--card-accent);
  color: #ffffff;
  padding: 3px 10px 4px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 6px color-mix(in srgb, var(--card-accent) 45%, transparent);
  white-space: nowrap;
}
.card.main-tool:hover {
  border-color: var(--card-accent);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--card-accent) 35%, transparent);
  transform: translateY(-3px);
}
.card.main-tool .card-title {
  font-size: 17px;
  font-weight: 700;
}
.card.main-tool .card-desc {
  font-size: 13px;
}
[data-theme="dark"] .card.main-tool {
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--card-accent) 28%, transparent) 0%,
      transparent 65%),
    var(--surface);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--card-accent) 30%, transparent);
}

.card.add-new {
  border: 2px dashed var(--border-strong);
  background: transparent;
  box-shadow: none;
  align-items: center; justify-content: center;
  color: var(--text-sub);
  font-size: 13px; font-weight: 500;
  text-align: center;
}
.card.add-new:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
}
.card.add-new .plus { font-size: 24px; margin-bottom: 4px; }

.card.hidden { display: none; }
.section.hidden { display: none; }

/* ===== Empty State ===== */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}
.empty-state .empty-main {
  font-size: 15px; font-weight: 500;
  color: var(--text-sub);
  margin-bottom: 8px;
}
.empty-state .empty-sub {
  font-size: 13px;
  color: var(--text-sub);
  opacity: 0.75;
}

/* ===== Sidebar Overlay ===== */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
}

/* ===== Detail view ===== */
.detail-wrap {
  max-width: 720px;
  margin: 0 auto;
}
.back-btn {
  background: none; border: none;
  color: var(--text-sub);
  cursor: pointer;
  font-family: inherit; font-size: 13px;
  padding: 6px 0;
  margin-bottom: 20px;
  display: inline-flex; align-items: center; gap: 4px;
  transition: color 0.15s;
}
.back-btn:hover { color: var(--accent); }
.detail-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.detail-title {
  font-size: 24px; font-weight: 700;
  margin: 0;
}
.detail-desc {
  color: var(--text-sub);
  font-size: 14px;
  margin: 0 0 24px;
}
.detail-action {
  margin: 0 0 28px;
}
.action-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: white;
  text-decoration: none;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  transition: opacity 0.15s, transform 0.15s;
}
.action-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.detail-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.detail-body h2 {
  font-size: 18px; font-weight: 700;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.detail-body h2:not(:first-child) { margin-top: 28px; }
.detail-body p {
  font-size: 14px; line-height: 1.8;
  margin: 0 0 14px;
}
.detail-body ol, .detail-body ul {
  padding-left: 24px; margin: 0 0 16px;
}
.detail-body ol li, .detail-body ul li {
  font-size: 14px; line-height: 1.9;
  margin-bottom: 6px;
}
.detail-body code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  color: var(--accent);
}
.detail-placeholder {
  color: var(--text-sub);
  font-size: 14px;
  text-align: center;
  padding: 20px 0;
}

/* ===== Common Buttons ===== */
.btn-primary {
  background: var(--accent); color: white;
  border: none; padding: 9px 18px;
  border-radius: 8px; font-weight: 600; font-size: 13px;
  cursor: pointer; font-family: inherit;
  transition: opacity 0.15s, transform 0.15s;
}
.btn-primary:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 18px; border-radius: 8px;
  font-weight: 500; font-size: 13px;
  cursor: pointer; font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost {
  background: none; border: none;
  color: var(--text-sub);
  cursor: pointer;
  font-family: inherit; font-size: 13px;
  padding: 6px 0;
  margin-bottom: 12px;
  display: inline-flex; align-items: center; gap: 4px;
  transition: color 0.15s;
}
.btn-ghost:hover { color: var(--accent); }

/* ===== Modal (common skeleton) ===== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  align-items: flex-start; justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 800px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  margin: 0 auto;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 80px);
  min-height: min(640px, calc(100vh - 80px));
}
.modal-head {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 22px; color: var(--text-sub); padding: 0;
  width: 32px; height: 32px; line-height: 1;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body {
  padding: 18px 24px;
  overflow-y: auto;
  flex: 1 1 auto;
}
.modal-foot {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 2px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main { margin-left: 0; padding: calc(var(--header-h) + 20px) 16px 30px; }
  .user-email { display: none; }
  .logo-img { width: 36px; height: 36px; }
  .logo-main { font-size: 17px; }
  .logo-sub { font-size: 9px; }
}
@media (max-width: 480px) {
  .logout-btn { padding: 4px 8px; font-size: 10px; white-space: nowrap; }
  .header { gap: 10px; padding: 0 12px; }
}
