/* --- Panel Toolbar --- */
#wdb-panel-toolbar {
  padding: 5px;
  background-color: #f1f1f1;
  border-bottom: 1px solid #ddd;
  display: flex;
  justify-content: flex-start;
  /* Left align; gap will push other items */
  gap: 4px;
  /* Narrower spacing */
  position: relative;
  /* For dropdown positioning */
  flex-wrap: nowrap;
  /* No wrap; items hidden in edit mode if fewer */
}

/* --- Toolbar Buttons (Shared Style) --- */
.wdb-toolbar-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  /* Prevent horizontal shrink */
  transition: background-color 0.2s, border-color 0.2s;
  color: #333;
  text-decoration: none;
  position: relative;
  /* For dropdown positioning */
  box-sizing: border-box;
}

.wdb-toolbar-button:hover {
  background-color: #e9e9e9;
  border-color: #999;
}

/* Disabled state */
.wdb-toolbar-button.is-disabled,
#wdb-panel-toolbar .wdb-toolbar-button.is-disabled {
  background-color: #f5f5f5;
  border-color: #ddd;
  color: #aaa;
  cursor: not-allowed;
}

.wdb-toolbar-button.is-disabled:hover,
#wdb-panel-toolbar .wdb-toolbar-button.is-disabled:hover {
  background-color: #f5f5f5;
  border-color: #ddd;
}


#wdb-annotorious-toolbar {
  padding-left: 4px;
}

/* --- Export Dropdown Menu --- */
.wdb-toolbar-dropdown {
  position: absolute;
  top: 100%;
  /* Position below the button */
  right: 0;
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  z-index: 10;
  min-width: 180px;
  display: none;
  /* Hidden by default */
}

.wdb-toolbar-dropdown.is-visible {
  display: block;
  /* Shown with JS */
}

.wdb-dropdown-item {
  display: block;
  padding: 8px 12px;
  color: #333;
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.wdb-dropdown-item:hover {
  background-color: #f5f5f5;
}


/* --- Thumbnail Pager Modal --- */
.wdb-pager-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  background-color: rgba(0, 0, 0, 0.5);
  /* Semi-transparent background */
  display: none;
  /* Hidden by default */
  align-items: flex-start;
  justify-content: center;
}

.wdb-pager-modal.is-visible {
  display: flex;
}

.wdb-pager-modal-content {
  position: relative;
  background-color: #f0f0f0;
  padding: 20px;
  padding-top: 50px;
  /* Space for the close button */
  border-radius: 5px;
  max-width: 95%;
  width: 90%;
  height: auto;
  max-height: 40%;
  display: flex;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.wdb-pager-modal-close {
  position: absolute;
  top: 5px;
  right: 10px;
  border: none;
  background: none;
  font-size: 2rem;
  font-weight: bold;
  line-height: 1;
  color: #555;
  cursor: pointer;
  opacity: 0.7;
}

.wdb-pager-modal-close:hover {
  opacity: 1;
}

/* Thumbnail List inside the Pager */
.wdb-thumbnail-list {
  display: flex;
  flex-direction: row;
  list-style: none;
  margin: 0;
  padding: 0 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #888 #e0e0e0;
  width: 100%;
}

.wdb-thumbnail-list.rtl {
  flex-direction: row-reverse;
  /* For right-to-left languages */
}

/* Scrollbar styles for Webkit browsers (Chrome, Safari) */
.wdb-thumbnail-list::-webkit-scrollbar {
  height: 8px;
}

.wdb-thumbnail-list::-webkit-scrollbar-track {
  background: #e0e0e0;
}

.wdb-thumbnail-list::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.wdb-thumbnail-list::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Individual Thumbnail Items */
.wdb-thumbnail-list li {
  margin: 0 5px;
  flex-shrink: 0;
}

.wdb-thumbnail-list a {
  display: block;
  border: 3px solid transparent;
  padding: 2px;
  text-decoration: none;
  color: #333;
  text-align: center;
  border-radius: 4px;
  transition: border-color 0.2s;
  background: #fff;
}

.wdb-thumbnail-list a:hover {
  border-color: #007bff;
  /* Hover highlight */
}

.wdb-thumbnail-list li.is-current a {
  border-color: #dc3545;
  /* Current page highlight */
  box-shadow: 0 0 5px rgba(220, 53, 69, 0.7);
}

.wdb-thumbnail-list img {
  display: block;
  height: 100px;
  /* Thumbnail height */
  width: auto;
  margin-bottom: 4px;
}

.wdb-thumbnail-list span {
  font-size: 0.8rem;
  display: block;
}

/* ★★★ アクティブ状態のツールのスタイルを追加 ★★★ */
.wdb-toolbar-button.is-active {
  background-color: #cfe2ff;
  /* 明るい青 */
  border-color: #0d6efd;
  /* 青い枠線 */
}

.wdb-toolbar-button.is-active svg {
  color: #0d6efd;
}

/* ★★★ サムネイルページャーのボタンとデザインを揃える ★★★ */
#wdb-panel-toolbar .wdb-toolbar-button {
  /* サムネイルページャーのボタンと同じスタイルを適用 */
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  /* Fix width in flex context */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, border-color 0.2s;
  color: #333;
  text-decoration: none;
  position: relative;
}

#wdb-panel-toolbar .wdb-toolbar-button:hover {
  background-color: #e9e9e9;
  border-color: #999;
}

