/* ===== CSS Variables & Theme ===== */
:root {
  --accent: #d97706;
  --accent-soft: rgba(217, 119, 6, 0.12);
  --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(217, 119, 6, 0.14);
  --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(217, 119, 6, 0.22);
}
* { 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-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;
}
.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: column; align-items: flex-start;
  line-height: 1.1;
}
.logo-main {
  font-size: 20px; font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text);
}
.logo-sub {
  font-size: 10px; font-weight: 500;
  color: var(--text-sub);
  letter-spacing: 0.3px;
  margin-top: 2px;
}
.dev-env-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.5px;
  background: rgba(239, 68, 68, 0.15);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.35);
  white-space: nowrap;
}
/* hidden属性はUAスタイルの[hidden]{display:none}によるが、上のdisplay:inline-flexが
   同詳細度でそれを上書きしてしまい常時表示になる（.nav-item[hidden]と同じパターン）。明示的に優先させる */
.dev-env-badge[hidden] { display: none; }
[data-theme="dark"] .dev-env-badge { background: rgba(239, 68, 68, 0.25); color: #f87171; }
/* ===== ヘッダーアプリアイコン（M-Ad / M-Step） ===== */
.header-apps {
  display: flex; align-items: center; gap: 10px;
  padding: 0 4px;
  flex-shrink: 0;
}
/* アイコン単体では初見で何のアプリか判別しづらいため、下にラベルを添えて
   縦積みの1ブロック（.header-app-item）にする。ヘッダー高さ(--header-h:60px)に
   収まるようアイコン32px+ラベル9-10px程度に調整（2026-08-07 視認性改善）。 */
.header-app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  max-height: var(--header-h);
  transition: transform 0.15s ease-out;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.header-app-item:hover { transform: scale(1.06); }
.header-app-item:active { transform: scale(0.95); }
.header-app-item.is-soon { opacity: 0.45; }
.header-app-item[hidden] { display: none; }
.header-app-icon {
  width: 32px; height: 32px;
  object-fit: contain;
  border-radius: 8px;
  transition: opacity 0.15s ease-out;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}
.header-app-label {
  font-size: 9px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--text-sub);
  white-space: nowrap;
}
@media (max-width: 640px) {
  .header-apps { gap: 6px; }
  .header-app-icon { width: 28px; height: 28px; }
  /* 狭幅ではラベルを隠しアイコンのみにしてヘッダーの崩れを防ぐ */
  .header-app-label { display: none; }
}

.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;
}
.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: 4px; }
.nav-label {
  font-size: 10px; font-weight: 700;
  color: var(--text-sub);
  padding: 10px 12px 4px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.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;
}
/* 権限制御 (navigation.ts applyPermissions) が付ける hidden 属性を display:flex より優先する。
   これが無いと UA スタイルの [hidden]{display:none} が上の display:flex に負け、
   権限のないナビ項目が全員に見えてしまう (クリックするとサーバー側 403 になる)。 */
.nav-item[hidden] { display: none; }
.nav-item:hover { background: var(--accent-soft); color: var(--accent); }
.nav-item.active { background: color-mix(in srgb, var(--accent) 10%, transparent); 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.child.active { color: var(--accent); font-weight: 600; }
.nav-section-label {
  font-size: 0.95rem; font-weight: 700;
  color: var(--text);
  padding: 10px 14px 4px;
  letter-spacing: 0.4px;
}
.nav-section-label span {
  display: inline;
  background: linear-gradient(transparent 55%, color-mix(in srgb, var(--text-sub) 30%, transparent) 55%);
}
.nav-zone-service .nav-section-label span {
  background: linear-gradient(transparent 55%, color-mix(in srgb, var(--accent) 35%, transparent) 55%);
}
.nav-zone {
  padding: 6px 0 10px;
  margin: 4px 8px 10px;
}
.nav-zone[hidden] { display: none; }
.nav-zone .nav-group { padding-left: 8px; padding-right: 8px; }
.nav-zone-tools {
  border-top: 1px solid var(--border);
}
.nav-parent {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600;
}
.nav-parent .chevron {
  width: 16px; height: 16px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}
.nav-group.open > .nav-parent .chevron { transform: rotate(180deg); }
.nav-group:not(.open) > .nav-children { display: none; }
.nav-children { padding: 2px 0; }

/* ===== ナビの小見出し・一言説明・管理者向け折りたたみ（2026-09-06 PR-A・器の拡張） =====
   NAV_CONFIG の子項目に head / sub / adminOnly が付いたときだけ描かれる。
   何も付けなければ 1 行のリンクのまま＝従来の見た目に一切影響しない。 */
.nav-subhead {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-sub);
  letter-spacing: 0.6px;
  padding: 8px 12px 3px 20px;
}
.nav-subgroup[hidden], .nav-admin-fold[hidden] { display: none; }
/* 2 行項目。1 行目＝ラベル、2 行目＝一言説明。幅が足りなければ 1 行で省略する
   （--sidebar-w は変えない＝器全体に影響させない）。 */
