/*
 * Custom styles that work with Tailwind CSS.
 * Most styling should be done with Tailwind utility classes directly in the HTML.
 */

/* Global Header */
.global-header {
  background-color: #ffffff;
  border-bottom: 2px solid #e5e7eb;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.header-logo .logo-link {
  text-decoration: none;
  color: #1f2937;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: bold;
  color: #3b82f6;
}

.stages-link {
  color: #3b82f6;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 500;
  transition: color 0.2s ease;
}

.stages-link:hover {
  color: #2563eb;
  text-decoration: none;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.user-info {
  display: flex;
  align-items: center;
}

.welcome-text {
  color: #4b5563;
  font-size: 0.875rem;
}

.user-name {
  font-weight: bold;
  color: #1f2937;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-nav {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  margin: 0;
}

.btn-logout {
  background-color: #6b7280;
}

.btn-logout:hover {
  background-color: #4b5563;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: stretch;
  }

  .header-nav {
    flex-direction: column;
    width: 100%;
  }

  .user-info {
    justify-content: center;
    margin-bottom: 0.5rem;
  }

  .header-actions {
    justify-content: center;
  }
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  border: 0;
  cursor: pointer;
  transition: background-color 0.3s;
  margin-right: 0.625rem;
  margin-bottom: 0.625rem;
  text-decoration: none;
}

.btn-primary {
  background-color: #3b82f6;
  color: white;
}

.btn-primary:hover {
  background-color: #2563eb;
}

.btn-secondary {
  background-color: #6b7280;
  color: white;
}

.btn-secondary:hover {
  background-color: #4b5563;
}

.btn-danger {
  background-color: #ef4444;
  color: white;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-default {
  background-color: #f3f4f6;
  color: #1f2937;
}

.btn-default:hover {
  background-color: #d1d5db;
}

/* Header Section */
.header-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.welcome {
  color: #4b5563;
  font-weight: bold;
  margin-right: 0.625rem;
}

.admin-badge {
  background-color: #ef4444;
  color: white;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  margin-left: 0.25rem;
  font-weight: normal;
}

/* Language Menu Dropdown */
.language-menu-container {
  position: relative;
}

.language-menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  background-color: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: #1f2937;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

/* CSS Anchor Positioning support */
@supports (anchor-name: --anchor) {
  .language-menu-trigger {
    anchor-name: --language-menu-anchor;
  }
}

.language-menu-trigger:hover {
  background-color: #e5e7eb;
  border-color: #9ca3af;
}

.language-icon {
  font-size: 1.125rem;
  line-height: 1;
}

.language-code {
  font-weight: 600;
  color: #3b82f6;
  min-width: 2rem;
  text-align: center;
}


.language-menu-popover {
  position: fixed;
  background-color: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  padding: 0.5rem;
  margin: 0;
  min-width: 200px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 9999;
  inset: unset;
}

/* CSS Anchor Positioning - for modern browsers */
@supports (anchor-name: --anchor) {
  .language-menu-popover {
    position-anchor: --language-menu-anchor;
    top: calc(anchor(bottom) + 0.5rem);
    left: anchor(left);
    right: auto;
    bottom: auto;
  }

  /* Position fallback options for edge cases */
  .language-menu-popover {
    position-try-options: flip-block, flip-inline;
    position-visibility: anchors-visible;
  }
}

/* Fallback positioning for browsers without anchor positioning */
@supports not (anchor-name: --anchor) {
  .language-menu-popover {
    top: 100%;
    left: 0;
    margin-top: 0.5rem;
  }

  .language-menu-container {
    position: relative;
  }
}

.language-menu-popover::backdrop {
  background-color: transparent;
}

.language-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: #1f2937;
  font-size: 0.875rem;
  border-radius: 0.375rem;
  transition: background-color 0.2s ease;
  cursor: pointer;
}

.language-menu-item:hover {
  background-color: #f3f4f6;
  color: #1f2937;
}

.language-menu-item.active {
  background-color: #dbeafe;
  color: #1e40af;
  font-weight: 600;
}

.language-menu-item.active:hover {
  background-color: #bfdbfe;
}

.language-name {
  flex: 1;
}

.language-code-small {
  font-size: 0.75rem;
  color: #6b7280;
  font-weight: 600;
  min-width: 2rem;
  text-align: right;
}

.language-menu-item.active .language-code-small {
  color: #1e40af;
}

