/* entity-admin.css — Fields & Entities studio (card P2-06).
 * All classes prefixed `ea-`. Dark theme via existing CSS vars.
 * Assumes the host page defines --bg, --bg-alt, --surface, --border,
 * --text, --text-muted, --accent, --danger colours. Falls back to
 * reasonable dark-mode values via local fallbacks. */

/* -------------------------------------------------------------------------
 * Root / layout
 * ------------------------------------------------------------------------- */

.ea-root {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--text, #e2e8f0);
}

.ea-hint {
  margin: 0;
  padding: 0.5rem 0.75rem;
  background: var(--surface, #1e293b);
  border-left: 3px solid var(--accent, #6366f1);
  border-radius: 3px;
  color: var(--text-muted, #94a3b8);
  font-size: 0.8rem;
}

.ea-error {
  padding: 0.5rem 0.75rem;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 4px;
  color: #fca5a5;
  font-size: 0.8rem;
}

.ea-error.hidden { display: none; }

/* Two-column layout */
.ea-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  align-items: start;
}

/* -------------------------------------------------------------------------
 * Column headings
 * ------------------------------------------------------------------------- */

.ea-col-heading {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text, #e2e8f0);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* -------------------------------------------------------------------------
 * Type list (left column)
 * ------------------------------------------------------------------------- */

.ea-type-col {
  background: var(--surface, #1e293b);
  border: 1px solid var(--border, #334155);
  border-radius: 6px;
  padding: 0.75rem;
}

.ea-type-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ea-type-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.375rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s;
  color: var(--text-muted, #94a3b8);
}

.ea-type-item:hover {
  background: var(--bg-alt, #0f172a);
  color: var(--text, #e2e8f0);
}

.ea-type-item.ea-selected {
  background: var(--accent, #6366f1);
  color: #fff;
}

.ea-type-name {
  font-weight: 500;
}

.ea-type-count {
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 9999px;
  padding: 1px 7px;
  min-width: 1.5rem;
  text-align: center;
}

/* -------------------------------------------------------------------------
 * Field column (right)
 * ------------------------------------------------------------------------- */

.ea-field-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ea-empty {
  color: var(--text-muted, #94a3b8);
  font-style: italic;
  margin: 0;
}

/* -------------------------------------------------------------------------
 * Field table
 * ------------------------------------------------------------------------- */

.ea-field-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.ea-field-table th {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border, #334155);
  color: var(--text-muted, #94a3b8);
  font-weight: 600;
  white-space: nowrap;
}

.ea-field-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border, #1e293b);
  vertical-align: middle;
}

.ea-field-row:hover td {
  background: var(--bg-alt, #0f172a);
}

.ea-field-row.ea-archived {
  opacity: 0.5;
}

.ea-field-key {
  font-family: monospace;
  color: var(--accent, #6366f1);
  white-space: nowrap;
}

.ea-archived-badge {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.65rem;
  font-family: sans-serif;
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border-radius: 3px;
  padding: 0 4px;
  vertical-align: middle;
}

/* Inline editable inputs */
.ea-inline-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text, #e2e8f0);
  font-size: 0.8rem;
  padding: 2px 4px;
  width: 100%;
  transition: border-color 0.12s;
}

.ea-inline-input:hover,
.ea-inline-input:focus {
  border-color: var(--accent, #6366f1);
  outline: none;
  background: var(--bg-alt, #0f172a);
}

.ea-inline-check {
  accent-color: var(--accent, #6366f1);
  cursor: pointer;
}

/* -------------------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------------------- */

.ea-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border, #334155);
  border-radius: 4px;
  background: var(--surface, #1e293b);
  color: var(--text, #e2e8f0);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}

.ea-btn:hover {
  background: var(--bg-alt, #0f172a);
  border-color: var(--accent, #6366f1);
}

.ea-btn-primary {
  background: var(--accent, #6366f1);
  border-color: var(--accent, #6366f1);
  color: #fff;
}

.ea-btn-primary:hover {
  background: #4f46e5;
  border-color: #4f46e5;
}

.ea-btn-sm {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
}

.ea-btn-arch {
  color: var(--text-muted, #94a3b8);
}

.ea-field-actions {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}

/* -------------------------------------------------------------------------
 * Add-field form
 * ------------------------------------------------------------------------- */

.ea-add-form {
  background: var(--surface, #1e293b);
  border: 1px solid var(--border, #334155);
  border-radius: 6px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.ea-form-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: 0.5rem;
}

.ea-form-row.hidden { display: none; }

.ea-form-label {
  color: var(--text-muted, #94a3b8);
  font-size: 0.8rem;
}

.ea-form-input {
  background: var(--bg-alt, #0f172a);
  border: 1px solid var(--border, #334155);
  border-radius: 4px;
  color: var(--text, #e2e8f0);
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
  width: 100%;
  box-sizing: border-box;
}

.ea-form-input:focus {
  outline: none;
  border-color: var(--accent, #6366f1);
}

.ea-options-ta {
  resize: vertical;
  min-height: 4rem;
  font-family: monospace;
}

.ea-form-check {
  accent-color: var(--accent, #6366f1);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.ea-form-errors {
  color: #fca5a5;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ea-form-errors.hidden { display: none; }

.ea-form-btns {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.25rem;
}

/* -------------------------------------------------------------------------
 * Responsive: collapse to single column on narrow viewports.
 * ------------------------------------------------------------------------- */

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

  .ea-type-list {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .ea-type-item {
    flex: 0 0 auto;
  }
}
