.edit-template-modal {
  display: none;
}

/* Keep template-related modals hidden by default.
   ui-dialogs.css sets `body .modal { display: flex; }`, which can
   cause first-frame flashes on refresh before JS cleanup runs. */
body .modal.edit-template-modal {
  display: none;
}

.edit-template-modal.is-open {
  display: flex;
}

.edit-template-modal__container {
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
}

.edit-template-modal__header {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
}

.edit-template-modal__close {
  color: #ffffff;
}

.edit-template-modal__label {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
  display: block;
}

.edit-template-modal__fields {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 15px;
  border: 1px solid var(--border-color);
}

.edit-template-modal__fields-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.edit-template-modal__tips {
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  padding: 15px;
  border-radius: 6px;
  margin-top: 20px;
}

.edit-template-modal__tips-text {
  margin: 0;
  color: #92400e;
  font-size: 13px;
  line-height: 1.6;
}

.edit-template-modal__footer {
  display: flex;
  justify-content: space-between;
}

.edit-template-modal__save-btn {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border: none;
}

.problem-template-modal {
  display: none;
  z-index: 99997;
}

body .modal.problem-template-modal {
  display: none;
}

.problem-template-modal__container {
  max-width: 650px;
}

.problem-template-modal__header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #ffffff;
}

.problem-template-modal__close {
  color: #ffffff;
}

.problem-template-modal__body {
  padding: 16px;
  max-height: 60vh;
  overflow-y: auto;
}

.problem-template-modal__desc {
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 13px;
}

.problem-template-modal__list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.problem-template-modal__footer {
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
}

.problem-template-modal__footer-btn {
  min-width: 80px;
}

.parse-template-config-modal {
  display: none;
}

body .modal.parse-template-config-modal {
  display: none;
}

.parse-template-config-modal .is-hidden {
  display: none;
}

.template-config-modal__container {
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
}

.template-config-modal__header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #ffffff;
}

.template-config-modal__close {
  color: #ffffff;
}

.template-config-steps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 30px;
  position: relative;
}

.template-config-steps-track {
  position: absolute;
  top: 20px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--bg-tertiary);
  z-index: 0;
}

.template-config-steps-progress {
  position: absolute;
  top: 20px;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  z-index: 1;
  width: 0%;
  transition: width 0.3s;
}

.template-config-step {
  flex: 1;
  text-align: center;
  position: relative;
  z-index: 2;
}

.template-config-step-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
  font-weight: bold;
}

