/* ==========================================================================
   ホーム・上の帯・すべての機能（js/home.js）。見本は docs/portal/preview-home.html。
   左のメニューはやめて、上の帯の「すべての機能」で一覧を開く。飾り（影・色付きの丸いアイコン・動き）は使わない。
   index.css の左のメニュー・狭い画面の規則（!important のもの）を上書きするので、theme.css の後に読み込む。
   ========================================================================== */

/* ── 骨組み：本文を横いっぱいに ───────────────────────── */
body .layout { display: block !important; height: 100vh; overflow: hidden; }
body .main-wrapper { width: 100% !important; height: 100vh; }

/* ── 上の帯 ─────────────────────────────────────── */
body .topbar { justify-content: flex-start; gap: 14px; padding: 0 20px !important; }
.topbar-logo { font-weight: 700; font-size: 14.5px; color: var(--c-ink); text-decoration: none; white-space: nowrap; }
.topbar-logo small { font-weight: 400; color: var(--c-muted); font-size: 11.5px; margin-left: 6px; }
body .page-title.text-h1 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 0 auto; max-width: 40%; }
body.on-home .page-title.text-h1 { display: none; }
/* ダッシュボードに戻る：ダッシュボード以外のすべての画面の上に出す。押す場所だと分かるよう枠と主色の文字にする */
.topbar-back {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; flex-shrink: 0;
  border: 1px solid var(--c-brand); border-radius: 4px; background: var(--c-surface); color: var(--c-brand);
  font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.topbar-back:hover { background: var(--c-brand-50, #f7f9f3); }
.topbar-back:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 1px; }
body.on-home .topbar-back { display: none; }
body .sidebar-toggle {
  display: inline-flex !important; align-items: center; gap: 7px; width: auto; height: 32px; padding: 0 11px; margin: 0;
  border: 1px solid var(--c-line-strong, #d1cbbe); border-radius: 4px; background: var(--c-surface); color: var(--c-ink);
  font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer; flex-shrink: 0;
}
body .sidebar-toggle i { font-size: 13px; color: var(--c-ink-2); }
.sidebar-open .sidebar-toggle { background: var(--c-gray-100, #f7f5f2); }
.topbar-find {
  flex: 0 1 300px; min-width: 0; display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px;
  border: 1px solid var(--c-line); border-radius: 4px; background: var(--c-surface); color: var(--c-faint);
  font-size: 12.5px; cursor: text; white-space: nowrap; overflow: hidden;
}
.topbar-find kbd { margin-left: auto; font-family: inherit; font-size: 11px; color: var(--c-muted); }
.topbar-sp { flex: 1; }
.topbar-notice { border: 0; background: none; cursor: pointer; font-size: 13px; color: var(--c-ink-2); white-space: nowrap; padding: 4px 6px; border-radius: 4px; }
.topbar-notice:hover { background: var(--c-gray-50, #f8f6f1); }
.user-profile .text-muted { white-space: nowrap; }
.topbar-notice b { color: var(--c-danger, #9b4134); font-weight: 700; }

/* ── すべての機能（今までの左のメニューを、上の帯の下に開く一覧にする） ── */
body .sidebar { display: none !important; }
body .sidebar-open .sidebar {
  display: flex !important; flex-direction: column;
  position: fixed !important; top: var(--header-height) !important; left: 0 !important; right: 0; bottom: auto;
  width: auto !important; max-height: calc(100vh - var(--header-height)); transform: none !important;
  background: var(--c-surface); border-right: 0; border-bottom: 1px solid var(--c-line-strong, #d1cbbe);
  box-shadow: none !important; z-index: 500 !important;
}
body .sidebar-overlay { display: none; position: fixed; inset: var(--header-height) 0 0 0; background: rgba(38, 36, 32, .18); z-index: 150; }
body .sidebar-open .sidebar-overlay { display: block !important; opacity: 1; }
.launcher-head { display: flex; align-items: center; gap: 12px; padding: 14px 24px 4px; flex-shrink: 0; }
.launcher-head input {
  flex: 1; max-width: 380px; height: 32px; border: 1px solid var(--c-line-strong, #d1cbbe); border-radius: 4px; padding: 0 10px;
  font: inherit; font-size: 13.5px; outline: none; background: var(--c-surface);
}
.launcher-head input:focus { border-color: var(--c-ink-2); }
.launcher-hint { font-size: 12px; color: var(--c-muted); }
.launcher-pick .launcher-hint { color: var(--c-brand); }
.launcher-sp { flex: 1; }
.launcher-close { height: 28px; padding: 0 10px; border: 1px solid var(--c-line-strong, #d1cbbe); border-radius: 4px; background: var(--c-surface); font-size: 12.5px; cursor: pointer; }
body .sidebar-nav { columns: 230px 4; column-gap: 32px; padding: 6px 24px 20px; overflow-y: auto; }
body .sidebar-nav .nav-section-label {
  margin: 12px 0 4px; padding: 0 0 4px; border-bottom: 1px solid var(--c-line); color: var(--c-muted);
  font-size: 12px; font-weight: 500; letter-spacing: 0;
}
body .sidebar-nav .nav-group { break-inside: avoid; padding-bottom: 6px; }
body .sidebar-nav .nav-group:first-child .nav-item:first-child { margin-top: 12px; }
body .sidebar-nav .nav-item { break-inside: avoid; min-height: 32px; padding: 5px 6px; margin: 0; border-radius: 3px; font-size: 13.5px; font-weight: 400; }
body .sidebar-nav .nav-item i { color: var(--c-muted); font-size: 13px; }
body .sidebar-nav .nav-item.active { background: var(--c-gray-100, #f7f5f2); color: var(--c-ink); font-weight: 600; }
body .sidebar-nav .nav-item.active i { color: var(--c-ink-2); }
body .sidebar-nav .nav-item .nav-badge { margin-left: 6px; background: none; color: var(--c-danger, #9b4134); padding: 0; min-width: 0; font-size: 12.5px; }
.nav-item .home-pin { margin-left: auto; border: 0; background: none; padding: 0 2px; cursor: pointer; font-size: 12px; color: var(--c-brand); white-space: nowrap; }
.nav-item .home-pin.on { color: var(--c-muted); }
.nav-item .home-pin:hover { text-decoration: underline; }
.launcher-pick .home-pin, .launcher-notice .home-pin { display: none; }
body .sidebar .home-hide { display: none !important; }
.launcher-empty { color: var(--c-muted); font-size: 13px; margin: 10px 0; }
.launcher-notice .nav-item .nav-badge::after { content: attr(title); color: var(--c-muted); font-weight: 400; margin-left: 8px; font-size: 12px; }

/* ── 横の一覧：広い画面では、どのページでも上の帯の下の左に機能の一覧をいつも出す ──
   同じ #sidebar を使い、「すべての機能」・「＋ 機能を足す」・お知らせで開いたときは上の大きな一覧に切り替わる */
@media (min-width: 901px) {
  body .layout:not(.sidebar-open) .sidebar {
    display: flex !important; flex-direction: column;
    position: fixed !important; top: var(--header-height) !important; left: 0 !important; right: auto; bottom: 0 !important;
    width: 200px !important; max-height: none; transform: none !important; box-shadow: none !important; z-index: 100 !important;
    background: var(--c-surface); border-right: 1px solid var(--c-line); border-bottom: 0;
  }
  body .main-wrapper .content-area { margin-left: 200px; }
  .layout:not(.sidebar-open) .launcher-head, .layout:not(.sidebar-open) .home-pin { display: none; }
  body .layout:not(.sidebar-open) .sidebar-nav { columns: auto; flex: 1; padding: 6px 10px 20px; overflow-y: auto; }
  body .layout:not(.sidebar-open) .sidebar-nav .nav-section-label { margin: 12px 0 2px; padding: 0 8px; border-bottom: 0; font-size: 11.5px; }
  body .layout:not(.sidebar-open) .sidebar-nav .nav-group { padding-bottom: 0; }
  body .layout:not(.sidebar-open) .sidebar-nav .nav-group:first-child .nav-item:first-child { margin-top: 4px; }
  body .layout:not(.sidebar-open) .sidebar-nav .nav-item { min-height: 30px; padding: 4px 8px; font-size: 13px; gap: 9px; }
  body .layout:not(.sidebar-open) .sidebar-nav .nav-item:hover { background: var(--c-gray-50, #f8f6f1); }
  body .layout:not(.sidebar-open) .sidebar-nav .nav-item .nav-badge { margin-left: auto; }
  /* 大項目の並べ替え：見出しを押したまま上下に動かす */
  body .layout:not(.sidebar-open) .sidebar-nav .nav-section-label { display: flex; align-items: center; cursor: grab; user-select: none; }
  .layout:not(.sidebar-open) .nav-sec-grip { margin-left: auto; font-size: 10px; color: var(--c-faint); opacity: 0; }
  .layout:not(.sidebar-open) .nav-section-label:hover .nav-sec-grip { opacity: 1; }
  .nav-dragging { background: var(--c-brand-50, #f7f9f3); border-radius: 4px; outline: 1px dashed var(--c-brand); }
  body.nav-sorting, body.nav-sorting * { cursor: grabbing !important; user-select: none; }
}
.nav-sec-grip { display: none; }
@media (min-width: 901px) { .layout:not(.sidebar-open) .nav-sec-grip { display: inline; } }

/* ── ホーム ─────────────────────────────────────── */
.dsb-hero { align-items: center; margin-bottom: 16px; }
.dsb-hero > div:first-child { display: flex; align-items: baseline; gap: 12px; flex-direction: row-reverse; justify-content: flex-end; }
.dsb-greeting { font-size: 17px !important; font-weight: 700; letter-spacing: 0; margin: 0; }
.dsb-date { font-size: 12.5px !important; letter-spacing: 0 !important; margin: 0 !important; color: var(--c-muted); }
/* ブロック：6 列の格子に、横幅（全体・1/2・1/3）で 6・3・2 列ぶん置く。狭いブロックは横に並ぶ */
.home-groups { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; align-items: start; }
.home-fav { grid-column: span 6; min-width: 0; }
.home-fav.home-w-half { grid-column: span 3; }
.home-fav.home-w-third { grid-column: span 2; }
.home-fav .dsb-card-head { flex-wrap: wrap; gap: 6px 10px; }
.home-gname { font: inherit; font-size: 14px; font-weight: 700; padding: 3px 8px; border: 1px solid var(--c-line-strong, #d1cbbe); border-radius: 4px; width: 12em; max-width: 100%; }
.home-gsize { font-size: 12px; color: var(--c-ink-2); white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.home-gsize select { font: inherit; font-size: 12px; padding: 2px 4px; }
.home-gdel { color: var(--c-danger, #9b4134); }
.home-gadd { grid-column: span 6; border: 1px dashed var(--c-line-strong, #d1cbbe); border-radius: 8px; background: none; color: var(--c-muted); padding: 14px; cursor: pointer; font: inherit; font-size: 13px; }
.home-gadd:hover { color: var(--c-ink-2); background: var(--c-gray-50, #f8f6f1); }
/* 縦幅：段の数で高さを決め、入りきらない分はブロックの中でスクロール */
.home-tiles.home-rows { grid-auto-rows: 64px; max-height: calc(var(--rows) * 64px + (var(--rows) - 1) * 8px); overflow-y: auto; }
.home-fav .dsb-card-head { margin-bottom: 10px; }
.home-fav-sub { font-size: 12px; color: var(--c-muted); }
.home-link { border: 0; background: none; padding: 0; color: var(--c-brand); cursor: pointer; font-size: 12.5px; white-space: nowrap; text-decoration: none; }
.home-link:hover { text-decoration: underline; }
.home-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 8px; touch-action: pan-y; min-height: 44px; }
.home-tile {
  position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 2px 10px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--c-line); border-radius: 4px; background: var(--c-surface); color: var(--c-ink);
  cursor: pointer; text-align: left; font: inherit; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.home-tile:hover { border-color: var(--c-line-strong, #d1cbbe); background: var(--c-gray-50, #f8f6f1); }
.home-tile:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 1px; }
.home-tile > i { color: var(--c-ink-2); font-size: 14px; text-align: center; }
.home-nm { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-cnt { color: var(--c-danger, #9b4134); font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.home-st { grid-column: 2 / 4; font-size: 11.5px; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-st:empty { display: none; }
.home-grip { position: absolute; left: 3px; top: 50%; transform: translateY(-50%); color: var(--c-faint); font-size: 10px; opacity: 0; }
.home-tile:hover .home-grip { opacity: 1; }
.home-x { display: none; border: 0; background: none; color: var(--c-muted); cursor: pointer; font-size: 12px; padding: 0 2px; }
.home-groups.editing .home-x { display: inline; }
.home-groups.editing .home-cnt { display: none; }
.home-add { grid-template-columns: 1fr; text-align: center; border-style: dashed; color: var(--c-muted); font-size: 12.5px; min-height: 44px; }
.home-add:hover { color: var(--c-ink-2); }
.home-holder { border: 1px dashed var(--c-brand); background: var(--c-brand-50, #f7f9f3); }
.home-holder > * { visibility: hidden; }
.home-ghost { position: fixed; z-index: 3000; pointer-events: none; border-color: var(--c-ink-2) !important; background: #fff !important; box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .35); }
.home-note { font-size: 11.5px; color: var(--c-muted); margin-top: 8px; }
.home-recent-wrap { display: flex; gap: 6px 16px; flex-wrap: wrap; align-items: baseline; margin: 10px 4px 16px; font-size: 12.5px; }
.home-recent-label { color: var(--c-muted); font-size: 12px; }
.home-recent { display: inline-flex; gap: 4px 16px; flex-wrap: wrap; }
.home-recent a { color: var(--c-brand); text-decoration: none; }
.home-recent a:hover { text-decoration: underline; }
.home-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--c-ink); color: #fff; padding: 7px 14px;
  border-radius: 4px; font-size: 12.5px; opacity: 0; transition: opacity .15s; pointer-events: none; z-index: 3000; white-space: nowrap;
}
.home-toast.on { opacity: 1; }
.home-toast.err { background: var(--c-danger, #9b4134); }

@media (max-width: 1100px) {
  .topbar-find span { display: none; }
  .topbar-find { flex: 0 0 auto; }
  .topbar-find kbd { margin-left: 6px; }
}

/* ── スマホの下のボタン ─────────────────────────────── */
.mobile-tabbar { display: none; }

@media (max-width: 900px) {
  body .layout { height: auto; overflow: visible; }
  body .main-wrapper { height: auto; }
  body .topbar { gap: 10px; padding: 0 12px !important; }
  .topbar-logo small, .topbar-find, .topbar-notice, body .sidebar-toggle { display: none !important; }
  /* スマホでは帯が狭いので、ロゴの代わりに「戻る」を出す */
  body:not(.on-home) .topbar-logo { display: none; }
  .topbar-back { padding: 0 10px; }
  .topbar-back span { font-size: 12.5px; }
  body .user-profile .text-muted { display: none; }

  body .content-area { padding-bottom: 80px !important; }
  .mobile-tabbar {
    display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 600;
    background: var(--c-surface); border-top: 1px solid var(--c-line); padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-tabbar a, .mobile-tabbar button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; border: 0; background: none;
    font: inherit; font-size: 11px; color: var(--c-muted); text-decoration: none; cursor: pointer;
  }
  .mobile-tabbar i { font-size: 16px; }
  .mobile-tabbar .on { color: var(--c-ink); font-weight: 700; }
  .mobile-tabbar b { color: var(--c-danger, #9b4134); }
  body .sidebar-open .sidebar { bottom: 58px; max-height: none; }
  body .sidebar-overlay { bottom: 58px; }
  .launcher-head { padding: 12px 12px 4px; }
  .launcher-hint { display: none; }
  body .sidebar-nav { columns: 1; padding: 4px 12px 16px; }
  body .sidebar-nav .nav-item { min-height: 40px; }
  .home-fav.home-w-half, .home-fav.home-w-third { grid-column: span 6; }   /* スマホの幅ではどのブロックも全体 */
  .home-tiles { grid-template-columns: 1fr 1fr; gap: 6px; }
  .home-tile { padding: 12px 10px; }
  .home-grip { display: none !important; }
  .home-fav-sub { display: none; }
  .dsb-hero { flex-wrap: wrap; }
}

/* ── ログインの引き継ぎ（コードで入る・コードを出す。js/app.js） ── */
.login-handoff { margin-top: 18px; text-align: center; }
.login-handoff-toggle { border: 0; background: none; color: var(--c-brand); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; }
.login-handoff-box { margin-top: 10px; text-align: left; font-size: 12.5px; color: var(--c-ink-2); }
.login-handoff-box p { margin: 0 0 8px; }
.login-handoff-box input { width: 100%; height: 40px; border: 1px solid var(--c-line-strong, #d1cbbe); border-radius: 6px; padding: 0 12px; font-size: 18px; letter-spacing: .15em; text-transform: uppercase; text-align: center; }
.login-handoff-go { width: 100%; height: 40px; margin-top: 8px; border: 0; border-radius: 6px; background: var(--c-ink); color: #fff; font: inherit; font-size: 14px; cursor: pointer; }
.login-handoff-error { color: var(--c-danger, #9b4134); margin-top: 8px !important; }
.handoff-bg { position: fixed; inset: 0; background: rgba(38, 36, 32, .32); display: flex; align-items: center; justify-content: center; z-index: 3000; padding: 16px; }
.handoff-card { background: #fff; border-radius: 8px; padding: 22px 22px 18px; width: 380px; max-width: 100%; font-size: 13px; color: var(--c-ink-2); }
.handoff-card h3 { margin: 0 0 8px; font-size: 16px; color: var(--c-ink); }
.handoff-code { margin: 14px 0; text-align: center; font-size: 34px; font-weight: 700; letter-spacing: .12em; color: var(--c-ink); font-variant-numeric: tabular-nums; }
.handoff-note { color: var(--c-muted); font-size: 12px; }
.handoff-close { display: block; margin: 14px 0 0 auto; height: 32px; padding: 0 14px; border: 1px solid var(--c-line-strong, #d1cbbe); border-radius: 4px; background: #fff; font: inherit; cursor: pointer; }
