@import "tailwindcss";
@import "./tom-select.css";
@import "./trix.css";

@theme {
  --color-primary: #1890ff;
  --color-primary-hover: #40a9ff;
  --color-primary-active: #096dd9;
  --color-success: #52c41a;
  --color-warning: #faad14;
  --color-error: #ff4d4f;
  --color-heading: rgba(0, 0, 0, 0.85);
  --color-text: rgba(0, 0, 0, 0.65);
  --color-text-secondary: rgba(0, 0, 0, 0.45);
  --color-disabled: rgba(0, 0, 0, 0.25);
  --color-border: #f0f0f0;
  --color-bg-sidebar: #001529;
  --color-bg-sidebar-hover: #1890ff;
}

@layer base {
  body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    background-color: #f0f2f5; /* AntD default background */
  }

  h1, h2, h3, h4, h5, h6 {
    color: var(--color-heading);
    font-weight: 500;
  }
}

/* AntD Card Style */
.antd-card {
  background: #fff;
  border-radius: 8px; /* Slightly softer */
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03), 0 1px 6px -1px rgba(0, 0, 0, 0.02);
  border: 1px solid #f0f0f0;
}

/* AntD Table Style overrides */
.antd-table {
  width: 100%;
  border-spacing: 0;
  background: #fff;
  font-size: 14px;
  table-layout: fixed; /* 核心：使用固定布局以精确控制宽度 */
}

.antd-table thead th {
  background: #fafafa;
  color: var(--color-heading);
  font-weight: 500;
  text-align: left;
  padding: 12px 8px;
  border-bottom: 1px solid var(--color-border);
  width: 120px; /* 默认 120px */
  min-width: 120px; /* 强制最小 */
  max-width: 120px; /* 强制最大 */
}

/* 特殊列宽度覆盖 - 使用 !important 确保优先级 */
.antd-table .col-avatar { width: 64px !important; min-width: 64px !important; max-width: 64px !important; }
.antd-table .col-status { width: 100px !important; min-width: 100px !important; max-width: 100px !important; }
.antd-table .col-online { width: 80px !important; min-width: 80px !important; max-width: 80px !important; }
.antd-table .col-group { width: 140px !important; min-width: 140px !important; max-width: 140px !important; }
.antd-table .col-tags { width: 120px !important; min-width: 120px !important; max-width: 120px !important; }
.antd-table .col-actions { 
  width: 200px !important; 
  min-width: 200px !important; 
  max-width: 200px !important; 
  overflow: visible !important; 
}

.antd-table td {
  padding: 12px 8px;
  border-bottom: 1px solid var(--color-border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 120px; 
  min-width: 120px;
  max-width: 120px;
}

/* 拖拽手柄样式 */
.drag-handle {
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}

.sortable-ghost {
  opacity: 0.4;
  background: #e6f7ff !important;
}

.sortable-chosen {
  background: #fafafa !important;
}

.antd-table tbody tr:hover td {
  background: #fafafa;
}

/* Sticky Actions Column (Right) */
.antd-table th:last-child,
.antd-table td:last-child {
  position: sticky !important;
  right: 0;
  z-index: 30;
  text-align: right !important;
  white-space: nowrap !important;
  width: 200px !important;
  min-width: 200px !important;
  max-width: 200px !important;
}

/* 加深左侧阴影边界 */
.antd-table th:last-child::after,
.antd-table td:last-child::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -15px; /* 增加宽度 */
  width: 15px;
  pointer-events: none;
  /* 强化阴影颜色和层次 */
  background: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.12));
  border-right: 1px solid rgba(0, 0, 0, 0.05); /* 增加一条极细的实线边界 */
}

.antd-table th:last-child {
  background: #fafafa !important;
}

.antd-table td:last-child {
  background: #fff !important;
  white-space: nowrap; /* 核心：防止按钮换行，宽度自适应数量 */
}

.antd-table tbody tr:hover td:last-child {
  background: #fafafa !important;
}

.antd-table tbody tr:last-child td {
  border-bottom: none;
}

/* AntD Button Style */
.antd-btn-primary {
  background-color: var(--color-primary);
  border: 1px solid var(--color-primary);
  color: #fff;
  transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 4px 15px;
  height: 32px;
  font-size: 14px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);
  cursor: pointer;
}

