/* =============================================================================
   SQSA CSV Table Importer & Editor
   ============================================================================= */

.sqsa-csv-builder {
  max-width: 960px;
  margin: 0 auto;
  font-family: inherit;
  color: #1f2b3a;
  position: relative;
}

/* ── Mode tabs ── */
.sqsa-ci-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #c99600;
  margin-bottom: 24px;
}

.sqsa-ci-tab {
  padding: 10px 22px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-bottom: none;
  font-size: 14px;
  font-weight: 600;
  color: #555;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
  transition: background 0.15s, color 0.15s;
  margin-right: 4px;
}

.sqsa-ci-tab:hover {
  background: #ebebeb;
  color: #1f2b3a;
}

.sqsa-ci-tab.is-active {
  background: #c99600;
  color: #ffffff;
  border-color: #c99600;
}

/* ── Step titles ── */
.sqsa-ci-step-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 12px;
  color: #1f2b3a;
}

.sqsa-ci-hint {
  font-size: 15px;
  color: #555;
  margin: 0 0 20px;
}

/* ── Upload area ── */
.sqsa-ci-upload-area {
  position: relative;
  border: 2px dashed #a0adb8;
  border-radius: 8px;
  background: #f7f9fb;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.sqsa-ci-upload-area:hover,
.sqsa-ci-upload-area.is-dragover {
  border-color: #c99600;
  background: #fdf9ee;
}

.sqsa-ci-file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.sqsa-ci-upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  cursor: pointer;
  pointer-events: none;
}

.sqsa-ci-upload-icon {
  font-size: 40px;
  line-height: 1;
  color: #c99600;
  margin-bottom: 12px;
}

.sqsa-ci-upload-text {
  font-size: 16px;
  text-align: center;
  color: #444;
  line-height: 1.6;
}

.sqsa-ci-upload-text small {
  font-size: 13px;
  color: #777;
}

/* ── Messages ── */
.sqsa-ci-error {
  margin-top: 12px;
  padding: 12px 16px;
  background: #fff5f5;
  border: 1px solid #e05252;
  border-radius: 4px;
  color: #b91c1c;
  font-size: 14px;
  line-height: 1.5;
}

.sqsa-ci-warning {
  padding: 16px 20px;
  background: #fffbeb;
  border: 1px solid #d97706;
  border-radius: 4px;
  color: #92400e;
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 20px;
}

.sqsa-ci-warning a { color: #92400e; }

.sqsa-ci-success {
  padding: 16px 20px;
  background: #f0fdf4;
  border: 1px solid #22c55e;
  border-radius: 4px;
  color: #166534;
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 20px;
}

.sqsa-ci-loading {
  margin-top: 12px;
  font-size: 14px;
  color: #555;
  font-style: italic;
}

/* ── Fields ── */
.sqsa-ci-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.sqsa-ci-field {
  flex: 1 1 300px;
}

.sqsa-ci-field label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #1f2b3a;
}

.sqsa-ci-field input[type="text"],
.sqsa-ci-field input[type="number"],
.sqsa-ci-field select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #c0cad4;
  border-radius: 4px;
  font-size: 15px;
  color: #1f2b3a;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.sqsa-ci-field input:focus,
.sqsa-ci-field select:focus {
  outline: none;
  border-color: #c99600;
  box-shadow: 0 0 0 3px rgba(201,150,0,0.15);
}

.sqsa-ci-required { color: #e05252; }

.sqsa-ci-field-error {
  margin-top: 6px;
  font-size: 13px;
  color: #b91c1c;
}

/* ── Settings bar ── */
.sqsa-ci-settings-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  padding: 14px 16px;
  background: #f7f9fb;
  border: 1px solid #dde2e7;
  border-radius: 6px;
  margin-bottom: 16px;
}

.sqsa-ci-settings-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sqsa-ci-settings-field--full {
  flex: 1 1 100%;
}

.sqsa-ci-settings-field label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sqsa-ci-settings-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: #888;
}

.sqsa-ci-setting-intro {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #c0cad4;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
  resize: vertical;
}

.sqsa-ci-setting-intro:focus {
  outline: none;
  border-color: #c99600;
}

.sqsa-ci-setting-header-bg {
  width: 40px;
  height: 32px;
  padding: 2px;
  border: 1px solid #c0cad4;
  border-radius: 4px;
  cursor: pointer;
}

.sqsa-ci-align-group {
  display: flex;
  gap: 0;
}

.sqsa-ci-align-btn {
  padding: 5px 12px;
  border: 1px solid #c0cad4;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  color: #555;
  transition: background 0.12s, color 0.12s;
}

.sqsa-ci-align-btn:first-child { border-radius: 4px 0 0 4px; }
.sqsa-ci-align-btn:last-child  { border-radius: 0 4px 4px 0; border-left: none; }
.sqsa-ci-align-btn:not(:first-child):not(:last-child) { border-left: none; }

