/* config.css - Config editor styles (extends base design system) */

/* ---- Save bar ---- */
.cfg-save-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}
.cfg-save-bar .cfg-dirty {
  margin-left: auto;
  font-size: 12px;
  color: var(--status-warning);
  font-weight: 500;
}
.cfg-save-bar .hidden { display: none; }

/* ---- Banners ---- */
.cfg-banner {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}
.cfg-banner.success {
  background: var(--status-success-bg);
  color: var(--status-success);
  border: 1px solid var(--status-success);
}
.cfg-banner.error {
  background: var(--status-error-bg);
  color: var(--status-error);
  border: 1px solid var(--status-error);
}
.cfg-banner.warning {
  background: var(--status-warning-bg);
  color: var(--status-warning);
  border: 1px solid var(--status-warning);
}
.cfg-banner.info {
  background: var(--status-info-bg);
  color: var(--status-info);
  border: 1px solid var(--status-info);
}

/* ---- Scope badges ---- */
.cfg-scope {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}
.cfg-scope.cfg-server {
  background: var(--status-info-bg);
  color: var(--status-info);
}
.cfg-scope.cfg-repo {
  background: var(--status-success-bg);
  color: var(--status-success);
}
.cfg-scope.cfg-task {
  background: var(--status-warning-bg);
  color: var(--status-warning);
}

/* ---- Field row ---- */
.cfg-field {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.cfg-field:last-child { border-bottom: none; }
.cfg-field-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

/* ---- Field labels ---- */
.cfg-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
  text-align: left;
  min-width: 0;
}

/* ---- Source selector (base) ---- */
.cfg-source {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  font-size: 11px;
}
.cfg-source button {
  background: var(--bg-surface);
  border: none;
  padding: 2px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 11px;
  border-right: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.cfg-source button:last-child { border-right: none; }
.cfg-source button:hover:not(.active) {
  background: var(--bg-inset);
}
.cfg-source button.active { color: white; }
.cfg-source button.active[data-source="unset"] { background: var(--text-tertiary); }
.cfg-source button.active[data-source="literal"] { background: var(--status-info); }
.cfg-source button.active[data-source="env"] { background: var(--status-warning); }
.cfg-source button.active[data-source="var"] { background: var(--status-success); }

/* ---- Tabbed field wrapper (scalar fields) ---- */
.cfg-tabbed {
  max-width: 400px;
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  /* Background matches border color so any sub-pixel gap between
     the tab bar and input shows border-color instead of white. */
  background: var(--border);
}
.cfg-tabbed .cfg-source {
  display: flex;
  width: 100%;
  border: none;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
}
.cfg-tabbed .cfg-source button {
  flex: 1;
  padding: 5px 4px;
  text-align: center;
}
.cfg-tabbed .cfg-input {
  border: none;
  border-radius: 0;
  margin-top: 0;
  max-width: 100%;
}
/* Use outline for focus inside tabbed wrapper — box-shadow is
   clipped by overflow:hidden on the container. */
.cfg-tabbed .cfg-input:focus {
  box-shadow: none;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.cfg-tabbed select.cfg-input {
  max-width: 100%;
}
/* Source-specific field tinting */
.cfg-tabbed[data-source="unset"] .cfg-input { background: var(--bg-inset); }
.cfg-tabbed[data-source="literal"] .cfg-input { background: var(--status-info-bg); }
.cfg-tabbed[data-source="env"] .cfg-input { background: var(--status-warning-bg); }
.cfg-tabbed[data-source="var"] .cfg-input { background: var(--status-success-bg); }
/* Match container bg to source tint so rounded corners don't show gray */
.cfg-tabbed-multiline[data-source="literal"] { background: var(--status-info-bg); }

/* ---- Input ---- */
.cfg-input {
  width: 100%;
  max-width: 400px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  background: var(--bg-surface);
  box-sizing: border-box;
  margin-top: 4px;
}
.cfg-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}
.cfg-input::placeholder {
  color: var(--text-tertiary);
}
select.cfg-input {
  max-width: 120px;
  cursor: pointer;
}
.cfg-input:disabled {
  background: var(--bg-inset);
  color: var(--text-tertiary);
  cursor: default;
}
textarea.cfg-textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.4;
  white-space: pre;
}
.cfg-tabbed-multiline {
  max-width: 600px;
}

/* ---- Help text ---- */
.cfg-help {
  display: block;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 3px;
}

/* ---- Buttons ---- */
.cfg-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
}
.cfg-btn:hover {
  background: var(--bg-inset);
  color: var(--text-primary);
}
.cfg-btn.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.cfg-btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.cfg-btn.danger {
  color: var(--status-error);
  border-color: var(--status-error);
}
.cfg-btn.danger:hover {
  background: var(--status-error-bg);
}
.cfg-btn:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* ---- Small action button (version bar) ---- */
.action-btn.sm {
  font-size: 12px;
  padding: 3px 10px;
}