.template-config-step-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.template-config-step.is-current .template-config-step-circle {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.template-config-step.is-current .template-config-step-label {
  color: #1e2329;
  font-weight: 600;
}

.template-config-step.is-complete .template-config-step-circle {
  background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
  color: #ffffff;
}

.template-config-step.is-complete .template-config-step-label {
  color: #4caf50;
}

.template-config-card {
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.template-config-card--intro {
  background: linear-gradient(135deg, #e3f2fd 0%, #e8f5e9 100%);
  border-left: 4px solid #667eea;
}

.template-config-card--auto-detect {
  background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
  border-left: 4px solid #ff9800;
}

.template-config-card--manual {
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border-left: 4px solid #2196f3;
}

.template-config-card--annotate {
  background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
  border-left: 4px solid #9c27b0;
}

.template-config-card--complete {
  background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
  border-left: 4px solid #4caf50;
}

.template-config-card__title {
  margin: 0 0 10px 0;
  color: var(--text-primary);
  font-size: 16px;
}

.template-config-card__desc {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.8;
}

.template-config-upload {
  border: 2px dashed #e6e8ea;
  border-radius: 8px;
  padding: 40px;
  text-align: center;
  background: var(--bg-secondary);
}

.template-config-upload__input {
  display: none;
}

.template-config-upload__icon {
  margin-bottom: 20px;
}

.template-config-upload__button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
}

.template-config-upload__note {
  margin-top: 15px;
  color: var(--text-secondary);
  font-size: 14px;
}

.template-config-sample-list {
  margin-top: 20px;
}

.template-config-sample-title {
  font-size: 16px;
  margin-bottom: 10px;
  color: var(--text-primary);
}

.template-config-sample-container {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px;
  background: var(--bg-secondary);
}

.template-config-auto-result {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 20px;
  border: 1px solid var(--border-color);
}

.template-config-manual-section {
  margin-top: 30px;
}

.template-config-current-field {
  color: #667eea;
}

.template-config-segments {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.template-config-segments-title {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.template-config-segments-clear {
  font-size: 12px;
  padding: 4px 12px;
}

.template-config-segments-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.template-config-manual-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.template-config-document-card {
  background: var(--bg-primary);
  border: 2px solid #667eea;
  border-radius: 8px;
  padding: 20px;
}

.template-config-document-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.template-config-document-title {
  margin: 0;
  color: var(--text-primary);
  font-size: 14px;
}

.template-config-document-switch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.template-config-document-label {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
}

.template-config-document-select {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
}

.template-config-document-preview {
  max-height: 400px;
  overflow-y: auto;
  padding: 15px;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
  user-select: text;
  cursor: text;
}

.template-config-annotation-actions {
  margin-top: 15px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.template-config-action-btn {
  flex: 1;
}

.template-config-action-btn--add {
  background: linear-gradient(135deg, #3dcfff 0%, #1e9fd6 100%);
  border: none;
}

.template-config-annotate-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.template-config-section-title {
  margin: 0 0 10px 0;
  color: var(--text-primary);
  font-size: 14px;
}

.template-config-document-view {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  max-height: 500px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.8;
  user-select: text;
}

.template-config-field-group {
  margin-bottom: 15px;
}

.template-config-field-title {
  font-size: 13px;
  color: #667eea;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.template-config-field-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.template-config-field-btn {
  justify-content: flex-start;
}

.template-config-field-btn--full {
  grid-column: span 3;
}

.template-config-annotated-panel {
  margin-top: 20px;
  padding: 15px;
  background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
  border-radius: 8px;
  border: 1px solid #4caf50;
}

.template-config-annotated-title {
  margin: 0 0 10px 0;
  color: var(--text-primary);
  font-size: 13px;
}

.template-config-annotated-list {
  font-size: 12px;
  color: var(--text-secondary);
}

.template-config-annotated-empty {
  margin: 0;
  color: var(--text-secondary);
}

.template-config-summary {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 20px;
  border: 1px solid var(--border-color);
  margin-top: 20px;
}

.template-config-summary-title {
  margin: 0 0 15px 0;
  color: var(--text-primary);
  font-size: 14px;
}

.template-config-summary-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 2;
}

.template-config-footer {
  display: flex;
  justify-content: space-between;
}

.template-config-footer-spacer {
  flex: 1;
}

.template-config-btn--next {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
}

.template-config-loading {
  text-align: center;
  padding: 40px;
}

.template-config-loading-icon {
  font-size: 32px;
  color: #667eea;
}

.template-config-loading-text {
  margin-top: 15px;
  color: #848e9c;
}

.template-config-detect-empty {
  text-align: center;
  padding: 40px;
}

.template-config-detect-empty-icon {
  font-size: 48px;
  color: #ff9800;
}

.template-config-detect-empty-text {
  margin-top: 15px;
  color: #848e9c;
}

.template-config-detect-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 15px;
}

.template-config-detect-card {
  background: #ffffff;
  border: 1px solid #e6e8ea;
  border-radius: 8px;
  padding: 15px;
}

.template-config-detect-header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.template-config-detect-icon {
  color: #4caf50;
  margin-right: 8px;
}

.template-config-detect-title {
  font-weight: 600;
  color: #1e2329;
}

.template-config-detect-meta {
  font-size: 12px;
  color: #848e9c;
  margin-bottom: 5px;
}

.template-config-detect-code {
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 3px;
}

.template-config-detect-value {
  font-size: 12px;
  color: #5e6673;
}

.template-config-detect-tip {
  margin-top: 20px;
  padding: 15px;
  background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
  border-radius: 8px;
  border: 1px solid #4caf50;
}

.template-config-detect-tip-text {
  margin: 0;
  color: #1e2329;
  font-size: 14px;
}

.template-config-pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  margin: 0;
}

.template-config-sample-item {
  display: flex;
  align-items: center;
  padding: 10px;
  background: #ffffff;
  border-radius: 6px;
  margin-bottom: 8px;
  border: 1px solid #e6e8ea;
}

.template-config-sample-icon {
  color: #667eea;
  font-size: 24px;
  margin-right: 12px;
}

.template-config-sample-info {
  flex: 1;
}

.template-config-sample-name {
  font-weight: 600;
  color: #1e2329;
  margin-bottom: 4px;
}

.template-config-sample-size {
  font-size: 12px;
  color: #848e9c;
}

.template-config-sample-tag {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #ffffff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.template-config-annotated-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #e6e8ea;
}

.template-config-annotated-name {
  color: #1e2329;
  font-weight: 600;
}

.template-config-annotated-keyword {
  color: #848e9c;
  font-size: 11px;
}

.template-config-summary-item {
  margin-bottom: 15px;
}

.template-config-summary-label {
  color: #1e2329;
}

.template-config-summary-value {
  color: #5e6673;
}

.template-config-summary-section {
  margin-top: 10px;
}

.template-config-summary-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.template-config-summary-card {
  background: #ffffff;
  border: 1px solid #e6e8ea;
  border-radius: 8px;
  padding: 12px;
}

.template-config-summary-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.template-config-summary-field {
  font-weight: 600;
  color: #1e2329;
}

.template-config-summary-method {
  background: #f5f5f5;
  color: #848e9c;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
}

.template-config-summary-detail {
  font-size: 12px;
  color: #5e6673;
}

.template-config-summary-code {
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 3px;
}

.template-config-summary-sample {
  color: #1e2329;
}
