/* =====================================================================
   Libit 部品（ボタン・サムネイル・フォルダカード・タグのチップ・
   ダイアログ・通知・操作バー・ツリー）
   libit-tokens.css を先に読み込むこと。見本：design/components.html
   ===================================================================== */

/* ---- 土台 ---- */
.libit,
.libit * { box-sizing: border-box; }
.libit {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-ui);
  letter-spacing: var(--ls-body);
  -webkit-font-smoothing: antialiased;
}
.libit button,
.libit input,
.libit select { font: inherit; color: inherit; letter-spacing: inherit; }
.libit :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.libit [hidden] { display: none !important; }
.libit .heading {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: var(--fw-normal);
  font-size: var(--fs-24);
  line-height: var(--lh-head);
  letter-spacing: var(--ls-head);
}
.libit .sub { color: var(--text-sub); }
.libit .icon { width: var(--icon-m); height: var(--icon-m); flex: none; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.libit .dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--accent); }
.libit .spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--text-sub); animation: libit-spin .9s linear infinite; }
@keyframes libit-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .libit .spinner { animation-duration: 3s; } }

/* ---- ボタン ---- */
.btn {
  height: var(--btn-h);
  padding: 0 var(--sp-20);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-8);
  border: var(--line-w) solid var(--text);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-14);
  font-weight: var(--fw-bold);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface); }
.btn.is-sm { height: var(--btn-h-sm); padding: 0 var(--sp-12); font-size: var(--fs-13); gap: 6px; }
.btn.is-quiet { border-color: var(--line); font-weight: var(--fw-normal); }
.btn.is-primary { border-color: transparent; background: var(--accent-strong); color: var(--on-accent); }
.btn.is-primary:hover { background: var(--accent-strong); filter: brightness(1.08); }
.btn.is-danger { border-color: transparent; background: var(--danger); color: var(--on-danger); }
.btn.is-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn.is-danger-outline { border-color: var(--danger); color: var(--danger); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .4; cursor: default; filter: none; }
.btn[disabled]:hover, .btn[aria-disabled="true"]:hover { background: transparent; }
.btn.is-primary[disabled]:hover, .btn.is-primary[aria-disabled="true"]:hover { background: var(--accent-strong); }
.btn .label-hint { color: var(--text-sub); font-weight: var(--fw-normal); }

.btn-text {
  height: var(--btn-h); padding: 0 6px;
  display: inline-flex; align-items: center;
  border: 0; background: none; color: inherit;
  font-size: var(--fs-14); text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer;
}
.btn-link { border: 0; padding: 0; background: none; color: var(--accent-strong); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--radius); background: transparent; color: inherit;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn .icon { width: var(--icon-l); height: var(--icon-l); stroke-width: 1.2; }

/* 分割ボタン（ライト／ダーク、大中小、正方形／縦横比どおり） */
.seg { display: inline-flex; height: var(--btn-h-sm); border: var(--line-w) solid var(--line); }
.seg > button {
  min-width: 34px; padding: 0 var(--sp-12);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: transparent; color: var(--text-sub);
  font-size: var(--fs-13); cursor: pointer;
}
.seg > button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: var(--fw-bold); }