.antd-btn-primary:hover {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.antd-btn-primary:active {
  background-color: var(--color-primary-active);
  border-color: var(--color-primary-active);
}

/* AntD Form & Input Standards */
.antd-form-item {
  margin-bottom: 24px;
}

.antd-form-label {
  display: block;
  margin-bottom: 8px;
  color: var(--color-heading);
  font-size: 14px;
}

/* Strictly Ant Design Specification */
.antd-input {
  @apply block w-full rounded-md border border-[#d9d9d9] px-3 py-1.5 text-sm text-gray-900 shadow-none transition-all duration-200;
  height: 36px; /* AntD Standard Height */
}

.antd-input:hover {
  @apply border-primary;
}

.antd-input:focus {
  @apply border-primary ring-4 ring-primary/10 outline-none;
}

.antd-input::placeholder {
  color: #bfbfbf;
}

/* 特殊高度适配 */
textarea.antd-input {
  height: auto !important;
}

/* 增强 Select 样式 (AntD 风格) */
select.antd-input {
  @apply bg-white pr-8 appearance-none cursor-pointer;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23bfbfbf' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.2em 1.2em;
}

.antd-form-label {
  @apply block text-sm font-normal text-[#262626] mb-2;
}

.antd-form-item {
  @apply mb-6;
}

.antd-btn-primary {
  @apply inline-flex items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary transition-all active:scale-95;
  height: 36px;
}

.antd-input:hover {
  border-color: var(--color-primary-hover);
}

.antd-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

.antd-input::placeholder {
  color: #bfbfbf;
}

/* Error state */
.field_with_errors .antd-input {
  border-color: var(--color-error) !important;
}

.field_with_errors .antd-input:focus {
  box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important;
}

/* TomSelect AntD Theme Overrides */
.ts-control {
  @apply !block !w-full !rounded-md !border !border-[#d9d9d9] !px-3 !py-1.5 !text-sm !text-gray-900 !shadow-none !transition-all !duration-200 !min-h-[36px];
}

.ts-wrapper.focus .ts-control {
  @apply !border-primary !ring-4 !ring-primary/10 !outline-none;
}

.ts-wrapper.multi .ts-control > div {
  @apply !bg-gray-100 !border-gray-200 !text-gray-700 !rounded !px-2 !mr-1;
}

.ts-dropdown {
  @apply !rounded-md !border-[#d9d9d9] !shadow-lg !mt-1;
}

.ts-dropdown .active {
  @apply !bg-blue-50 !text-primary;
}

.ts-control .item {
  @apply !flex !items-center;
}

/* 兼容 AntD 箭头图标 */
.ts-wrapper:not(.input-active) .ts-control {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23bfbfbf' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important;
  background-position: right 0.5rem center !important;
  background-repeat: no-repeat !important;
  background-size: 1.2em 1.2em !important;
}

/* Trix / Action Text Fixes */
trix-editor {
  background-color: white !important;
}

.trix-content ul {
  list-style-type: disc !important;
  margin-left: 1rem !important;
}

.trix-content ol {
  list-style-type: decimal !important;
  margin-left: 1rem !important;
}

/* Pagination Styles (Bootstrap compatible classes for Pagy) */
.pagination {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 8px;
}

.page-item .page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  color: var(--color-text);
  text-decoration: none;
  transition: all 0.3s;
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
}

.page-item.active .page-link {
  border-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 500;
}

.page-item.disabled .page-link {
  color: var(--color-disabled);
  border-color: #d9d9d9;
  background: #f5f5f5;
  cursor: not-allowed;
}

.page-item:not(.active):not(.disabled) .page-link:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Tom Select AntD refinement */
.ts-control {
  border-radius: 6px !important;
  padding: 5px 12px !important;
  border-color: #d9d9d9 !important;
  box-shadow: none !important;
}

.ts-control:hover {
  border-color: var(--color-primary-hover) !important;
}

.ts-wrapper.focus .ts-control {
  border-color: var(--color-primary) !important;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2) !important;
}

/* Clear Button visibility and positioning */
.ts-wrapper .clear-button {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: absolute !important;
  right: 10px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  font-size: 14px !important;
  color: var(--color-text-secondary) !important;
  opacity: 0 !important; /* Hide by default, show on hover */
  transition: all 0.2s !important;
  width: 16px !important;
  height: 16px !important;
  border-radius: 50% !important;
  background: #fff !important;
  margin-right: 0 !important;
  z-index: 10 !important;
}

.ts-wrapper:hover .clear-button {
  opacity: 0.6 !important;
}

.ts-wrapper .clear-button:hover {
  opacity: 1 !important;
  color: var(--color-text) !important;
}

/* Ensure control padding accounts for buttons */
.ts-control {
  padding-right: 30px !important;
}

/* Multiple Tags (Items) styling */
.ts-wrapper.multi .ts-control > div {
  background: #f5f5f5 !important;
  border: 1px solid #f0f0f0 !important;
  border-radius: 4px !important;
  color: var(--color-text) !important;
  padding: 0 4px 0 8px !important;
  margin: 2px 4px 2px 0 !important;
}

.ts-wrapper.multi .ts-control > div .remove {
  border-left: none !important;
  margin-left: 4px !important;
  color: var(--color-text-secondary) !important;
  font-size: 14px !important;
}

.ts-wrapper.multi .ts-control > div .remove:hover {
  background: transparent !important;
  color: var(--color-text) !important;
}

/* --- Tom Select Repair & AntD Alignment --- */

.ts-wrapper {
  width: 100%;
}

.ts-control {
  min-height: 32px !important;
  border-radius: 6px !important;
  border: 1px solid #d9d9d9 !important;
  padding: 4px 11px !important;
  box-shadow: none !important;
  background-color: #fff !important;
  transition: all 0.2s !important;
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  position: relative !important;
}

/* 移除 Tom Select 的默认边框阴影 */
.ts-wrapper.single .ts-control, .ts-wrapper.multi .ts-control {
  border: 1px solid #d9d9d9 !important;
}

.ts-control:hover {
  border-color: var(--color-primary-hover) !important;
}

.ts-wrapper.focus .ts-control {
  border-color: var(--color-primary) !important;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2) !important;
}

.ts-control > input {
  font-size: 14px !important;
  color: var(--color-text) !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

/* 修正单选模式下的显示 */
.ts-wrapper.single .ts-control {
  padding-right: 30px !important;
}

.ts-wrapper.single .ts-control::after {
  content: "";
  display: block;
  width: 8px;
  height: 8px;
  border-right: 1px solid rgba(0,0,0,.25);
  border-bottom: 1px solid rgba(0,0,0,.25);
  transform: rotate(45deg);
  position: absolute;
  right: 12px;
  top: 10px;
  transition: all 0.3s;
}

.ts-wrapper.single.dropdown-active .ts-control::after {
  transform: rotate(-135deg);
  top: 14px;
}

/* Selected Items (Tags) */
.ts-wrapper.multi .ts-control > div {
  background: #f5f5f5 !important;
  border: 1px solid #f0f0f0 !important;
  border-radius: 4px !important;
  color: var(--color-text) !important;
  padding: 0 7px !important;
  margin: 2px 4px 2px 0 !important;
  font-size: 12px !important;
  height: 22px !important;
  display: flex !important;
  align-items: center !important;
}

.ts-wrapper.multi .ts-control > div .remove {
  border-left: none !important;
  margin-left: 4px !important;
  color: rgba(0, 0, 0, 0.45) !important;
  font-size: 10px !important;
}

/* 下拉菜单深度美化 */
.ts-dropdown {
  position: absolute !important;
  margin-top: 4px !important;
  border: none !important;
  border-radius: 8px !important;
  box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05) !important;
  padding: 4px !important;
  z-index: 2000 !important;
  background: #fff !important;
}

.ts-dropdown .option {
  padding: 5px 12px !important;
  font-size: 14px !important;
  color: var(--color-text) !important;
  border-radius: 4px !important;
  cursor: pointer;
}

.ts-dropdown .active {
  background-color: #f5f5f5 !important;
}

.ts-dropdown .selected {
  background-color: #e6f7ff !important;
  font-weight: 600 !important;
}

.ts-wrapper .clear-button {
  right: 10px !important;
  background: #fff !important;
  z-index: 11 !important;
}