/* ═══════════════════════════════════════════════════════════════════════════
   cardTemplates.css  —  page-specific styles for the Templates page.
   Global layout helpers (panel, section-note, pill-filter, repl-*) live in
   style.css and are not repeated here.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── "New Template" button in panel header ─────────────────────────────── */
/* Base style comes from .panel-action-btn in style.css */

.template-create-btn {
  margin-left: auto; /* push to right of panel header */
}

/* ── Alphabetic section headers (when many templates) ───────────────────── */
#templates .ui.dividing.header {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.78em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
}

/* ── Template card (accordion) ──────────────────────────────────────────── */
/*
  Mirrors font-card's minimal style: near-transparent background, subtle
  border, no shadow. Avoids glass-morphism so both pages look consistent.
*/
.template-card,
.template-card.ui.accordion {
  background: rgba(0, 0, 0, 0.025) !important;
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
  margin-bottom: 0.5rem !important;
  padding: 0 !important;
  overflow: hidden;
}

html.dark .template-card,
html.dark .template-card.ui.accordion {
  background: rgba(255, 255, 255, 0.04) !important;
  border-color: rgba(255, 255, 255, 0.07) !important;
}

/* ── Accordion title bar ────────────────────────────────────────────────── */
.template-card > .title.template-title {
  display: flex !important;
  align-items: center !important;
  gap: 0.65em !important;
  padding: 0.75rem 1.1rem !important;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  border-bottom: none !important;
  color: rgba(0, 0, 0, 0.78) !important;
  background: transparent !important;
}

html.dark .template-card > .title.template-title {
  color: rgba(255, 255, 255, 0.85) !important;
}

.template-card > .title.template-title:hover {
  background: rgba(0, 0, 0, 0.03) !important;
}

html.dark .template-card > .title.template-title:hover {
  background: rgba(255, 255, 255, 0.03) !important;
}

/* Separator appears only when the panel is open */
.template-card > .title.active.template-title {
  border-bottom: 1px solid rgba(0, 0, 0, 0.07) !important;
}

html.dark .template-card > .title.active.template-title {
  border-bottom-color: rgba(255, 255, 255, 0.06) !important;
}

/* Template name text */
.template-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Caret: pushed to the right.
   Keep Fomantic's default 0° (closed, pointing right ›) → 90° (open, ↓).
   This differs from font-card which uses −90° → 0°. */
.template-card > .title.template-title > .dropdown.icon.template-caret {
  margin-left: auto !important;
  opacity: 0.35;
  font-size: 0.9em !important;
  transition: transform 0.18s ease, opacity 0.18s !important;
}

.template-card > .title.template-title:hover > .dropdown.icon.template-caret {
  opacity: 0.65;
}

/* ── Accordion content area ─────────────────────────────────────────────── */
.template-content {
  padding: 1.25rem 1.4rem 1.4rem !important;
}

/* ── Subtle section label (replaces Fomantic h4 dividers) ──────────────── */
.template-section-label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 1.4rem 0 0.85rem;
  font-size: 0.7em;
  font-weight: 700;
  letter-spacing: 0.1em;
  /* text-transform: uppercase; */
  color: rgba(0, 0, 0, 0.38);
}

.template-section-label:first-of-type {
  margin-top: 0.75rem;
}

.template-section-label::before,
.template-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(0, 0, 0, 0.08);
}

html.dark .template-section-label {
  color: rgba(255, 255, 255, 0.3);
}

html.dark .template-section-label::before,
html.dark .template-section-label::after {
  background: rgba(255, 255, 255, 0.07);
}

/* ── Preview section ────────────────────────────────────────────────────── */
.template-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.5rem;
  align-items: start;
}

@media (max-width: 600px) {
  .template-preview-grid {
    grid-template-columns: 1fr;
  }
}

.template-preview-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Nested preview-form is a div — reset Fomantic ui.form padding if needed */
[data-value="preview-form"] {
  margin: 0 !important;
}

/* Ensure preview image fills the card */
.preview.card img {
  max-width: 100%;
  display: block;
}

/* Preview card is clickable */
.preview.card {
  cursor: pointer;
}

/* Ensure preview card loader is above content */
.ui.loading.card::before {
  z-index: 10;
}

.template-refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.45rem 0.9rem;
  font-size: 0.84em;
  font-weight: 600;
  border-radius: 7px;
  border: 1px solid rgba(99, 145, 210, 0.35);
  background: rgba(99, 145, 210, 0.08);
  color: var(--tcm-blue-color);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  align-self: flex-start;
}

