/* ==========================================================================
   components.css — Modal, badges, alerts, expanders, forms, tables,
   empty states, dropdown, skeleton, tooltip, kbd, chips, progress,
   btn-group, rich editor, segmented control, pagination
   UI/UX Pro Max — Notion/Linear-level shared component library
   ========================================================================== */

/* ---------- Modal / Dialog ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: modal-overlay-in 0.2s ease;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: modal-slide-in 0.2s cubic-bezier(0.21, 1.02, 0.73, 1);
}

.modal-sm { max-width: 400px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 900px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 150ms ease;
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.modal-close:focus-visible {
  box-shadow: var(--focus-ring);
}

.modal-close:active {
  transform: scale(0.92);
}

.modal-close:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.modal-body {
  padding: var(--space-xl);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

@keyframes modal-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-slide-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Modal closing animation */
.modal-overlay.closing {
  animation: modal-overlay-out 0.15s ease-in forwards;
}

.modal-overlay.closing .modal {
  animation: modal-slide-out 0.15s ease-in forwards;
}

@keyframes modal-overlay-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes modal-slide-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
}

/* ---------- Expander / Collapsible ---------- */
.expander {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: visible;
  margin-bottom: var(--space-sm);
  background: var(--surface);
}

.expander-header {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.expander-header[aria-expanded="false"] {
  border-radius: var(--radius-lg);
}

.expander + .expander {
  margin-top: -1px;
}

.expander-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: 12px 16px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 150ms ease;
}

.expander-header:hover {
  background: var(--surface-hover);
}

.expander-header:focus-visible {
  box-shadow: inset var(--focus-ring);
}

.expander-header:active {
  background: var(--gray-100);
}

.expander-chevron {
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

.expander-header[aria-expanded="true"] .expander-chevron {
  transform: rotate(90deg);
}

.expander-body {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-light);
  animation: expander-open 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.expander-header[aria-expanded="false"] + .expander-body {
  display: none;
}

@keyframes expander-open {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Badges — small pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
  border-radius: var(--radius-full);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.badge-default,
.badge-subtle {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

.badge-primary {
  background: #EEF2FF;
  color: #4F46E5;
}

.badge-success {
  background: var(--success-50);
  color: #065F46;
}

.badge-warning {
  background: var(--warning-50);
  color: #92400E;
}

.badge-danger {
  background: var(--danger-50);
  color: #991B1B;
}

.badge-info {
  background: var(--info-50);
  color: #1E40AF;
}

.badge-count {
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--danger-500);
  color: #FFFFFF;
  padding: 0 5px;
}

/* Badge with dot indicator */
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
}

.badge-dot.dot-success { background: var(--success-500); }
.badge-dot.dot-warning { background: var(--warning-500); }
.badge-dot.dot-danger { background: var(--danger-500); }
.badge-dot.dot-info { background: var(--info-500); }

/* ---------- Alerts — Notion callout 風格：灰階為主、平面、小圓角 ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: var(--gray-50);
  border: none;
  border-radius: 4px;
  box-shadow: none;
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--text);
}

/* 變體只用極淡色底區分，文字維持中性灰 */
.alert-info    { background: var(--info-50); }
.alert-success { background: var(--success-50); }
.alert-warning { background: var(--warning-50); }
.alert-danger  { background: var(--danger-50); }

.alert strong {
  font-weight: 600;
  color: var(--text);
}

/* emoji/icon 前綴用原色，不靠 left-border */
.alert-icon {
  flex-shrink: 0;
  margin-top: 2px;
  width: 16px;
  height: 16px;
  color: var(--gray-500);
}
.alert-info    .alert-icon { color: var(--info-500); }
.alert-success .alert-icon { color: var(--success-500); }
.alert-warning .alert-icon { color: var(--warning-500); }
.alert-danger  .alert-icon { color: var(--danger-500); }

.alert-icon {
  flex-shrink: 0;
  margin-top: 1px;
  width: 18px;
  height: 18px;
}

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

.alert-title {
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

/* ---------- Form Group ---------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-bottom: 16px;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.form-label .required {
  color: var(--danger-500);
  margin-left: 2px;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: var(--leading-relaxed);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--danger-500);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.form-row {
  display: flex;
  gap: var(--space-lg);
}

.form-row > * {
  flex: 1;
}

/* Input with error state */
.form-group.has-error input,
.form-group.has-error textarea,
.form-group.has-error select {
  border-color: var(--danger-500);
}

.form-group.has-error input:focus,
.form-group.has-error textarea:focus,
.form-group.has-error select:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-3xl) var(--space-xl);
  text-align: center;
}

