/* ============================================================================
   CATALOG EDITOR — Table Layout
   ============================================================================ */

.ce-container {
  display: flex;
  height: calc(100vh - 160px);
  gap: 0;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  overflow: hidden;
}

/* ---- Left panel: catalog list ---- */

.ce-sidebar {
  width: 240px;
  min-width: 240px;
  border-right: 1px solid var(--border-color, #e2e8f0);
  display: flex;
  flex-direction: column;
  background: #f8fafc;
}

.ce-sidebar-title {
  padding: 16px 16px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
}

.ce-catalog-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.ce-catalog-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #475569;
  transition: all 0.15s;
}

.ce-catalog-item:hover {
  background: #e2e8f0;
}

.ce-catalog-item.active {
  background: var(--color-primary, #2563eb);
  color: #fff;
}

.ce-catalog-item .ce-catalog-count {
  margin-left: auto;
  font-size: 12px;
  opacity: 0.6;
}

/* ---- Right panel ---- */

.ce-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ce-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  flex-shrink: 0;
}

.ce-header-left h2 {
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
  margin: 0;
}

.ce-header-left .ce-subtitle {
  font-size: 13px;
  color: #94a3b8;
  margin-top: 2px;
}

.ce-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ce-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--color-primary, #2563eb);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.ce-add-btn:hover {
  filter: brightness(1.1);
}

/* ---- Table ---- */

.ce-table-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
}

.ce-table {
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

/* Header */

.ce-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.ce-table th {
  background: #f8fafc;
  border-bottom: 2px solid var(--border-color, #e2e8f0);
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  white-space: nowrap;
  vertical-align: middle;
}

.ce-col-handle {
  width: 40px;
  min-width: 40px;
}

.ce-col-status {
  width: 56px;
  min-width: 56px;
  text-align: center !important;
}

.ce-col-lang {
  min-width: 200px;
  position: relative;
}

.ce-col-lang.base-lang {
  background: #eff6ff !important;
}

/* Language column header content */

.ce-lang-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ce-lang-header-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
}

.ce-base-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-primary, #2563eb);
  background: var(--color-primary-bg, #eff6ff);
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 2px;
}

.ce-lang-missing-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--color-warning, #f59e0b);
  border-radius: 99px;
  line-height: 1;
}

.ce-header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.1s;
  margin-left: auto;
}

.ce-header-btn:hover {
  background: #e2e8f0;
  color: #475569;
}

.ce-header-btn.active {
  color: var(--color-primary, #2563eb);
  background: #dbeafe;
}

/* Preview popover */

.ce-preview-popover {
  position: absolute;
  top: 100%;
  left: 8px;
  right: 8px;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  padding: 10px;
  margin-top: 4px;
}

.ce-preview-popover label {
  font-size: 11px;
  font-weight: 500;
  color: #94a3b8;
  display: block;
  margin-bottom: 4px;
}

.ce-preview-select {
  width: 100%;
  padding: 7px 10px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 6px;
  background: #fff;
  color: #1e293b;
  outline: none;
  cursor: pointer;
}

.ce-preview-select:focus {
  border-color: var(--color-primary, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ---- Table body ---- */

.ce-table td {
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  padding: 0;
  vertical-align: middle;
  height: 44px;
}

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

/* Drag handle cell */

.ce-td-handle {
  text-align: center;
  width: 40px;
}

.ce-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0 auto;
  color: #c7cdd5;
  cursor: grab;
  border-radius: 4px;
  transition: all 0.1s;
}

.ce-drag-handle:hover {
  color: #64748b;
  background: #e2e8f0;
}

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

/* Status cell */

.ce-td-status {
  text-align: center;
  width: 56px;
}

.ce-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  transition: all 0.1s;
  margin: 0 auto;
}

.ce-toggle-btn.on {
  color: var(--color-success, #22c55e);
}

.ce-toggle-btn.off {
  color: var(--color-error, #ef4444);
}

.ce-toggle-btn:hover {
  background: #f1f5f9;
}

/* Language cells */

.ce-td-lang {
  min-width: 200px;
}

.ce-td-lang.base-lang-cell {
  background: #fafcff;
}

.ce-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  min-height: 32px;
  cursor: text;
  border-radius: 4px;
  margin: 2px 4px;
  transition: background 0.1s;
}

.ce-cell:hover {
  background: #f1f5f9;
}

.ce-cell-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #1e293b;
}

.ce-table tr.disabled-row .ce-cell-text {
  color: #94a3b8;
  text-decoration: line-through;
}

.ce-cell-empty {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #cbd5e1;
  font-style: italic;
  font-size: 13px;
}

.ce-cell-translate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.1s;
  opacity: 0;
  flex-shrink: 0;
}

.ce-cell:hover .ce-cell-translate-btn,
.ce-cell-translate-btn.translating {
  opacity: 1;
}

.ce-cell-translate-btn:hover {
  background: var(--color-primary-bg, #eff6ff);
  color: var(--color-primary, #2563eb);
}

.ce-cell-translate-btn.translating {
  animation: ce-spin 1s linear infinite;
  color: var(--color-primary, #2563eb);
}

@keyframes ce-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Cell input (editing mode) */

.ce-cell-input {
  width: 100%;
  padding: 6px 10px;
  margin: 2px 4px;
  font-size: 14px;
  font-family: inherit;
  border: 2px solid var(--color-primary, #2563eb);
  border-radius: 6px;
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  box-sizing: border-box;
}

/* ---- New item row ---- */

.ce-table tr.ce-new-row td {
  border-top: 2px dashed var(--color-primary, #2563eb);
  background: #fafcff;
  padding: 4px;
}

.ce-new-input {
  width: 100%;
  padding: 6px 10px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 6px;
  outline: none;
  box-sizing: border-box;
}

.ce-new-input:focus {
  border-color: var(--color-primary, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.ce-new-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.ce-save-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: var(--color-success, #22c55e);
  color: #fff;
  cursor: pointer;
}

.ce-save-btn:hover {
  filter: brightness(1.1);
}

.ce-cancel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: #f1f5f9;
  color: #64748b;
  cursor: pointer;
}

.ce-cancel-btn:hover {
  background: #e2e8f0;
}

/* ---- Drag & drop states ---- */

.ce-table tr.dragging {
  opacity: 0.4;
  background: var(--color-primary-bg, #eff6ff);
}

.ce-table tr.drag-over-above td {
  box-shadow: inset 0 2px 0 0 var(--color-primary, #2563eb);
}

.ce-table tr.drag-over-below td {
  box-shadow: inset 0 -2px 0 0 var(--color-primary, #2563eb);
}

/* ---- Empty state ---- */

.ce-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #94a3b8;
  gap: 8px;
}

.ce-empty p {
  font-size: 14px;
}

/* ---- Responsive ---- */

@media (max-width: 640px) {
  .ce-sidebar {
    width: 180px;
    min-width: 180px;
  }
  .ce-col-lang {
    min-width: 160px;
  }
}
