/* Regex Tester — tool-specific styles */

/* ── Match highlight colours ── */
:root {
  --rt-color-1: rgba(255, 200, 0, 0.38);
  --rt-color-2: rgba(60, 200, 120, 0.35);
  --rt-color-3: rgba(30, 150, 240, 0.35);
  --rt-color-4: rgba(255, 120, 30, 0.38);
  --rt-color-5: rgba(180, 70, 240, 0.35);
}

/* ── Mode bar ── */
.rt-mode-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg-hover, #f5f5f5);
  border-radius: 8px;
  padding: 4px;
  width: fit-content;
}

.rt-mode-btn {
  padding: 6px 18px;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  transition: background 0.15s, color 0.15s;
}

.rt-mode-btn--active {
  background: var(--bg-card, #ffffff);
  color: var(--text-primary, #1a1a1a);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ── Two-column layout ── */
.rt-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

@media (max-width: 768px) {
  .rt-layout {
    grid-template-columns: 1fr;
  }
}

.rt-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Panel shared styles ── */
.rt-panel {
  padding: 16px;
}

.rt-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.rt-panel-header--results {
  align-items: flex-start;
}

.rt-panel-title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary, #6b7280);
  margin: 0 0 4px;
}

/* ── Pattern input ── */
.rt-pattern-row {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: var(--radius-control, 6px);
  overflow: hidden;
  background: var(--bg-input, #ffffff);
  transition: border-color 0.15s;
}

.rt-pattern-row:focus-within {
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 3px var(--focus-ring, rgba(37, 99, 235, 0.12));
}

.rt-pattern-row.rt-pattern-row--invalid {
  border-color: #b91c1c;
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12);
}

.rt-delim {
  padding: 0 8px;
  font-family: monospace;
  font-size: 1rem;
  color: var(--text-secondary, #6b7280);
  user-select: none;
  flex-shrink: 0;
}

.rt-pattern-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: monospace;
  font-size: 0.9375rem;
  color: var(--text-primary, #1a1a1a);
  padding: 8px 0;
  line-height: 1.4;
}

.rt-clear-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary, #6b7280);
  font-size: 1.125rem;
  line-height: 1;
  padding: 6px 10px;
  flex-shrink: 0;
  transition: color 0.15s;
}

.rt-clear-btn:hover {
  color: var(--text-primary, #1a1a1a);
}

/* ── Flag toggles ── */
.rt-flags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.rt-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  font-family: monospace;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
}

.rt-flag:hover {
  border-color: var(--accent, #2563eb);
  color: var(--accent, #2563eb);
}

.rt-flag--active {
  background: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
  color: #ffffff;
}

/* ── Error message ── */
.rt-error {
  color: #b91c1c;
  font-size: 0.8125rem;
  margin-top: 8px;
  padding: 6px 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  line-height: 1.5;
}

/* ── Textarea + mirror ── */
.rt-mirror-wrap {
  position: relative;
}

.rt-mirror {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 8px 12px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: hidden;
  pointer-events: none;
  border: 1px solid transparent;
  border-radius: var(--radius-control, 6px);
  box-sizing: border-box;
  color: transparent;
  z-index: 0;
  margin: 0;
}

.rt-textarea {
  display: block;
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 8px 12px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background: transparent;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: var(--radius-control, 6px);
  box-sizing: border-box;
  color: var(--text-primary, #1a1a1a);
  caret-color: var(--text-primary, #1a1a1a);
  resize: vertical;
  min-height: 160px;
  white-space: pre-wrap;
  word-wrap: break-word;
  transition: border-color 0.15s;
  outline: none;
}

.rt-textarea:focus {
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 3px var(--focus-ring, rgba(37, 99, 235, 0.12));
}

.rt-textarea-meta {
  font-size: 0.75rem;
  color: var(--text-secondary, #6b7280);
  margin-top: 6px;
  text-align: right;
}

/* ── Highlights ── */
.rt-hl-1 { background: var(--rt-color-1); border-radius: 2px; }
.rt-hl-2 { background: var(--rt-color-2); border-radius: 2px; }
.rt-hl-3 { background: var(--rt-color-3); border-radius: 2px; }
.rt-hl-4 { background: var(--rt-color-4); border-radius: 2px; }
.rt-hl-5 { background: var(--rt-color-5); border-radius: 2px; }

/* ── Replacement panel ── */
.rt-replace-input {
  width: 100%;
  padding: 8px 12px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.875rem;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: var(--radius-control, 6px);
  background: var(--bg-input, #ffffff);
  color: var(--text-primary, #1a1a1a);
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 12px;
}

.rt-replace-input:focus {
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 3px var(--focus-ring, rgba(37, 99, 235, 0.12));
}

.rt-replace-result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.rt-replace-result-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
}

.rt-replace-output {
  resize: vertical;
  min-height: 80px;
  background: var(--bg-hover, #f5f5f5);
  cursor: default;
  color: var(--text-primary, #1a1a1a);
}

/* ── Match count ── */
.rt-match-count {
  font-size: 0.8125rem;
  color: var(--text-secondary, #6b7280);
  margin: 0;
}

/* ── Tabs ── */
.rt-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  margin-bottom: 12px;
}

.rt-tab {
  padding: 8px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-secondary, #6b7280);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

.rt-tab:hover {
  color: var(--text-primary, #1a1a1a);
}

.rt-tab--active {
  color: var(--accent, #2563eb);
  border-bottom-color: var(--accent, #2563eb);
}

/* ── Match list ── */
.rt-match-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 400px;
  overflow-y: auto;
}

.rt-match-item {
  padding: 8px 12px;
  border-radius: 6px;
  border-left: 3px solid var(--border-color, #e5e7eb);
  background: var(--bg-hover, #f9fafb);
  cursor: pointer;
  transition: background 0.1s;
}

.rt-match-item:hover {
  background: var(--bg-card, #ffffff);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.1));
}

.rt-match-item--1 { border-left-color: hsl(47, 100%, 50%); }
.rt-match-item--2 { border-left-color: hsl(145, 63%, 49%); }
.rt-match-item--3 { border-left-color: hsl(210, 100%, 52%); }
.rt-match-item--4 { border-left-color: hsl(27, 100%, 56%); }
.rt-match-item--5 { border-left-color: hsl(276, 80%, 61%); }

.rt-match-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.rt-match-num {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.rt-match-val {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8125rem;
  color: var(--text-primary, #1a1a1a);
  word-break: break-all;
  flex: 1;
  min-width: 0;
}

.rt-match-pos {
  font-size: 0.75rem;
  color: var(--text-secondary, #6b7280);
  flex-shrink: 0;
}

.rt-match-groups {
  margin-top: 4px;
  padding-left: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rt-group-line {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.75rem;
  color: var(--text-secondary, #6b7280);
}

.rt-group-line strong {
  color: var(--text-primary, #1a1a1a);
}

/* ── Groups panel ── */
.rt-groups-content {
  max-height: 400px;
  overflow-y: auto;
}

.rt-groups-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.rt-groups-table th {
  text-align: left;
  padding: 6px 10px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary, #6b7280);
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.rt-groups-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  color: var(--text-primary, #1a1a1a);
  font-family: 'Courier New', Courier, monospace;
  word-break: break-all;
  vertical-align: top;
}

.rt-groups-table td:first-child,
.rt-groups-table td:nth-child(2) {
  white-space: nowrap;
  font-family: inherit;
  font-size: 0.75rem;
  color: var(--text-secondary, #6b7280);
}

.rt-no-groups {
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
  padding: 16px 0;
  text-align: center;
}

/* ── Collapsible sections ── */
.rt-collapsible-section {
  padding: 0;
  overflow: hidden;
}

.rt-collapsible-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary, #1a1a1a);
  text-align: left;
  transition: background 0.15s;
}

.rt-collapsible-toggle:hover {
  background: var(--bg-hover, #f5f5f5);
}

.rt-chevron {
  flex-shrink: 0;
  transition: transform 0.2s ease;
  color: var(--text-secondary, #6b7280);
}

.rt-collapsible-toggle[aria-expanded="true"] .rt-chevron {
  transform: rotate(180deg);
}

.rt-collapsible-body {
  padding: 0 18px 18px;
}

/* ── Patterns grid ── */
.rt-patterns-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (max-width: 768px) {
  .rt-patterns-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .rt-patterns-grid {
    grid-template-columns: 1fr;
  }
}

.rt-pattern-card {
  padding: 10px 14px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  background: var(--bg-card, #ffffff);
}

.rt-pattern-card:hover {
  border-color: var(--accent, #2563eb);
  background: var(--accent-light, rgba(37, 99, 235, 0.05));
}

.rt-pattern-card__name {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary, #1a1a1a);
  margin-bottom: 4px;
}

.rt-pattern-card__pattern {
  display: block;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.6875rem;
  color: var(--text-secondary, #6b7280);
  word-break: break-all;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Cheatsheet ── */
.rt-cheatsheet-hint {
  font-size: 0.8125rem;
  color: var(--text-secondary, #6b7280);
  margin: 0 0 14px;
}

.rt-cheatsheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.rt-cheatsheet-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rt-cheatsheet-group__title {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 2px;
}

.rt-cheatsheet-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.rt-token {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.75rem;
  color: var(--text-primary, #1a1a1a);
  background: var(--bg-hover, #f9fafb);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}

.rt-token:hover {
  background: var(--accent-light, rgba(37, 99, 235, 0.08));
  border-color: var(--accent, #2563eb);
}

/* ── Dark mode ── */
@media (prefers-color-scheme: dark) {
  .rt-mode-btn--active {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }

  .rt-error {
    background: rgba(185, 28, 28, 0.15);
    border-color: #991b1b;
    color: #fca5a5;
  }

  .rt-replace-output {
    background: rgba(255, 255, 255, 0.04);
  }

  .rt-match-item {
    background: rgba(255, 255, 255, 0.04);
  }

  .rt-match-item:hover {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: none;
  }

  .rt-pattern-card {
    background: rgba(255, 255, 255, 0.04);
  }

  .rt-token {
    background: rgba(255, 255, 255, 0.06);
  }

  .rt-token:hover {
    background: rgba(37, 99, 235, 0.25);
  }

  .rt-groups-table td,
  .rt-groups-table th {
    border-color: rgba(255, 255, 255, 0.08);
  }
}