.empty-state-icon {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--surface-hover) 0%, var(--border-light) 100%);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

.empty-state-icon svg {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-sm);
}

.empty-state-desc {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 320px;
  line-height: var(--leading-relaxed);
}

.empty-state-action {
  margin-top: var(--space-xl);
}

/* ---------- Button Group ---------- */
.btn-group {
  display: inline-flex;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.btn-group .btn,
.btn-group button {
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--border);
  margin: 0;
}

.btn-group .btn:last-child,
.btn-group button:last-child {
  border-right: none;
}

.btn-group .btn:first-child,
.btn-group button:first-child {
  border-top-left-radius: var(--radius);
  border-bottom-left-radius: var(--radius);
}

.btn-group .btn:last-child,
.btn-group button:last-child {
  border-top-right-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}

.btn-group .btn.active,
.btn-group button.active {
  background: #EEF2FF;
  color: #6366F1;
  font-weight: 600;
}

/* ---------- Rich Editor ---------- */
.rich-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.rich-editor-toolbar,
.rich-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: var(--space-xs) var(--space-sm);
  background: #F9FAFB;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
}

.rich-editor-toolbar button,
.rich-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 150ms ease;
}

.rich-editor-toolbar button:hover,
.rich-toolbar button:hover {
  background: var(--gray-200);
  color: var(--text);
}

.rich-editor-toolbar button:focus-visible,
.rich-toolbar button:focus-visible {
  box-shadow: var(--focus-ring);
}

.rich-editor-toolbar button:active,
.rich-toolbar button:active {
  transform: scale(0.92);
}

.rich-editor-toolbar button:disabled,
.rich-toolbar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.rich-editor-toolbar button.active,
.rich-toolbar button.active {
  background: #EEF2FF;
  color: #6366F1;
}

.rich-editor-content {
  min-height: 120px;
  padding: var(--space-md) var(--space-lg);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  outline: none;
}

.rich-editor-content:focus {
  box-shadow: inset 0 0 0 2px rgba(99, 102, 241, 0.15);
}

/* ---------- Segmented Control ---------- */
.segmented-control {
  display: inline-flex;
  background: #F3F4F6;
  border-radius: var(--radius-lg);
  padding: 3px;
  gap: 2px;
}

.segmented-control button {
  padding: 5px 14px;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.segmented-control button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.5);
}

.segmented-control button:focus-visible {
  box-shadow: var(--focus-ring);
}

.segmented-control button:active {
  transform: scale(0.97);
}

.segmented-control button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.segmented-control button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 var(--space-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 150ms ease;
}

.pagination-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: #6366F1;
}

.pagination-btn:focus-visible {
  box-shadow: var(--focus-ring);
}

.pagination-btn:active {
  transform: scale(0.95);
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.pagination-btn.active {
  background: #6366F1;
  color: #FFFFFF;
  border-color: #6366F1;
}

.pagination-info {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: 0 var(--space-sm);
}

/* ---------- Data Table ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  background: #F9FAFB;
}

.data-table td {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}

.data-table tbody tr {
  transition: background 150ms ease;
}

.data-table tbody tr:hover {
  background: #F9FAFB;
}

.data-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.015);
}

.data-table tbody tr:nth-child(even):hover {
  background: #F9FAFB;
}

/* Sortable table header */
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 150ms ease;
}

.data-table th.sortable:hover {
  color: #6366F1;
}

/* ---------- Progress Bar ---------- */
.progress-bar {
  height: 6px;
  background: var(--surface-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366F1 0%, var(--sidebar-accent) 100%);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
  position: relative;
}

.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  animation: progress-shimmer 2s infinite;
}