.nav-item.child.has-sub {
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding-top: 6px;
  padding-bottom: 6px;
}
.nav-item.child.has-sub .nav-label,
.nav-item.child.has-sub .nav-sub {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 1 行目（項目名）。上の汎用 .nav-label（10px・大文字・薄色・padding 付き）を
   そのまま浴びると項目名が小さな薄いラベルになるため、ここで明示的に上書きする
   （2026-09-06 PR-B。PR-A では sub を使う項目が 0 だったので画面に出ていなかった）。 */
.nav-item.child.has-sub .nav-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: normal;
  text-transform: none;
  padding: 0;
}
/* 2 行目（一言説明）。薄くしすぎると読めない（藤山さん恒久ルール＝薄文字は不可）。
   var(--text-sub) をそのまま使う: ライト #6b7280 on #fff ＝ 4.8:1、ダーク #9ca3af on #1a1d25 ＝ 7.4:1。 */
.nav-item.child.has-sub .nav-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-sub);
}
.nav-item.child.has-sub:hover .nav-sub { color: inherit; }
/* 管理者向けは既定で畳む（<details> の既定 closed）。見出しは小見出しと同じ見た目＋▸ */
.nav-admin-fold > summary {
  list-style: none;
  cursor: pointer;
}
.nav-admin-fold > summary::-webkit-details-marker { display: none; }
.nav-admin-fold > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s ease;
}
.nav-admin-fold[open] > summary::before { transform: rotate(90deg); }

/* ===== 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; }

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

/* ===== View ===== */
.view { display: none; }
.view.active { display: block; }

/* ===== Home ===== */
.home-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 0 60px;
}
.home-hero {
  display: flex; align-items: center; gap: 24px;
  margin-bottom: 32px;
}
.home-logo {
  width: 96px; height: 96px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(217, 119, 6, 0.2));
}
.home-greet { flex: 1; }
.home-greet-main {
  font-size: 24px; font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.3;
}
.home-greet-sub {
  font-size: 14px; color: var(--text-sub);
  line-height: 1.6;
}
.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 8px;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 20px 18px;
  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-icon {
  font-size: 28px;
  margin-bottom: 10px;
  line-height: 1;
}
.card-title {
  font-size: 15px; font-weight: 600;
  margin: 0 0 6px;
}
.card-desc {
  font-size: 12.5px; color: var(--text-sub);
  margin: 0;
  flex: 1;
  line-height: 1.6;
}
.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); }
[data-theme="dark"] .badge.active { color: #4ade80; }
[data-theme="dark"] .badge.dev { color: #facc15; }

/* ===== Placeholder View ===== */
.placeholder-wrap {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  padding: 80px 20px 60px;
  text-align: center;
  max-width: 560px;
  margin: 0 auto;
}
.placeholder-icon {
  font-size: 52px;
  margin-bottom: 20px;
  line-height: 1;
}
.placeholder-title {
  font-size: 22px; font-weight: 700;
  margin: 0 0 12px;
}
.placeholder-desc {
  font-size: 14px; color: var(--text-sub);
  line-height: 1.8;
  margin: 0 0 20px;
}
.placeholder-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(234, 179, 8, 0.15);
  color: #a16207;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.placeholder-badge::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--status-dev);
}
[data-theme="dark"] .placeholder-badge { color: #facc15; }

/* シナリオ生成は詳しめプレースホルダー */
.scenario-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  margin-top: 24px;
  text-align: left;
  width: 100%;
  box-shadow: var(--shadow);
}
.scenario-detail h3 {
  font-size: 14px; font-weight: 700;
  color: var(--text-sub);
  margin: 0 0 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 11px;
}
.scenario-detail ul {
  margin: 0;
  padding-left: 20px;
  color: var(--text-sub);
  font-size: 13px;
  line-height: 1.9;
}

/* ===== 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); }

/* ===== Modal ===== */
.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: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  margin: 0 auto;
  display: flex; flex-direction: column;
}
.modal-head {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.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;
}
.modal-foot {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ===== 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: 16px; }
  .logo-sub { font-size: 9px; }
  .home-hero { flex-direction: column; text-align: center; gap: 16px; }
  .home-greet-main { font-size: 20px; }
}
@media (max-width: 480px) {
  .logout-btn { padding: 6px 8px; font-size: 11px; }
  .header { gap: 10px; padding: 0 12px; }
}

/* ===== iOS 自動ズーム対策（ポキ/AI秘書 第8弾パターンの移植 2026-08-07） =====
   iOS Safari は font-size<16px の input/select/textarea にフォーカスすると
   画面を自動で拡大する。これを防ぐため、タッチ端末（スマホ幅）でのみ
   フォーム要素を 16px 以上に強制する。
   PC は業務ツールとしての情報密度を保つため既存サイズのまま。
   viewport 側でも maximum-scale=1.0 / user-scalable=no を設定している。 */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  touch-action: manipulation; /* ダブルタップズームの抑止 */
}
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
    max-width: 100%;
    box-sizing: border-box;
  }
}