/* User Menu Dropdown */
.user-menu-container {
  position: relative;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  background-color: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: #1f2937;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

/* CSS Anchor Positioning support */
@supports (anchor-name: --anchor) {
  .user-menu-trigger {
    anchor-name: --user-menu-anchor;
  }
}

.user-menu-trigger:hover {
  background-color: #e5e7eb;
  border-color: #9ca3af;
}

.user-menu-name {
  font-weight: 600;
  color: #3b82f6;
}

.user-menu-popover {
  background-color: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  padding: 0.5rem;
  margin: 0;
  min-width: 200px;
}

/* CSS Anchor Positioning - for modern browsers */
/* Fallback positioning for browsers without anchor positioning */
@supports not (anchor-name: --anchor) {
  .user-menu-popover {
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
  }

  .user-menu-container {
    position: relative;
  }
}

@supports (anchor-name: --anchor) {
  .user-menu-popover {
    position-anchor: --user-menu-anchor;
    top: calc(anchor(bottom) + 0.5rem);
    left: anchor(left);
    right: auto;
    bottom: auto;
  }

  /* Position fallback options for edge cases */
  .user-menu-popover {
    position-try-options: flip-block, flip-inline;
    position-visibility: anchors-visible;
  }
}

.user-menu-popover::backdrop {
  background-color: transparent;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: #1f2937;
  font-size: 0.875rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 0.375rem;
  transition: background-color 0.2s ease;
  text-align: left;
}

.user-menu-item:hover {
  background-color: #f3f4f6;
  color: #1f2937;
}

.user-menu-item-logout:hover {
  background-color: #fee2e2;
  color: #dc2626;
}

.user-menu-item-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

/* ボタンのデフォルトスタイルをリセット */
.user-menu-item[type="submit"] {
  font-family: inherit;
}

/* Actions */
.actions {
  margin: 1.25rem 0;
}

.login-prompt {
  padding: 1rem;
  background-color: #fffbeb;
  border: 1px solid #fbbf24;
  border-radius: 0.25rem;
  color: #92400e;
}

.login-prompt a {
  color: #1d4ed8;
  font-weight: bold;
}

.form-actions {
  margin-top: 1.25rem;
}

/* Stages List */
.stages-list {
  margin-top: 2rem;
}

.stage-card {
  background-color: white;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.3s;
}

.stage-card:hover {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.stage-card h2 {
  margin-top: 0;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.stage-card h2 a {
  color: #1e40af;
  text-decoration: none;
  transition: all 0.2s ease-in-out;
  display: inline-block;
}

.stage-card h2 a:hover {
  color: #3b82f6;
  transform: translateX(4px);
  text-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.stage-info {
  margin: 0.625rem 0;
  font-size: 0.875rem;
}

.stage-number {
  background-color: #3b82f6;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
}

.stage-guid {
  background-color: #9333ea;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.stage-link-white {
  color: white;
  text-decoration: underline;
  font-weight: 500;
}

.stage-link-white:hover {
  color: white;
  opacity: 0.9;
  text-decoration: underline;
}

.clipboard-container {
    display: inline-flex;
    align-items: center;
}

.clipboard-content {
}

.clipboard-button {
  color: white;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-left: 0.25rem;
  font-size: 0.875rem;
  transition: opacity 0.2s;
}

.clipboard-button:hover {
  opacity: 0.8;
}

.clipboard-button .bi.bi-copy {
  fill: white;
}

.clipboard-button:hover .bi.bi-copy {
  fill: white;
  opacity: 0.8;
}

.difficulty {
  background-color: #f97316;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  display: inline-block;
}

.language {
  background-color: #06b6d4;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
  font-weight: 500;
}

/* マルチプレイ募集バッジ */
.multiplay-recruitment-link {
  text-decoration: none;
  display: inline-block;
  margin-right: 0.625rem;
  transition: transform 0.2s ease;
}

.multiplay-recruitment-link:hover {
  transform: translateY(-1px);
}

.multiplay-badge {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  display: inline-block;
  font-weight: 600;
  font-size: 0.875rem;
  box-shadow: 0 1px 2px rgba(16, 185, 129, 0.2);
  transition: all 0.2s ease;
}

.multiplay-recruitment-link:hover .multiplay-badge {
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

/* マルチプレイ募集のステータスバッジ */
.max-players {
  background-color: #10b981;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
}

.start-time {
  background-color: #6366f1;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
}

.status-recruiting {
  background-color: #10b981;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
  font-weight: bold;
}

.status-closed {
  background-color: #6b7280;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
}

.status-ongoing {
  background-color: #f59e0b;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
  font-weight: bold;
}

.status-finished {
  background-color: #374151;
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
}

.status-default {
  background-color: #d1d5db;
  color: #1f2937;
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  margin-right: 0.625rem;
  display: inline-block;
}

.description {
  color: #4b5563;
  margin: 1rem 0;
  line-height: 1.625;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.meta {
  color: #9ca3af;
  font-size: 0.75rem;
  margin-top: 1rem;
  border-top: 1px solid #e5e7eb;
  padding-top: 0.625rem;
}

.date {
  font-style: italic;
}

.author {
  color: #4b5563;
  margin-right: 1rem;
  font-weight: bold;
}

.comments-count {
  color: #6366f1;
  margin-right: 1rem;
  font-weight: 500;
}

.no-stages {
  text-align: center;
  color: #9ca3af;
  padding: 2.5rem;
  font-size: 1rem;
}

/* Stage Detail */
.stage-detail {
  padding: 1.25rem;
}

.stage-content {
  margin: 2rem 0;
}

.stage-content h3 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1f2937;
  margin-top: 2rem;
  margin-bottom: 1rem;
  position: relative;
}

.stage-content h3::before {
  content: "■";
  color: #3b82f6;
  margin-right: 0.5rem;
  font-size: 1.2rem;
}

.tips {
  background: linear-gradient(135deg, #f5e6d3 0%, #e8d5b7 100%);
  border: 2px solid #b8956a;
  border-radius: 2px;
  padding: 1rem;
  margin: 0.625rem 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.15),
    inset 0 0 20px rgba(139, 115, 85, 0.05);
  position: relative;
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
}

.tips::before {
  content: "📌";
  position: absolute;
  top: -8px;
  left: 10px;
  font-size: 1.5rem;
  filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.3));
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-weight: bold;
  margin-bottom: 0.25rem;
  color: #4b5563;
}

.form-group label .required {
  color: #ef4444;
  margin-left: 0.25rem;
  font-weight: bold;
}

.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  box-sizing: border-box;
}

.form-control:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea.form-control {
  resize: vertical;
  font-family: inherit;
}

/* Error Messages */
.error-messages {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 0.25rem;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.error-messages h3 {
  color: #b91c1c;
  margin-top: 0;
}

.error-messages ul {
  margin: 0.625rem 0 0 1.25rem;
  color: #b91c1c;
}

/* Notice Messages */
.notice {
  background-color: #d1fae5;
  border: 1px solid #86efac;
  color: #065f46;
  padding: 0.75rem 1.25rem;
  border-radius: 0.25rem;
  margin: 1rem auto;
  max-width: 1200px;
  text-align: center;
  font-weight: 500;
}

.alert {
  background-color: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 0.75rem 1.25rem;
  border-radius: 0.25rem;
  margin: 1rem auto;
  max-width: 1200px;
  text-align: center;
  font-weight: 500;
}

/* Authentication Forms */
.auth-form {
  max-width: 32rem;
  margin: 3rem auto;
  padding: 2rem;
  background-color: white;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.auth-form h1 {
  text-align: center;
  margin-bottom: 2rem;
}

.oauth-divider {
  text-align: center;
  margin: 1.5rem 0;
  position: relative;
}

.oauth-divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background-color: #e5e7eb;
  z-index: 0;
}

.oauth-divider span {
  background-color: #ffffff;
  padding: 0 1rem;
  color: #9ca3af;
  font-size: 0.875rem;
  position: relative;
  z-index: 1;
}

.oauth-buttons {
  margin-top: 1rem;
}

.btn-google {
  width: 100%;
  background-color: #ffffff;
  color: #3c4043;
  border: 1px solid #dadce0;
  padding: 0.625rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.btn-google:hover {
  background-color: #f8f9fa;
  border-color: #d2e3fc;
  box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
}

.btn-google:active {
  background-color: #f1f3f4;
  border-color: #d2e3fc;
}

.auth-links {
  text-align: center;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e5e7eb;
}

.auth-links a {
  color: #3b82f6;
  font-weight: bold;
}

/* Comments Section */
.comments-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px solid #e5e7eb;
}

.comments-title {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 1.5rem;
  color: #1f2937;
}

.comment-form-container {
  background-color: #f9fafb;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.comment-form-container h3 {
  margin-top: 0;
  margin-bottom: 1rem;
  color: #1f2937;
}

.comments-list {
  margin-top: 1.5rem;
}

.comment-item {
  background-color: white;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  transition: box-shadow 0.3s;
}

.comment-item:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #f3f4f6;
}

.comment-author {
  font-weight: bold;
  color: #1f2937;
  font-size: 0.875rem;
}

.comment-date-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.comment-date,
.diff-date {
  color: #9ca3af;
  font-size: 0.75rem;
}

.comment-content {
  color: #4b5563;
  line-height: 1.625;
  margin-bottom: 0.5rem;
}

.comment-content p {
  margin: 0.5rem 0;
}

.comment-actions {
  text-align: right;
  margin-top: 0.5rem;
}

.btn-comment-delete {
  background-color: #ef4444;
  color: white;
  border: none;
  padding: 0.25rem 0.75rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background-color 0.3s;
}

.btn-comment-delete:hover {
  background-color: #dc2626;
}

.no-comments {
  text-align: center;
  color: #9ca3af;
  padding: 2rem;
  font-style: italic;
}

/* Responsive adjustments for comments */
@media (max-width: 768px) {
  .comment-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
}

/* Tag Selection Popover (using Popover API) */
[popover].tag-modal-popover {
  background-color: white;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  max-width: 700px;
  width: 90vw;
  max-height: 85vh;
  overflow: hidden;
  padding: 0;
  margin: auto;
  position: fixed;
  inset: 0;
}

/* Popover backdrop styling */
[popover].tag-modal-popover::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

/* Opening animation */
[popover].tag-modal-popover:popover-open {
  animation: slideUpFade 0.3s ease;
}

@keyframes slideUpFade {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Closing animation */
@starting-style {
  [popover].tag-modal-popover:popover-open {
    transform: translateY(20px);
    opacity: 0;
  }
}

.tag-modal-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 85vh;
}

.tag-modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #f9fafb;
}

.tag-modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1f2937;
  margin: 0;
}