@keyframes progress-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.progress-fill.success {
  background: linear-gradient(90deg, var(--success-500) 0%, #34D399 100%);
}

.progress-fill.warning {
  background: linear-gradient(90deg, var(--warning-500) 0%, #FBBF24 100%);
}

.progress-fill.danger {
  background: linear-gradient(90deg, var(--danger-500) 0%, #F87171 100%);
}

/* Progress with label */
.progress-labeled {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.progress-labeled .progress-bar {
  flex: 1;
}

.progress-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 36px;
  text-align: right;
}

/* ---------- Divider ---------- */
.divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-lg) 0;
  border: none;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.divider-text::before,
.divider-text::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-light);
}

/* ---------- Chip / Tag ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--surface-hover);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-light);
  transition: all 150ms ease;
}

.chip:hover {
  border-color: var(--border);
}

.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-full);
  transition: all 150ms ease;
  margin-left: 2px;
}

.chip-remove:hover {
  background: var(--danger-50);
  color: var(--danger-500);
}

.chip-remove:focus-visible {
  box-shadow: var(--focus-ring);
}

.chip-remove:active {
  transform: scale(0.9);
}

/* ---------- Skeleton Loader ---------- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--gray-100) 25%,
    var(--gray-200) 50%,
    var(--gray-100) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

.skeleton-text {
  height: 14px;
  margin-bottom: var(--space-sm);
}

.skeleton-text:last-child {
  width: 60%;
}

.skeleton-text.short {
  width: 40%;
}

.skeleton-card {
  height: 80px;
  margin-bottom: var(--space-md);
  border-radius: var(--radius-lg);
}

.skeleton-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
}

.skeleton-button {
  width: 80px;
  height: 36px;
  border-radius: var(--radius);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Tooltip (CSS-only) ---------- */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) scale(0.95);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  color: #FFFFFF;
  background: var(--gray-800);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: all 150ms ease;
  z-index: 50;
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ---------- Keyboard Shortcut ---------- */
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  line-height: 1;
}

/* ---------- Dropdown Menu ---------- */
.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 180px;
  padding: var(--space-xs) 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  z-index: 50;
  animation: dropdown-in 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
  transition: background 150ms ease;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background: #F9FAFB;
}

.dropdown-item:focus-visible {
  box-shadow: inset var(--focus-ring);
}

.dropdown-item:active {
  background: var(--gray-100);
}

.dropdown-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.dropdown-item.danger {
  color: var(--danger-500);
}

.dropdown-item.danger:hover {
  background: var(--danger-50);
}

.dropdown-divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-xs) 0;
}

@keyframes dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ========== Searchable Select (.ss-*) ========== */
.ss-wrapper {
  position: relative;
  display: inline-flex;
  width: 100%;
}
.ss-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 36px;
  padding: 5px 10px;
  font-size: var(--text-base);
  color: var(--gray-900);
  background: var(--surface);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  text-align: left;
  gap: 8px;
}
.ss-trigger:hover { border-color: var(--gray-300); }
.ss-trigger:focus-visible {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.ss-trigger-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Multi-select: allow chips to wrap */
.ss-multiple .ss-trigger {
  align-items: flex-start;
  min-height: auto;
  padding: 4px 8px;
}
.ss-multiple .ss-trigger-text {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  white-space: normal;
  overflow: visible;
}
.ss-chip {
  display: inline-block;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 500;
  background: var(--primary-50, #eef2ff);
  color: var(--primary-700, #4338ca);
  border-radius: 9999px;
  white-space: nowrap;
  line-height: 1.5;
}
.ss-trigger-text.ss-placeholder { color: var(--gray-400); }
.ss-chevron {
  flex-shrink: 0;
  transition: transform var(--transition-fast);
  color: var(--gray-400);
}
.ss-open .ss-chevron { transform: rotate(180deg); }

/* Dropdown panel */
.ss-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  min-width: 200px;
  max-height: 320px;
  background: var(--surface);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  overflow: hidden;
  flex-direction: column;
}
.ss-open .ss-dropdown { display: flex; }

/* Search input */
.ss-search-wrap {
  padding: 8px;
  border-bottom: 1px solid var(--gray-100);
}
.ss-search {
  width: 100%;
  padding: 6px 10px;
  font-size: var(--text-sm);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--gray-50);
  transition: border-color var(--transition-fast);
}
.ss-search:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.1);
  background: var(--surface);
}
.ss-search::placeholder { color: var(--gray-400); }