/* ---- サムネイル ---- */
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--thumb-m), 1fr)); gap: var(--sp-2); }
.thumb-grid.is-s { grid-template-columns: repeat(auto-fill, minmax(var(--thumb-s), 1fr)); }
.thumb-grid.is-l { grid-template-columns: repeat(auto-fill, minmax(var(--thumb-l), 1fr)); }
@media (max-width: 599px) {
  .thumb-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .thumb-grid.is-s { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .thumb-grid.is-l { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.thumb {
  position: relative; display: block; width: 100%;
  aspect-ratio: 1 / 1; margin: 0; padding: 0; border: 0;
  background: var(--tile-bg); color: #ffffff; overflow: hidden;
  cursor: pointer; text-decoration: none;
}
.thumb > img { width: 100%; height: 100%; display: block; object-fit: cover; }
.thumb-grid.is-fit .thumb > img { object-fit: contain; }   /* 縦横比どおり */
.thumb::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.thumb.is-selected::after { box-shadow: inset 0 0 0 4px var(--accent-strong); }
.thumb.is-last::after { box-shadow: inset 0 0 0 3px var(--accent-strong); }   /* ビューアーから戻ったとき */
.thumb-grid.is-selecting .thumb.is-last:not(.is-selected)::after { box-shadow: none; }   /* 選択モード中は出さない */
.thumb .new { position: absolute; top: 8px; right: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid #ffffff; }
.thumb .marks { position: absolute; top: 6px; left: 6px; height: 20px; padding: 0 4px; display: flex; align-items: center; gap: 4px; background: var(--thumb-marks-bg); }
.thumb .marks svg { width: 12px; height: 12px; }
.thumb .badge,
.thumb .duration { position: absolute; bottom: 6px; padding: 2px 5px; font-size: var(--fs-10); font-weight: 700; letter-spacing: .06em; line-height: 1.4; color: #ffffff; background: var(--thumb-badge-bg); }
.thumb .badge { left: 6px; }
.thumb .duration { right: 6px; display: flex; align-items: center; gap: 3px; }
.thumb .type { position: absolute; top: 6px; left: 6px; padding: 3px 5px; font-size: var(--fs-10); font-weight: 700; letter-spacing: .06em; line-height: 1.2; color: var(--badge-fg); background: var(--badge-bg); }
.thumb .check {
  position: absolute; top: 8px; left: 8px; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--thumb-check-line); background: var(--thumb-check-off);
}
.thumb .check svg { width: 16px; height: 16px; fill: none; stroke: #ffffff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; }
.thumb.is-selected .check { background: var(--accent-strong); }
.thumb.is-selected .check svg { visibility: visible; }
.thumb.is-generating { display: flex; align-items: center; justify-content: center; }
.thumb.is-doc { background: var(--surface); display: flex; align-items: center; justify-content: center; }
.thumb.is-doc > img { width: 74%; height: 74%; object-fit: contain; }
.thumb.is-doc .check { top: auto; left: auto; right: 8px; bottom: 8px; border-color: var(--text-sub); background: var(--bg); }   /* 書類は左上に種類の札があるので右下 */
.thumb.is-doc.is-selected .check { border-color: var(--accent-strong); background: var(--accent-strong); }
@media (max-width: 599px) { .thumb .check { width: 26px; height: 26px; top: 6px; left: 6px; } }

/* 一覧のキャプション（タグ・お気に入りでは元のフォルダ名） */
.thumb-item { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.thumb-caption { display: flex; align-items: center; gap: 4px; font-size: var(--fs-12); color: var(--text-sub); white-space: nowrap; overflow: hidden; }
.thumb-caption span { overflow: hidden; text-overflow: ellipsis; }

/* ---- フォルダカード ---- */
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--sp-16); }
@media (max-width: 599px) { .folder-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-12); } }
.folder-card { display: flex; flex-direction: column; gap: var(--sp-8); min-width: 0; color: inherit; text-decoration: none; }
.folder-card .cover { aspect-ratio: 3 / 2; background: var(--surface); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.folder-card .cover > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.folder-card .cover .icon { width: 40px; height: 40px; stroke: var(--accent); stroke-width: 1; }
.folder-card .name { display: flex; align-items: center; gap: var(--sp-8); min-width: 0; font-size: var(--fs-14); }
.folder-card .name > span:first-of-type { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-card .count { margin-left: auto; flex: none; font-size: var(--fs-12); color: var(--text-sub); }
.folder-card:hover .name > span:first-of-type { text-decoration: underline; text-underline-offset: 3px; }

/* ---- タグのチップ ---- */
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-8); }
.chip {
  height: 34px; padding: 0 var(--sp-12);
  display: inline-flex; align-items: center; gap: var(--sp-8);
  border: var(--line-w) solid var(--line); background: var(--surface); color: var(--text);
  font-size: var(--fs-14); white-space: nowrap;
}
.chip:has(.chip-x) { padding-right: 6px; }
.chip .chip-x { width: 24px; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; color: var(--text-sub); cursor: pointer; }
.chip .chip-x svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.chip .chip-note,
.chip .chip-count { font-size: var(--fs-12); color: var(--text-sub); }
.chip.is-partial { border-style: dashed; border-color: var(--text-sub); background: transparent; }
.chip.is-partial .chip-fill { border: 0; padding: 0; background: none; display: inline-flex; align-items: center; gap: var(--sp-8); cursor: pointer; }
button.chip.is-suggest,
.chip.is-suggest { background: transparent; cursor: pointer; }
.chip.is-suggest:hover { background: var(--surface); }
.chip.is-active { border-color: transparent; background: var(--accent-strong); color: var(--on-accent); font-weight: var(--fw-bold); }
.chip.is-active .chip-x { color: inherit; }
@media (max-width: 599px) { .chip { height: 40px; font-size: var(--fs-16); } .chip .chip-x { width: 36px; height: 38px; } }

/* ---- ダイアログ（iPhone では下からのシート） ---- */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: var(--z-dialog);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-24); background: var(--scrim);
}
.dialog {
  width: 100%; max-width: var(--dialog-w); max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  border: var(--line-w) solid var(--line);
}
.dialog.is-narrow { max-width: 440px; }
.dialog-head { height: 64px; flex: none; display: flex; align-items: center; gap: var(--sp-12); padding: 0 var(--sp-12) 0 28px; border-bottom: var(--line-w) solid var(--line); }
.dialog-head h2 { margin: 0; font-family: var(--font-serif); font-weight: var(--fw-normal); font-size: var(--fs-18); letter-spacing: var(--ls-head); }
.dialog-head .sub { font-size: var(--fs-13); }
.dialog-head .icon-btn { margin-left: auto; }
.dialog-body { flex: 1; min-height: 0; overflow: auto; padding: var(--sp-24) 28px; display: flex; flex-direction: column; gap: var(--sp-24); }
.dialog-foot { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-12); padding: var(--sp-16) 28px; border-top: var(--line-w) solid var(--line); }
.dialog-foot .hint { margin-right: auto; font-size: var(--fs-12); color: var(--text-sub); }
.dialog-text { margin: 0; line-height: var(--lh-text); }
.field { display: flex; flex-direction: column; }
.field > label { margin-bottom: var(--sp-8); font-size: var(--fs-12); color: var(--text-sub); }
.input {
  height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 var(--sp-12);
  border: 2px solid var(--line); background: var(--bg);
}
.input:focus-within { border-color: var(--accent-strong); }
.input > input { flex: 1; min-width: 0; border: 0; outline: 0; padding: 0; background: none; font-size: 15px; color: var(--text); }
.suggest { margin: 0; padding: 4px 0; list-style: none; border: var(--line-w) solid var(--line); border-top: 0; }
.suggest button { width: 100%; height: 40px; padding: 0 14px; display: flex; align-items: center; gap: var(--sp-8); border: 0; background: none; text-align: left; cursor: pointer; }
.suggest button:hover,
.suggest button[aria-selected="true"] { background: var(--surface); }
.suggest .sub { font-size: var(--fs-13); }
.suggest .is-create { color: var(--accent-strong); }
@media (max-width: 599px) {
  .dialog-backdrop { align-items: flex-end; padding: 0; }
  .dialog { max-width: none; height: 78%; border: 0; padding-bottom: env(safe-area-inset-bottom); }
  .dialog.is-narrow { height: auto; }   /* 短い確認は中身の高さ */
  .dialog-head { height: 52px; padding-left: var(--sp-20); }
  .dialog-body { padding: var(--sp-16) var(--sp-20) var(--sp-32); gap: var(--sp-20); }
  .input { height: 48px; }
  .input > input { font-size: var(--fs-16); }   /* 16px 未満だと iPhone が拡大する */
  .suggest button { height: 44px; }
}