.tag-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #6b7280;
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  transition: all 0.2s ease;
}

.tag-modal-close:hover {
  background-color: #e5e7eb;
  color: #1f2937;
}

.tag-modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-height: 0;
}

.tag-category-section {
  margin-bottom: 2rem;
}

.tag-category-section:last-child {
  margin-bottom: 0;
}

.tag-category-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e5e7eb;
}

.tag-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.625rem;
}

@media (min-width: 640px) {
  .tag-checkboxes {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .tag-checkboxes {
    grid-template-columns: repeat(3, 1fr);
  }
}

.tag-checkbox-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 0.875rem;
  border: 1.5px solid #e5e7eb;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  cursor: pointer;
  background-color: white;
  min-height: 2.75rem;
}

.tag-checkbox-item:hover {
  background-color: #f3f4f6;
  border-color: #93c5fd;
  box-shadow: 0 1px 3px rgba(59, 130, 246, 0.1);
}

.tag-checkbox-item:has(input[type="checkbox"]:checked) {
  background-color: #eff6ff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.tag-checkbox-item input[type="checkbox"] {
  width: 1.125rem;
  height: 1.125rem;
  cursor: pointer;
  margin-right: 0.625rem;
  accent-color: #3b82f6;
  flex-shrink: 0;
}

