/* JavaScript regular expression tester */
.container--regex-tool {
  max-width: var(--container);
}

.regex-intro {
  max-width: 62rem;
}

.regex-workbench,
.regex-builder,
.regex-editor,
.regex-results,
.regex-replacement {
  min-width: 0;
}

.regex-workbench {
  display: grid;
  gap: 1rem;
  margin-bottom: 2rem;
}

.regex-builder,
.regex-editor,
.regex-results,
.regex-replacement {
  display: grid;
  align-content: start;
  gap: 0.9rem;
}

.regex-section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  min-width: 0;
  gap: 1rem;
}

.regex-section-heading h2,
.regex-section-heading p,
.regex-code-grid h3,
.regex-editor h3 {
  margin: 0;
}

.regex-section-heading p,
.regex-help,
.regex-field-meta,
.regex-copy-status {
  color: var(--color-muted);
  font-size: 0.84rem;
}

.regex-label {
  font-weight: 800;
}

.regex-pattern-input,
.regex-textarea {
  display: block;
  width: 100%;
  min-width: 0;
  resize: vertical;
  padding: 0.85rem;
  overflow: auto;
  border: 1px solid #b9cac5;
  border-radius: var(--radius-sm);
  outline: none;
  background: #fcfdfc;
  color: var(--color-text);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre;
}

.regex-pattern-input:focus,
.regex-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.regex-textarea {
  min-height: 18rem;
}

.regex-textarea--short {
  min-height: 9.5rem;
}

.regex-field-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.regex-flags {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
  margin: 0;
  padding: 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.regex-flags legend {
  padding-inline: 0.35rem;
  font-weight: 800;
}

.regex-flags label {
  display: flex;
  align-items: flex-start;
  min-width: 0;
  gap: 0.5rem;
  padding: 0.65rem;
  border: 1px solid #d6e0dd;
  border-radius: 0.55rem;
  background: var(--color-surface-soft);
  cursor: pointer;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.regex-flags input {
  flex: 0 0 auto;
  margin-top: 0.2rem;
}

.regex-flags label:has(input:focus-visible) {
  box-shadow: var(--shadow-focus);
}

.regex-flags label:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.58;
}

.regex-flags code {
  color: var(--color-primary-dark);
  font-size: 1rem;
  font-weight: 900;
}

.regex-flags small {
  color: var(--color-muted);
}

.regex-code-grid,
.regex-main-grid,
.regex-replacement-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
  gap: 1rem;
}

.regex-code-grid > section {
  display: grid;
  align-content: start;
  min-width: 0;
  gap: 0.55rem;
  padding: 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.regex-code-grid pre,
.regex-match-card pre {
  max-width: 100%;
  margin: 0;
  padding: 0.75rem;
  overflow: auto;
  border-radius: 0.5rem;
  background: #102d29;
  color: #f2fffb;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.regex-code-grid button {
  justify-self: start;
}

.regex-primary-actions,
.regex-samples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.regex-samples button {
  padding: 0.45rem 0.65rem;
  border: 1px solid #a8c8c1;
  border-radius: 999px;
  background: #fff;
  color: var(--color-primary-dark);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 750;
}

.regex-samples button:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.regex-worker-note {
  padding: 0.85rem;
  border: 1px solid #d6b66d;
  border-radius: var(--radius-sm);
  background: #fff9e8;
}

.regex-worker-note p {
  margin: 0.3rem 0 0;
  font-size: 0.84rem;
}

.regex-highlight {
  min-height: 8rem;
  max-height: 20rem;
  margin: 0;
  padding: 0.85rem;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #f7faf8;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.regex-highlight mark {
  border-radius: 0.2rem;
  background: #ffe08a;
  color: #312600;
  box-shadow: inset 0 -2px 0 #c98f00;
}

.regex-status,
.regex-limit-notice,
.regex-copy-status {
  min-height: 1.4em;
  margin: 0;
  overflow-wrap: anywhere;
}

.regex-status[data-state="success"],
.regex-copy-status[data-state="success"] {
  color: #0b6b54;
  font-weight: 800;
}

.regex-status[data-state="error"],
.regex-copy-status[data-state="error"] {
  color: var(--color-danger);
  font-weight: 800;
}

.regex-status[data-state="pending"] {
  color: var(--color-muted);
}

.regex-limit-notice {
  padding: 0.65rem 0.75rem;
  border: 1px solid #d6b66d;
  border-radius: 0.5rem;
  background: #fff9e8;
  color: #6b4d00;
  font-weight: 750;
}

.regex-limit-notice[hidden] {
  display: none;
}

.regex-match-list {
  display: grid;
  min-width: 0;
  gap: 0.75rem;
}

.regex-match-card {
  min-width: 0;
  padding: 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-soft);
}

.regex-match-card h3,
.regex-match-card h4 {
  margin: 0;
}

.regex-match-card h4 {
  margin-top: 0.8rem;
  font-size: 0.88rem;
}

.regex-match-meta {
  margin: 0.25rem 0 0.55rem;
  color: var(--color-muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.regex-value-list {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.regex-value-row {
  display: grid;
  grid-template-columns: minmax(5.5rem, 0.5fr) minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.45rem 0.55rem;
  border-radius: 0.4rem;
  background: #fff;
  font-size: 0.78rem;
}

.regex-value-row code {
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.regex-value-row span {
  color: var(--color-muted);
  font-size: 0.72rem;
}

.regex-empty-result {
  margin: 0;
  padding: 0.8rem;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  text-align: center;
}

.regex-replacement-grid > div {
  display: grid;
  align-content: start;
  min-width: 0;
  gap: 0.65rem;
}

.regex-guide code,
.regex-guide pre {
  overflow-wrap: anywhere;
}

.regex-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.regex-table-wrap table {
  width: 100%;
  min-width: 34rem;
  border-collapse: collapse;
}

.regex-table-wrap th,
.regex-table-wrap td {
  padding: 0.65rem;
  border: 1px solid var(--color-border);
  text-align: left;
}

.regex-table-wrap th {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.regex-cheatsheet {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.regex-cheatsheet > div {
  display: grid;
  grid-template-columns: minmax(4.5rem, auto) minmax(0, 1fr);
  gap: 0.6rem;
  min-width: 0;
  padding: 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
}

.regex-cheatsheet code {
  color: var(--color-primary-dark);
  font-weight: 900;
}

.regex-faq-list details {
  border-bottom: 1px solid var(--color-border);
}

.regex-faq-list summary {
  padding: 0.75rem 0;
  color: var(--color-primary-dark);
  cursor: pointer;
  font-weight: 800;
}

.regex-faq-list details p {
  margin: 0 0 0.8rem;
}

@media (max-width: 800px) {
  .regex-flags {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .regex-main-grid,
  .regex-code-grid,
  .regex-replacement-grid {
    grid-template-columns: 1fr;
  }

  .regex-cheatsheet {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .regex-section-heading {
    flex-direction: column;
  }

  .regex-section-heading .button,
  .regex-primary-actions .button,
  .regex-code-grid .button,
  .regex-replacement-grid .button {
    width: 100%;
    min-width: 0;
  }

  .regex-flags,
  .regex-cheatsheet {
    grid-template-columns: 1fr;
  }

  .regex-value-row {
    grid-template-columns: 1fr;
  }

  .regex-field-meta {
    display: grid;
  }
}