/* ---- 通知（下の中央）と帯（上） ---- */
.toast {
  position: fixed; left: 50%; bottom: var(--sp-24); z-index: var(--z-toast);
  transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--sp-16);
  padding: var(--sp-12) var(--sp-12) var(--sp-12) var(--sp-20);
  background: var(--toast-bg); color: var(--toast-fg);
  font-size: var(--fs-14); white-space: nowrap;
}
.toast.has-actionbar { bottom: calc(var(--actionbar-h) + 20px); }
.toast .toast-action { height: 32px; padding: 0 14px; border: var(--line-w) solid currentColor; background: none; color: inherit; font-weight: var(--fw-bold); cursor: pointer; }
.toast .icon { width: 18px; height: 18px; stroke-width: 1.8; }
@media (max-width: 599px) {
  .toast { left: var(--sp-12); right: var(--sp-12); transform: none; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); white-space: normal; padding: var(--sp-8) var(--sp-8) var(--sp-8) var(--sp-16); }
  .toast .toast-action { height: 40px; white-space: nowrap; }
}

.banner { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-8) var(--sp-12); padding: var(--sp-12) var(--sp-16); background: var(--accent-soft); font-size: var(--fs-14); }
.banner .grow { flex: 1; }
.banner .dot { width: 9px; height: 9px; }
.banner.is-error { background: var(--danger-soft); font-size: var(--fs-13); }
.banner.is-error .title { color: var(--danger); font-weight: var(--fw-bold); }
.banner.is-error .icon { stroke: var(--danger); }
.banner.is-error .btn { height: 30px; border-color: var(--danger); color: var(--danger); }
.banner.is-progress { height: 36px; padding: 0 var(--sp-16); background: var(--surface); font-size: var(--fs-13); }
.banner.is-progress::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: var(--progress, 0%); background: var(--accent); }