.tag-checkbox-item label {
  cursor: pointer;
  font-size: 0.875rem;
  color: #1f2937;
  margin: 0;
  font-weight: 400;
  flex: 1;
  line-height: 1.4;
  word-break: break-word;
}

.tag-checkbox-item:has(input[type="checkbox"]:checked) label {
  font-weight: 600;
  color: #1e40af;
}

.tag-modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  background-color: #f9fafb;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-shrink: 0;
}

.tag-modal-footer .btn {
  margin: 0;
  white-space: nowrap;
}

.tag-selection-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  background-color: #3b82f6;
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tag-selection-trigger:hover {
  background-color: #2563eb;
}

.tag-selection-summary {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background-color: #f3f4f6;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: #4b5563;
  min-height: 2.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.tag-selection-summary.empty {
  color: #9ca3af;
  font-style: italic;
}

.tag-summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  background-color: #3b82f6;
  color: white;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
}

/* Search Toggle Button */
.search-toggle-button {
  background: linear-gradient(to bottom, #ffffff, #f9fafb);
  border: none;
  text-align: left;
}

.search-toggle-button:hover {
  background: linear-gradient(to bottom, #f9fafb, #f3f4f6);
}

.search-toggle-button:active {
  background: #f3f4f6;
}

.search-icon {
  transition: transform 0.2s ease;
}

.search-toggle-button:hover .search-icon {
  transform: scale(1.1);
}

.search-chevron {
  transition: transform 0.3s ease;
}

.rotate-180 {
  transform: rotate(180deg);
}

@media (max-width: 640px) {
  [popover].tag-modal-popover {
    width: 95vw;
    max-height: 90vh;
  }

  .tag-checkboxes {
    grid-template-columns: 1fr !important;
  }

  .tag-modal-footer {
    flex-direction: column;
  }

  .tag-modal-footer .btn {
    width: 100%;
  }

  .tag-modal-header {
    padding: 1rem;
  }

  .tag-modal-body {
    padding: 1rem;
  }

  .tag-category-section {
    margin-bottom: 1.5rem;
  }

  .search-toggle-button {
    padding: 1rem 1.25rem;
  }

  .search-text {
    font-size: 0.875rem;
  }
}

/* ========================================
   Stage Selection Modal (Popover API)
   ======================================== */

/* Stage selection trigger button */
.stage-selection-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  background-color: #3b82f6;
  color: white;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.stage-selection-trigger:hover {
  background-color: #2563eb;
}

/* Stage selection summary */
.stage-selection-summary {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background-color: #f3f4f6;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  min-height: 3rem;
  display: flex;
  align-items: center;
}

.stage-selected-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background-color: #dbeafe;
  color: #1e40af;
  border-radius: 0.375rem;
  font-weight: 500;
  font-size: 0.875rem;
}

.stage-clear-button {
  background: none;
  border: none;
  color: #1e40af;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0;
  margin-left: 0.5rem;
  line-height: 1;
  transition: color 0.2s;
}

.stage-clear-button:hover {
  color: #1e3a8a;
}

/* Stage modal popover */
[popover].stage-modal-popover {
  background-color: white;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  max-width: 700px;
  width: 90vw;
  padding: 0;
  margin: auto;
  inset: 0;
  max-height: 85vh;
}

[popover].stage-modal-popover::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

[popover].stage-modal-popover:popover-open {
  animation: slideUpFade 0.3s ease;
}

.stage-modal-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 85vh;
}