/* Options list */
.ss-list {
  overflow-y: auto;
  max-height: 260px;
  padding: 4px;
}

/* Group label */
.ss-group-label {
  padding: 8px 10px 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--primary-600);
  background: var(--primary-50);
  border-left: 3px solid var(--primary-500);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  user-select: none;
  margin: 2px 4px;
}
.ss-group-label:not(:first-child) {
  margin-top: 8px;
}
.ss-divider {
  height: 1px;
  background: var(--gray-100);
  margin: 4px 0;
}

/* Options under a group are indented */
.ss-option.ss-grouped {
  padding-left: 24px;
  font-size: var(--text-sm);
}

/* Option item */
.ss-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: var(--text-sm);
  color: var(--gray-700);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.ss-option:hover, .ss-option.ss-focused {
  background: var(--primary-50);
  color: var(--primary-700);
}
.ss-option.ss-selected {
  color: var(--primary-600);
  font-weight: 500;
}
.ss-option.ss-selected::after {
  content: "✓";
  margin-left: auto;
  font-size: 12px;
  color: var(--primary-500);
}
.ss-option.ss-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.ss-check {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--primary-500);
}
.ss-option mark {
  background: rgba(99,102,241,0.15);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.ss-empty {
  padding: 16px;
  text-align: center;
  color: var(--gray-400);
  font-size: var(--text-sm);
}

/* Size variants */
.ss-wrapper .ss-trigger.form-select-sm,
select.searchable.form-select-sm + .ss-wrapper .ss-trigger {
  min-height: 28px;
  padding: 3px 8px;
  font-size: var(--text-sm);
}

/* Alias hint in searchable select */
.ss-option-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.ss-option-alias {
  font-size: 11px;
  color: var(--gray-400);
  padding-left: 4px;
  line-height: 1.3;
}
.ss-option:hover .ss-option-alias,
.ss-option.ss-focused .ss-option-alias {
  color: var(--primary-400);
}

/* ===== Drop zone (file drag-drop upload) ===== */
.drop-zone {
  position: relative;
  transition: outline 0.15s ease, background 0.15s ease;
}
.drop-zone-active {
  outline: 2px dashed var(--primary-500, #3b82f6);
  outline-offset: -2px;
  background: rgba(59, 130, 246, 0.06);
}
.drop-zone-active::after {
  content: "拖放此處上傳";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--primary-600, #2563eb);
  font-weight: 500;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 14px;
  border-radius: 4px;
  z-index: 10;
}

/* ===== 已上傳附件：可在 rich editor 內拖曳改變位置 ===== */
.attachment-block {
  cursor: move;
  margin: 0.5em 0;
  padding: 2px;
  border-radius: 4px;
  transition: outline 0.1s;
}
.attachment-block:hover {
  outline: 1px dashed var(--gray-400, #9ca3af);
}
.attachment-block.dragging {
  opacity: 0.4;
}

/* ===== 圖片預覽尺寸 =====
   - 預設：max-height 50vh，避免直式截圖把編輯器撐爆
   - 點擊圖片切換 sm / md / lg 三段（資料寫在 .attachment-block[data-size]）
   - 切過的尺寸會跟著 HTML 一起存進 log.md，重新打開仍維持 */
.rich-content img,
.markdown-body img,
.progress-scroll-area img,
.ai-markdown img {
  max-width: 100%;
  max-height: 50vh;
  height: auto;
  width: auto;
}
.rich-content .attachment-block img {
  cursor: zoom-in;
}
.attachment-block[data-size="sm"] img { max-height: 200px; }
.attachment-block[data-size="md"] img { max-height: 50vh; }
.attachment-block[data-size="lg"] img { max-height: none; }

/* hover 時在右上角顯示目前尺寸標記，給使用者一個視覺提示 */
.rich-content .attachment-block { position: relative; }
.rich-content .attachment-block[data-attachment="image"]::after {
  content: attr(data-size);
  position: absolute; top: 4px; right: 4px;
  padding: 1px 6px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: #fff; background: rgba(0, 0, 0, 0.55);
  border-radius: 3px; pointer-events: none;
  opacity: 0; transition: opacity 0.15s;
}
.rich-content .attachment-block[data-attachment="image"]:hover::after {
  opacity: 1;
}