.template-refresh-btn:hover {
  background: rgba(99, 145, 210, 0.18);
  border-color: rgba(99, 145, 210, 0.6);
}

.template-refresh-btn i.icon {
  margin: 0;
}

/* ── Filter conditions ──────────────────────────────────────────────────── */
[data-value="conditions"] {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.filter-condition-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* The two dropdowns share equal space */
.filter-condition-row .ui.dropdown[data-value="filter-arguments"],
.filter-condition-row .ui.dropdown[data-value="filter-operators"] {
  flex: 1 1 140px;
  min-width: 0;
}

/* Reference text input stretches to fill remaining space */
.filter-condition-row input[name="reference"] {
  flex: 1 1 120px;
  min-width: 0;
  /* Borrow Fomantic's input styling */
  padding: 0.58em 0.75em;
  border: 1px solid rgba(34, 36, 38, 0.15);
  border-radius: 4px;
  font-size: 1em;
  outline: none;
  background: transparent;
  color: inherit;
  transition: border-color 0.15s;
}

html.dark .filter-condition-row input[name="reference"] {
  border-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.87);
}

.filter-condition-row input[name="reference"]:focus {
  border-color: var(--tcm-blue-color);
}

/* ── Season Titles (row-based editor) ───────────────────────────────────── */
.season-titles-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.season-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.season-title-row input[name="season_title_ranges"] {
  flex: 0 0 180px;
  min-width: 0;
}

.season-title-row input[name="season_title_values"] {
  flex: 1;
  min-width: 0;
}

/* Give the bare inputs inside the Fomantic form proper styling */
.season-title-row input {
  padding: 0.58em 0.75em;
  border: 1px solid rgba(34, 36, 38, 0.15);
  border-radius: 4px;
  font-size: 1em;
  outline: none;
  background: transparent;
  color: inherit;
  transition: border-color 0.15s;
}

html.dark .season-title-row input {
  border-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.87);
}

.season-title-row input:focus {
  border-color: var(--tcm-blue-color);
}

/* Format hint that appears below the season titles list */
.season-title-format-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3em 0.5em;
  margin: 0.45rem 0 0 !important;
  font-size: 0.78em;
  color: rgba(0, 0, 0, 0.42);
}

html.dark .season-title-format-note {
  color: rgba(255, 255, 255, 0.32);
}

.season-title-format-note code {
  font-size: 0.95em;
  padding: 0.05em 0.3em;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.6);
  font-family: monospace;
}

html.dark .season-title-format-note code {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.55);
}

.format-sep {
  opacity: 0.4;
}

/* ── Translation quick settings ──────────────────────────────────────────── */

.series-translation-quick {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr);
  gap: 1rem 1.5rem;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

html.dark .series-translation-quick {
  border-bottom-color: rgba(255, 255, 255, 0.07);
}

@media (max-width: 700px) {
  .series-translation-quick {
    grid-template-columns: 1fr;
  }
}

.series-translations-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.series-translations-list:not(:empty) {
  padding: 0.75rem 0.85rem;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.02);
}

html.dark .series-translations-list:not(:empty) {
  border-color: rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
}

.series-translations-empty {
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px dashed rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  text-align: center;
  color: rgba(0, 0, 0, 0.45);
}

html.dark .series-translations-empty {
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.38);
}

.series-translations-empty[hidden] {
  display: none;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.toggle-switch {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin: 0;
}

.toggle-switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 11px;
  transition: background 0.22s, border-color 0.22s;
}

html.dark .toggle-track {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.15);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--tcm-blue-color);
  border-color: var(--tcm-blue-color);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.22s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

html.dark .toggle-thumb {
  background: rgba(255, 255, 255, 0.7);
}

.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
  background: white;
}

.toggle-label {
  font-size: 0.93em;
  color: rgba(0, 0, 0, 0.78);
  line-height: 1.3;
  display: flex;
  align-items: center;
}

html.dark .toggle-label {
  color: rgba(255, 255, 255, 0.82);
}

/* ── Card extras ────────────────────────────────────────────────────────── */
.field[data-value="extras"] .field {
  margin-bottom: 0.3em;
}

/* ── Form action buttons ────────────────────────────────────────────────── */
.template-form-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.07);
  flex-wrap: wrap;
}

html.dark .template-form-actions {
  border-top-color: rgba(255, 255, 255, 0.07);
}

.template-form-actions .ui.error.message {
  margin: 0;
  flex: 1;
}

/* ── "Add" field buttons (add condition / add translation inline) ────────── */
.add-field.button {
  background: transparent;
}