.stage-modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.stage-modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1f2937;
  margin: 0;
}

.stage-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #6b7280;
  cursor: pointer;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  transition: all 0.2s;
}

.stage-modal-close:hover {
  background-color: #e5e7eb;
  color: #1f2937;
}

/* Search input */
.stage-modal-search {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.stage-modal-search input {
  width: 100%;
}

/* Tabs */
.stage-modal-tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.stage-tab {
  flex: 1;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #6b7280;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.stage-tab:hover {
  color: #3b82f6;
  background-color: #f9fafb;
}

.stage-tab.active {
  color: #3b82f6;
  border-bottom-color: #3b82f6;
  background-color: #eff6ff;
}

/* Tab content */
.stage-tab-content {
  display: none;
  animation: fadeIn 0.2s ease;
}

.stage-tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.stage-modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-height: 0;
}

/* Stage list */
.stage-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stage-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  background-color: white;
  transition: all 0.2s;
  cursor: pointer;
}

.stage-item:hover {
  border-color: #3b82f6;
  background-color: #f9fafb;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.stage-item:active {
  transform: scale(0.98);
}

.stage-item-content {
  flex: 1;
  min-width: 0;
}

.stage-item-title {
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-item-guid {
  font-size: 0.875rem;
  color: #6b7280;
  font-family: 'Courier New', monospace;
}

/* Responsive */
@media (max-width: 768px) {
  [popover].stage-modal-popover {
    width: 95vw;
    max-height: 90vh;
  }

  .stage-modal-header {
    padding: 1rem;
  }

  .stage-modal-body {
    padding: 1rem;
  }

  .stage-modal-search {
    padding: 0.75rem 1rem;
  }

  .stage-item {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .stage-item .btn {
    width: 100%;
  }
}