.sqsa-ci-align-btn.is-active {
  background: #c99600;
  color: #fff;
  border-color: #c99600;
}

.sqsa-ci-align-btn:hover:not(.is-active) {
  background: #f5f5f5;
}

.sqsa-ci-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  color: #333;
}

.sqsa-ci-toggle input { cursor: pointer; }

/* ── Grid ── */
.sqsa-ci-grid-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #d0d5db;
  border-radius: 6px;
  margin-bottom: 16px;
}

.sqsa-ci-grid-hint {
  font-size: 12px;
  color: #888;
  padding: 6px 10px;
  background: #fafafa;
  border-bottom: 1px solid #e8e8e8;
}

.sqsa-ci-grid-hint strong {
  color: #555;
  font-weight: 600;
}

.sqsa-ci-hint-btn {
  background: none;
  border: 1px solid #c0cad4;
  border-radius: 3px;
  padding: 2px 10px;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sqsa-ci-hint-btn:hover,
.sqsa-ci-hint-btn.is-active {
  background: #c99600;
  border-color: #c99600;
  color: #fff;
}

/* Column width row */
.sqsa-ci-col-widths-row {
  background: #f0f4ff;
  border-bottom: 1px solid #c0cad4;
  padding: 8px 10px 6px;
}

.sqsa-ci-col-widths-row[hidden] { display: none; }

.sqsa-ci-col-widths-inner {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.sqsa-ci-col-width-cell {
  display: flex;
  align-items: center;
  gap: 3px;
}

.sqsa-ci-col-width-input {
  width: 60px;
  padding: 4px 6px;
  font-size: 13px;
  border: 1px solid #c0cad4;
  border-radius: 3px;
  text-align: right;
}

.sqsa-ci-col-width-input:focus {
  outline: none;
  border-color: #c99600;
}

.sqsa-ci-col-width-pct {
  font-size: 13px;
  color: #666;
}

.sqsa-ci-col-widths-total {
  font-size: 12px;
  color: #555;
}

.sqsa-ci-col-widths-total-val.is-ok  { color: #2e7d32; font-weight: 600; }
.sqsa-ci-col-widths-total-val.is-warn { color: #c0392b; font-weight: 600; }

/* Format toolbar */
.sqsa-ci-format-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
  flex-wrap: wrap;
}

.sqsa-ci-fmt-btn {
  padding: 4px 10px;
  font-size: 13px;
  line-height: 1.4;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
  color: #333;
  min-width: 32px;
  text-align: center;
  transition: background 0.1s, border-color 0.1s;
}

.sqsa-ci-fmt-btn:hover {
  background: #f0e8cc;
  border-color: #c99600;
  color: #7a5c00;
}

.sqsa-ci-fmt-btn:active {
  background: #c99600;
  color: #fff;
  border-color: #c99600;
}

.sqsa-ci-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

/* Header row */
.sqsa-ci-header-row {
  background: #c99600;
}

.sqsa-ci-header-row th {
  padding: 0;
  border: 1px solid rgba(255,255,255,0.2);
}

.sqsa-ci-row-handle-th,
.sqsa-ci-row-delete-th {
  width: 32px;
}

/* Body rows */
.sqsa-ci-body-row td {
  padding: 0;
  border: 1px solid #d0d5db;
  vertical-align: top;
}

.sqsa-ci-body-row:nth-child(even) { background: #f5f7f9; }
.sqsa-ci-body-row.is-dragging     { opacity: 0.4; }

/* Cells */
.sqsa-ci-cell {
  min-height: 36px;
  padding: 8px 10px;
  outline: none;
  line-height: 1.45;
  word-break: break-word;
}

.sqsa-ci-cell:focus {
  background: rgba(201,150,0,0.06);
  box-shadow: inset 0 0 0 2px #c99600;
}

.sqsa-ci-header-cell {
  color: #fff;
  font-weight: 600;
  background: #c99600;
  cursor: text;
}

/* Placeholder text when header cell is empty */
.sqsa-ci-header-cell:empty::before {
  content: attr(data-placeholder);
  opacity: 0.5;
  pointer-events: none;
  font-style: italic;
  font-weight: 400;
}

/* Hide placeholder while editing */
.sqsa-ci-header-cell:focus::before {
  content: '';
}

/* Hover signal — dashed white outline */
.sqsa-ci-header-cell:hover:not(:focus) {
  outline: 2px dashed rgba(255, 255, 255, 0.65);
  outline-offset: -2px;
}

.sqsa-ci-body-cell {
  color: #1f2b3a;
}

/* Row controls */
.sqsa-ci-row-handle {
  width: 28px;
  text-align: center;
  color: #aaa;
  cursor: grab;
  font-size: 16px;
  user-select: none;
}

.sqsa-ci-row-handle:active { cursor: grabbing; }

.sqsa-ci-row-delete-td {
  width: 28px;
  text-align: center;
  vertical-align: middle;
}

.sqsa-ci-row-delete {
  background: none;
  border: none;
  color: #ccc;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
  transition: color 0.12s;
}

.sqsa-ci-row-delete:hover { color: #e05252; }

/* Grid actions */
.sqsa-ci-grid-actions {
  padding: 10px;
  background: #fafafa;
  border-top: 1px solid #e8e8e8;
}

/* ── Title row ── */
.sqsa-ci-grid-title-row {
  margin-bottom: 16px;
}

.sqsa-ci-grid-title {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #c0cad4;
  border-radius: 4px;
  font-size: 15px;
  color: #1f2b3a;
  box-sizing: border-box;
}

.sqsa-ci-grid-title:focus {
  outline: none;
  border-color: #c99600;
  box-shadow: 0 0 0 3px rgba(201,150,0,0.15);
}


/* ── Actions ── */
.sqsa-ci-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
}

.sqsa-ci-grid-save-actions {
  margin-top: 8px;
}

.sqsa-ci-btn {
  padding: 10px 22px;
  border-radius: 4px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
  line-height: 1.2;
}

.sqsa-ci-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.sqsa-ci-btn--primary {
  background: #c99600;
  color: #ffffff;
  border-color: #c99600;
}

.sqsa-ci-btn--primary:hover:not(:disabled) {
  background: #a67600;
  border-color: #a67600;
}

.sqsa-ci-btn--secondary {
  background: transparent;
  color: #1f4e6e;
  border-color: #1f4e6e;
}

.sqsa-ci-btn--secondary:hover:not(:disabled) {
  background: #eef4f8;
}

.sqsa-ci-btn--warning {
  background: #d97706;
  color: #ffffff;
  border-color: #d97706;
}

.sqsa-ci-btn--warning:hover:not(:disabled) {
  background: #b45309;
  border-color: #b45309;
}

.sqsa-ci-btn--danger {
  background: transparent;
  color: #b91c1c;
  border-color: #b91c1c;
}

.sqsa-ci-btn--danger:hover:not(:disabled) {
  background: #b91c1c;
  color: #ffffff;
}

/* ── Edit link ── */
.sqsa-ci-edit-link {
  display: inline-block;
  margin-top: 4px;
  font-weight: 600;
  color: #166534;
  text-decoration: underline;
}

/* ── Tom Select overrides ── */
/* Hide the native <select> — TomSelect renders its own control */
#sqsa-ci-edit-picker {
  display: none !important;
}

.ts-wrapper {
  font-size: 16px;
  width: 100%;
}

/* Single visible input */
.ts-wrapper.single .ts-control {
  border: 2px solid #c0cad4;
  border-radius: 6px;
  padding: 10px 14px;
  background: #fff;
  cursor: pointer;
  min-height: 48px;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
}

.ts-wrapper.single .ts-control:focus-within,
.ts-wrapper.single.focus .ts-control {
  border-color: #c99600 !important;
  box-shadow: 0 0 0 3px rgba(201,150,0,0.15) !important;
  outline: none;
}

/* Selected item label — gets priority over the search input for space */
.ts-wrapper.single .ts-control .item {
  flex: 3 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #1f2b3a;
  font-size: 16px;
}

/* Search input — fills the whole control when nothing is selected yet
   (was capped at a cramped fixed 120px before); once an item is selected,
   it still gets a reasonable minimum width for re-searching without
   crowding out the selected item's label. */
.ts-wrapper.single .ts-control input {
  flex: 1 1 80px;
  width: auto !important;
  min-width: 80px;
  font-size: 16px;
  color: #1f2b3a;
  border: none;
  background: transparent;
  padding: 0;
}

.ts-wrapper.single .ts-control input:focus {
  outline: none;
}

/* Caret arrow */
.ts-wrapper.single .ts-control::after {
  content: '▾';
  flex: 0 0 auto;
  color: #888;
  font-size: 14px;
  margin-left: 6px;
  pointer-events: none;
}

/* Dropdown */
.ts-dropdown {
  border: 2px solid #c0cad4;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  font-size: 16px;
}

.ts-dropdown .option {
  padding: 11px 14px;
  cursor: pointer;
  color: #1f2b3a;
}

.ts-dropdown .option.selected,
.ts-dropdown .option:hover,
.ts-dropdown .option.active {
  background: #c99600 !important;
  color: #fff !important;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .sqsa-ci-actions { flex-direction: column; align-items: stretch; }
  .sqsa-ci-btn     { text-align: center; }
  .sqsa-ci-field   { flex: 1 1 100%; }
  .sqsa-ci-settings-bar { flex-direction: column; }
}

/* ── CSV header toggle ── */
.sqsa-ci-csv-header-toggle {
  margin-top: 14px;
  flex: 0 0 auto;
}

.sqsa-ci-csv-header-toggle label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #333;
  cursor: pointer;
}