#wdb-panel-toolbar .wdb-toolbar-button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* Condensed layout for very narrow side panels */
@media (max-width: 480px) {
  #wdb-panel-toolbar {
    gap: 3px;
  }

  .wdb-toolbar-button,
  #wdb-panel-toolbar .wdb-toolbar-button {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
  }

  #wdb-panel-toolbar .wdb-toolbar-button svg,
  .wdb-toolbar-button svg {
    width: 16px;
    height: 16px;
  }
}

/* Ordering classes (left-to-right smaller -> larger). */
#wdb-panel-toolbar .order-mode {
  order: 10;
}

#wdb-panel-toolbar .order-prev {
  order: 20;
}

#wdb-panel-toolbar .order-next {
  order: 30;
}

#wdb-panel-toolbar .order-pager {
  order: 40;
}

/* View mode only */
#wdb-panel-toolbar .order-export {
  order: 50;
}

#wdb-panel-toolbar .order-manifest {
  order: 60;
}

/* Edit mode only (occupy export/manifest slots) */
#wdb-panel-toolbar .order-draw {
  order: 50;
}

#wdb-panel-toolbar .order-select {
  order: 60;
}

/* Always first */
#wdb-panel-toolbar .order-dir {
  order: 0;
  margin-right: 4px;
}

/* Direction badge */
.wdb-dir-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 4px;
  /* harmless, just in case */
  background: transparent;
  /* not a button */
  color: #666;
  /* subdued */
  cursor: default;
  /* not clickable */
  pointer-events: auto;
  /* allow tooltip (title) to show on hover */
  opacity: 0.9;
  /* slight de-emphasis */
  box-sizing: border-box;
}

.wdb-dir-badge svg {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: currentColor;
  /* supplied icons are solid paths */
}

@media (max-width: 480px) {
  .wdb-dir-badge {
    width: 28px;
    height: 28px;
    font-size: 10px;
  }

  .wdb-dir-badge svg {
    width: 20px;
    height: 20px;
    margin-top: 2px;
  }
}

/* Flexible gap to push right-side buttons */
.wdb-toolbar-gap {
  flex: 1 1 0;
  /* can shrink fully to avoid overflow */
  min-width: 0;
  /* no minimum width to prevent overflow */
}

/* --- Annotation Tooltip --- */
.wdb-tooltip {
  position: absolute;
  /* 直接の display 切替はせず、opacity/visibility で制御してトランジション可能にする */
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease, visibility 0s linear 120ms;
  padding: 5px 10px;
  background-color: rgba(0, 0, 0, 0.85);
  color: #fff;
  border-radius: 4px;
  font-size: 0.9em;
  max-width: 300px;
  z-index: 10001;
  /* 他のUI要素より手前に表示 */
  pointer-events: none;
  /* ツールチップ自身がクリックイベントを邪魔しないように */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wdb-tooltip.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 120ms ease, transform 120ms ease, visibility 0s;
}

/* アノテーションパネル サムネイル */
#wdb-annotation-panel-content .sign-thumbnail,
#wdb-annotation-panel-content .word-thumbnail {
  border-bottom: 1px solid rgb(204, 204, 204);
  flex-shrink: 0;
  max-width: 250px;
  max-height: 125px;
  background-color: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
}

#wdb-annotation-panel-content polygon {
  fill: rgba(255, 255, 255, 0.2);
  stroke: #fff;
  stroke-width: 2;
}

.sign-thumbnail.is-clickable,
.sign-item.is-clickable,
.word-thumbnail.is-clickable {
  cursor: pointer;
  transition: background-color 0.2s;
}

.sign-thumbnail.is-clickable:hover,
.sign-item.is-clickable:hover,
.word-thumbnail.is-clickable:hover {
  background-color: #e9e9e9;
  border-color: #999;
}

.panel-navigation {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  background: #f9f9f9;
  border-bottom: 1px solid #eee;
}

.nav-group {
  display: flex;
  align-items: center;
}

.nav-label {
  font-weight: bold;
  margin-right: 8px;
  font-size: 0.9em;
  color: #555;
}

.nav-button-icon {
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background-color: #fff;
  text-decoration: none;
  color: #333;
  margin: 0 2px;
  font-size: 0.85em;
  white-space: nowrap;
}

.nav-button-icon:hover {
  background-color: #f0f0f0;
  border-color: #999;
}

.nav-button-icon[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: #f5f5f5;
  pointer-events: none;
}

.item-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.item-navigation {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background-color: #f0f0f0;
  padding: 2px 0;
  border-radius: 15px;
}

.item-navigation .item-title {
  font-weight: bold;
  font-size: 0.9em;
  color: #555;
}

a.nav-button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  /* ボタンのサイズを定義 */
  height: 28px;
  border-radius: 50%;
  background-color: #e9e9e9;
  color: #333;
  transition: background-color 0.2s;
  text-decoration: none;
}

a.nav-button-icon:hover {
  background-color: #d5d5d5;
}

a.nav-button-icon[disabled] {
  opacity: 0.2;
  cursor: not-allowed;
  background-color: #f5f5f5;
  pointer-events: none;
}

a.nav-button-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

#wdb-full-text-content .word-unit {
  cursor: pointer;
  transition: color 0.2s ease-in-out, background-color 0.2s ease-in-out;
}

#wdb-full-text-content .word-unit:hover {
  color: #0056b3;
  background-color: #e7f3ff;
  border-radius: 3px;
}

#wdb-full-text-content .word-unit.is-highlighted {
  background-color: #ffe082;
  /* 例: 明るい黄色 */
  box-shadow: 0 0 5px #ffc107;
  border-radius: 3px;
}