/* ---- Diff display ---- */
.cfg-diff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.cfg-diff-table th {
  text-align: left;
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 2px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cfg-diff-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
.cfg-diff-old {
  color: var(--status-error);
  font-family: var(--font-mono);
  font-size: 12px;
}
.cfg-diff-new {
  color: var(--status-success);
  font-family: var(--font-mono);
  font-size: 12px;
}
.cfg-diff-summary {
  font-size: 13px;
  margin-bottom: 12px;
  color: var(--text-secondary);
}
.cfg-diff-summary .cfg-scope {
  margin-left: 6px;
}
.cfg-remove-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 10px;
}
.cfg-input-inline {
  max-width: 250px;
  display: inline-block;
}

/* ---- Repo list ---- */
.cfg-repo-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  margin-bottom: 8px;
  background: var(--bg-surface);
}
.cfg-repo-card:hover {
  border-color: var(--accent);
}
.cfg-repo-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.cfg-repo-meta {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ---- Add repo form ---- */
.cfg-add-repo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

/* ---- Dialog / modal ---- */
.cfg-dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  max-width: 700px;
  width: 90vw;
  margin: auto;
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
}
.cfg-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}
.cfg-dialog-header {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}
.cfg-dialog-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ---- Env hint ---- */
.cfg-env-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: italic;
  margin-top: 2px;
}

/* ---- List widget ---- */
.cfg-list-items { margin: 8px 0; }
.cfg-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.cfg-list-input { flex: 1; }
.cfg-list-remove {
  padding: 3px 8px;
  font-size: 11px;
  flex-shrink: 0;
}
.cfg-list-add { margin-top: 6px; }

/* ---- Tagged union list ---- */
.cfg-tagged-items { margin: 8px 0; }
.cfg-tagged-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
select.cfg-tagged-type { max-width: 200px; flex-shrink: 0; }
.cfg-tagged-value { flex: 1; }
.cfg-tagged-placeholder { flex: 1; }
.cfg-tagged-item .cfg-list-remove { margin-left: auto; }

/* ---- Subsection divider ---- */
.cfg-subsection {
  margin-top: 14px;
  padding-top: 4px;
}
.cfg-subsection + .cfg-subsection {
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 14px;
}
.cfg-subsection-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin: 0 0 8px;
  line-height: 1.4;
}

/* ---- Dict key-value widget ---- */
.cfg-dict-items { margin: 8px 0; }
.cfg-dict-item {
  margin-bottom: 6px;
}
.cfg-dict-key {
  display: block;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.cfg-dict-item-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.cfg-dict-add {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
/* Tabbed widget inside dict entries and variable controls */
.cfg-dict-item .cfg-tabbed {
  flex: 1;
  margin-top: 0;
  max-width: none;
}
.cfg-var-controls .cfg-tabbed {
  flex: 1;
  min-width: 150px;
  margin-top: 0;
  max-width: none;
}

/* ---- Variables widget ---- */
.cfg-var-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}
.cfg-var-item:last-child { border-bottom: none; }
.cfg-var-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.cfg-var-controls {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}
.cfg-var-refs {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-inset);
  padding: 1px 6px;
  border-radius: 3px;
}
.cfg-var-refs-none {
  color: var(--status-warning);
}
.cfg-var-rename-btn {
  flex-shrink: 0;
}

/* ---- Keyed collection widget ---- */
.cfg-collection-card {
  border: 1px solid var(--border-light);
  border-radius: 6px;
  margin: 8px 0;
  background: var(--bg-surface);
}
.cfg-collection-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
.cfg-collection-header::-webkit-details-marker { display: none; }
.cfg-collection-header::before {
  content: '\25B6';
  font-size: 10px;
  color: var(--text-tertiary);
  transition: transform 0.15s;
}
details.cfg-collection-card[open] > .cfg-collection-header::before {
  transform: rotate(90deg);
}
.cfg-collection-key {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.cfg-collection-type {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: auto;
  margin-right: 8px;
}
.cfg-collection-body {
  padding: 4px 12px 12px;
  border-top: 1px solid var(--border-light);
}
.cfg-collection-body .cfg-label {
  font-size: 12px;
  font-weight: 500;
}

/* ---- Add channel buttons ---- */
.cfg-add-channel {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  margin-bottom: 16px;
}

/* ---- Small button variant ---- */
.cfg-btn-sm {
  font-size: 11px;
  padding: 3px 8px;
}

/* ---- Responsive ---- */
@media (max-width: 700px) {
  .cfg-field-header {
    flex-wrap: wrap;
  }
  .cfg-label {
    max-width: 60vw;
  }
  .cfg-input {
    max-width: 100%;
  }
  .cfg-tabbed,
  .cfg-tabbed-multiline {
    max-width: 100%;
  }
  /* Prevent iOS Safari auto-zoom on focused inputs */
  .cfg-input, select.cfg-input {
    font-size: 16px;
  }
}