/* ---- 操作バー（選択中） ---- */
.actionbar {
  min-height: var(--actionbar-h);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-8) var(--sp-12);
  padding: 10px var(--sp-24);
  background: var(--bar-bg); color: var(--bar-fg);
}
.actionbar .count { margin-right: var(--sp-8); font-size: 15px; font-weight: var(--fw-bold); }
.actionbar .btn { border-color: var(--bar-line); color: var(--bar-fg); font-weight: var(--fw-normal); }
.actionbar .btn:hover { background: rgba(255, 255, 255, .08); }
.actionbar .btn.is-primary { border-color: transparent; background: var(--accent-strong); color: var(--on-accent); font-weight: var(--fw-bold); }
.actionbar .grow { flex: 1; }
.actionbar .btn-text { color: var(--bar-fg); }
/* 暗い操作バーの上では、キーボードの枠を明るいアクセントにする（ライトで 2.2 → 7.0。Home の色とロゴの提案、2026-11-16 承認） */
.actionbar :focus-visible { outline-color: var(--accent-on-bar); }

/* iPhone の下のバー（ふだん：.tabbar、選択中：.actionbar.is-phone） */
.tabbar,
.actionbar.is-phone {
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 0 env(safe-area-inset-bottom);
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0;
}
.tabbar { border-top: var(--line-w) solid var(--line); background: var(--bg); }
.tabbar > a,
.tabbar > button,
.actionbar.is-phone > button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--text-sub); font-size: var(--fs-10); text-decoration: none; cursor: pointer;
}
.tabbar > a, .tabbar > button { font-size: var(--fs-11); letter-spacing: 0; }
.tabbar > [aria-current="page"] { color: var(--accent-strong); font-weight: var(--fw-bold); }
.actionbar.is-phone > button { color: var(--bar-fg); }
.actionbar.is-phone > button.is-primary { color: var(--accent-on-bar); font-weight: var(--fw-bold); }
.tabbar .icon,
.actionbar.is-phone .icon { width: 24px; height: 24px; }

/* ---- ツリー ---- */
.tree { margin: 0; padding: 0; list-style: none; }
.tree ul { margin: 0; padding: 0; list-style: none; }
.tree li[aria-expanded="false"] > ul { display: none; }
.tree-drive { height: 36px; display: flex; align-items: center; gap: var(--sp-8); padding: 0 var(--sp-20); font-size: var(--fs-12); color: var(--text-sub); }
.tree-drive .state { margin-left: auto; display: flex; align-items: center; gap: 5px; }
.tree-drive .state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tree-drive .state.is-ok { color: var(--ok); }
.tree-drive .state.is-missing { color: var(--danger); }
.tree-row {
  height: var(--tree-row-h);
  display: flex; align-items: center; gap: 4px;
  padding: 0 var(--sp-16) 0 calc(12px + var(--depth, 0) * 18px);
  color: var(--text);
}
.tree-row:hover { background: var(--surface); }
.tree-row.is-current { background: var(--accent-strong); color: var(--on-accent); font-weight: var(--fw-bold); }
.tree-row .twisty { width: 20px; height: 20px; flex: none; padding: 0; display: flex; align-items: center; justify-content: center; border: 0; background: none; color: inherit; cursor: pointer; }
.tree-row .twisty svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 1.2; transition: transform var(--dur-fast) var(--ease); }
.tree li[aria-expanded="true"] > .tree-row .twisty svg { transform: rotate(90deg); }
.tree-row .name { flex: 0 1 auto; min-width: 0; align-self: stretch; display: flex; align-items: center; color: inherit; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-row .dot { margin-left: 2px; }
.tree-row.is-current .dot { background: var(--on-accent); }
.tree-foot { border-top: var(--line-w) solid var(--line); padding: var(--sp-8) 0 var(--sp-12); }
.tree-foot a { height: 40px; display: flex; align-items: center; gap: 10px; padding: 0 var(--sp-20); color: inherit; text-decoration: none; }
.tree-foot a:hover { background: var(--surface); }
.tree-foot .count { margin-left: auto; font-size: var(--fs-12); color: var(--text-sub); }
.tree-foot .icon { width: var(--icon-l); height: var(--icon-l); stroke-width: 1.2; }
